@quillsql/node 0.4.2 → 0.4.3

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.
@@ -0,0 +1,4 @@
1
+ export declare const PG_TYPES: {
2
+ typname: string;
3
+ oid: number;
4
+ }[];
@@ -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,55 @@
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
+ postgres = "postgres",
11
+ postgresql = "postgresql",
12
+ snowflake = "snowflake",
13
+ bigquery = "bigquery",
14
+ mysql = "mysql"
15
+ }
16
+ export type DatabaseConnection = Pool | snowflake.Connection | BigQuery | MysqlPool;
17
+ export interface QuillQueryResults {
18
+ fields: {
19
+ name: string;
20
+ dataTypeID: number;
21
+ }[];
22
+ rows: {
23
+ [fieldName: string]: any;
24
+ }[];
25
+ }
26
+ export declare function getDatabaseCredentials(databaseType: DatabaseType, connectionString: string): PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig | undefined;
27
+ export declare function connectToDatabase(databaseType: DatabaseType, config: PostgresConnectionConfig | SnowflakeConnectionConfig | BigQueryConfig | MysqlConnectionConfig): DatabaseConnection;
28
+ export declare function runQueryByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, sql: string): Promise<QuillQueryResults> | undefined;
29
+ export declare function disconnectFromDatabase(databaseType: DatabaseType, database: DatabaseConnection): void | Promise<void>;
30
+ export declare function getSchemasByDatabase(databaseType: DatabaseType, connection: DatabaseConnection): Promise<string[] | undefined>;
31
+ export declare function getTablesBySchemaByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string | string[]): Promise<string[] | {
32
+ tableName: string;
33
+ schemaName: string;
34
+ }[] | undefined>;
35
+ export declare function getColumnsByTableByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string, tableName: string): Promise<string[] | undefined>;
36
+ export declare function getForiegnKeysByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string, tableName: string, primaryKey: string): Promise<string[] | undefined>;
37
+ export declare function getColumnInfoBySchemaByDatabase(databaseType: DatabaseType, connection: DatabaseConnection, schemaName: string, tables: string[] | {
38
+ tableName: string;
39
+ schemaName: string;
40
+ }[]): Promise<{
41
+ tableName: string;
42
+ columns: {
43
+ columnName: string;
44
+ dataTypeID: number;
45
+ }[];
46
+ }[]> | Promise<{
47
+ tableName: string;
48
+ displayName: string;
49
+ columns: {
50
+ columnName: any;
51
+ displayName: any;
52
+ dataTypeID: number;
53
+ fieldType: any;
54
+ }[];
55
+ }[]> | undefined;
@@ -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
+ }[]>;
@@ -0,0 +1,18 @@
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 default class QuillClass {
10
+ targetConnection: CachedConnection;
11
+ private baseUrl;
12
+ private config;
13
+ constructor(privateKey: string, databaseType: DatabaseType, databaseConnectionString?: string, databaseCredentials?: any, cache?: Partial<CacheCredentials>, metadataServerURL?: string);
14
+ query({ orgId, metadata }: QuillQueryParams): Promise<any>;
15
+ private runQueries;
16
+ private postQuill;
17
+ close(): Promise<void>;
18
+ }
File without changes
@@ -0,0 +1 @@
1
+ export {};
@@ -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,5 @@
1
+ export interface DatabaseCredentials {
2
+ databaseConnectionString: string;
3
+ stagingDatabaseConnectionString: string;
4
+ databaseType: string;
5
+ }
@@ -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,7 @@
1
+ export declare class PgError extends Error {
2
+ code?: string;
3
+ detail?: string;
4
+ hint?: string;
5
+ position?: string;
6
+ }
7
+ export declare function isSuperset(obj: any, baseClass: any): boolean;
@@ -0,0 +1,3 @@
1
+ import { CachedConnection } from "../db/CachedConnection";
2
+ export declare function removeFields(queryResults: any, fieldsToRemove: string[]): any;
3
+ export declare function mapQueries(queries: string[], targetConnection: CachedConnection): Promise<any[]>;
@@ -0,0 +1 @@
1
+ export declare function convertTypeToPostgres(data_type_id: number): string;
@@ -0,0 +1,2 @@
1
+ export declare function capitalize(text: string): string;
2
+ export declare function depluralize(text: string): string;
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@quillsql/node",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
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/tsconfig.json CHANGED
@@ -6,6 +6,7 @@
6
6
  "forceConsistentCasingInFileNames": true,
7
7
  "strict": true,
8
8
  "skipLibCheck": true,
9
+ "declaration": true,
9
10
  "outDir": "./dist",
10
11
  "rootDir": "./src"
11
12
  },