Draft Lexicon Style Guide (Lexinomicon) #4245
Replies: 2 comments 3 replies
-
|
More thorough thoughts when I have a sec but this seems contradictory:
Are enums stuck-closed or can they be open? |
Beta Was this translation helpful? Give feedback.
-
Is it an idea to standardize this pattern ? for example let the PDS create an base record based on the clientID metadata at first login ? something like. An app can then create a sidecar record for it with app specific properties. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
More folks are starting to design Lexicon schemas from scratch, which is great! This is particularly driven by ecosystem projects like Slices and microcosm which make it easier to work with AT network data in a generic way.
One piece of developer documentation that has been missing is guidance on writing Lexicons themselves: a Lexicon style guide, or Lexinomincon. Below is an early draft of such a guide, which we intend to integrate in to the the atproto.com website. We are also working on linting tools and other resources for developers drafting and publishing lexicon schemas.
This will probably be a living document, but early questions and feedback are very much welcome.
Basic Guidelines
Name casing conventions:
lowerCamelCasecapitalization for schemas and names (as opposed toUpperCamelCase,snake_case,ALL_CAPS, etc).UpperCamelCaseknownValues):kebab-caseAcceptable characters:
$at any level of nesting; these are reserved for future protocol-level extensionsNaming conventions:
recordschemaspost,like,profilequeryandprocedureendpointsgetPost,listLikes,putProfilequeryendpoints are:get,list,search(for full-text search),query(for flexible matching or filtering filtering)procedureendpoints:create,update,delete,upsert,putsubscriptionsubscribeLabelspermission-setschema naming has not be established yet, but probably has “auth” prefix (eg,authBasic).temp.or.unspecced.in the NSID hierarchydefaultorlengthas schema namesDocumentation and Completeness:
mainschema definition (records, API endpoints, etc)uriorcid: CID of what?NSID namespace grouping:
app.bsky.feed.*,app.bsky.graph.*.defsschema for definitions which might be reused by multiple schemas in the same namespace, or by third partiesapp.bsky.feed.defsapp.bsky.feed.post#mainvsapp.bsky.feed.post.main, orcom.example.record#fooandcom.example.record.fooapp.bsky.feed(as a record) andapp.bsky.feed.post(withapp.bsky.feedas a group)Other guidelines:
knownValuesprovides more flexible alternativeknownValuesmay include simple string constants, or may include schema references to atoken(eg, the string"com.example.defs#tokenOne")com.atproto.moderation.defs#reasonTypeandcom.atproto.sync.defs#hostStatusfor two contrasting instances, the former extensible and the later more constrainedcom.atproto.repo.strongRef(for versioned references to records) orcom.atproto.label.defs#label(in an array, for hydrated labels)at-identifierso that clients can avoid callingresolveHandleif they only have an account handleoutputwithencoding, even if they have no meaningful response dataapplication/jsonwith the schema being an object with no defined propertiesbooleanfields should be phrased such thatfalseis the default and expected valueexcludeFoo(defaultfalse) andincludeBar(defaultfalse), as opposed toexcludeBar(defaulttrue)cid-link)Schema Evolution and Extension
All schemas should be flexible to extension and evolution over time, without breaking the Lexicon schema evolution rules. This is particularly true for record schemas. Given the distributed storage model of atproto, developers do not have a reliable mechanism to update all data records in the network. Extensions could come from the original designer, or other developers and projects.
Experimental schemas and projects can use variant NSIDs (eg, including
.temp.in the name hierarchy) to develop in the live network without committing to a stable record data schemas.Major non-backwards-compatible schema changes are possible by declaring a new schema. The current naming convention is to append “V2” to the original name (or “V3”, etc).
Design recommendations to make schemas flexible to future evolution and extension:
requiredunless they are truly required for functionalityrequiredfields can not be made optional or deprecated under the evolution rulesoptionalfields to a schema without changing backwards compatibility or requiring a V2 schema, but you can’t add newrequiredfieldsaccountfield listing the DID, instead of an array of stringsDesign Patterns
queryAPI endpoints:limit(integer) and optionalcursor(string)cursor(string) and a required array of response objects (with context-specific pluralized field name)cursor. If the response includes acursor, then more results are available, and the client should query again with the newcursorto get more resultslimitvalue is an upper limit, and the response may include fewer (or even zero) results, while further results are still available. It is the lack ofcursorin responses that indicates pagination is complete. The response set may have items removed if they are tombstoned or have been otherwise filtered from the response set.cursorquery parameter (integer)seqfield (integer). Theseqof messages increases monotonically, though may have gaps.cursoris not provided, the server will start returning new messages from the current point forwardcursoris provided, the server will attempt to return historical messages starting with the matchingseq, continuing through to the current streamcursoris in the future (higher than the current sequence), an error is returned and the connection closed (TODO: is this the convention?)cursoris older than the earliest available message (or is 0), the server returns an info message of nameOutdatedCursor, then returns messages starting from the oldest availableapp.bsky.richtext.facetsystem can be used to annotate short text strings in a way that is simpler and safer to work with than full-featured markup languagesBeta Was this translation helpful? Give feedback.
All reactions