Skip to content

Commit

Permalink
Merge pull request #47 from mgagliardo91/feat-support-promises
Browse files Browse the repository at this point in the history
feat: Add promise support
  • Loading branch information
samkim authored Nov 1, 2022
2 parents a39a398 + 3093dbf commit ac200a1
Show file tree
Hide file tree
Showing 95 changed files with 3,598 additions and 1,670 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ client.checkPermission(checkPermissionRequest, (err, response) => {
});
```

### Promises (async/await) support

Each method available in the client has an associated promise-style method in place of callbacks, that can be accessed at the `.promises` property on the client.

```js
import { v1 } from '@authzed/authzed-node';

const client = v1.NewClient('token');
const { promises: promiseClient } = client; // access client.promises

const checkPermissionRequest = /** from above **/;

const result = await promiseClient.checkPermission(checkPermissionRequest);
```

For stream-returning methods, including `client.readRelationships()`, `client.lookupResources()` and `client.lookupSubjects()`, the promise-style method will result in an array of response objects once the stream has been closed.

```js
import { v1 } from '@authzed/authzed-node';

const client = v1.NewClient('token');
const { promises: promiseClient } = client; // access client.promises

const results = await promiseClient.readRelationships(/** req **/);
console.log(results[0]); // first ReadRelationship result
```

## Requirements

Supported Node.js versions: 14, 16, 17
Expand Down
2 changes: 1 addition & 1 deletion buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env -S buf generate buf.build/authzed/api:418c57bfce56bc4fb44870bbbc84217d14cc0c9f --template
#!/usr/bin/env -S buf generate buf.build/authzed/api:97e6f8e5f9669b673a53a40658241609fb1a94e3 --template
# To regenerate:
# npm install -g grpc-tools
# ./buf.gen.yaml
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
spicedb-servetesting:
image: quay.io/authzed/spicedb:latest
ports: ['50051:50051']
command: serve-testing
healthcheck:
test: ["CMD", "/usr/local/bin/grpc_health_probe", "-addr=:50051"]
interval: 30s
timeout: 30s
retries: 3
2 changes: 1 addition & 1 deletion js-dist/jasmine.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"spec_dir": "src",
"spec_files": ["*.test.js"],
"helpers": []
}
}
Loading

0 comments on commit ac200a1

Please sign in to comment.