Formatting.

This commit is contained in:
mike12345567 2021-06-24 18:17:26 +01:00
parent 374081d720
commit 6cae9cbdb8
14 changed files with 164 additions and 103 deletions

View File

@ -1,29 +1,28 @@
export interface Table { export interface Table {
_id: string, _id: string
_rev?: string, _rev?: string
type?: string, type?: string
views?: {}, views?: {}
name?: string, name?: string
primary?: string[], primary?: string[]
schema: { schema: {
[key: string]: { [key: string]: {
// TODO: replace with field types enum when done // TODO: replace with field types enum when done
type: string, type: string
fieldName?: string, fieldName?: string
name: string, name: string
constraints?: { constraints?: {
type?: string, type?: string
email?: boolean, email?: boolean
inclusion?: string[], inclusion?: string[]
length?: { length?: {
minimum?: string | number, minimum?: string | number
maximum?: string | number, maximum?: string | number
},
presence?: boolean,
},
} }
}, presence?: boolean
primaryDisplay?: string, }
sourceId?: string, }
}
primaryDisplay?: string
sourceId?: string
} }

View File

@ -1,4 +1,8 @@
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
} from "./base/definitions"
module AirtableModule { module AirtableModule {
const Airtable = require("airtable") const Airtable = require("airtable")

View File

@ -1,4 +1,8 @@
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
} from "./base/definitions"
module ArangoModule { module ArangoModule {
const { Database, aql } = require("arangojs") const { Database, aql } = require("arangojs")

View File

@ -27,76 +27,76 @@ export enum DatasourceFieldTypes {
} }
export interface QueryDefinition { export interface QueryDefinition {
type: QueryTypes, type: QueryTypes
displayName?: string, displayName?: string
readable?: boolean, readable?: boolean
customisable?: boolean, customisable?: boolean
fields?: object, fields?: object
urlDisplay?: boolean, urlDisplay?: boolean
} }
export interface Integration { export interface Integration {
docs: string, docs: string
plus?: boolean, plus?: boolean
description: string, description: string
friendlyName: string, friendlyName: string
datasource: {}, datasource: {}
query: { query: {
[key: string]: QueryDefinition, [key: string]: QueryDefinition
} }
} }
export interface SearchFilters { export interface SearchFilters {
allOr: boolean, allOr: boolean
string?: { string?: {
[key: string]: string, [key: string]: string
}, }
fuzzy?: { fuzzy?: {
[key: string]: string, [key: string]: string
}, }
range?: { range?: {
[key: string]: { [key: string]: {
high: number | string, high: number | string
low: number | string, low: number | string
}, }
}, }
equal?: { equal?: {
[key: string]: any, [key: string]: any
}, }
notEqual?: { notEqual?: {
[key: string]: any, [key: string]: any
}, }
empty?: { empty?: {
[key: string]: any, [key: string]: any
}, }
notEmpty?: { notEmpty?: {
[key: string]: any, [key: string]: any
}, }
} }
export interface QueryJson { export interface QueryJson {
endpoint: { endpoint: {
datasourceId: string, datasourceId: string
entityId: string, entityId: string
operation: Operation, operation: Operation
}, }
resource: { resource: {
fields: string[], fields: string[]
}, }
filters?: SearchFilters, filters?: SearchFilters
sort?: { sort?: {
[key: string]: SortDirection, [key: string]: SortDirection
}, }
paginate?: { paginate?: {
limit: number, limit: number
page: string | number, page: string | number
}, }
body?: object, body?: object
extra: { extra: {
idFilter?: SearchFilters, idFilter?: SearchFilters
}, }
} }
export interface QueryOptions { export interface QueryOptions {
disableReturning?: boolean, disableReturning?: boolean
} }

View File

@ -1,10 +1,21 @@
import { Knex, knex } from "knex" import { Knex, knex } from "knex"
const BASE_LIMIT = 5000 const BASE_LIMIT = 5000
import { QueryJson, SearchFilters, QueryOptions, SortDirection, Operation } from "./definitions" import {
QueryJson,
SearchFilters,
QueryOptions,
SortDirection,
Operation,
} from "./definitions"
function addFilters(
function addFilters(query: any, filters: SearchFilters | undefined): Knex.QueryBuilder { query: any,
function iterate(structure: { [key: string]: any }, fn: (key: string, value: any) => void) { 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)) { for (let [key, value] of Object.entries(structure)) {
fn(key, value) fn(key, value)
} }

View File

@ -1,4 +1,8 @@
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
} from "./base/definitions"
module CouchDBModule { module CouchDBModule {
const PouchDB = require("pouchdb") const PouchDB = require("pouchdb")

View File

@ -1,4 +1,8 @@
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
} from "./base/definitions"
module DynamoModule { module DynamoModule {
const AWS = require("aws-sdk") const AWS = require("aws-sdk")

View File

@ -1,4 +1,8 @@
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
} from "./base/definitions"
module ElasticsearchModule { module ElasticsearchModule {
const { Client } = require("@elastic/elasticsearch") const { Client } = require("@elastic/elasticsearch")

View File

@ -1,4 +1,9 @@
import {Integration, DatasourceFieldTypes, QueryTypes, QueryJson} from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
QueryJson,
} from "./base/definitions"
module MSSQLModule { module MSSQLModule {
const sqlServer = require("mssql") const sqlServer = require("mssql")

View File

@ -1,4 +1,8 @@
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
} from "./base/definitions"
module MongoDBModule { module MongoDBModule {
const { MongoClient } = require("mongodb") const { MongoClient } = require("mongodb")

View File

@ -1,4 +1,10 @@
import { Integration, DatasourceFieldTypes, QueryTypes, Operation, QueryJson } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
Operation,
QueryJson,
} from "./base/definitions"
module MySQLModule { module MySQLModule {
const mysql = require("mysql") const mysql = require("mysql")
@ -141,7 +147,9 @@ module MySQLModule {
{ sql: "SHOW TABLES;" }, { sql: "SHOW TABLES;" },
false 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) { for (let tableName of tableNames) {
const primaryKeys = [] const primaryKeys = []
const schema: any = {} const schema: any = {}

View File

@ -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" import { Table } from "../constants/definitions"
module PostgresModule { module PostgresModule {
@ -8,12 +13,12 @@ module PostgresModule {
const { buildExternalTableId, convertType } = require("./utils") const { buildExternalTableId, convertType } = require("./utils")
interface PostgresConfig { interface PostgresConfig {
host: string, host: string
port: number, port: number
database: string, database: string
user: string, user: string
password: string, password: string
ssl?: boolean, ssl?: boolean
} }
const SCHEMA: Integration = { const SCHEMA: Integration = {
@ -83,7 +88,10 @@ module PostgresModule {
json: FieldTypes.JSON, json: FieldTypes.JSON,
} }
async function internalQuery(client: any, query: { sql: string, bindings?: object }) { async function internalQuery(
client: any,
query: { sql: string; bindings?: object }
) {
try { try {
return await client.query(query.sql, query.bindings || {}) return await client.query(query.sql, query.bindings || {})
} catch (err) { } catch (err) {
@ -131,7 +139,9 @@ module PostgresModule {
async buildSchema(datasourceId: string) { async buildSchema(datasourceId: string) {
let tableKeys: { [key: string]: string[] } = {} let tableKeys: { [key: string]: string[] } = {}
try { 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) { for (let table of primaryKeysResponse.rows) {
const tableName = table.table_name const tableName = table.table_name
if (!tableKeys[tableName]) { if (!tableKeys[tableName]) {

View File

@ -1,12 +1,16 @@
import { Integration, DatasourceFieldTypes, QueryTypes } from "./base/definitions" import {
Integration,
DatasourceFieldTypes,
QueryTypes,
} from "./base/definitions"
module RestModule { module RestModule {
const fetch = require("node-fetch") const fetch = require("node-fetch")
interface RestConfig { interface RestConfig {
url: string, url: string
defaultHeaders: { defaultHeaders: {
[key: string]: any, [key: string]: any
} }
} }

View File

@ -4,9 +4,9 @@ module S3Module {
const AWS = require("aws-sdk") const AWS = require("aws-sdk")
interface S3Config { interface S3Config {
region: string, region: string
accessKeyId: string, accessKeyId: string
secretAccessKey: string, secretAccessKey: string
} }
const SCHEMA: Integration = { const SCHEMA: Integration = {