Skip to content

Commit

Permalink
Merge pull request #4 from guardian/aa/data
Browse files Browse the repository at this point in the history
feat: Add a simple table, with dummy data
  • Loading branch information
akash1810 authored Sep 26, 2023
2 parents 8695b7b + 5a988af commit f02bc4a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
node_modules
dist

# CloudQuery cache directory
.cq

# Output directory for CloudQuery
data

# CloudQuery log file
cloudquery.log
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
A [CloudQuery](https://www.cloudquery.io/) source plugin for [NS1](https://ns1.com/).

Written in TypeScript using the recently added [CloudQuery JavaScript SDK](https://www.cloudquery.io/blog/announcing-cloudquery-javascript-sdk).

## Developing
1. Start the plugin via `npm start`
2. Use the plugin via `npm run test:integration`
17 changes: 17 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
kind: source
spec:
name: "ns1"
registry: "grpc"
path: "localhost:7777"
tables: ['*']
destinations: ['file']
---
kind: destination
spec:
name: "file"
path: "cloudquery/file"
version: "v3.4.6"
spec:
path: "data/{{TABLE}}/{{UUID}}.{{FORMAT}}"
format: "csv"
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"lint": "eslint src/** --ext .ts --no-error-on-unmatched-pattern",
"format": "prettier --write src/**/*.ts",
"build": "tsc",
"start": "ts-node --esm src/index.ts serve"
"start": "ts-node --esm src/index.ts serve",
"test:integration": "cloudquery sync config.yml --log-level debug"
},
"dependencies": {
"@cloudquery/plugin-sdk-javascript": "^0.0.6",
Expand Down
45 changes: 42 additions & 3 deletions src/tables.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import type { Table } from '@cloudquery/plugin-sdk-javascript/schema/table';
import type { Writable } from 'stream';
import { Utf8 } from '@cloudquery/plugin-sdk-javascript/arrow';
import { createColumn } from '@cloudquery/plugin-sdk-javascript/schema/column';
import { pathResolver } from '@cloudquery/plugin-sdk-javascript/schema/resolvers';
import { createTable } from '@cloudquery/plugin-sdk-javascript/schema/table';
import type {
Table,
TableResolver,
} from '@cloudquery/plugin-sdk-javascript/schema/table';
import type { Logger } from 'winston';
import type { Spec } from './spec.js';

export const getTables = async (
logger: Logger,

Check warning on line 14 in src/tables.ts

View workflow job for this annotation

GitHub Actions / CI

'logger' is defined but never used
spec: Spec,

Check warning on line 15 in src/tables.ts

View workflow job for this annotation

GitHub Actions / CI

'spec' is defined but never used
): Promise<Table[]> => {
// TOD add tables
return Promise.resolve([]);
const resolver: TableResolver = async (
clientMeta: unknown,
parent: unknown,
stream: Writable,
) => {
await new Promise((_) => setTimeout(_, 500));

const data = new Array(10).fill(undefined);
data.forEach((_, index) => {
stream.write({ id: [index], name: [`hello ${index}`] });
});
return;
};

const table = createTable({
name: 'test',
columns: [
createColumn({
name: 'id',
type: new Utf8(),
resolver: pathResolver('id'),
}),
createColumn({
name: 'name',
type: new Utf8(),
resolver: pathResolver('name'),
}),
],
description: 'testing',
resolver,
});

return Promise.resolve([table]);
};

0 comments on commit f02bc4a

Please sign in to comment.