atproto_lexicon/ast

The lexicon AST: types covering the atproto lexicon spec (https://atproto.com/specs/lexicon), faithfully enough to round-trip JSON through decode and encode without loss.

The spec distinguishes “primary types” (only valid as the type of a top-level def) from “field types” (only valid inside an object’s properties or an array’s items). This module mirrors that split:

Every def and every property/item carries its own optional description, matching the spec.

Types

A type valid as an array’s items. Narrower than PropertyType: the spec disallows nested arrays and bare (non-ref) objects here.

pub type ArrayItemType {
  ItemBoolean(BooleanConstraints)
  ItemInteger(IntegerConstraints)
  ItemString(StringConstraints)
  ItemBytes(BytesConstraints)
  ItemCidLink(description: option.Option(String))
  ItemBlob(BlobConstraints)
  ItemRef(description: option.Option(String), ref: String)
  ItemUnion(UnionConstraints)
  ItemUnknown(description: option.Option(String))
}

Constructors

pub type ArrayShape {
  ArrayShape(
    description: option.Option(String),
    items: ArrayItemType,
    min_length: option.Option(Int),
    max_length: option.Option(Int),
  )
}

Constructors

pub type BlobConstraints {
  BlobConstraints(
    description: option.Option(String),
    accept: option.Option(List(String)),
    max_size: option.Option(Int),
  )
}

Constructors

pub type Body {
  Body(
    description: option.Option(String),
    encoding: String,
    schema: option.Option(BodySchema),
  )
}

Constructors

pub type BodySchema {
  BodySchemaObject(ObjectSchema)
  BodySchemaRef(ref: String)
  BodySchemaUnion(UnionConstraints)
}

Constructors

pub type BooleanConstraints {
  BooleanConstraints(
    description: option.Option(String),
    default: option.Option(Bool),
    const_: option.Option(Bool),
  )
}

Constructors

pub type BytesConstraints {
  BytesConstraints(
    description: option.Option(String),
    max_length: option.Option(Int),
    min_length: option.Option(Int),
  )
}

Constructors

pub type IntegerConstraints {
  IntegerConstraints(
    description: option.Option(String),
    minimum: option.Option(Int),
    maximum: option.Option(Int),
    enum: option.Option(List(Int)),
    default: option.Option(Int),
    const_: option.Option(Int),
  )
}

Constructors

A parsed lexicon document: one JSON file under a NSID.

pub type LexiconDoc {
  LexiconDoc(
    lexicon: Int,
    id: String,
    revision: option.Option(Int),
    description: option.Option(String),
    defs: List(#(String, PrimaryDef)),
  )
}

Constructors

pub type LexiconError {
  LexiconError(name: String, description: option.Option(String))
}

Constructors

pub type ObjectSchema {
  ObjectSchema(
    description: option.Option(String),
    required: List(String),
    nullable: List(String),
    properties: List(#(String, PropertyType)),
  )
}

Constructors

  • ObjectSchema(
      description: option.Option(String),
      required: List(String),
      nullable: List(String),
      properties: List(#(String, PropertyType)),
    )
pub type ParamsItemType {
  ParamsItemBoolean(BooleanConstraints)
  ParamsItemInteger(IntegerConstraints)
  ParamsItemString(StringConstraints)
}

Constructors

A type valid as a params property. The spec restricts query/procedure parameters to primitives and arrays of primitives: no ref, union, blob, bytes or cid-link.

pub type ParamsPropertyType {
  ParamsBoolean(BooleanConstraints)
  ParamsInteger(IntegerConstraints)
  ParamsString(StringConstraints)
  ParamsUnknown(description: option.Option(String))
  ParamsArray(
    description: option.Option(String),
    items: ParamsItemType,
    min_length: option.Option(Int),
    max_length: option.Option(Int),
  )
}

Constructors

pub type ParamsSchema {
  ParamsSchema(
    description: option.Option(String),
    required: List(String),
    properties: List(#(String, ParamsPropertyType)),
  )
}

Constructors

The type of a top-level definition (a value in the defs map).

pub type PrimaryDef {
  DefRecord(RecordDef)
  DefQuery(QueryDef)
  DefProcedure(ProcedureDef)
  DefSubscription(SubscriptionDef)
  DefObject(ObjectSchema)
  DefArray(ArrayShape)
  DefToken(description: option.Option(String))
  DefString(StringConstraints)
  DefInteger(IntegerConstraints)
  DefBoolean(BooleanConstraints)
  DefBytes(BytesConstraints)
  DefCidLink(description: option.Option(String))
  DefUnknown(description: option.Option(String))
  DefBlob(BlobConstraints)
}

Constructors

pub type ProcedureDef {
  ProcedureDef(
    description: option.Option(String),
    parameters: option.Option(ParamsSchema),
    input: option.Option(Body),
    output: option.Option(Body),
    errors: List(LexiconError),
  )
}

Constructors

A type valid in property position: an object’s property value, or the value referenced by a ref/union. Strictly wider than ArrayItemType (adds arrays) and ParamsPropertyType (adds blob/bytes/cid-link/ref/ union/nested object refs).

pub type PropertyType {
  PropBoolean(BooleanConstraints)
  PropInteger(IntegerConstraints)
  PropString(StringConstraints)
  PropBytes(BytesConstraints)
  PropCidLink(description: option.Option(String))
  PropBlob(BlobConstraints)
  PropRef(description: option.Option(String), ref: String)
  PropUnion(UnionConstraints)
  PropUnknown(description: option.Option(String))
  PropArray(ArrayShape)
}

Constructors

pub type QueryDef {
  QueryDef(
    description: option.Option(String),
    parameters: option.Option(ParamsSchema),
    output: option.Option(Body),
    errors: List(LexiconError),
  )
}

Constructors

pub type RecordDef {
  RecordDef(
    description: option.Option(String),
    key: RecordKey,
    record: ObjectSchema,
  )
}

Constructors

pub type RecordKey {
  KeyTid
  KeyAny
  KeyLiteral(value: String)
  KeyOther(raw: String)
}

Constructors

  • KeyTid
  • KeyAny
  • KeyLiteral(value: String)
  • KeyOther(raw: String)

    Preserves a key strategy the spec doesn’t define yet, rather than erroring or silently coercing it into KeyAny.

pub type StringConstraints {
  StringConstraints(
    description: option.Option(String),
    format: option.Option(StringFormat),
    max_length: option.Option(Int),
    min_length: option.Option(Int),
    max_graphemes: option.Option(Int),
    min_graphemes: option.Option(Int),
    known_values: option.Option(List(String)),
    enum: option.Option(List(String)),
    default: option.Option(String),
    const_: option.Option(String),
  )
}

Constructors

pub type StringFormat {
  FormatAtIdentifier
  FormatAtUri
  FormatCid
  FormatDatetime
  FormatDid
  FormatHandle
  FormatLanguage
  FormatNsid
  FormatRecordKey
  FormatTid
  FormatUri
  FormatOther(raw: String)
}

Constructors

  • FormatAtIdentifier
  • FormatAtUri
  • FormatCid
  • FormatDatetime
  • FormatDid
  • FormatHandle
  • FormatLanguage
  • FormatNsid
  • FormatRecordKey
  • FormatTid
  • FormatUri
  • FormatOther(raw: String)

    Preserves a format value the spec doesn’t define yet.

pub type SubscriptionDef {
  SubscriptionDef(
    description: option.Option(String),
    parameters: option.Option(ParamsSchema),
    message: option.Option(SubscriptionMessage),
    errors: List(LexiconError),
  )
}

Constructors

pub type SubscriptionMessage {
  SubscriptionMessage(
    description: option.Option(String),
    schema: option.Option(BodySchema),
  )
}

Constructors

pub type UnionConstraints {
  UnionConstraints(
    description: option.Option(String),
    refs: List(String),
    closed: option.Option(Bool),
  )
}

Constructors

Search Document