Skip to content

Commit

Permalink
New XRPC-based Server and API implementations (bluesky-social#180)
Browse files Browse the repository at this point in the history
* Add xrpc-cli package; implement 'new' and 'gen-md' commands

* Add gen-ts-obj to xrpc-cli

* Add gen-api command to xrpc-cli

* Add gen-server to xrpc-cli

* Update codegen from xrpc-cli to run prettier and include a banner comment

* Use 'void' instead of 'undefined' for return type

* Skip invalid schemas when generating code

* Rewrite schemas package to use new simplified schema

* Output type definitions in nested folders

* Add record schema code-generation

* Change xrcp client call() signature to be easier to use

* Update client codegen to match new xrpc call signature

* Fixes and improvements to generated record APIs

* Update generated api to use per-service instances

* Add xrpc-cli readme

* (WIP) Rewrite server to use xrpc

* Add missing references to server/tsconfig.json

* Replace api implementation with xrpc generated client

* Add /schemas folder with todo.adx

* Add /schemas/todo.social

* Update api package to include todo.social xrpc and adx schemas

* Update server package to include todo.social xrpc and adx schemas

* Fix some schema definitions

* (WIP) Work toward xrpc update of server

* Update auth package to use nsids for collections

* Update repo package to use nsids for collections

* Update AdxUri to use nsid collection IDs

* Bring server CRUD tests to passing state

* Move API to simpler xrpc call signature

* Apply fixes and improvements to record apis

* Update to new generated api with per-service instances

* Rename the todo.social.* view methods

* Rewrite the views system to use xrpc

* Remove paths accidentally added to tsconfig

* Remove microblog package

* Add simple API readme

* todo about deduping ucan prfs

* increase postThread default depth to fix failing test. & fix USE_TEST_SERVER config

Co-authored-by: dholms <[email protected]>
  • Loading branch information
pfrazee and dholms authored Sep 20, 2022
1 parent c15f71b commit 1425b0c
Show file tree
Hide file tree
Showing 221 changed files with 8,927 additions and 6,192 deletions.
2 changes: 1 addition & 1 deletion docs/specs/adx/repo.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Here is an example schema:
{
"adx": 1,
"id": "com.example.post",
"schema": {
"record": {
"type": "object",
"required": ["text", "createdAt"],
"properties": {
Expand Down
56 changes: 21 additions & 35 deletions packages/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,29 @@
## Usage

```typescript
import { adx } from '@adxp/api'
import API from '@adxp/api'

// configure the API
adx.configure({
schemas: [ublogSchema, likeSchema, pollSchema, followSchema, feedViewSchema]
})

const alice = adx.user('alice.com')
await alice.collections() // list all of alice's collections
const feed = alice.collection('blueskyweb.xyz:Feed')

await feed.list('*') // fetch all (apply no validation)
await feed.list('Ublog') // fetch only ublogs
await feed.list(['Ublog', 'Like']) // fetch ublogs and likes
await feed.list(['Ublog', 'Like', '*']) // fetch all, but apply validation on ublogs and likes
await feed.list({type: 'Ublog', ext: 'Poll'}) // fetch only ublogs and support poll extensions

await feed.get('Ublog', key) // fetch the record and validate as a ublog
await feed.get('*', key) // fetch the record and don't validate

await feed.create('Ublog', record) // create a record after validating as a ublog
await feed.create({type: 'Ublog', ext: 'Poll'}, record) // create a record after validating as a ublog with the poll extension
await feed.create('*', record) // create a record with no validation

await feed.put('Ublog', record) // write a record after validating as a ublog
await feed.put({type: 'Ublog', ext: 'Poll'}, record) // write a record after validating as a ublog with the poll extension
await feed.put('*', record) // write a record after no validation
const client = API.service('http://example.com')

await feed.del(record) // delete a record

await alice.view('FeedView') // fetch the feed view from alice's PDS

const ublogSchema = adx.schema({type: 'Ublog', ext: 'Poll'}) // create a validator for ublog posts
for (const post in (await alice.view('FeedView')).posts) {
if (ublogSchema.isValid(post)) {
// good to go
// xrpc methods
const res1 = await client.todo.adx.repoCreateRecord(
{did: alice.did, type: 'todo.social.post'},
{
$type: 'todo.social.post',
text: 'Hello, world!',
createdAt: (new Date()).toISOString()
}
}
)
const res2 = await client.todo.adx.repoListRecords({did: alice.did, type: 'todo.social.post'})

// repo record methods
const res3 = await client.todo.social.post.create({did: alice.did}, {
text: 'Hello, world!',
createdAt: (new Date()).toISOString()
})
const res4 = await client.todo.social.post.list({did: alice.did})
```

## License

MIT
8 changes: 5 additions & 3 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"main": "src/index.ts",
"scripts": {
"codegen": "xrpc-cli gen-api ./src ../../schemas/todo.adx/*",
"prettier": "prettier --check src/",
"prettier:fix": "prettier --write src/",
"lint": "eslint . --ext .ts,.tsx",
Expand All @@ -14,8 +15,9 @@
},
"license": "MIT",
"dependencies": {
"@adxp/auth": "*",
"@adxp/common": "*",
"@adxp/schemas": "*"
"@adxp/xrpc": "*"
},
"devDependencies": {
"@adxp/xrpc-cli": "*"
}
}
40 changes: 0 additions & 40 deletions packages/api/src/errors.ts

This file was deleted.

62 changes: 0 additions & 62 deletions packages/api/src/http-types.ts

This file was deleted.

Loading

0 comments on commit 1425b0c

Please sign in to comment.