@quillsql/node 0.4.2 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/pgtypes.d.ts +4 -0
- package/dist/clients/QuillServerClient.d.ts +8 -0
- package/dist/db/BigQuery.d.ts +27 -0
- package/dist/db/CachedConnection.d.ts +16 -0
- package/dist/db/DatabaseHelper.d.ts +54 -0
- package/dist/db/DatabaseHelper.js +0 -1
- package/dist/db/Mysql.d.ts +29 -0
- package/dist/db/Postgres.d.ts +32 -0
- package/dist/db/Snowflake.d.ts +33 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.ispec.d.ts +0 -0
- package/dist/index.js +14 -8
- package/dist/index.uspec.d.ts +0 -0
- package/dist/index.uspec.js +40 -38
- package/dist/models/Cache.d.ts +12 -0
- package/dist/models/Client.d.ts +29 -0
- package/dist/models/Database.d.ts +5 -0
- package/dist/models/Formats.d.ts +7 -0
- package/dist/models/Quill.d.ts +70 -0
- package/dist/utils/Error.d.ts +7 -0
- package/dist/utils/RunQueryProcesses.d.ts +3 -0
- package/dist/utils/schemaConversion.d.ts +1 -0
- package/dist/utils/textProcessing.d.ts +2 -0
- package/package.json +2 -1
- package/src/db/DatabaseHelper.ts +0 -1
- package/src/index.ts +33 -14
- package/src/index.uspec.ts +40 -40
- package/tsconfig.json +1 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** This client is currently not used but is a good design pratice */
|
|
2
|
+
declare class QuillServerClient {
|
|
3
|
+
private baseUrl;
|
|
4
|
+
private config;
|
|
5
|
+
constructor(privateKey: string);
|
|
6
|
+
postQuill(route: string, payload: any): Promise<any>;
|
|
7
|
+
}
|
|
8
|
+
export default QuillServerClient;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { BigQuery } from "@google-cloud/bigquery";
|
|
2
|
+
import { QuillQueryResults } from "./DatabaseHelper";
|
|
3
|
+
export interface BigQueryConfig {
|
|
4
|
+
datasetName: string;
|
|
5
|
+
projectId: string;
|
|
6
|
+
credentials: any;
|
|
7
|
+
}
|
|
8
|
+
export declare function formatBigQueryConfig(connectionString: string): BigQueryConfig;
|
|
9
|
+
export declare function connectToBigQuery(config: BigQueryConfig): BigQuery;
|
|
10
|
+
export declare function runQueryBigQuery(sql: string, bigQuery: BigQuery): Promise<QuillQueryResults>;
|
|
11
|
+
export declare function getSchemaBigQuery(bigQuery: BigQuery): Promise<string[]>;
|
|
12
|
+
export declare function getTablesBySchemaBigQuery(bigQuery: BigQuery, schemaNames: string[]): Promise<{
|
|
13
|
+
tableName: string;
|
|
14
|
+
schemaName: string;
|
|
15
|
+
}[]>;
|
|
16
|
+
export declare function getColumnsByTableBigQuery(bigQuery: BigQuery, schemaName: string, tableName: string): Promise<string[]>;
|
|
17
|
+
export declare function getForeignKeysBigQuery(connection: BigQuery, schemaName: string, tableName: string, primaryKey: string): Promise<string[]>;
|
|
18
|
+
export declare function getSchemaColumnInfoBigQuery(connection: BigQuery, schemaName: string, tableNames: {
|
|
19
|
+
tableName: string;
|
|
20
|
+
schemaName: string;
|
|
21
|
+
}[]): Promise<{
|
|
22
|
+
tableName: string;
|
|
23
|
+
columns: {
|
|
24
|
+
columnName: string;
|
|
25
|
+
dataTypeID: number;
|
|
26
|
+
}[];
|
|
27
|
+
}[]>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Mapable, CacheCredentials } from "../models/Cache";
|
|
2
|
+
import { DatabaseConnection, DatabaseType } from "./DatabaseHelper";
|
|
3
|
+
export declare class CachedConnection {
|
|
4
|
+
databaseType: DatabaseType;
|
|
5
|
+
pool: DatabaseConnection;
|
|
6
|
+
orgId: any;
|
|
7
|
+
ttl: number;
|
|
8
|
+
cache: Mapable | null;
|
|
9
|
+
constructor(databaseType: DatabaseType, config: any, cacheConfig?: Partial<CacheCredentials>);
|
|
10
|
+
query(text: string, values?: any[]): Promise<any>;
|
|
11
|
+
/**
|
|
12
|
+
* Configures and returns a cache instance or null if none could be created.
|
|
13
|
+
*/
|
|
14
|
+
private getCache;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Pool } from "pg";
|
|
2
|
+
import snowflake from "snowflake-sdk";
|
|
3
|
+
import { Pool as MysqlPool } from "mysql2";
|
|
4
|
+
import { BigQuery } from "@google-cloud/bigquery";
|
|
5
|
+
import { PostgresConnectionConfig } from "./Postgres";
|
|
6
|
+
import { SnowflakeConnectionConfig } from "./Snowflake";
|
|
7
|
+
import { BigQueryConfig } from "./BigQuery";
|
|
8
|
+
import { MysqlConnectionConfig } from "./Mysql";
|
|
9
|
+
export declare enum DatabaseType {
|
|
10
|
+
postgresql = "postgresql",
|
|
11
|
+
snowflake = "snowflake",
|
|
12
|
+
bigquery = "bigquery",
|
|
13
|
+
mysql = "mysql"
|
|
14
|
+
}
|
|
15
|
+
export type DatabaseConnection = Pool | snowflake.Connection | BigQuery | MysqlPool;
|
|
16
|
+
export interface QuillQueryResults {
|
|
17
|
+
fields: {
|
|
18
|
+
name: string;
|
|
19
|
+
dataTypeID: number;
|
|
20
|
+
}[];
|
|
21
|
+
rows: {
|
|
22
|
+
[fieldName: string]: any;
|
|
23
|
+
}[];
|
|
24
|
+
}
|
|
25
|
+
export declare function getDatabaseCredentials(databaseType: DatabaseType, connectionString: string): PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig | undefined;
|
|
26
|
+
export declare function connectToDatabase(databaseType: DatabaseType, config: PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig): DatabaseConnection;
|
|
27
|
+
export declare function runQueryByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, sql: string): Promise<QuillQueryResults> | undefined;
|
|
28
|
+
export declare function disconnectFromDatabase(databaseType: DatabaseType, database: DatabaseConnection): void | Promise<void>;
|
|
29
|
+
export declare function getSchemasByDatabase(databaseType: DatabaseType, connection: DatabaseConnection): Promise<string[] | undefined>;
|
|
30
|
+
export declare function getTablesBySchemaByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string | string[]): Promise<string[] | {
|
|
31
|
+
tableName: string;
|
|
32
|
+
schemaName: string;
|
|
33
|
+
}[] | undefined>;
|
|
34
|
+
export declare function getColumnsByTableByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string, tableName: string): Promise<string[] | undefined>;
|
|
35
|
+
export declare function getForiegnKeysByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string, tableName: string, primaryKey: string): Promise<string[] | undefined>;
|
|
36
|
+
export declare function getColumnInfoBySchemaByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string, tables: string[] | {
|
|
37
|
+
tableName: string;
|
|
38
|
+
schemaName: string;
|
|
39
|
+
}[]): Promise<{
|
|
40
|
+
tableName: string;
|
|
41
|
+
columns: {
|
|
42
|
+
columnName: string;
|
|
43
|
+
dataTypeID: number;
|
|
44
|
+
}[];
|
|
45
|
+
}[]> | Promise<{
|
|
46
|
+
tableName: string;
|
|
47
|
+
displayName: string;
|
|
48
|
+
columns: {
|
|
49
|
+
columnName: any;
|
|
50
|
+
displayName: any;
|
|
51
|
+
dataTypeID: number;
|
|
52
|
+
fieldType: any;
|
|
53
|
+
}[];
|
|
54
|
+
}[]> | undefined;
|
|
@@ -16,7 +16,6 @@ const BigQuery_1 = require("./BigQuery");
|
|
|
16
16
|
const Mysql_1 = require("./Mysql");
|
|
17
17
|
var DatabaseType;
|
|
18
18
|
(function (DatabaseType) {
|
|
19
|
-
DatabaseType["postgres"] = "postgres";
|
|
20
19
|
DatabaseType["postgresql"] = "postgresql";
|
|
21
20
|
DatabaseType["snowflake"] = "snowflake";
|
|
22
21
|
DatabaseType["bigquery"] = "bigquery";
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Pool as MysqlPool } from "mysql2";
|
|
2
|
+
import { QuillQueryResults } from "./DatabaseHelper";
|
|
3
|
+
export interface MysqlConnectionConfig {
|
|
4
|
+
host: string;
|
|
5
|
+
user: string;
|
|
6
|
+
password: string;
|
|
7
|
+
database: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function formatMysqlConfig(connectionString: string): MysqlConnectionConfig;
|
|
10
|
+
export declare function connectToMysql(config: MysqlConnectionConfig): MysqlPool;
|
|
11
|
+
export declare function disconnectFromMysql(connection: MysqlPool): void;
|
|
12
|
+
export declare function runQueryMysql(sql: string, connection: MysqlPool): Promise<QuillQueryResults>;
|
|
13
|
+
export declare function getSchemasMysql(connection: MysqlPool): Promise<string[]>;
|
|
14
|
+
export declare function getTablesBySchemaMysql(connection: MysqlPool, schemaNames: string[]): Promise<{
|
|
15
|
+
tableName: string;
|
|
16
|
+
schemaName: string;
|
|
17
|
+
}[]>;
|
|
18
|
+
export declare function getColumnsByTableMysql(connection: MysqlPool, schemaName: string, tableName: string): Promise<string[]>;
|
|
19
|
+
export declare function getForeignKeysMysql(connection: MysqlPool, schemaName: string, tableName: string, primaryKey: string): Promise<string[]>;
|
|
20
|
+
export declare function getSchemaColumnInfoMysql(connection: MysqlPool, schemaName: string, tableNames: {
|
|
21
|
+
tableName: string;
|
|
22
|
+
schemaName: string;
|
|
23
|
+
}[]): Promise<{
|
|
24
|
+
tableName: string;
|
|
25
|
+
columns: {
|
|
26
|
+
columnName: string;
|
|
27
|
+
dataTypeID: number;
|
|
28
|
+
}[];
|
|
29
|
+
}[]>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Pool } from "pg";
|
|
2
|
+
import { QuillQueryResults } from "./DatabaseHelper";
|
|
3
|
+
export type PostgresConnectionConfig = {
|
|
4
|
+
connectionString: string;
|
|
5
|
+
ssl?: {
|
|
6
|
+
rejectUnauthorized: false;
|
|
7
|
+
ca?: string;
|
|
8
|
+
key?: string;
|
|
9
|
+
cert?: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare function connectToPostgres(config: PostgresConnectionConfig): Pool;
|
|
13
|
+
export declare function disconnectFromPostgres(pool: Pool): void;
|
|
14
|
+
export declare function runQueryPostgres(sql: string, pool: Pool): Promise<QuillQueryResults>;
|
|
15
|
+
export declare function getSchemasPostgres(pool: Pool): Promise<string[]>;
|
|
16
|
+
export declare function getTablesBySchemaPostgres(pool: Pool, schemaNames: string[]): Promise<{
|
|
17
|
+
tableName: string;
|
|
18
|
+
schemaName: string;
|
|
19
|
+
}[]>;
|
|
20
|
+
export declare function getColumnsByTablePostgres(pool: Pool, schemaName: string, tableName: string): Promise<string[]>;
|
|
21
|
+
export declare function getForeignKeysPostgres(pool: Pool, schemaName: string, tableName: string, primaryKey: string): Promise<string[]>;
|
|
22
|
+
export declare function getSchemaColumnInfoPostgress(pool: Pool, schemaName: string, tableNames: {
|
|
23
|
+
tableName: string;
|
|
24
|
+
schemaName: string;
|
|
25
|
+
}[]): Promise<{
|
|
26
|
+
tableName: string;
|
|
27
|
+
columns: {
|
|
28
|
+
columnName: string;
|
|
29
|
+
dataTypeID: number;
|
|
30
|
+
}[];
|
|
31
|
+
}[]>;
|
|
32
|
+
export declare function formatPostgresConfig(connectionString: string): PostgresConnectionConfig;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import snowflake from "snowflake-sdk";
|
|
2
|
+
import { QuillQueryResults } from "./DatabaseHelper";
|
|
3
|
+
export type SnowflakeConnectionConfig = {
|
|
4
|
+
account: string;
|
|
5
|
+
username: string;
|
|
6
|
+
password: string;
|
|
7
|
+
database: string;
|
|
8
|
+
warehouse: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function runQuerySnowflake(sql: string, connection: snowflake.Connection): Promise<QuillQueryResults>;
|
|
11
|
+
export declare function getSchemasSnowflake(connection: snowflake.Connection): Promise<string[]>;
|
|
12
|
+
export declare function getTablesBySchemaSnowflake(connection: snowflake.Connection, schemaNames: string[]): Promise<{
|
|
13
|
+
tableName: string;
|
|
14
|
+
schemaName: string;
|
|
15
|
+
}[]>;
|
|
16
|
+
export declare function getColumnsByTableSnowflake(connection: snowflake.Connection, schemaName: string, tableName: string): Promise<string[]>;
|
|
17
|
+
export declare function formatSnowflakeConfig(connectionString: string): SnowflakeConnectionConfig;
|
|
18
|
+
export declare function connectToSnowflake(config: SnowflakeConnectionConfig): snowflake.Connection;
|
|
19
|
+
export declare function disconnectFromSnowflake(connection: snowflake.Connection): Promise<void>;
|
|
20
|
+
export declare function getForeignKeysSnowflake(connection: snowflake.Connection, schemaName: string, tableName: string, primaryKey: string): Promise<string[]>;
|
|
21
|
+
export declare function getSchemaColumnInfoSnowflake(connection: snowflake.Connection, schemaName: string, tableNames: {
|
|
22
|
+
tableName: string;
|
|
23
|
+
schemaName: string;
|
|
24
|
+
}[]): Promise<{
|
|
25
|
+
tableName: string;
|
|
26
|
+
displayName: string;
|
|
27
|
+
columns: {
|
|
28
|
+
columnName: any;
|
|
29
|
+
displayName: any;
|
|
30
|
+
dataTypeID: number;
|
|
31
|
+
fieldType: any;
|
|
32
|
+
}[];
|
|
33
|
+
}[]>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CacheCredentials } from "./models/Cache";
|
|
2
|
+
import { QuillQueryParams } from "./models/Quill";
|
|
3
|
+
import { CachedConnection } from "./db/CachedConnection";
|
|
4
|
+
import "dotenv/config";
|
|
5
|
+
import { DatabaseType } from "./db/DatabaseHelper";
|
|
6
|
+
/**
|
|
7
|
+
* Quill - Fullstack API Platform for Dashboards and Reporting.
|
|
8
|
+
*/
|
|
9
|
+
export interface QuillQueryResult {
|
|
10
|
+
data?: any;
|
|
11
|
+
status: string;
|
|
12
|
+
error?: string;
|
|
13
|
+
queries?: {
|
|
14
|
+
rows: any[];
|
|
15
|
+
fields: any[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export default class QuillClass {
|
|
19
|
+
targetConnection: CachedConnection;
|
|
20
|
+
private baseUrl;
|
|
21
|
+
private config;
|
|
22
|
+
constructor(data: {
|
|
23
|
+
privateKey: string;
|
|
24
|
+
databaseType: DatabaseType;
|
|
25
|
+
databaseConnectionString?: string;
|
|
26
|
+
databaseConfig?: any;
|
|
27
|
+
cache?: Partial<CacheCredentials>;
|
|
28
|
+
metadataServerURL?: string;
|
|
29
|
+
});
|
|
30
|
+
query({ orgId, metadata, }: QuillQueryParams): Promise<QuillQueryResult>;
|
|
31
|
+
private runQueries;
|
|
32
|
+
private postQuill;
|
|
33
|
+
close(): Promise<void>;
|
|
34
|
+
}
|
|
File without changes
|
package/dist/index.js
CHANGED
|
@@ -21,20 +21,18 @@ const schemaConversion_1 = require("./utils/schemaConversion");
|
|
|
21
21
|
const HOST = process.env.ENV === "development"
|
|
22
22
|
? "http://localhost:8080"
|
|
23
23
|
: "https://quill-344421.uc.r.appspot.com";
|
|
24
|
-
/**
|
|
25
|
-
* Quill - Fullstack API Platform for Dashboards and Reporting.
|
|
26
|
-
*/
|
|
27
24
|
class QuillClass {
|
|
28
|
-
constructor(
|
|
25
|
+
constructor(data) {
|
|
26
|
+
const { privateKey, databaseType, databaseConnectionString, databaseConfig, cache, metadataServerURL, } = data;
|
|
29
27
|
this.baseUrl = metadataServerURL ? metadataServerURL : HOST;
|
|
30
28
|
this.config = { headers: { Authorization: `Bearer ${privateKey}` } };
|
|
31
|
-
let credentials =
|
|
29
|
+
let credentials = databaseConfig;
|
|
32
30
|
if (databaseConnectionString) {
|
|
33
31
|
credentials = (0, DatabaseHelper_1.getDatabaseCredentials)(databaseType, databaseConnectionString);
|
|
34
32
|
}
|
|
35
|
-
this.targetConnection = new CachedConnection_1.CachedConnection(databaseType, credentials, cache);
|
|
33
|
+
this.targetConnection = new CachedConnection_1.CachedConnection(databaseType, credentials, cache || {});
|
|
36
34
|
}
|
|
37
|
-
query({ orgId, metadata }) {
|
|
35
|
+
query({ orgId, metadata, }) {
|
|
38
36
|
var _a, _b, _c;
|
|
39
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
38
|
this.targetConnection.orgId = orgId;
|
|
@@ -169,7 +167,14 @@ class QuillClass {
|
|
|
169
167
|
}
|
|
170
168
|
exports.default = QuillClass;
|
|
171
169
|
const Quill = ({ privateKey, databaseConnectionString, databaseConfig, cache, databaseType, metadataServerURL, }) => {
|
|
172
|
-
return new QuillClass(
|
|
170
|
+
return new QuillClass({
|
|
171
|
+
privateKey,
|
|
172
|
+
databaseType,
|
|
173
|
+
databaseConnectionString,
|
|
174
|
+
databaseConfig,
|
|
175
|
+
cache,
|
|
176
|
+
metadataServerURL,
|
|
177
|
+
});
|
|
173
178
|
};
|
|
174
179
|
module.exports = Quill;
|
|
175
180
|
module.exports.Quill = Quill;
|
|
@@ -183,3 +188,4 @@ module.exports.getColumnInfoBySchemaByDatabase =
|
|
|
183
188
|
DatabaseHelper_1.getColumnInfoBySchemaByDatabase;
|
|
184
189
|
module.exports.connectToDatabase = DatabaseHelper_1.connectToDatabase;
|
|
185
190
|
module.exports.runQueryByDatabase = DatabaseHelper_1.runQueryByDatabase;
|
|
191
|
+
module.exports.DatabaseType = DatabaseHelper_1.DatabaseType;
|
|
File without changes
|
package/dist/index.uspec.js
CHANGED
|
@@ -1,39 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
2
|
+
// import Quill from ".";
|
|
3
|
+
// import { DatabaseType } from "./db/DatabaseHelper";
|
|
4
|
+
// jest.mock(".");
|
|
5
|
+
// describe("Quill", () => {
|
|
6
|
+
// let quill: Quill;
|
|
7
|
+
// beforeEach(() => {
|
|
8
|
+
// quill = new Quill(
|
|
9
|
+
// "dummy_private_key",
|
|
10
|
+
// DatabaseType.postgres,
|
|
11
|
+
// "dummy_db_url",
|
|
12
|
+
// {},
|
|
13
|
+
// undefined
|
|
14
|
+
// );
|
|
15
|
+
// quill.targetConnection.query = jest.fn().mockResolvedValue([]);
|
|
16
|
+
// });
|
|
17
|
+
// describe("query", () => {
|
|
18
|
+
// it("return nothing when suppling no queries", () => {
|
|
19
|
+
// const metadata = {
|
|
20
|
+
// task: "test",
|
|
21
|
+
// queries: [],
|
|
22
|
+
// };
|
|
23
|
+
// const result = quill.query({
|
|
24
|
+
// orgId: "dummy",
|
|
25
|
+
// metadata,
|
|
26
|
+
// });
|
|
27
|
+
// expect(result).resolves.toEqual([]);
|
|
28
|
+
// });
|
|
29
|
+
// it("returns an error for the improper query", () => {
|
|
30
|
+
// const metadata = {
|
|
31
|
+
// task: "test",
|
|
32
|
+
// queries: ["SELECT * FROM test"],
|
|
33
|
+
// };
|
|
34
|
+
// const result = quill.query({
|
|
35
|
+
// orgId: "dummy",
|
|
36
|
+
// metadata,
|
|
37
|
+
// });
|
|
38
|
+
// });
|
|
39
|
+
// });
|
|
40
|
+
// // Add more test cases as needed
|
|
41
|
+
// });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Mapable {
|
|
2
|
+
get(key: string): Promise<string | null>;
|
|
3
|
+
set(key: string, value: string, type?: string, ttl?: number): Promise<string | null>;
|
|
4
|
+
}
|
|
5
|
+
export interface CacheCredentials {
|
|
6
|
+
username: string;
|
|
7
|
+
password: string;
|
|
8
|
+
host: string;
|
|
9
|
+
port: string;
|
|
10
|
+
cacheType: string;
|
|
11
|
+
ttl?: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface Client {
|
|
2
|
+
name: string;
|
|
3
|
+
databaseConnectionString: string;
|
|
4
|
+
etlDatabaseConnectionString: string;
|
|
5
|
+
stagingDatabaseConnectionString: string;
|
|
6
|
+
customerTableTitleFieldName: string;
|
|
7
|
+
databaseType: string;
|
|
8
|
+
customerFieldName: string;
|
|
9
|
+
customerTableFieldName: string;
|
|
10
|
+
customerTableName: string;
|
|
11
|
+
customerView: string;
|
|
12
|
+
customerFieldType: string;
|
|
13
|
+
useSsl: boolean;
|
|
14
|
+
serverCa: string;
|
|
15
|
+
clientCert: string;
|
|
16
|
+
clientKey: string;
|
|
17
|
+
defaultQuery: string;
|
|
18
|
+
ignoreDarkMode: boolean;
|
|
19
|
+
domainName: string;
|
|
20
|
+
hideSqlEditor: boolean;
|
|
21
|
+
adminCustomerId: string;
|
|
22
|
+
stagingAdminCustomerId: string;
|
|
23
|
+
cacheCloudConfig: {
|
|
24
|
+
type: {
|
|
25
|
+
cacheQueries: boolean;
|
|
26
|
+
};
|
|
27
|
+
default: null;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type FieldFormat = "whole_number" | "one_decimal_place" | "two_decimal_places" | "dollar_amount" | "MMM_yyyy" | "MMM_dd_yyyy" | "MMM_dd-MMM_dd" | "MMM_dd_hh:mm_ap_pm" | "hh_ap_pm" | "percent" | "string";
|
|
2
|
+
export interface FormattedColumn {
|
|
3
|
+
label: string;
|
|
4
|
+
field: string;
|
|
5
|
+
chartType: string;
|
|
6
|
+
format: FieldFormat;
|
|
7
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { CacheCredentials } from "./Cache";
|
|
2
|
+
import { DatabaseCredentials } from "./Database";
|
|
3
|
+
import { FieldFormat, FormattedColumn } from "./Formats";
|
|
4
|
+
export interface QuillRequestMetadata {
|
|
5
|
+
task: string;
|
|
6
|
+
queries?: string[];
|
|
7
|
+
preQueries?: string[];
|
|
8
|
+
runQueryConfig?: AdditionalProcessing;
|
|
9
|
+
query?: string;
|
|
10
|
+
id?: string;
|
|
11
|
+
filters?: any[];
|
|
12
|
+
name?: string;
|
|
13
|
+
xAxisField?: string;
|
|
14
|
+
yAxisFields?: FormattedColumn[];
|
|
15
|
+
xAxisLabel?: string;
|
|
16
|
+
xAxisFormat?: FieldFormat;
|
|
17
|
+
yAxisLabel?: string;
|
|
18
|
+
chartType?: string;
|
|
19
|
+
dashboardName?: string;
|
|
20
|
+
columns?: FormattedColumn[];
|
|
21
|
+
dateField?: {
|
|
22
|
+
table: string;
|
|
23
|
+
field: string;
|
|
24
|
+
};
|
|
25
|
+
template?: boolean;
|
|
26
|
+
clientId?: string;
|
|
27
|
+
deleted?: boolean;
|
|
28
|
+
databaseType?: string;
|
|
29
|
+
}
|
|
30
|
+
export interface QuillQueryParams {
|
|
31
|
+
orgId: string;
|
|
32
|
+
metadata: QuillRequestMetadata;
|
|
33
|
+
environment?: string;
|
|
34
|
+
}
|
|
35
|
+
export interface QuillConfig {
|
|
36
|
+
privateKey: string;
|
|
37
|
+
db: Partial<DatabaseCredentials>;
|
|
38
|
+
cache: Partial<CacheCredentials>;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use db credential object instead
|
|
41
|
+
*/
|
|
42
|
+
databaseConnectionString?: string;
|
|
43
|
+
/**
|
|
44
|
+
* @deprecated Use db credential object instead
|
|
45
|
+
*/
|
|
46
|
+
stagingDatabaseConnectionString?: string;
|
|
47
|
+
}
|
|
48
|
+
export interface AdditionalProcessing {
|
|
49
|
+
getSchema?: boolean;
|
|
50
|
+
getColumns?: boolean;
|
|
51
|
+
getTables?: boolean;
|
|
52
|
+
schema?: string;
|
|
53
|
+
schemaNames?: string[];
|
|
54
|
+
table?: string;
|
|
55
|
+
removeFields?: string[];
|
|
56
|
+
arrayToMap?: {
|
|
57
|
+
arrayName: string;
|
|
58
|
+
field: string;
|
|
59
|
+
};
|
|
60
|
+
overridePost?: boolean;
|
|
61
|
+
convertDatatypes?: boolean;
|
|
62
|
+
limitThousand?: boolean;
|
|
63
|
+
limitBy?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface QuillClientResponse {
|
|
66
|
+
queries: string[];
|
|
67
|
+
metadata: any;
|
|
68
|
+
runQueryConfig: AdditionalProcessing;
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function convertTypeToPostgres(data_type_id: number): string;
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quillsql/node",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Quill's client SDK for node backends.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
7
8
|
"scripts": {
|
|
8
9
|
"build": "tsc --outDir dist",
|
|
9
10
|
"start:dev": "nodemon ./examples/node-server/app.ts",
|
package/src/db/DatabaseHelper.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -31,6 +31,13 @@ const HOST =
|
|
|
31
31
|
* Quill - Fullstack API Platform for Dashboards and Reporting.
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
|
+
export interface QuillQueryResult {
|
|
35
|
+
data?: any;
|
|
36
|
+
status: string;
|
|
37
|
+
error?: string;
|
|
38
|
+
queries?: { rows: any[]; fields: any[] };
|
|
39
|
+
}
|
|
40
|
+
|
|
34
41
|
export default class QuillClass {
|
|
35
42
|
// Configure cached connection pools with the given config.
|
|
36
43
|
public targetConnection;
|
|
@@ -41,17 +48,25 @@ export default class QuillClass {
|
|
|
41
48
|
};
|
|
42
49
|
};
|
|
43
50
|
|
|
44
|
-
constructor(
|
|
45
|
-
privateKey: string
|
|
46
|
-
databaseType: DatabaseType
|
|
47
|
-
databaseConnectionString?: string
|
|
48
|
-
|
|
49
|
-
cache
|
|
50
|
-
metadataServerURL?: string
|
|
51
|
-
) {
|
|
51
|
+
constructor(data: {
|
|
52
|
+
privateKey: string;
|
|
53
|
+
databaseType: DatabaseType;
|
|
54
|
+
databaseConnectionString?: string;
|
|
55
|
+
databaseConfig?: any;
|
|
56
|
+
cache?: Partial<CacheCredentials>;
|
|
57
|
+
metadataServerURL?: string;
|
|
58
|
+
}) {
|
|
59
|
+
const {
|
|
60
|
+
privateKey,
|
|
61
|
+
databaseType,
|
|
62
|
+
databaseConnectionString,
|
|
63
|
+
databaseConfig,
|
|
64
|
+
cache,
|
|
65
|
+
metadataServerURL,
|
|
66
|
+
} = data;
|
|
52
67
|
this.baseUrl = metadataServerURL ? metadataServerURL : HOST;
|
|
53
68
|
this.config = { headers: { Authorization: `Bearer ${privateKey}` } };
|
|
54
|
-
let credentials =
|
|
69
|
+
let credentials = databaseConfig;
|
|
55
70
|
if (databaseConnectionString) {
|
|
56
71
|
credentials = getDatabaseCredentials(
|
|
57
72
|
databaseType,
|
|
@@ -61,11 +76,14 @@ export default class QuillClass {
|
|
|
61
76
|
this.targetConnection = new CachedConnection(
|
|
62
77
|
databaseType,
|
|
63
78
|
credentials,
|
|
64
|
-
cache
|
|
79
|
+
cache || {}
|
|
65
80
|
);
|
|
66
81
|
}
|
|
67
82
|
|
|
68
|
-
public async query({
|
|
83
|
+
public async query({
|
|
84
|
+
orgId,
|
|
85
|
+
metadata,
|
|
86
|
+
}: QuillQueryParams): Promise<QuillQueryResult> {
|
|
69
87
|
this.targetConnection.orgId = orgId;
|
|
70
88
|
try {
|
|
71
89
|
const preQueryResults = metadata.preQueries
|
|
@@ -256,14 +274,14 @@ const Quill = ({
|
|
|
256
274
|
databaseConfig: any;
|
|
257
275
|
metadataServerURL?: string;
|
|
258
276
|
}) => {
|
|
259
|
-
return new QuillClass(
|
|
277
|
+
return new QuillClass({
|
|
260
278
|
privateKey,
|
|
261
279
|
databaseType,
|
|
262
280
|
databaseConnectionString,
|
|
263
281
|
databaseConfig,
|
|
264
282
|
cache,
|
|
265
|
-
metadataServerURL
|
|
266
|
-
);
|
|
283
|
+
metadataServerURL,
|
|
284
|
+
});
|
|
267
285
|
};
|
|
268
286
|
|
|
269
287
|
module.exports = Quill;
|
|
@@ -278,3 +296,4 @@ module.exports.getColumnInfoBySchemaByDatabase =
|
|
|
278
296
|
getColumnInfoBySchemaByDatabase;
|
|
279
297
|
module.exports.connectToDatabase = connectToDatabase;
|
|
280
298
|
module.exports.runQueryByDatabase = runQueryByDatabase;
|
|
299
|
+
module.exports.DatabaseType = DatabaseType;
|
package/src/index.uspec.ts
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import Quill from ".";
|
|
2
|
-
import { DatabaseType } from "./db/DatabaseHelper";
|
|
1
|
+
// import Quill from ".";
|
|
2
|
+
// import { DatabaseType } from "./db/DatabaseHelper";
|
|
3
3
|
|
|
4
|
-
jest.mock(".");
|
|
4
|
+
// jest.mock(".");
|
|
5
5
|
|
|
6
|
-
describe("Quill", () => {
|
|
7
|
-
|
|
6
|
+
// describe("Quill", () => {
|
|
7
|
+
// let quill: Quill;
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
// beforeEach(() => {
|
|
10
|
+
// quill = new Quill(
|
|
11
|
+
// "dummy_private_key",
|
|
12
|
+
// DatabaseType.postgres,
|
|
13
|
+
// "dummy_db_url",
|
|
14
|
+
// {},
|
|
15
|
+
// undefined
|
|
16
|
+
// );
|
|
17
|
+
// quill.targetConnection.query = jest.fn().mockResolvedValue([]);
|
|
18
|
+
// });
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
20
|
+
// describe("query", () => {
|
|
21
|
+
// it("return nothing when suppling no queries", () => {
|
|
22
|
+
// const metadata = {
|
|
23
|
+
// task: "test",
|
|
24
|
+
// queries: [],
|
|
25
|
+
// };
|
|
26
|
+
// const result = quill.query({
|
|
27
|
+
// orgId: "dummy",
|
|
28
|
+
// metadata,
|
|
29
|
+
// });
|
|
30
|
+
// expect(result).resolves.toEqual([]);
|
|
31
|
+
// });
|
|
32
|
+
// it("returns an error for the improper query", () => {
|
|
33
|
+
// const metadata = {
|
|
34
|
+
// task: "test",
|
|
35
|
+
// queries: ["SELECT * FROM test"],
|
|
36
|
+
// };
|
|
37
|
+
// const result = quill.query({
|
|
38
|
+
// orgId: "dummy",
|
|
39
|
+
// metadata,
|
|
40
|
+
// });
|
|
41
|
+
// });
|
|
42
|
+
// });
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
});
|
|
44
|
+
// // Add more test cases as needed
|
|
45
|
+
// });
|