forked from bluesky-social/atproto
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved XRPC error protocol (bluesky-social#194)
* Add lexicon doc * Update error-handling spec * Implement new error-behaviors in xrpc and xrpc-server packages * Update lexicon and lex-cli packages to add xrpc error behaviors * Generate new API and test an error behavior
- Loading branch information
Showing
72 changed files
with
1,032 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# Lexicon Schema Documents | ||
|
||
Lexicon is a schemas document format used to define [XRPC](./xrpc.md) methods and [ATP Repository](./adx/repo.md) record types. Every Lexicon schema is written in JSON and follows the interface specified below. The schemas are identified using [NSIDs](./nsid.md) which are then used to identify the methods or record types they describe. | ||
|
||
## Interface | ||
|
||
```typescript | ||
interface LexiconDoc { | ||
lexicon: 1 | ||
id: string // an NSID | ||
type: 'query' | 'procedure' | 'record' | ||
revision?: number | ||
description?: string | ||
} | ||
|
||
interface RecordLexiconDoc extends LexiconDoc { | ||
record: JSONSchema | ||
} | ||
|
||
interface XrpcLexiconDoc extends LexiconDoc { | ||
parameters?: Record<string, XrpcParameter> | ||
input?: XrpcBody | ||
output?: XrpcBody | ||
errors?: XrpcError[] | ||
} | ||
|
||
interface XrpcParameter { | ||
type: 'string' | 'number' | 'integer' | 'boolean' | ||
description?: string | ||
default?: string | number | boolean | ||
required?: boolean | ||
minLength?: number | ||
maxLength?: number | ||
minimum?: number | ||
maximum?: number | ||
} | ||
|
||
interface XrpcBody { | ||
encoding: string|string[] | ||
schema: JSONSchema | ||
} | ||
|
||
interface XrpcError { | ||
name: string | ||
description?: string | ||
} | ||
``` | ||
|
||
## Examples | ||
|
||
### XRPC Method | ||
|
||
```json | ||
{ | ||
"lexicon": 1, | ||
"id": "todo.adx.createAccount", | ||
"type": "procedure", | ||
"description": "Create an account.", | ||
"parameters": {}, | ||
"input": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["email", "username", "password"], | ||
"properties": { | ||
"email": {"type": "string"}, | ||
"username": {"type": "string"}, | ||
"inviteCode": {"type": "string"}, | ||
"password": {"type": "string"} | ||
} | ||
} | ||
}, | ||
"output": { | ||
"encoding": "application/json", | ||
"schema": { | ||
"type": "object", | ||
"required": ["jwt", "name", "did"], | ||
"properties": { | ||
"jwt": { "type": "string" }, | ||
"name": {"type": "string"}, | ||
"did": {"type": "string"} | ||
} | ||
} | ||
}, | ||
"errors": [ | ||
{"name": "InvalidEmail"}, | ||
{"name": "InvalidUsername"}, | ||
{"name": "InvalidPassword"}, | ||
{"name": "InvalidInviteCode"}, | ||
{"name": "UsernameTaken"}, | ||
] | ||
} | ||
``` | ||
|
||
### ATP Record Type | ||
|
||
```json | ||
{ | ||
"lexicon": 1, | ||
"id": "todo.social.repost", | ||
"type": "record", | ||
"record": { | ||
"type": "object", | ||
"required": ["subject", "createdAt"], | ||
"properties": { | ||
"subject": {"type": "string"}, | ||
"createdAt": {"type": "string", "format": "date-time"} | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.