1
0
Fork 0
mirror of synced 2024-07-01 04:21:06 +12:00

Formatting.

This commit is contained in:
mike12345567 2021-06-24 18:17:26 +01:00
parent ffc54c3720
commit aea08af49c
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, primaryDisplay?: string
sourceId?: 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) {
@ -129,9 +137,11 @@ module PostgresModule {
* @param {*} datasourceId - datasourceId to fetch * @param {*} datasourceId - datasourceId to fetch
*/ */
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]) {
@ -171,7 +181,7 @@ module PostgresModule {
async create(sql: string) { async create(sql: string) {
const response = await internalQuery(this.client, { sql }) 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) { async read(sql: string) {
@ -181,19 +191,19 @@ module PostgresModule {
async update(sql: string) { async update(sql: string) {
const response = await internalQuery(this.client, { sql }) 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) { async delete(sql: string) {
const response = await internalQuery(this.client, { sql }) 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) { async query(json: QueryJson) {
const operation = this._operation(json).toLowerCase() const operation = this._operation(json).toLowerCase()
const input = this._query(json) const input = this._query(json)
const response = await internalQuery(this.client, input) const response = await internalQuery(this.client, input)
return response.rows.length ? response.rows : [{[operation]: true}] return response.rows.length ? response.rows : [{ [operation]: true }]
} }
} }

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
} }
} }
@ -143,7 +147,7 @@ module RestModule {
return await this.parseResponse(response) return await this.parseResponse(response)
} }
async read({path = "", queryString = "", headers = {}}) { async read({ path = "", queryString = "", headers = {} }) {
this.headers = { this.headers = {
...this.config.defaultHeaders, ...this.config.defaultHeaders,
...headers, ...headers,
@ -156,7 +160,7 @@ module RestModule {
return await this.parseResponse(response) return await this.parseResponse(response)
} }
async update({path = "", queryString = "", headers = {}, json = {}}) { async update({ path = "", queryString = "", headers = {}, json = {} }) {
this.headers = { this.headers = {
...this.config.defaultHeaders, ...this.config.defaultHeaders,
...headers, ...headers,
@ -171,7 +175,7 @@ module RestModule {
return await this.parseResponse(response) return await this.parseResponse(response)
} }
async delete({path = "", queryString = "", headers = {}}) { async delete({ path = "", queryString = "", headers = {} }) {
this.headers = { this.headers = {
...this.config.defaultHeaders, ...this.config.defaultHeaders,
...headers, ...headers,

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 = {