Skip to content

Commit

Permalink
Lexicon rework (bluesky-social#379)
Browse files Browse the repository at this point in the history
* Implement types and validation for new NIH lexicon DSL

* Update xprc and xrpc-server to use new NIH lexicon DSL

* Simplification: dont allow lexicon definitions to be refs or ref arrays

* Add 'unknown' primitive type to NIH lexicon

* Implement client codegen for NIH Lexicon

* Implement server codegen for NIH Lexicon

* Add the 'datetime' primitive type to the NIH Lexicon

* Rework lexicons to use new NIH Lexicon DSL

* Readd tokens to code generation

* Update all code to use new NIH Lexicon (all tests passing!)

* Add imports from external files to lex-cli codegen

* Do not allow records, queries, or procedures outside of the main def

* Update packages/lex-cli/src/util.ts

Co-authored-by: devin ivy <devinivy@gmail.com>

* Linter pass

* Add knownValue output to codegen

* Add comments to codegen

* Use enum and const in codegen

* Rework lexicon 'properties' structure

* Treat falsy query params as undefined

Co-authored-by: devin ivy <devinivy@gmail.com>

* Remove now-redundant param presence validation

Co-authored-by: devin ivy <devinivy@gmail.com>
  • Loading branch information
pfrazee and devinivy authored Dec 1, 2022
1 parent 645a2ca commit 63b9873
Show file tree
Hide file tree
Showing 243 changed files with 13,169 additions and 15,329 deletions.
74 changes: 33 additions & 41 deletions lexicons/app/bsky/actor/createScene.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,48 @@
{
"lexicon": 1,
"id": "app.bsky.actor.createScene",
"type": "procedure",
"description": "Create a scene.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["handle"],
"properties": {
"handle": {"type": "string"},
"recoveryKey": {"type": "string"}
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["handle", "did", "declaration"],
"properties": {
"handle": { "type": "string" },
"did": { "type": "string" },
"declaration": {"$ref": "#/defs/declaration"}
}
}
},
"errors": [
{"name": "InvalidHandle"},
{"name": "HandleNotAvailable"}
],
"defs": {
"main": {
"type": "procedure",
"description": "Create a scene.",
"input": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["handle"],
"properties": {
"handle": {"type": "string"},
"recoveryKey": {"type": "string"}
}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["handle", "did", "declaration"],
"properties": {
"handle": { "type": "string" },
"did": { "type": "string" },
"declaration": "#declaration"
}
}
},
"errors": [
{"name": "InvalidHandle"},
{"name": "HandleNotAvailable"}
]
},
"declaration": {
"type": "object",
"required": ["cid", "actorType"],
"properties": {
"cid": {"type": "string"},
"actorType": {
"oneOf": [
{"$ref": "#/defs/actorKnown"},
{"$ref": "#/defs/actorUnknown"}
]
"type": "string",
"knownValues": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]
}
}
},
"actorKnown": {
"type": "string",
"enum": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]
},
"actorUnknown": {
"type": "string",
"not": {"enum": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]}
}
}
}
89 changes: 41 additions & 48 deletions lexicons/app/bsky/actor/getProfile.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,60 @@
{
"lexicon": 1,
"id": "app.bsky.actor.getProfile",
"type": "query",
"parameters": {
"type": "object",
"required": ["actor"],
"properties": {
"actor": {"type": "string"}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["did", "declaration", "handle", "creator", "followersCount", "followsCount", "membersCount", "postsCount"],
"properties": {
"did": {"type": "string"},
"declaration": {"$ref": "#/defs/declaration"},
"handle": {"type": "string"},
"creator": {"type": "string"},
"displayName": {
"type": "string",
"maxLength": 64
},
"description": {
"type": "string",
"maxLength": 256
},
"followersCount": {"type": "integer"},
"followsCount": {"type": "integer"},
"membersCount": {"type": "integer"},
"postsCount": {"type": "integer"},
"myState": {
"defs": {
"main": {
"type": "query",
"parameters": {
"type": "params",
"required": ["actor"],
"properties": {
"actor": {"type": "string"}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["did", "declaration", "handle", "creator", "followersCount", "followsCount", "membersCount", "postsCount"],
"properties": {
"follow": {"type": "string"},
"member": {"type": "string"}
"did": {"type": "string"},
"declaration": "#declaration",
"handle": {"type": "string"},
"creator": {"type": "string"},
"displayName": {
"type": "string",
"maxLength": 64
},
"description": {
"type": "string",
"maxLength": 256
},
"followersCount": {"type": "integer"},
"followsCount": {"type": "integer"},
"membersCount": {"type": "integer"},
"postsCount": {"type": "integer"},
"myState": "#myState"
}
}
}
}
},
"defs": {
},
"myState": {
"type": "object",
"properties": {
"follow": {"type": "string"},
"member": {"type": "string"}
}
},
"declaration": {
"type": "object",
"required": ["cid", "actorType"],
"properties": {
"cid": {"type": "string"},
"actorType": {
"oneOf": [
{"$ref": "#/defs/actorKnown"},
{"$ref": "#/defs/actorUnknown"}
]
"type": "string",
"knownValues": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]
}
}
},
"actorKnown": {
"type": "string",
"enum": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]
},
"actorUnknown": {
"type": "string",
"not": {"enum": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]}
}
}
}
98 changes: 46 additions & 52 deletions lexicons/app/bsky/actor/getSuggestions.json
Original file line number Diff line number Diff line change
@@ -1,70 +1,64 @@
{
"lexicon": 1,
"id": "app.bsky.actor.getSuggestions",
"type": "query",
"description": "Get a list of actors suggested for following. Used in discovery UIs.",
"parameters": {
"type": "object",
"properties": {
"limit": {"type": "integer", "minimum": 1, "maximum": 100, "default": 50},
"cursor": {"type": "string"}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["actors"],
"properties": {
"cursor": {"type": "string"},
"actors": {
"type": "array",
"items": {
"type": "object",
"required": ["did", "declaration", "handle"],
"properties": {
"did": {"type": "string"},
"declaration": {"$ref": "#/defs/declaration"},
"handle": {"type": "string"},
"displayName": {
"type": "string",
"maxLength": 64
},
"description": {"type": "string"},
"indexedAt": {"type": "string", "format": "date-time"},
"myState": {
"type": "object",
"properties": {
"follow": {"type": "string"}
}
}
"defs": {
"main": {
"type": "query",
"description": "Get a list of actors suggested for following. Used in discovery UIs.",
"parameters": {
"type": "params",
"properties": {
"limit": {"type": "integer", "minimum": 1, "maximum": 100, "default": 50},
"cursor": {"type": "string"}
}
},
"output": {
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["actors"],
"properties": {
"cursor": {"type": "string"},
"actors": {
"type": "array",
"items": "#actor"
}
}
}
}
}
},
"defs": {
},
"actor": {
"type": "object",
"required": ["did", "declaration", "handle"],
"properties": {
"did": {"type": "string"},
"declaration": "#declaration",
"handle": {"type": "string"},
"displayName": {
"type": "string",
"maxLength": 64
},
"description": {"type": "string"},
"indexedAt": {"type": "datetime"},
"myState": "#myState"
}
},
"myState": {
"type": "object",
"properties": {
"follow": {"type": "string"}
}
},
"declaration": {
"type": "object",
"required": ["cid", "actorType"],
"properties": {
"cid": {"type": "string"},
"actorType": {
"oneOf": [
{"$ref": "#/defs/actorKnown"},
{"$ref": "#/defs/actorUnknown"}
]
"type": "string",
"knownValues": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]
}
}
},
"actorKnown": {
"type": "string",
"enum": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]
},
"actorUnknown": {
"type": "string",
"not": {"enum": ["app.bsky.system.actorUser", "app.bsky.system.actorScene"]}
}
}
}
30 changes: 17 additions & 13 deletions lexicons/app/bsky/actor/profile.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
{
"lexicon": 1,
"id": "app.bsky.actor.profile",
"type": "record",
"key": "literal:self",
"record": {
"type": "object",
"required": ["displayName"],
"properties": {
"displayName": {
"type": "string",
"maxLength": 64
},
"description": {
"type": "string",
"maxLength": 256
"defs": {
"main": {
"type": "record",
"key": "literal:self",
"record": {
"type": "object",
"required": ["displayName"],
"properties": {
"displayName": {
"type": "string",
"maxLength": 64
},
"description": {
"type": "string",
"maxLength": 256
}
}
}
}
}
Expand Down
Loading

0 comments on commit 63b9873

Please sign in to comment.