budibase/packages/server/src/definitions/datasource.ts

288 lines
4.9 KiB
TypeScript
Raw Normal View History

import { Row, Table, Base } from "./common"
export enum Operation {
CREATE = "CREATE",
READ = "READ",
UPDATE = "UPDATE",
DELETE = "DELETE",
BULK_CREATE = "BULK_CREATE",
2021-10-28 20:39:42 +02:00
CREATE_TABLE = "CREATE_TABLE",
UPDATE_TABLE = "UPDATE_TABLE",
DELETE_TABLE = "DELETE_TABLE",
}
export enum SortDirection {
ASCENDING = "ASCENDING",
DESCENDING = "DESCENDING",
}
export enum QueryTypes {
SQL = "sql",
JSON = "json",
FIELDS = "fields",
}
export enum DatasourceFieldTypes {
STRING = "string",
LONGFORM = "longForm",
BOOLEAN = "boolean",
NUMBER = "number",
PASSWORD = "password",
LIST = "list",
OBJECT = "object",
JSON = "json",
FILE = "file",
}
export enum SourceNames {
POSTGRES = "POSTGRES",
DYNAMODB = "DYNAMODB",
MONGODB = "MONGODB",
ELASTICSEARCH = "ELASTICSEARCH",
COUCHDB = "COUCHDB",
SQL_SERVER = "SQL_SERVER",
S3 = "S3",
AIRTABLE = "AIRTABLE",
MYSQL = "MYSQL",
ARANGODB = "ARANGODB",
REST = "REST",
ORACLE = "ORACLE",
2021-11-25 18:12:12 +01:00
GOOGLE_SHEETS = "GOOGLE_SHEETS",
FIREBASE = "FIREBASE",
}
export enum IncludeRelationships {
INCLUDE = 1,
2021-09-06 17:24:51 +02:00
EXCLUDE = 0,
}
export enum FilterTypes {
STRING = "string",
FUZZY = "fuzzy",
RANGE = "range",
EQUAL = "equal",
NOT_EQUAL = "notEqual",
EMPTY = "empty",
NOT_EMPTY = "notEmpty",
ONE_OF = "oneOf",
}
export interface QueryDefinition {
2021-06-25 19:34:21 +02:00
type: QueryTypes
displayName?: string
readable?: boolean
customisable?: boolean
fields?: object
urlDisplay?: boolean
}
export interface ExtraQueryConfig {
[key: string]: {
2021-07-29 11:11:52 +02:00
displayName: string
type: string
required: boolean
data?: object
}
}
export interface Integration {
2021-06-25 19:34:21 +02:00
docs: string
plus?: boolean
2022-01-18 17:41:38 +01:00
auth?: { type: string }
2022-01-26 17:45:28 +01:00
relationships?: boolean
2021-06-25 19:34:21 +02:00
description: string
friendlyName: string
datasource: {}
query: {
2021-06-25 19:34:21 +02:00
[key: string]: QueryDefinition
}
extra?: ExtraQueryConfig
}
export interface SearchFilters {
allOr?: boolean
string?: {
2021-06-25 19:34:21 +02:00
[key: string]: string
}
fuzzy?: {
2021-06-25 19:34:21 +02:00
[key: string]: string
}
range?: {
[key: string]: {
2021-06-25 19:34:21 +02:00
high: number | string
low: number | string
}
}
equal?: {
2021-06-25 19:34:21 +02:00
[key: string]: any
}
notEqual?: {
2021-06-25 19:34:21 +02:00
[key: string]: any
}
empty?: {
2021-06-25 19:34:21 +02:00
[key: string]: any
}
notEmpty?: {
2021-06-25 19:34:21 +02:00
[key: string]: any
}
2021-07-01 15:10:44 +02:00
oneOf?: {
[key: string]: any[]
}
}
export interface SortJson {
[key: string]: SortDirection
}
export interface PaginationJson {
limit: number
page?: string | number
}
export interface RenameColumn {
old: string
updated: string
}
export interface RelationshipsJson {
through?: string
from?: string
to?: string
fromPrimary?: string
toPrimary?: string
2021-06-25 19:34:21 +02:00
tableName: string
column: string
}
export interface QueryJson {
endpoint: {
2021-06-25 19:34:21 +02:00
datasourceId: string
entityId: string
operation: Operation
schema?: string
2021-06-25 19:34:21 +02:00
}
resource: {
2021-06-25 19:34:21 +02:00
fields: string[]
}
filters?: SearchFilters
sort?: SortJson
paginate?: PaginationJson
body?: Row | Row[]
2021-10-28 20:39:42 +02:00
table?: Table
meta?: {
2021-09-27 15:57:22 +02:00
table?: Table
2021-10-28 20:39:42 +02:00
tables?: Record<string, Table>
renamed: RenameColumn
}
extra?: {
2021-06-25 19:34:21 +02:00
idFilter?: SearchFilters
}
relationships?: RelationshipsJson[]
}
export interface SqlQuery {
2021-06-25 19:34:21 +02:00
sql: string
bindings?: string[]
}
export interface QueryOptions {
2021-06-25 19:34:21 +02:00
disableReturning?: boolean
2021-06-24 19:17:26 +02:00
}
export interface Datasource extends Base {
type: string
name: string
source: SourceNames
// the config is defined by the schema
config: {
[key: string]: string | number | boolean
}
plus: boolean
entities?: {
[key: string]: Table
}
}
export enum AuthType {
BASIC = "basic",
BEARER = "bearer",
}
interface AuthConfig {
_id: string
name: string
type: AuthType
config: BasicAuthConfig | BearerAuthConfig
}
export interface BasicAuthConfig {
username: string
password: string
}
export interface BearerAuthConfig {
token: string
}
export interface QueryParameter {
name: string
default: string
}
export interface RestQueryFields {
path: string
queryString?: string
headers: { [key: string]: any }
disabledHeaders: { [key: string]: any }
requestBody: any
bodyType: string
json: object
method: string
authConfigId: string
pagination: PaginationConfig | null
paginationValues: PaginationValues | null
}
export interface RestConfig {
url: string
defaultHeaders: {
[key: string]: any
}
authConfigs: AuthConfig[]
staticVariables: {
[key: string]: string
}
dynamicVariables: [
{
name: string
queryId: string
value: string
}
]
}
export interface PaginationConfig {
type: string
location: string
pageParam: string
sizeParam: string | null
responseParam: string | null
}
export interface PaginationValues {
page: string | number | null
limit: number | null
}
export interface Query {
_id?: string
datasourceId: string
name: string
parameters: QueryParameter[]
fields: RestQueryFields | any
transformer: string | null
schema: any
readable: boolean
queryVerb: string
}