2021-04-27 12:52:26 +00:00
|
|
|
import { APIResponseError } from "api/ApiResponses";
|
2021-01-12 04:17:28 +00:00
|
|
|
import { Property } from "entities/Action";
|
|
|
|
|
import _ from "lodash";
|
|
|
|
|
export interface DatasourceAuthentication {
|
|
|
|
|
authType?: string;
|
|
|
|
|
username?: string;
|
|
|
|
|
password?: string;
|
2021-06-25 06:45:48 +00:00
|
|
|
label?: string;
|
|
|
|
|
value?: string;
|
|
|
|
|
addTo?: string;
|
|
|
|
|
bearerToken?: string;
|
2021-08-25 10:36:55 +00:00
|
|
|
authenticationStatus?: string;
|
2021-01-12 04:17:28 +00:00
|
|
|
}
|
2020-07-01 10:01:07 +00:00
|
|
|
|
2021-01-12 04:17:28 +00:00
|
|
|
export interface DatasourceColumns {
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DatasourceKeys {
|
|
|
|
|
name: string;
|
|
|
|
|
type: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DatasourceStructure {
|
|
|
|
|
tables?: DatasourceTable[];
|
2021-04-27 12:52:26 +00:00
|
|
|
error?: APIResponseError;
|
2021-01-12 04:17:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface QueryTemplate {
|
|
|
|
|
title: string;
|
|
|
|
|
body: string;
|
2021-05-19 05:35:24 +00:00
|
|
|
pluginSpecifiedTemplates?: Array<{ key?: string; value?: unknown }>;
|
2021-01-12 04:17:28 +00:00
|
|
|
}
|
|
|
|
|
export interface DatasourceTable {
|
|
|
|
|
type: string;
|
|
|
|
|
name: string;
|
|
|
|
|
columns: DatasourceColumns[];
|
|
|
|
|
keys: DatasourceKeys[];
|
|
|
|
|
templates: QueryTemplate[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// todo: check which fields are truly optional and move the common ones into base
|
|
|
|
|
interface BaseDatasource {
|
|
|
|
|
pluginId: string;
|
|
|
|
|
name: string;
|
|
|
|
|
organizationId: string;
|
|
|
|
|
isValid: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const isEmbeddedRestDatasource = (
|
|
|
|
|
val: any,
|
|
|
|
|
): val is EmbeddedRestDatasource => {
|
|
|
|
|
if (!_.isObject(val)) return false;
|
|
|
|
|
if (!("datasourceConfiguration" in val)) return false;
|
|
|
|
|
val = <EmbeddedRestDatasource>val;
|
|
|
|
|
// Object should exist and have value
|
|
|
|
|
if (!val.datasourceConfiguration) return false;
|
|
|
|
|
//url might exist as a key but not have value, so we won't check value
|
|
|
|
|
if (!("url" in val.datasourceConfiguration)) return false;
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export interface EmbeddedRestDatasource extends BaseDatasource {
|
|
|
|
|
datasourceConfiguration: { url: string };
|
|
|
|
|
invalids: Array<string>;
|
2021-04-26 12:17:38 +00:00
|
|
|
messages: Array<string>;
|
2021-01-12 04:17:28 +00:00
|
|
|
}
|
|
|
|
|
export interface Datasource extends BaseDatasource {
|
|
|
|
|
id: string;
|
|
|
|
|
datasourceConfiguration: {
|
|
|
|
|
url: string;
|
|
|
|
|
authentication?: DatasourceAuthentication;
|
2021-02-11 12:28:06 +00:00
|
|
|
properties?: Property[];
|
2021-01-12 04:17:28 +00:00
|
|
|
headers?: Property[];
|
|
|
|
|
databaseName?: string;
|
|
|
|
|
};
|
|
|
|
|
invalids?: string[];
|
|
|
|
|
structure?: DatasourceStructure;
|
2021-04-26 12:17:38 +00:00
|
|
|
messages?: string[];
|
2021-09-06 05:53:21 +00:00
|
|
|
success?: boolean;
|
2021-01-12 04:17:28 +00:00
|
|
|
}
|
2020-07-01 10:01:07 +00:00
|
|
|
|
2021-07-07 03:46:16 +00:00
|
|
|
export interface MockDatasource {
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
2021-07-08 05:59:11 +00:00
|
|
|
packageName: string;
|
|
|
|
|
pluginType: string;
|
|
|
|
|
pluginName?: string;
|
2021-07-07 03:46:16 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-03 08:58:58 +00:00
|
|
|
export const DEFAULT_DATASOURCE = (
|
|
|
|
|
pluginId: string,
|
|
|
|
|
organizationId: string,
|
2021-01-12 04:17:28 +00:00
|
|
|
): EmbeddedRestDatasource => ({
|
2020-07-01 10:01:07 +00:00
|
|
|
name: "DEFAULT_REST_DATASOURCE",
|
|
|
|
|
datasourceConfiguration: {
|
|
|
|
|
url: "",
|
|
|
|
|
},
|
|
|
|
|
invalids: [],
|
|
|
|
|
isValid: true,
|
|
|
|
|
pluginId,
|
2020-07-03 08:58:58 +00:00
|
|
|
organizationId,
|
2021-04-26 12:17:38 +00:00
|
|
|
messages: [],
|
2020-07-01 10:01:07 +00:00
|
|
|
});
|