Skip to content

Commit d1568f5

Browse files
authored
feat: Implement GetSpecSchema plugin gRPC API call (#133)
Closes cloudquery/cloudquery#16504
1 parent f429954 commit d1568f5

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
},
8989
"dependencies": {
9090
"@apache-arrow/esnext-esm": "^12.0.1",
91-
"@cloudquery/plugin-pb-javascript": "^0.0.14",
91+
"@cloudquery/plugin-pb-javascript": "^0.0.15",
9292
"@grpc/grpc-js": "^1.9.0",
9393
"@types/luxon": "^3.3.1",
9494
"ajv": "^8.12.0",

src/grpc/plugin.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ export class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPlu
4747
): void {
4848
return callback(null, new pluginV3.cloudquery.plugin.v3.GetVersion.Response({ version: this.plugin.version() }));
4949
}
50+
51+
GetSpecSchema(
52+
call: grpc.ServerUnaryCall<
53+
pluginV3.cloudquery.plugin.v3.GetSpecSchema.Request,
54+
pluginV3.cloudquery.plugin.v3.GetSpecSchema.Response
55+
>,
56+
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.GetSpecSchema.Response>,
57+
): void {
58+
return callback(
59+
null,
60+
new pluginV3.cloudquery.plugin.v3.GetSpecSchema.Response({ json_schema: this.plugin.jsonSchema() }),
61+
);
62+
}
63+
5064
Init(
5165
call: grpc.ServerUnaryCall<pluginV3.cloudquery.plugin.v3.Init.Request, pluginV3.cloudquery.plugin.v3.Init.Response>,
5266
callback: grpc.sendUnaryData<pluginV3.cloudquery.plugin.v3.Init.Response>,

src/memdb/memdb.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,28 @@ export const newMemDBPlugin = (): Plugin => {
9595
return Promise.resolve(pluginClient);
9696
};
9797

98-
const plugin = newPlugin('memdb', '0.0.1', newClient, { team: 'cloudquery', kind: 'source' });
98+
const plugin = newPlugin('memdb', '0.0.1', newClient, {
99+
team: 'cloudquery',
100+
kind: 'source',
101+
jsonSchema: `{
102+
"$schema": "https://json-schema.org/draft/2020-12/schema",
103+
"$id": "https://github.com/cloudquery/plugin-sdk-javascript/memdb/spec",
104+
"$ref": "#/$defs/Spec",
105+
"$defs": {
106+
"Spec": {
107+
"properties": {
108+
"concurrency": {
109+
"type": "integer",
110+
"minimum": 1,
111+
"description": "Concurrency."
112+
}
113+
},
114+
"additionalProperties": false,
115+
"type": "object",
116+
},
117+
}
118+
}`,
119+
});
99120
pluginClient.plugin = plugin;
100121
return plugin;
101122
};

src/plugin/plugin.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export type PluginOptions = {
4242
kind: PluginKind;
4343
dockerFile?: string;
4444
buildTargets?: BuildTarget[];
45+
jsonSchema?: string;
4546
};
4647

4748
export interface SourceClient {
@@ -65,6 +66,7 @@ export interface Plugin extends Client {
6566
version: () => string;
6667
team: () => string | undefined;
6768
kind: () => PluginKind | undefined;
69+
jsonSchema: () => string | undefined;
6870
dockerFile: () => string;
6971
buildTargets: () => BuildTarget[];
7072
init: (spec: string, options: NewClientOptions) => Promise<void>;
@@ -102,6 +104,7 @@ export const newPlugin = (
102104
version: () => version,
103105
team: () => options?.team,
104106
kind: () => options?.kind,
107+
jsonSchema: () => options?.jsonSchema,
105108
dockerFile: () => options?.dockerFile || 'Dockerfile',
106109
buildTargets: () => options?.buildTargets || defaultBuildTargets,
107110
write: (stream: WriteStream) => {

0 commit comments

Comments
 (0)