11import { pluginV3 } from '@cloudquery/plugin-pb-javascript' ;
22import grpc = require( '@grpc/grpc-js' ) ;
3- import winston from 'winston' ;
3+
4+ import { Plugin } from '../plugin/plugin.js' ;
45
56export class PluginServer extends pluginV3 . cloudquery . plugin . v3 . UnimplementedPluginService {
7+ // Needed due to some TypeScript nonsense
8+ private plugin : Plugin & grpc . UntypedHandleCall ;
9+
10+ constructor ( plugin : Plugin ) {
11+ super ( ) ;
12+ this . plugin = plugin as Plugin & grpc . UntypedHandleCall ;
13+ }
14+
615 GetName (
716 call : grpc . ServerUnaryCall <
817 pluginV3 . cloudquery . plugin . v3 . GetName . Request ,
918 pluginV3 . cloudquery . plugin . v3 . GetName . Response
1019 > ,
1120 callback : grpc . sendUnaryData < pluginV3 . cloudquery . plugin . v3 . GetName . Response > ,
1221 ) : void {
13- throw new Error ( 'Method not implemented.' ) ;
22+ return callback ( null , new pluginV3 . cloudquery . plugin . v3 . GetName . Response ( { name : this . plugin . name ( ) } ) ) ;
1423 }
1524 GetVersion (
1625 call : grpc . ServerUnaryCall <
@@ -19,13 +28,27 @@ export class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPlu
1928 > ,
2029 callback : grpc . sendUnaryData < pluginV3 . cloudquery . plugin . v3 . GetVersion . Response > ,
2130 ) : void {
22- throw new Error ( 'Method not implemented.' ) ;
31+ return callback ( null , new pluginV3 . cloudquery . plugin . v3 . GetVersion . Response ( { version : this . plugin . version ( ) } ) ) ;
2332 }
2433 Init (
2534 call : grpc . ServerUnaryCall < pluginV3 . cloudquery . plugin . v3 . Init . Request , pluginV3 . cloudquery . plugin . v3 . Init . Response > ,
2635 callback : grpc . sendUnaryData < pluginV3 . cloudquery . plugin . v3 . Init . Response > ,
2736 ) : void {
28- throw new Error ( 'Method not implemented.' ) ;
37+ const {
38+ request : { spec, no_connection : noConnection } ,
39+ } = call ;
40+
41+ const stringSpec = new TextDecoder ( ) . decode ( spec ) ;
42+ this . plugin
43+ . init ( stringSpec , { noConnection } )
44+ . then ( ( ) => {
45+ // eslint-disable-next-line promise/no-callback-in-promise
46+ return callback ( null , new pluginV3 . cloudquery . plugin . v3 . Init . Response ( ) ) ;
47+ } )
48+ . catch ( ( error ) => {
49+ // eslint-disable-next-line promise/no-callback-in-promise
50+ return callback ( error , null ) ;
51+ } ) ;
2952 }
3053 GetTables (
3154 call : grpc . ServerUnaryCall <
@@ -34,23 +57,54 @@ export class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPlu
3457 > ,
3558 callback : grpc . sendUnaryData < pluginV3 . cloudquery . plugin . v3 . GetTables . Response > ,
3659 ) : void {
37- throw new Error ( 'Method not implemented.' ) ;
60+ const {
61+ request : { tables, skip_tables : skipTables , skip_dependent_tables : skipDependentTables } ,
62+ } = call ;
63+
64+ this . plugin
65+ . tables ( { tables, skipTables, skipDependentTables } )
66+ . then ( ( tables ) => {
67+ const encodedTables = tables . map ( ( table ) => new TextEncoder ( ) . encode ( table ) ) ;
68+ // eslint-disable-next-line promise/no-callback-in-promise
69+ return callback ( null , new pluginV3 . cloudquery . plugin . v3 . GetTables . Response ( { tables : encodedTables } ) ) ;
70+ } )
71+ . catch ( ( error ) => {
72+ // eslint-disable-next-line promise/no-callback-in-promise
73+ return callback ( error , null ) ;
74+ } ) ;
3875 }
3976 Sync (
4077 call : grpc . ServerWritableStream <
4178 pluginV3 . cloudquery . plugin . v3 . Sync . Request ,
4279 pluginV3 . cloudquery . plugin . v3 . Sync . Response
4380 > ,
4481 ) : void {
45- throw new Error ( 'Method not implemented.' ) ;
82+ const {
83+ request : {
84+ tables,
85+ skip_tables : skipTables ,
86+ skip_dependent_tables : skipDependentTables ,
87+ deterministic_cq_id : deterministicCQId ,
88+ backend : { connection, table_name : tableName } ,
89+ } ,
90+ } = call ;
91+
92+ this . plugin . sync ( {
93+ tables,
94+ skipTables,
95+ skipDependentTables,
96+ deterministicCQId,
97+ backendOptions : { connection, tableName } ,
98+ stream : call ,
99+ } ) ;
46100 }
47101 Read (
48102 call : grpc . ServerWritableStream <
49103 pluginV3 . cloudquery . plugin . v3 . Read . Request ,
50104 pluginV3 . cloudquery . plugin . v3 . Read . Response
51105 > ,
52106 ) : void {
53- throw new Error ( 'Method not implemented.' ) ;
107+ this . plugin . read ( call ) ;
54108 }
55109 Write (
56110 call : grpc . ServerReadableStream <
@@ -59,7 +113,8 @@ export class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPlu
59113 > ,
60114 callback : grpc . sendUnaryData < pluginV3 . cloudquery . plugin . v3 . Write . Response > ,
61115 ) : void {
62- throw new Error ( 'Method not implemented.' ) ;
116+ this . plugin . write ( call ) ;
117+ callback ( null , new pluginV3 . cloudquery . plugin . v3 . Write . Response ( ) ) ;
63118 }
64119 Close (
65120 call : grpc . ServerUnaryCall <
@@ -68,6 +123,15 @@ export class PluginServer extends pluginV3.cloudquery.plugin.v3.UnimplementedPlu
68123 > ,
69124 callback : grpc . sendUnaryData < pluginV3 . cloudquery . plugin . v3 . Close . Response > ,
70125 ) : void {
71- throw new Error ( 'Method not implemented.' ) ;
126+ this . plugin
127+ . close ( )
128+ . then ( ( ) => {
129+ // eslint-disable-next-line promise/no-callback-in-promise
130+ return callback ( null , new pluginV3 . cloudquery . plugin . v3 . Close . Response ( ) ) ;
131+ } )
132+ . catch ( ( error ) => {
133+ // eslint-disable-next-line promise/no-callback-in-promise
134+ return callback ( error , null ) ;
135+ } ) ;
72136 }
73137}
0 commit comments