@cloudquery/plugin-sdk-javascript
Version:
This is the high-level package to use for developing CloudQuery plugins in JavaScript
54 lines • 2.28 kB
JavaScript
import { UnimplementedError, InitializationError } from '../errors/errors.js';
export const newUnimplementedSource = () => {
return {
tables: () => Promise.reject(new UnimplementedError('unimplemented', { props: { method: 'tables' } })),
sync: () => Promise.reject(new UnimplementedError('unimplemented', { props: { method: 'sync' } })),
};
};
export const newUnimplementedDestination = () => {
return {
read: () => Promise.reject(new UnimplementedError('unimplemented', { props: { method: 'read' } })),
write: () => Promise.reject(new UnimplementedError('unimplemented', { props: { method: 'write' } })),
};
};
const defaultBuildTargets = [
{ os: 'linux', arch: 'amd64' },
{ os: 'linux', arch: 'arm64' },
];
export const newPlugin = (name, version, newClient, options) => {
const plugin = {
client: undefined,
logger: undefined,
name: () => name,
version: () => version,
team: () => options?.team,
kind: () => options?.kind,
jsonSchema: () => options?.jsonSchema,
dockerFile: () => options?.dockerFile || 'Dockerfile',
buildTargets: () => options?.buildTargets || defaultBuildTargets,
write: (stream) => {
return plugin.client?.write(stream) ?? Promise.reject(new InitializationError('client not initialized'));
},
read: (stream) => {
return plugin.client?.read(stream) ?? new InitializationError('client not initialized');
},
getLogger: () => {
return plugin.logger;
},
setLogger: (logger) => {
plugin.logger = logger;
},
sync: (options) => {
return plugin.client?.sync(options) ?? new InitializationError('client not initialized');
},
tables: (options) => {
return plugin.client?.tables(options) ?? Promise.reject(new InitializationError('client not initialized'));
},
init: async (spec, options) => {
plugin.client = await newClient(plugin.logger, spec, options);
},
close: () => plugin.client?.close() ?? Promise.reject(new InitializationError('client not initialized')),
};
return plugin;
};
//# sourceMappingURL=plugin.js.map