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:
PrimaryDefis the def-position universe (record, query, procedure, subscription, object, array, token, and the primitive defs).PropertyTypeis the field-position universe used by object properties (adds ref, union, and nested arrays).ArrayItemTypeis the narrower universe valid as array items (no nested arrays, no bare objects; the spec requires a ref for those).ParamsPropertyType/ParamsItemTypeare narrower still, sinceparams(query/procedure parameters) only allows primitives and arrays of primitives.
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
-
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))
pub type ArrayShape {
ArrayShape(
description: option.Option(String),
items: ArrayItemType,
min_length: option.Option(Int),
max_length: option.Option(Int),
)
}
Constructors
-
ArrayShape( description: option.Option(String), items: ArrayItemType, min_length: option.Option(Int), max_length: option.Option(Int), )
pub type BlobConstraints {
BlobConstraints(
description: option.Option(String),
accept: option.Option(List(String)),
max_size: option.Option(Int),
)
}
Constructors
-
BlobConstraints( description: option.Option(String), accept: option.Option(List(String)), max_size: option.Option(Int), )
pub type Body {
Body(
description: option.Option(String),
encoding: String,
schema: option.Option(BodySchema),
)
}
Constructors
-
Body( description: option.Option(String), encoding: String, schema: option.Option(BodySchema), )
pub type BodySchema {
BodySchemaObject(ObjectSchema)
BodySchemaRef(ref: String)
BodySchemaUnion(UnionConstraints)
}
Constructors
-
BodySchemaObject(ObjectSchema) -
BodySchemaRef(ref: String) -
BodySchemaUnion(UnionConstraints)
pub type BooleanConstraints {
BooleanConstraints(
description: option.Option(String),
default: option.Option(Bool),
const_: option.Option(Bool),
)
}
Constructors
-
BooleanConstraints( description: option.Option(String), default: option.Option(Bool), const_: option.Option(Bool), )
pub type BytesConstraints {
BytesConstraints(
description: option.Option(String),
max_length: option.Option(Int),
min_length: option.Option(Int),
)
}
Constructors
-
BytesConstraints( description: option.Option(String), max_length: option.Option(Int), min_length: option.Option(Int), )
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
-
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), )
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
-
LexiconDoc( lexicon: Int, id: String, revision: option.Option(Int), description: option.Option(String), defs: List(#(String, PrimaryDef)), )
pub type LexiconError {
LexiconError(name: String, description: option.Option(String))
}
Constructors
-
LexiconError(name: String, description: option.Option(String))
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
-
ParamsItemBoolean(BooleanConstraints) -
ParamsItemInteger(IntegerConstraints) -
ParamsItemString(StringConstraints)
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
-
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), )
pub type ParamsSchema {
ParamsSchema(
description: option.Option(String),
required: List(String),
properties: List(#(String, ParamsPropertyType)),
)
}
Constructors
-
ParamsSchema( description: option.Option(String), required: List(String), properties: List(#(String, ParamsPropertyType)), )
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
-
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)
pub type ProcedureDef {
ProcedureDef(
description: option.Option(String),
parameters: option.Option(ParamsSchema),
input: option.Option(Body),
output: option.Option(Body),
errors: List(LexiconError),
)
}
Constructors
-
ProcedureDef( description: option.Option(String), parameters: option.Option(ParamsSchema), input: option.Option(Body), output: option.Option(Body), errors: List(LexiconError), )
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
-
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)
pub type QueryDef {
QueryDef(
description: option.Option(String),
parameters: option.Option(ParamsSchema),
output: option.Option(Body),
errors: List(LexiconError),
)
}
Constructors
-
QueryDef( description: option.Option(String), parameters: option.Option(ParamsSchema), output: option.Option(Body), errors: List(LexiconError), )
pub type RecordDef {
RecordDef(
description: option.Option(String),
key: RecordKey,
record: ObjectSchema,
)
}
Constructors
-
RecordDef( description: option.Option(String), key: RecordKey, record: ObjectSchema, )
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
-
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), )
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
-
SubscriptionDef( description: option.Option(String), parameters: option.Option(ParamsSchema), message: option.Option(SubscriptionMessage), errors: List(LexiconError), )
pub type SubscriptionMessage {
SubscriptionMessage(
description: option.Option(String),
schema: option.Option(BodySchema),
)
}
Constructors
-
SubscriptionMessage( description: option.Option(String), schema: option.Option(BodySchema), )
pub type UnionConstraints {
UnionConstraints(
description: option.Option(String),
refs: List(String),
closed: option.Option(Bool),
)
}
Constructors
-
UnionConstraints( description: option.Option(String), refs: List(String), closed: option.Option(Bool), )