Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add promise support #47

Merged
merged 13 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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