marianoguerra/atproto/data does not have a README file

    DecodeError

    pub(all) suberror DecodeError {
    DecodeError(path~ : String, reason~ : String)
    } derive(Eq,
    Debug
    )

    impl Show for DecodeError

    DecodeError::describe_error

    fn DecodeError::describe_error(self : DecodeError) -> String

    DecodeError::path

    fn DecodeError::path(self : DecodeError) -> String

    DecodeError::reason

    fn DecodeError::reason(self : DecodeError) -> String

    BlobRef

    pub(all) enum BlobRef {
    Typed(cid~ :
    Cid
    , mime_type~ : String, size~ : Int64)
    Legacy(cid~ :
    Cid
    , mime_type~ : String)
    } derive(Eq,
    Debug
    )

    A reference to a blob, in whichever of the two encodings it arrived in.

    BlobRef::from_lex

    fn BlobRef::from_lex(value : LexValue, path? : String) -> BlobRef raise DecodeError

    Accepts both encodings.

    The typed form's ref is a cid-link, so by the time this sees it the JSON codec has already turned {"$link": ...} into a Link. The legacy form's cid is a plain string, and has to be parsed here.

    BlobRef::is_legacy

    fn BlobRef::is_legacy(self : BlobRef) -> Bool

    BlobRef::mime_type

    fn BlobRef::mime_type(self : BlobRef) -> String

    BlobRef::size

    fn BlobRef::size(self : BlobRef) -> Int64?

    None for a legacy ref, which does not carry one.

    Note what this is not: a guarantee. The size is what the server recorded when the blob was uploaded, and nothing re-checks it.

    BlobRef::to_lex

    fn BlobRef::to_lex(self : BlobRef) -> LexValue

    Encodes back into whichever form it came from.

    A legacy ref is NOT upgraded on the way out. Rewriting it into the typed form would change the record's bytes and therefore its CID, turning a read-modify-write into a different record.

    LexValue

    pub(all) enum LexValue {
    Null
    Bool(Bool)
    Int(Int64)
    Str(String)
    Bytes(Bytes)
    Link(
    Cid
    )
    Arr(Array[LexValue])
    Obj(Map[String, LexValue])
    } derive(Eq,
    Debug
    )

    A value in the atproto data model.

    LexValue::as_array

    fn LexValue::as_array(self : LexValue) -> Array[LexValue]?

    LexValue::as_bool

    fn LexValue::as_bool(self : LexValue) -> Bool?

    LexValue::as_bytes

    fn LexValue::as_bytes(self : LexValue) -> Bytes?

    LexValue::as_int

    fn LexValue::as_int(self : LexValue) -> Int64?

    LexValue::as_object

    fn LexValue::as_object(self : LexValue) -> Map[String, LexValue]?

    LexValue::as_string

    fn LexValue::as_string(self : LexValue) -> String?

    LexValue::get

    fn LexValue::get(self : LexValue, key : String) -> LexValue?

    One field of an object, or None if this is not an object or has no such field. The two cases are deliberately not distinguished: a caller reaching for a field on a non-object has already gone wrong somewhere else.

    LexValue::kind

    fn LexValue::kind(self : LexValue) -> String

    The kind name, for error messages. Matches the Lexicon spelling of each type, so a mismatch reads in the same vocabulary the schema uses.

    LexValue::parse

    fn LexValue::parse(text : String) -> LexValue raise DecodeError

    Parses JSON into the data model, decoding $link and $bytes on the way.

    This and stringify are the only doors between JSON and everything above, which is what keeps Json out of the library's public API.

    LexValue::stringify

    fn LexValue::stringify(self : LexValue) -> String

    LexValue::type_tag

    fn LexValue::type_tag(self : LexValue) -> String?

    The $type discriminator, if this is a tagged object.

    Every record and every open-union member carries one, and it is what dispatch is done on -- never the shape of the object, which is how TypeScript does it and how rsky's untagged unions go wrong.

    Nullable

    pub(all) enum Nullable[T] {
    Absent
    Null
    Value(T)
    } derive(Eq,
    Debug
    )

    Nullable::is_absent

    fn[T] Nullable::is_absent(self : Nullable[T]) -> Bool

    Nullable::is_null

    fn[T] Nullable::is_null(self : Nullable[T]) -> Bool

    Nullable::value

    fn[T] Nullable::value(self : Nullable[T]) -> T?

    The value, if there is one. Both empty cases collapse here, which is fine for a reader -- it is the WRITER that needs all three.

    base64_decode

    fn base64_decode(text : String) -> Bytes?

    None if the text is not base64. A lone trailing character is not: base64 has no encoding that produces one, so a 4n+1 length means truncation.

    base64_encode

    fn base64_encode(bytes : Bytes) -> String

    expect_array

    fn[T] expect_array(value : LexValue, path : String, parse : (LexValue, String) -> T raise DecodeError) -> Array[T] raise DecodeError

    An array, every element decoded by parse. All-or-nothing, for the same reason take_array is: a half-decoded list round-trips as a shorter list.

    expect_bool

    fn expect_bool(value : LexValue, path : String) -> Bool raise DecodeError

    expect_bytes

    fn expect_bytes(value : LexValue, path : String) -> Bytes raise DecodeError

    expect_format

    fn[T] expect_format(value : LexValue, path : String, parse : (String) -> T raise
    SyntaxError
    ) -> T raise DecodeError

    A string in one of the eleven Lexicon formats.

    expect_int

    fn expect_int(value : LexValue, path : String) -> Int64 raise DecodeError

    fn expect_link(value : LexValue, path : String) ->
    Cid
    raise DecodeError

    expect_string

    fn expect_string(value : LexValue, path : String) -> String raise DecodeError

    field_path

    fn field_path(prefix : String, field : String) -> String

    Dotted for fields, bracketed for indices: feed[0].post.author.did. Empty at the root, where the path prefix is dropped rather than shown as a leading dot.

    fields_of

    fn fields_of(fields : Map[String, LexValue]) -> Map[String, LexValue]

    A working copy of an object's fields, for a decoder to consume.

    index_path

    fn index_path(prefix : String, index : Int) -> String

    merge_extra

    fn merge_extra(out : Map[String, LexValue], extra : Map[String, LexValue]) -> LexValue

    Writes back the fields the type did not model, and returns the finished object. Modelled fields win a collision -- extra should not contain one, and if it does the typed value is the one the caller set.

    object_fields

    fn object_fields(value : LexValue, path? : String) -> Map[String, LexValue] raise DecodeError

    The object's fields, or a decode error naming what arrived instead.

    put_array

    fn[T] put_array(out : Map[String, LexValue], key : String, value : Array[T]?, encode : (T) -> LexValue) -> Unit

    put_bool

    fn put_bool(out : Map[String, LexValue], key : String, value : Bool?) -> Unit

    put_int

    fn put_int(out : Map[String, LexValue], key : String, value : Int64?) -> Unit

    put_lex

    fn put_lex(out : Map[String, LexValue], key : String, value : LexValue?) -> Unit

    put_nullable

    fn[T] put_nullable(out : Map[String, LexValue], key : String, value : Nullable[T], encode : (T) -> LexValue) -> Unit

    Writes a nullable field. Absent writes nothing; Null writes an explicit null, which is the whole point -- this is the one place in the library where emitting a null is correct rather than a bug.

    put_object

    fn[T] put_object(out : Map[String, LexValue], key : String, value : T?, encode : (T) -> LexValue) -> Unit

    put_string

    fn put_string(out : Map[String, LexValue], key : String, value : String?) -> Unit

    put_string_array

    fn put_string_array(out : Map[String, LexValue], key : String, value : Array[String]?) -> Unit

    require_array

    fn[T] require_array(rest : Map[String, LexValue], key : String, path? : String, parse : (LexValue, String) -> T raise DecodeError) -> Array[T] raise DecodeError

    require_bool

    fn require_bool(rest : Map[String, LexValue], key : String, path? : String) -> Bool raise DecodeError

    require_bytes

    fn require_bytes(rest : Map[String, LexValue], key : String, path? : String) -> Bytes raise DecodeError

    require_format

    fn[T] require_format(rest : Map[String, LexValue], key : String, path? : String, parse : (String) -> T raise
    SyntaxError
    ) -> T raise DecodeError

    require_int

    fn require_int(rest : Map[String, LexValue], key : String, path? : String) -> Int64 raise DecodeError

    require_lex

    fn require_lex(rest : Map[String, LexValue], key : String, path? : String) -> LexValue raise DecodeError

    fn require_link(rest : Map[String, LexValue], key : String, path? : String) ->
    Cid
    raise DecodeError

    require_object

    fn[T] require_object(rest : Map[String, LexValue], key : String, path? : String, parse : (LexValue, String) -> T raise DecodeError) -> T raise DecodeError

    require_string

    fn require_string(rest : Map[String, LexValue], key : String, path? : String) -> String raise DecodeError

    tagged

    fn tagged(value : LexValue, type_ : String) -> LexValue

    Adds a $type to an object, for a value being encoded as a union member.

    The UNION owns the tag, not the member: com.atproto.repo.strongRef is a bare {uri, cid} on its own and only carries a $type where a union needs to tell it from its siblings. Tagging the member type instead -- which is what rsky does, inconsistently -- puts a $type on values that should not have one.

    A non-object is returned unchanged; there is nowhere to put a tag, and a union whose members are not objects could not be dispatched anyway.

    take_array

    fn[T] take_array(rest : Map[String, LexValue], key : String, path? : String, parse : (LexValue, String) -> T raise DecodeError) -> Array[T]? raise DecodeError

    An array, every element decoded by parse.

    All-or-nothing on purpose: a half-decoded list would round-trip as a shorter list, which is silent data loss.

    take_bool

    fn take_bool(rest : Map[String, LexValue], key : String) -> Bool?

    take_bytes

    fn take_bytes(rest : Map[String, LexValue], key : String) -> Bytes?

    take_format

    fn[T] take_format(rest : Map[String, LexValue], key : String, path? : String, parse : (String) -> T raise
    SyntaxError
    ) -> T? raise DecodeError

    A string field whose Lexicon declares a format, parsed into the matching type -- which is what stops a Did and a Handle from being the same thing at 214 and 28 call sites respectively.

    Absent gives None; present but malformed RAISES rather than answering None. A format failure is a server sending something it should not, and quietly dropping the field would turn that into a mysterious missing value.

    take_int

    fn take_int(rest : Map[String, LexValue], key : String) -> Int64?

    take_lex

    fn take_lex(rest : Map[String, LexValue], key : String) -> LexValue?

    fn take_link(rest : Map[String, LexValue], key : String) ->
    Cid
    ?

    take_nullable

    fn[T] take_nullable(rest : Map[String, LexValue], key : String, path? : String, parse : (LexValue, String) -> T raise DecodeError) -> Nullable[T] raise DecodeError

    Reads a nullable field, consuming it. Absent when the key is not there, Null when it is there and null.

    take_object

    fn[T] take_object(rest : Map[String, LexValue], key : String, path? : String, parse : (LexValue, String) -> T raise DecodeError) -> T? raise DecodeError

    A nested object, decoded by parse. Absent gives None; present and malformed raises, because a sub-object that fails to decode is a schema mismatch rather than an absent value.

    take_string

    fn take_string(rest : Map[String, LexValue], key : String) -> String?

    take_string_array

    fn take_string_array(rest : Map[String, LexValue], key : String, path? : String) -> Array[String]? raise DecodeError