Comments (9)
I've spent some time updating the PR with @bracki's work and migrating the tests over to typescript as well. I'm going to see if I can get it to communicate with my locally running spicedb instance and make sure the tests pass, then I'll update the PR
from authzed-node.
@sjaakiejj Would you mind sharing the index.d.ts
file you created?
from authzed-node.
@bracki I'll do you one better - opened #11 to setup typescript as part of the repository
from authzed-node.
What I settled for now is the following:
Edit the buf.gen.yaml
to look like this:
#!/usr/bin/env -S buf generate buf.build/authzed/api:7a18d413329a4f4fb0c4237afb640e8e --template
---
version: "v1"
# The plugins to run.
plugins:
# The name of the plugin.
# Required.
# By default, buf generate will look for a binary named protoc-gen-NAME on your $PATH.
- name: ts
# The the relative output directory.
# Required.
out: gen/ts
# See "available plugin parameters"
# https://github.com/timostamm/protobuf-ts/blob/master/MANUAL.md#the-protoc-plugin
opt: generate_dependencies,long_type_string
# The custom path to the plugin binary, if not protoc-gen-NAME on your $PATH.
# Assuming you have installed @protobuf-ts/plugin in the working directory:
path: ./node_modules/@protobuf-ts/plugin/bin/protoc-gen-ts
Run buf generate buf.build/authzed/api:7a18d413329a4f4fb0c4237afb640e8e --template buf.gen.yaml
.
Copy the stuff from gen/ts
.
Use it like this:
import * as grpc from '@grpc/grpc-js';
import { GrpcTransport } from '@protobuf-ts/grpc-transport';
import { PermissionsServiceClient } from '../authzed/authzed/api/v1/permission_service.client';
function createClientCreds(token: string, insecure = false): grpc.ChannelCredentials {
const metadata = new grpc.Metadata();
metadata.set('authorization', 'Bearer ' + token);
const creds = [];
if (!insecure) {
creds.push(grpc.credentials.createFromMetadataGenerator((_, callback) => {
callback(null, metadata);
}));
}
return grpc.credentials.combineChannelCredentials(
insecure ? grpc.credentials.createInsecure() : grpc.credentials.createSsl(),
...creds,
);
}
export function createPermissionsServiceClient(token: string): PermissionsServiceClient {
return new PermissionsServiceClient(new GrpcTransport({
host: 'grpc.authzed.com:443',
channelCredentials: createClientCreds(token),
}));
}
from authzed-node.
@bracki @sjaakiejj The Typescript generated proto code looks a lot nicer than the JS; would you guys be open to collaborating on @sjaakiejj's PR (#11) or a followup to change the client library to use the TS generated types?
from authzed-node.
Also @bracki @sjaakiejj If you guys want to discuss in more detail, we also have the Discord development channel for live discussions: https://discord.com/invite/jTysUaxXzM
from authzed-node.
@sjaakiejj Looks great. I'd recommend testing with v1 API
from authzed-node.
The PR is now ready for review - do you have any documentation or in particular, examples on how to use the v1 api?
from authzed-node.
@sjaakiejj V1 docs can be found here: https://buf.build/authzed/api/docs/main/authzed.api.v1 and we have some examples using Python here: https://github.com/authzed/authzed-py/tree/main/examples/v1
from authzed-node.
Related Issues (20)
- RST_STREAM with code 0 on bulkExportRelationships HOT 2
- Incorrect typing for some optional attributes HOT 2
- SyntaxError: Unexpected token '?' (Node 12)
- optionalPrecondition is required HOT 1
- Fix examples to reference V1
- Choose whether to connect/instantiate Schema and Watch services when creating a client
- Expose `ClientSecurity` type as main export HOT 3
- Support for simpler interfaces
- Add version client subpaths to package exports
- Type Errors when copying the example HOT 7
- Typescript error on optional type. HOT 4
- Add an example using the promisified client
- Expose grpc-js options HOT 2
- Random hangs with grpc-js version later than 1.6.9 HOT 3
- Consider dropping (yarn) lockfile
- Occasional `Received RST_STREAM with code 2` error HOT 1
- Cant get grpc client to connect HOT 1
- Add examples for reading relationships in the node client HOT 7
- Question: How to access StreamingBulkCheckPermission? HOT 1
- Error in writestream does not throw error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from authzed-node.