Skip to content

Commit 3abe320

Browse files
authored
feat: Implement discovery service (#19)
1 parent 80edcd5 commit 3abe320

File tree

7 files changed

+95
-87
lines changed

7 files changed

+95
-87
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
],
1010
"type": "module",
1111
"exports": {
12-
"./serve": "./dist/serve.js"
12+
"./serve": "./dist/serve/serve.js"
1313
},
1414
"scripts": {
15-
"dev": "ts-node src/index.ts",
15+
"dev": "ts-node --esm src/main.ts serve",
1616
"build": "rm -rf dist && tsc",
1717
"format": "prettier --write 'src/**/*.ts'",
1818
"format:check": "prettier --check 'src/**/*.ts'",

src/grpc/discovery.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import grpc = require('@grpc/grpc-js');
2+
import { discovery1 } from '@cloudquery/plugin-pb-javascript';
3+
4+
export class DiscoveryServer extends discovery1.cloudquery.discovery.v1.UnimplementedDiscoveryService {
5+
GetVersions(
6+
call: grpc.ServerUnaryCall<
7+
discovery1.cloudquery.discovery.v1.GetVersions.Request,
8+
discovery1.cloudquery.discovery.v1.GetVersions.Response
9+
>,
10+
callback: grpc.sendUnaryData<discovery1.cloudquery.discovery.v1.GetVersions.Response>,
11+
): void {
12+
return callback(null, new discovery1.cloudquery.discovery.v1.GetVersions.Response({ versions: [3] }));
13+
}
14+
}

src/grpc/plugin.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import grpc = require('@grpc/grpc-js');
2+
import { pluginV3 } from '@cloudquery/plugin-pb-javascript';
3+
4+
export class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPluginService {
5+
GetName(
6+
call: grpc.ServerUnaryCall<
7+
pluginV3.cloudquery.plugin.v3.GetName.Request,
8+
pluginV3.cloudquery.plugin.v3.GetName.Response
9+
>,
10+
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.GetName.Response>,
11+
): void {
12+
throw new Error('Method not implemented.');
13+
}
14+
GetVersion(
15+
call: grpc.ServerUnaryCall<
16+
pluginV3.cloudquery.plugin.v3.GetVersion.Request,
17+
pluginV3.cloudquery.plugin.v3.GetVersion.Response
18+
>,
19+
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.GetVersion.Response>,
20+
): void {
21+
throw new Error('Method not implemented.');
22+
}
23+
Init(
24+
call: grpc.ServerUnaryCall<pluginV3.cloudquery.plugin.v3.Init.Request, pluginV3.cloudquery.plugin.v3.Init.Response>,
25+
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.Init.Response>,
26+
): void {
27+
throw new Error('Method not implemented.');
28+
}
29+
GetTables(
30+
call: grpc.ServerUnaryCall<
31+
pluginV3.cloudquery.plugin.v3.GetTables.Request,
32+
pluginV3.cloudquery.plugin.v3.GetTables.Response
33+
>,
34+
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.GetTables.Response>,
35+
): void {
36+
throw new Error('Method not implemented.');
37+
}
38+
Sync(
39+
call: grpc.ServerWritableStream<
40+
pluginV3.cloudquery.plugin.v3.Sync.Request,
41+
pluginV3.cloudquery.plugin.v3.Sync.Response
42+
>,
43+
): void {
44+
throw new Error('Method not implemented.');
45+
}
46+
Read(
47+
call: grpc.ServerWritableStream<
48+
pluginV3.cloudquery.plugin.v3.Read.Request,
49+
pluginV3.cloudquery.plugin.v3.Read.Response
50+
>,
51+
): void {
52+
throw new Error('Method not implemented.');
53+
}
54+
Write(
55+
call: grpc.ServerReadableStream<
56+
pluginV3.cloudquery.plugin.v3.Write.Request,
57+
pluginV3.cloudquery.plugin.v3.Write.Response
58+
>,
59+
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.Write.Response>,
60+
): void {
61+
throw new Error('Method not implemented.');
62+
}
63+
Close(
64+
call: grpc.ServerUnaryCall<
65+
pluginV3.cloudquery.plugin.v3.Close.Request,
66+
pluginV3.cloudquery.plugin.v3.Close.Response
67+
>,
68+
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.Close.Response>,
69+
): void {
70+
throw new Error('Method not implemented.');
71+
}
72+
}

src/grpc/server.ts

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,8 @@
1-
import { discovery1 } from '@cloudquery/plugin-pb-javascript';
2-
import { pluginV3 } from '@cloudquery/plugin-pb-javascript';
31
import grpc = require('@grpc/grpc-js');
4-
5-
class DiscoveryServer extends discovery1.cloudquery.discovery.v1.UnimplementedDiscoveryService {
6-
GetVersions(
7-
call: grpc.ServerUnaryCall<
8-
discovery1.cloudquery.discovery.v1.GetVersions.Request,
9-
discovery1.cloudquery.discovery.v1.GetVersions.Response
10-
>,
11-
callback: grpc.sendUnaryData<discovery1.cloudquery.discovery.v1.GetVersions.Response>,
12-
): void {
13-
throw new Error('Method not implemented.');
14-
}
15-
}
16-
17-
class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPluginService {
18-
GetName(
19-
call: grpc.ServerUnaryCall<
20-
pluginV3.cloudquery.plugin.v3.GetName.Request,
21-
pluginV3.cloudquery.plugin.v3.GetName.Response
22-
>,
23-
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.GetName.Response>,
24-
): void {
25-
throw new Error('Method not implemented.');
26-
}
27-
GetVersion(
28-
call: grpc.ServerUnaryCall<
29-
pluginV3.cloudquery.plugin.v3.GetVersion.Request,
30-
pluginV3.cloudquery.plugin.v3.GetVersion.Response
31-
>,
32-
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.GetVersion.Response>,
33-
): void {
34-
throw new Error('Method not implemented.');
35-
}
36-
Init(
37-
call: grpc.ServerUnaryCall<pluginV3.cloudquery.plugin.v3.Init.Request, pluginV3.cloudquery.plugin.v3.Init.Response>,
38-
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.Init.Response>,
39-
): void {
40-
throw new Error('Method not implemented.');
41-
}
42-
GetTables(
43-
call: grpc.ServerUnaryCall<
44-
pluginV3.cloudquery.plugin.v3.GetTables.Request,
45-
pluginV3.cloudquery.plugin.v3.GetTables.Response
46-
>,
47-
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.GetTables.Response>,
48-
): void {
49-
throw new Error('Method not implemented.');
50-
}
51-
Sync(
52-
call: grpc.ServerWritableStream<
53-
pluginV3.cloudquery.plugin.v3.Sync.Request,
54-
pluginV3.cloudquery.plugin.v3.Sync.Response
55-
>,
56-
): void {
57-
throw new Error('Method not implemented.');
58-
}
59-
Read(
60-
call: grpc.ServerWritableStream<
61-
pluginV3.cloudquery.plugin.v3.Read.Request,
62-
pluginV3.cloudquery.plugin.v3.Read.Response
63-
>,
64-
): void {
65-
throw new Error('Method not implemented.');
66-
}
67-
Write(
68-
call: grpc.ServerReadableStream<
69-
pluginV3.cloudquery.plugin.v3.Write.Request,
70-
pluginV3.cloudquery.plugin.v3.Write.Response
71-
>,
72-
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.Write.Response>,
73-
): void {
74-
throw new Error('Method not implemented.');
75-
}
76-
Close(
77-
call: grpc.ServerUnaryCall<
78-
pluginV3.cloudquery.plugin.v3.Close.Request,
79-
pluginV3.cloudquery.plugin.v3.Close.Response
80-
>,
81-
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.Close.Response>,
82-
): void {
83-
throw new Error('Method not implemented.');
84-
}
85-
}
2+
import { pluginV3 } from '@cloudquery/plugin-pb-javascript';
3+
import { discovery1 } from '@cloudquery/plugin-pb-javascript';
4+
import { PluginServer } from './plugin.js';
5+
import { DiscoveryServer } from './discovery.js';
866

877
export const getServer = () => {
888
const server = new grpc.Server();

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env node
2-
import { serve } from './serve.js';
2+
import { serve } from './serve/serve.js';
33

44
serve.parse();

src/serve.ts renamed to src/serve/serve.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import yargs from 'yargs';
22
import { hideBin } from 'yargs/helpers';
3+
import { startServer } from '../grpc/server.js';
34

45
const NETWORK_CHOICES = ['tcp', 'tcp4', 'tcp6', 'unix', 'unixpacket'] as const;
56
const LOG_LEVEL_CHOICES = ['trace', 'debug', 'info', 'warn', 'error'] as const;
@@ -24,6 +25,7 @@ export const serve = yargs(hideBin(process.argv))
2425
() => {},
2526
({ address, network, logLevel, logFormat, sentry: sentry, otelEndpoint, telemetryLevel }: ServeArgs) => {
2627
console.log({ address, network, logLevel, logFormat, sentry, otelEndpoint, telemetryLevel });
28+
startServer(address);
2729
},
2830
)
2931
.options({

0 commit comments

Comments
 (0)