-
Notifications
You must be signed in to change notification settings - Fork 349
/
client-ts.ts
executable file
·46 lines (37 loc) · 1.31 KB
/
client-ts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
import { NodeHttpTransport } from '@improbable-eng/grpc-web-node-http-transport';
import { DashAPICredsClientImpl, DashStateClientImpl, GrpcWebImpl } from './example';
import { grpc } from '@improbable-eng/grpc-web';
const rpc = new GrpcWebImpl('http://localhost:9090', {
// Only necessary for tests running on node. Remove the
// transport config when actually using in the browser.
transport: NodeHttpTransport(),
debug: false,
metadata: new grpc.Metadata({ SomeHeader: 'bar' }),
});
const client = new DashStateClientImpl(rpc);
const creds = new DashAPICredsClientImpl(rpc);
async function main() {
console.log('calling client.UserSettings');
console.log(await client.UserSettings({}));
console.log('calling creds.Create');
const cred = await creds.Create({ description: 'test desc fooo' });
console.log(cred);
console.log('calling creds.Delete');
const del = await creds.Delete({ id: cred.id });
console.log(del);
console.log('calling creds.Update');
try {
await creds.Update({ description: 'test desc2' });
} catch (e) {
console.log('got expected error', e);
}
const obs = client.ActiveUserSettingsStream({});
await obs.forEach((value) => {
console.log('Got', value);
});
}
main().then(
() => console.log('done'),
(err) => console.log('failed', err)
);