From aea08af49cc0f1da81faa1133f2d362d0895ee31 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 24 Jun 2021 18:17:26 +0100 Subject: [PATCH] Formatting. --- packages/server/src/constants/definitions.ts | 41 ++++----- packages/server/src/integrations/airtable.ts | 6 +- packages/server/src/integrations/arangodb.ts | 6 +- .../src/integrations/base/definitions.ts | 92 +++++++++---------- packages/server/src/integrations/base/sql.ts | 19 +++- packages/server/src/integrations/couchdb.ts | 6 +- packages/server/src/integrations/dynamodb.ts | 6 +- .../server/src/integrations/elasticsearch.ts | 6 +- .../src/integrations/microsoftSqlServer.ts | 7 +- packages/server/src/integrations/mongodb.ts | 6 +- packages/server/src/integrations/mysql.ts | 12 ++- packages/server/src/integrations/postgres.ts | 38 +++++--- packages/server/src/integrations/rest.ts | 16 ++-- packages/server/src/integrations/s3.ts | 6 +- 14 files changed, 164 insertions(+), 103 deletions(-) diff --git a/packages/server/src/constants/definitions.ts b/packages/server/src/constants/definitions.ts index 77070ec34b..685c2a9824 100644 --- a/packages/server/src/constants/definitions.ts +++ b/packages/server/src/constants/definitions.ts @@ -1,29 +1,28 @@ - export interface Table { - _id: string, - _rev?: string, - type?: string, - views?: {}, - name?: string, - primary?: string[], + _id: string + _rev?: string + type?: string + views?: {} + name?: string + primary?: string[] schema: { [key: string]: { // TODO: replace with field types enum when done - type: string, - fieldName?: string, - name: string, + type: string + fieldName?: string + name: string constraints?: { - type?: string, - email?: boolean, - inclusion?: string[], + type?: string + email?: boolean + inclusion?: string[] length?: { - minimum?: string | number, - maximum?: string | number, - }, - presence?: boolean, - }, + minimum?: string | number + maximum?: string | number + } + presence?: boolean + } } - }, - primaryDisplay?: string, - sourceId?: string, + } + primaryDisplay?: string + sourceId?: string } diff --git a/packages/server/src/integrations/airtable.ts b/packages/server/src/integrations/airtable.ts index 84b0ef7dca..a99dfc7c72 100644 --- a/packages/server/src/integrations/airtable.ts +++ b/packages/server/src/integrations/airtable.ts @@ -1,4 +1,8 @@ -import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, +} from "./base/definitions" module AirtableModule { const Airtable = require("airtable") diff --git a/packages/server/src/integrations/arangodb.ts b/packages/server/src/integrations/arangodb.ts index 863764fe2e..7741b8be94 100644 --- a/packages/server/src/integrations/arangodb.ts +++ b/packages/server/src/integrations/arangodb.ts @@ -1,4 +1,8 @@ -import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, +} from "./base/definitions" module ArangoModule { const { Database, aql } = require("arangojs") diff --git a/packages/server/src/integrations/base/definitions.ts b/packages/server/src/integrations/base/definitions.ts index f51010eb49..78dbe6adc9 100644 --- a/packages/server/src/integrations/base/definitions.ts +++ b/packages/server/src/integrations/base/definitions.ts @@ -27,76 +27,76 @@ export enum DatasourceFieldTypes { } export interface QueryDefinition { - type: QueryTypes, - displayName?: string, - readable?: boolean, - customisable?: boolean, - fields?: object, - urlDisplay?: boolean, + type: QueryTypes + displayName?: string + readable?: boolean + customisable?: boolean + fields?: object + urlDisplay?: boolean } export interface Integration { - docs: string, - plus?: boolean, - description: string, - friendlyName: string, - datasource: {}, + docs: string + plus?: boolean + description: string + friendlyName: string + datasource: {} query: { - [key: string]: QueryDefinition, + [key: string]: QueryDefinition } } export interface SearchFilters { - allOr: boolean, + allOr: boolean string?: { - [key: string]: string, - }, + [key: string]: string + } fuzzy?: { - [key: string]: string, - }, + [key: string]: string + } range?: { [key: string]: { - high: number | string, - low: number | string, - }, - }, + high: number | string + low: number | string + } + } equal?: { - [key: string]: any, - }, + [key: string]: any + } notEqual?: { - [key: string]: any, - }, + [key: string]: any + } empty?: { - [key: string]: any, - }, + [key: string]: any + } notEmpty?: { - [key: string]: any, - }, + [key: string]: any + } } export interface QueryJson { endpoint: { - datasourceId: string, - entityId: string, - operation: Operation, - }, + datasourceId: string + entityId: string + operation: Operation + } resource: { - fields: string[], - }, - filters?: SearchFilters, + fields: string[] + } + filters?: SearchFilters sort?: { - [key: string]: SortDirection, - }, + [key: string]: SortDirection + } paginate?: { - limit: number, - page: string | number, - }, - body?: object, + limit: number + page: string | number + } + body?: object extra: { - idFilter?: SearchFilters, - }, + idFilter?: SearchFilters + } } export interface QueryOptions { - disableReturning?: boolean, -} \ No newline at end of file + disableReturning?: boolean +} diff --git a/packages/server/src/integrations/base/sql.ts b/packages/server/src/integrations/base/sql.ts index 5d61aaea45..27a99bf07c 100644 --- a/packages/server/src/integrations/base/sql.ts +++ b/packages/server/src/integrations/base/sql.ts @@ -1,10 +1,21 @@ import { Knex, knex } from "knex" const BASE_LIMIT = 5000 -import { QueryJson, SearchFilters, QueryOptions, SortDirection, Operation } from "./definitions" +import { + QueryJson, + SearchFilters, + QueryOptions, + SortDirection, + Operation, +} from "./definitions" - -function addFilters(query: any, filters: SearchFilters | undefined): Knex.QueryBuilder { - function iterate(structure: { [key: string]: any }, fn: (key: string, value: any) => void) { +function addFilters( + query: any, + filters: SearchFilters | undefined +): Knex.QueryBuilder { + function iterate( + structure: { [key: string]: any }, + fn: (key: string, value: any) => void + ) { for (let [key, value] of Object.entries(structure)) { fn(key, value) } diff --git a/packages/server/src/integrations/couchdb.ts b/packages/server/src/integrations/couchdb.ts index 798e99f759..a813cf2385 100644 --- a/packages/server/src/integrations/couchdb.ts +++ b/packages/server/src/integrations/couchdb.ts @@ -1,4 +1,8 @@ -import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, +} from "./base/definitions" module CouchDBModule { const PouchDB = require("pouchdb") diff --git a/packages/server/src/integrations/dynamodb.ts b/packages/server/src/integrations/dynamodb.ts index b24aaa7c35..0baf09a866 100644 --- a/packages/server/src/integrations/dynamodb.ts +++ b/packages/server/src/integrations/dynamodb.ts @@ -1,4 +1,8 @@ -import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, +} from "./base/definitions" module DynamoModule { const AWS = require("aws-sdk") diff --git a/packages/server/src/integrations/elasticsearch.ts b/packages/server/src/integrations/elasticsearch.ts index f9810bd1c4..2562ca0dcd 100644 --- a/packages/server/src/integrations/elasticsearch.ts +++ b/packages/server/src/integrations/elasticsearch.ts @@ -1,4 +1,8 @@ -import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, +} from "./base/definitions" module ElasticsearchModule { const { Client } = require("@elastic/elasticsearch") diff --git a/packages/server/src/integrations/microsoftSqlServer.ts b/packages/server/src/integrations/microsoftSqlServer.ts index 5f90f7ce85..05c9812e26 100644 --- a/packages/server/src/integrations/microsoftSqlServer.ts +++ b/packages/server/src/integrations/microsoftSqlServer.ts @@ -1,4 +1,9 @@ -import {Integration, DatasourceFieldTypes, QueryTypes, QueryJson} from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, + QueryJson, +} from "./base/definitions" module MSSQLModule { const sqlServer = require("mssql") diff --git a/packages/server/src/integrations/mongodb.ts b/packages/server/src/integrations/mongodb.ts index 0a3ebf4f63..b248be84c4 100644 --- a/packages/server/src/integrations/mongodb.ts +++ b/packages/server/src/integrations/mongodb.ts @@ -1,4 +1,8 @@ -import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, +} from "./base/definitions" module MongoDBModule { const { MongoClient } = require("mongodb") diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index 8a2f720973..31dd40bfb0 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -1,4 +1,10 @@ -import { Integration, DatasourceFieldTypes, QueryTypes, Operation, QueryJson } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, + Operation, + QueryJson, +} from "./base/definitions" module MySQLModule { const mysql = require("mysql") @@ -141,7 +147,9 @@ module MySQLModule { { sql: "SHOW TABLES;" }, false ) - const tableNames = tablesResp.map((obj: any) => obj[`Tables_in_${database}`]) + const tableNames = tablesResp.map( + (obj: any) => obj[`Tables_in_${database}`] + ) for (let tableName of tableNames) { const primaryKeys = [] const schema: any = {} diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index 4d6874df71..1b6fd47660 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -1,4 +1,9 @@ -import { Integration, DatasourceFieldTypes, QueryTypes, QueryJson } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, + QueryJson, +} from "./base/definitions" import { Table } from "../constants/definitions" module PostgresModule { @@ -8,12 +13,12 @@ module PostgresModule { const { buildExternalTableId, convertType } = require("./utils") interface PostgresConfig { - host: string, - port: number, - database: string, - user: string, - password: string, - ssl?: boolean, + host: string + port: number + database: string + user: string + password: string + ssl?: boolean } const SCHEMA: Integration = { @@ -83,7 +88,10 @@ module PostgresModule { json: FieldTypes.JSON, } - async function internalQuery(client: any, query: { sql: string, bindings?: object }) { + async function internalQuery( + client: any, + query: { sql: string; bindings?: object } + ) { try { return await client.query(query.sql, query.bindings || {}) } catch (err) { @@ -129,9 +137,11 @@ module PostgresModule { * @param {*} datasourceId - datasourceId to fetch */ async buildSchema(datasourceId: string) { - let tableKeys: { [key: string]: string[] } = {} + let tableKeys: { [key: string]: string[] } = {} try { - const primaryKeysResponse = await this.client.query(this.PRIMARY_KEYS_SQL) + const primaryKeysResponse = await this.client.query( + this.PRIMARY_KEYS_SQL + ) for (let table of primaryKeysResponse.rows) { const tableName = table.table_name if (!tableKeys[tableName]) { @@ -171,7 +181,7 @@ module PostgresModule { async create(sql: string) { const response = await internalQuery(this.client, { sql }) - return response.rows.length ? response.rows : [{created: true}] + return response.rows.length ? response.rows : [{ created: true }] } async read(sql: string) { @@ -181,19 +191,19 @@ module PostgresModule { async update(sql: string) { const response = await internalQuery(this.client, { sql }) - return response.rows.length ? response.rows : [{updated: true}] + return response.rows.length ? response.rows : [{ updated: true }] } async delete(sql: string) { const response = await internalQuery(this.client, { sql }) - return response.rows.length ? response.rows : [{deleted: true}] + return response.rows.length ? response.rows : [{ deleted: true }] } async query(json: QueryJson) { const operation = this._operation(json).toLowerCase() const input = this._query(json) const response = await internalQuery(this.client, input) - return response.rows.length ? response.rows : [{[operation]: true}] + return response.rows.length ? response.rows : [{ [operation]: true }] } } diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 6cafccf682..8b6d0e70da 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -1,12 +1,16 @@ -import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" +import { + Integration, + DatasourceFieldTypes, + QueryTypes, +} from "./base/definitions" module RestModule { const fetch = require("node-fetch") interface RestConfig { - url: string, + url: string defaultHeaders: { - [key: string]: any, + [key: string]: any } } @@ -143,7 +147,7 @@ module RestModule { return await this.parseResponse(response) } - async read({path = "", queryString = "", headers = {}}) { + async read({ path = "", queryString = "", headers = {} }) { this.headers = { ...this.config.defaultHeaders, ...headers, @@ -156,7 +160,7 @@ module RestModule { return await this.parseResponse(response) } - async update({path = "", queryString = "", headers = {}, json = {}}) { + async update({ path = "", queryString = "", headers = {}, json = {} }) { this.headers = { ...this.config.defaultHeaders, ...headers, @@ -171,7 +175,7 @@ module RestModule { return await this.parseResponse(response) } - async delete({path = "", queryString = "", headers = {}}) { + async delete({ path = "", queryString = "", headers = {} }) { this.headers = { ...this.config.defaultHeaders, ...headers, diff --git a/packages/server/src/integrations/s3.ts b/packages/server/src/integrations/s3.ts index e769020e43..58d58be443 100644 --- a/packages/server/src/integrations/s3.ts +++ b/packages/server/src/integrations/s3.ts @@ -4,9 +4,9 @@ module S3Module { const AWS = require("aws-sdk") interface S3Config { - region: string, - accessKeyId: string, - secretAccessKey: string, + region: string + accessKeyId: string + secretAccessKey: string } const SCHEMA: Integration = {