Formatting.
This commit is contained in:
parent
374081d720
commit
6cae9cbdb8
|
@ -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
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions"
|
||||
import {
|
||||
Integration,
|
||||
DatasourceFieldTypes,
|
||||
QueryTypes,
|
||||
} from "./base/definitions"
|
||||
|
||||
module AirtableModule {
|
||||
const Airtable = require("airtable")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
disableReturning?: boolean
|
||||
}
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions"
|
||||
import {
|
||||
Integration,
|
||||
DatasourceFieldTypes,
|
||||
QueryTypes,
|
||||
} from "./base/definitions"
|
||||
|
||||
module CouchDBModule {
|
||||
const PouchDB = require("pouchdb")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions"
|
||||
import {
|
||||
Integration,
|
||||
DatasourceFieldTypes,
|
||||
QueryTypes,
|
||||
} from "./base/definitions"
|
||||
|
||||
module MongoDBModule {
|
||||
const { MongoClient } = require("mongodb")
|
||||
|
|
|
@ -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 = {}
|
||||
|
|
|
@ -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 }]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in New Issue