diff --git a/packages/server/src/definitions/common.ts b/packages/server/src/definitions/common.ts index f7e5a9a049..cdbe82344f 100644 --- a/packages/server/src/definitions/common.ts +++ b/packages/server/src/definitions/common.ts @@ -1,70 +1,10 @@ export { Query, Datasource } from "./datasource" +export { FieldSchema, TableSchema, Table, Document, Row } from "@budibase/types" -export interface Base { - _id?: string - _rev?: string -} - -export interface Application extends Base { +export interface Application extends Document { appId?: string } -export interface FieldSchema { - // TODO: replace with field types enum when done - type: string - externalType?: string - fieldName?: string - name: string - tableId?: string - relationshipType?: string - through?: string - foreignKey?: string - autocolumn?: boolean - subtype?: string - throughFrom?: string - throughTo?: string - formula?: string - formulaType?: string - main?: boolean - ignoreTimezones?: boolean - meta?: { - toTable: string - toKey: string - } - constraints?: { - type?: string - email?: boolean - inclusion?: string[] - length?: { - minimum?: string | number - maximum?: string | number - } - presence?: boolean - } -} - -export interface TableSchema { - [key: string]: FieldSchema -} - -export interface Table extends Base { - type?: string - views?: {} - name: string - primary?: string[] - schema: TableSchema - primaryDisplay?: string - sourceId?: string - relatedFormula?: string[] - constrained?: string[] -} - -export interface Row extends Base { - type?: string - tableId?: string - [key: string]: any -} - interface JsonSchemaField { properties: { [key: string]: { @@ -94,7 +34,7 @@ export interface AutomationStep { type: string } -export interface Automation extends Base { +export interface Automation extends Document { name: string type: string appId?: string diff --git a/packages/server/src/definitions/datasource.ts b/packages/server/src/definitions/datasource.ts index 9752fc947a..ff4f5e9f5b 100644 --- a/packages/server/src/definitions/datasource.ts +++ b/packages/server/src/definitions/datasource.ts @@ -1,214 +1,42 @@ -import { Row, Table, Base } from "./common" +import { SortDirection, Operation, SourceNames } from "@budibase/types" +// export everything that used to be exported from here +export { + Operation, + SortDirection, + QueryTypes, + DatasourceFieldTypes, + SourceNames, + IncludeRelationships, + FilterTypes, + QueryDefinition, + ExtraQueryConfig, + Integration, + IntegrationBase, + QueryParameter, + PaginationConfig, + PaginationValues, + RestQueryFields, + Query, + Datasource, + SearchFilters, + SortJson, + PaginationJson, + RenameColumn, + RelationshipsJson, + QueryJson, + SqlQuery, +} from "@budibase/types" -export enum Operation { - CREATE = "CREATE", - READ = "READ", - UPDATE = "UPDATE", - DELETE = "DELETE", - BULK_CREATE = "BULK_CREATE", - 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", - GOOGLE_SHEETS = "GOOGLE_SHEETS", - FIRESTORE = "FIRESTORE", - REDIS = "REDIS", - SNOWFLAKE = "SNOWFLAKE", -} - -export enum IncludeRelationships { - INCLUDE = 1, - 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 { - type: QueryTypes - displayName?: string - readable?: boolean - customisable?: boolean - fields?: object - urlDisplay?: boolean -} - -export interface ExtraQueryConfig { - [key: string]: { - displayName: string - type: string - required: boolean - data?: object - } -} - -export interface Integration { - docs: string - plus?: boolean - auth?: { type: string } - relationships?: boolean - description: string - friendlyName: string - type?: string - datasource: {} - query: { - [key: string]: QueryDefinition - } - extra?: ExtraQueryConfig -} - -export interface SearchFilters { - allOr?: boolean - string?: { - [key: string]: string - } - fuzzy?: { - [key: string]: string - } - range?: { - [key: string]: { - high: number | string - low: number | string - } - } - equal?: { - [key: string]: any - } - notEqual?: { - [key: string]: any - } - empty?: { - [key: string]: any - } - notEmpty?: { - [key: string]: any - } - oneOf?: { - [key: string]: any[] - } - contains?: { - [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 - tableName: string - column: string -} - -export interface QueryJson { - endpoint: { - datasourceId: string - entityId: string - operation: Operation - schema?: string - } - resource: { - fields: string[] - } - filters?: SearchFilters - sort?: SortJson - paginate?: PaginationJson - body?: Row | Row[] - table?: Table - meta?: { - table?: Table - tables?: Record - renamed: RenameColumn - } - extra?: { - idFilter?: SearchFilters - } - relationships?: RelationshipsJson[] -} - -export interface SqlQuery { - sql: string - bindings?: string[] -} +/******************************************** + * This file contains structures which are * + * internal to the server and don't need to * + * be exposed for use by other services. * + ********************************************/ export interface QueryOptions { disableReturning?: boolean } -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", @@ -230,25 +58,6 @@ 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: { @@ -266,28 +75,3 @@ export interface RestConfig { } ] } - -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 -} diff --git a/packages/server/src/integrations/airtable.ts b/packages/server/src/integrations/airtable.ts index eaf4317953..199741b312 100644 --- a/packages/server/src/integrations/airtable.ts +++ b/packages/server/src/integrations/airtable.ts @@ -2,8 +2,8 @@ import { Integration, DatasourceFieldTypes, QueryTypes, -} from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" + IntegrationBase, +} from "@budibase/types" module AirtableModule { const Airtable = require("airtable") diff --git a/packages/server/src/integrations/arangodb.ts b/packages/server/src/integrations/arangodb.ts index e6e2c0db35..682b941b23 100644 --- a/packages/server/src/integrations/arangodb.ts +++ b/packages/server/src/integrations/arangodb.ts @@ -2,8 +2,8 @@ import { Integration, DatasourceFieldTypes, QueryTypes, -} from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" + IntegrationBase, +} from "@budibase/types" module ArangoModule { const { Database, aql } = require("arangojs") diff --git a/packages/server/src/integrations/base/IntegrationBase.ts b/packages/server/src/integrations/base/IntegrationBase.ts deleted file mode 100644 index bfda4fbd4d..0000000000 --- a/packages/server/src/integrations/base/IntegrationBase.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface IntegrationBase { - create?(query: any): Promise - read?(query: any): Promise - update?(query: any): Promise - delete?(query: any): Promise -} diff --git a/packages/server/src/integrations/base/datasourcePlus.ts b/packages/server/src/integrations/base/datasourcePlus.ts deleted file mode 100644 index f55dcf0f9a..0000000000 --- a/packages/server/src/integrations/base/datasourcePlus.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Table } from "../../definitions/common" -import { IntegrationBase } from "./IntegrationBase" - -export interface DatasourcePlus extends IntegrationBase { - tables: Record - schemaErrors: Record - - // if the datasource supports the use of bindings directly (to protect against SQL injection) - // this returns the format of the identifier - getBindingIdentifier(): string - getStringConcat(parts: string[]): string - buildSchema(datasourceId: string, entities: Record): any -} diff --git a/packages/server/src/integrations/couchdb.ts b/packages/server/src/integrations/couchdb.ts index 6d33658988..d32415ca29 100644 --- a/packages/server/src/integrations/couchdb.ts +++ b/packages/server/src/integrations/couchdb.ts @@ -2,8 +2,8 @@ import { Integration, DatasourceFieldTypes, QueryTypes, -} from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" + IntegrationBase, +} from "@budibase/types" module CouchDBModule { const PouchDB = require("pouchdb") diff --git a/packages/server/src/integrations/dynamodb.ts b/packages/server/src/integrations/dynamodb.ts index f06bba02e9..28e163a8aa 100644 --- a/packages/server/src/integrations/dynamodb.ts +++ b/packages/server/src/integrations/dynamodb.ts @@ -2,8 +2,8 @@ import { Integration, DatasourceFieldTypes, QueryTypes, -} from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" + IntegrationBase, +} from "@budibase/types" module DynamoModule { const AWS = require("aws-sdk") diff --git a/packages/server/src/integrations/elasticsearch.ts b/packages/server/src/integrations/elasticsearch.ts index eb27966df0..a2b90b4b87 100644 --- a/packages/server/src/integrations/elasticsearch.ts +++ b/packages/server/src/integrations/elasticsearch.ts @@ -2,8 +2,8 @@ import { Integration, DatasourceFieldTypes, QueryTypes, -} from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" + IntegrationBase, +} from "@budibase/types" module ElasticsearchModule { const { Client } = require("@elastic/elasticsearch") diff --git a/packages/server/src/integrations/firebase.ts b/packages/server/src/integrations/firebase.ts index c0f5d3c798..572514f739 100644 --- a/packages/server/src/integrations/firebase.ts +++ b/packages/server/src/integrations/firebase.ts @@ -2,8 +2,8 @@ import { DatasourceFieldTypes, Integration, QueryTypes, -} from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" + IntegrationBase, +} from "@budibase/types" import { Firestore, WhereFilterOp } from "@google-cloud/firestore" module Firebase { diff --git a/packages/server/src/integrations/googlesheets.ts b/packages/server/src/integrations/googlesheets.ts index d2562ddccf..644b8d352f 100644 --- a/packages/server/src/integrations/googlesheets.ts +++ b/packages/server/src/integrations/googlesheets.ts @@ -1,12 +1,13 @@ import { DatasourceFieldTypes, Integration, - QueryJson, QueryTypes, -} from "../definitions/datasource" + Table, + TableSchema, + QueryJson, + DatasourcePlus, +} from "@budibase/types" import { OAuth2Client } from "google-auth-library" -import { DatasourcePlus } from "./base/datasourcePlus" -import { Table, TableSchema } from "../definitions/common" import { buildExternalTableId } from "./utils" import { DataSourceOperation, FieldTypes } from "../constants" import { GoogleSpreadsheet } from "google-spreadsheet" diff --git a/packages/server/src/integrations/microsoftSqlServer.ts b/packages/server/src/integrations/microsoftSqlServer.ts index 1e5664748d..67b2b0cfe2 100644 --- a/packages/server/src/integrations/microsoftSqlServer.ts +++ b/packages/server/src/integrations/microsoftSqlServer.ts @@ -2,10 +2,13 @@ import { DatasourceFieldTypes, Integration, Operation, + Table, + TableSchema, QueryJson, QueryTypes, SqlQuery, -} from "../definitions/datasource" + DatasourcePlus, +} from "@budibase/types" import { getSqlQuery, buildExternalTableId, @@ -13,8 +16,6 @@ import { finaliseExternalTables, SqlClients, } from "./utils" -import { DatasourcePlus } from "./base/datasourcePlus" -import { Table, TableSchema } from "../definitions/common" module MSSQLModule { const sqlServer = require("mssql") diff --git a/packages/server/src/integrations/mongodb.ts b/packages/server/src/integrations/mongodb.ts index 802696ff40..b387bb80d8 100644 --- a/packages/server/src/integrations/mongodb.ts +++ b/packages/server/src/integrations/mongodb.ts @@ -2,8 +2,8 @@ import { Integration, DatasourceFieldTypes, QueryTypes, -} from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" + IntegrationBase, +} from "@budibase/types" import { MongoClient, ObjectID, diff --git a/packages/server/src/integrations/mysql.ts b/packages/server/src/integrations/mysql.ts index 1fdab66701..740bd4f2d6 100644 --- a/packages/server/src/integrations/mysql.ts +++ b/packages/server/src/integrations/mysql.ts @@ -4,8 +4,10 @@ import { QueryTypes, QueryJson, SqlQuery, -} from "../definitions/datasource" -import { Table, TableSchema } from "../definitions/common" + Table, + TableSchema, + DatasourcePlus, +} from "@budibase/types" import { getSqlQuery, SqlClients, @@ -13,7 +15,6 @@ import { convertSqlType, finaliseExternalTables, } from "./utils" -import { DatasourcePlus } from "./base/datasourcePlus" import dayjs from "dayjs" const { NUMBER_REGEX } = require("../utilities") diff --git a/packages/server/src/integrations/oracle.ts b/packages/server/src/integrations/oracle.ts index ab742d9009..1d96f5c44f 100644 --- a/packages/server/src/integrations/oracle.ts +++ b/packages/server/src/integrations/oracle.ts @@ -5,7 +5,9 @@ import { QueryJson, QueryTypes, SqlQuery, -} from "../definitions/datasource" + Table, + DatasourcePlus, +} from "@budibase/types" import { buildExternalTableId, convertSqlType, @@ -21,8 +23,6 @@ import oracledb, { Result, } from "oracledb" import Sql from "./base/sql" -import { Table } from "../definitions/common" -import { DatasourcePlus } from "./base/datasourcePlus" import { FieldTypes } from "../constants" module OracleModule { diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index 7cc01bdc79..58e6e8c214 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -4,8 +4,9 @@ import { QueryTypes, QueryJson, SqlQuery, -} from "../definitions/datasource" -import { Table } from "../definitions/common" + Table, + DatasourcePlus, +} from "@budibase/types" import { getSqlQuery, buildExternalTableId, @@ -13,7 +14,6 @@ import { finaliseExternalTables, SqlClients, } from "./utils" -import { DatasourcePlus } from "./base/datasourcePlus" module PostgresModule { const { Client, types } = require("pg") diff --git a/packages/server/src/integrations/queries/sql.ts b/packages/server/src/integrations/queries/sql.ts index 271a414d44..6e66114ec2 100644 --- a/packages/server/src/integrations/queries/sql.ts +++ b/packages/server/src/integrations/queries/sql.ts @@ -1,6 +1,5 @@ import { findHBSBlocks, processStringSync } from "@budibase/string-templates" -import { Integration } from "../../definitions/datasource" -import { DatasourcePlus } from "../base/datasourcePlus" +import { DatasourcePlus } from "@budibase/types" const CONST_CHAR_REGEX = new RegExp("'[^']*'", "g") diff --git a/packages/server/src/integrations/redis.ts b/packages/server/src/integrations/redis.ts index a1a9804cc0..92e245011f 100644 --- a/packages/server/src/integrations/redis.ts +++ b/packages/server/src/integrations/redis.ts @@ -1,8 +1,4 @@ -import { - DatasourceFieldTypes, - Integration, - QueryTypes, -} from "../definitions/datasource" +import { DatasourceFieldTypes, Integration, QueryTypes } from "@budibase/types" import Redis from "ioredis" module RedisModule { diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 9cc8e1a841..87ed374aef 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -2,15 +2,17 @@ import { Integration, DatasourceFieldTypes, QueryTypes, + PaginationConfig, + IntegrationBase, + PaginationValues, +} from "@budibase/types" +import { RestConfig, RestQueryFields as RestQuery, - PaginationConfig, AuthType, BasicAuthConfig, BearerAuthConfig, - PaginationValues, } from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" import { get } from "lodash" const BodyTypes = { diff --git a/packages/server/src/integrations/s3.ts b/packages/server/src/integrations/s3.ts index 12371e703f..e92eaf9417 100644 --- a/packages/server/src/integrations/s3.ts +++ b/packages/server/src/integrations/s3.ts @@ -1,5 +1,4 @@ -import { Integration, QueryTypes } from "../definitions/datasource" -import { IntegrationBase } from "./base/IntegrationBase" +import { Integration, QueryTypes, IntegrationBase } from "@budibase/types" module S3Module { const AWS = require("aws-sdk") diff --git a/packages/server/src/integrations/snowflake.ts b/packages/server/src/integrations/snowflake.ts index 5e04e858e5..82f26e733a 100644 --- a/packages/server/src/integrations/snowflake.ts +++ b/packages/server/src/integrations/snowflake.ts @@ -1,4 +1,4 @@ -import { Integration, QueryTypes, SqlQuery } from "../definitions/datasource" +import { Integration, QueryTypes, SqlQuery } from "@budibase/types" import { Snowflake } from "snowflake-promise" module SnowflakeModule { diff --git a/packages/types/src/documents/app/datasource.ts b/packages/types/src/documents/app/datasource.ts index 3a8704a0a9..68f84e4b98 100644 --- a/packages/types/src/documents/app/datasource.ts +++ b/packages/types/src/documents/app/datasource.ts @@ -1,5 +1,17 @@ import { Document } from "../document" +import { SourceNames } from "../../sdk" +import { Table } from "./table" export interface Datasource extends Document { - source: string + 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 + } } diff --git a/packages/types/src/documents/app/row.ts b/packages/types/src/documents/app/row.ts index d053d3d938..41ad1b1449 100644 --- a/packages/types/src/documents/app/row.ts +++ b/packages/types/src/documents/app/row.ts @@ -1,3 +1,23 @@ import { Document } from "../document" -export interface Row extends Document {} +export enum FieldTypes { + STRING = "string", + LONGFORM = "longform", + OPTIONS = "options", + NUMBER = "number", + BOOLEAN = "boolean", + ARRAY = "array", + DATETIME = "datetime", + ATTACHMENT = "attachment", + LINK = "link", + FORMULA = "formula", + AUTO = "auto", + JSON = "json", + INTERNAL = "internal", +} + +export interface Row extends Document { + type?: string + tableId?: string + [key: string]: any +} diff --git a/packages/types/src/documents/app/table.ts b/packages/types/src/documents/app/table.ts index 4ee7afd03c..72cff4f056 100644 --- a/packages/types/src/documents/app/table.ts +++ b/packages/types/src/documents/app/table.ts @@ -1,6 +1,52 @@ import { Document } from "../document" import { View } from "./view" -export interface Table extends Document { - views: { [key: string]: View } +export interface FieldSchema { + // TODO: replace with field types enum when done + type: string + externalType?: string + fieldName?: string + name: string + tableId?: string + relationshipType?: string + through?: string + foreignKey?: string + autocolumn?: boolean + subtype?: string + throughFrom?: string + throughTo?: string + formula?: string + formulaType?: string + main?: boolean + ignoreTimezones?: boolean + meta?: { + toTable: string + toKey: string + } + constraints?: { + type?: string + email?: boolean + inclusion?: string[] + length?: { + minimum?: string | number + maximum?: string | number + } + presence?: boolean + } +} + +export interface TableSchema { + [key: string]: FieldSchema +} + +export interface Table extends Document { + type?: string + views?: { [key: string]: View } + name: string + primary?: string[] + schema: TableSchema + primaryDisplay?: string + sourceId?: string + relatedFormula?: string[] + constrained?: string[] } diff --git a/packages/types/src/sdk/datasources.ts b/packages/types/src/sdk/datasources.ts new file mode 100644 index 0000000000..6e2f158c09 --- /dev/null +++ b/packages/types/src/sdk/datasources.ts @@ -0,0 +1,121 @@ +import { Table } from "../documents" + +export enum Operation { + CREATE = "CREATE", + READ = "READ", + UPDATE = "UPDATE", + DELETE = "DELETE", + BULK_CREATE = "BULK_CREATE", + 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", + GOOGLE_SHEETS = "GOOGLE_SHEETS", + FIRESTORE = "FIRESTORE", + REDIS = "REDIS", + SNOWFLAKE = "SNOWFLAKE", +} + +export enum IncludeRelationships { + INCLUDE = 1, + 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 { + type: QueryTypes + displayName?: string + readable?: boolean + customisable?: boolean + fields?: object + urlDisplay?: boolean +} + +export interface ExtraQueryConfig { + [key: string]: { + displayName: string + type: string + required: boolean + data?: object + } +} + +export interface Integration { + docs: string + plus?: boolean + auth?: { type: string } + relationships?: boolean + description: string + friendlyName: string + type?: string + datasource: {} + query: { + [key: string]: QueryDefinition + } + extra?: ExtraQueryConfig +} + +export interface IntegrationBase { + create?(query: any): Promise + read?(query: any): Promise + update?(query: any): Promise + delete?(query: any): Promise +} + +export interface DatasourcePlus extends IntegrationBase { + tables: Record + schemaErrors: Record + + // if the datasource supports the use of bindings directly (to protect against SQL injection) + // this returns the format of the identifier + getBindingIdentifier(): string + getStringConcat(parts: string[]): string + buildSchema(datasourceId: string, entities: Record): any +} diff --git a/packages/types/src/sdk/index.ts b/packages/types/src/sdk/index.ts index 0f2eee6e13..d6ca92f607 100644 --- a/packages/types/src/sdk/index.ts +++ b/packages/types/src/sdk/index.ts @@ -3,3 +3,5 @@ export * from "./context" export * from "./events" export * from "./licensing" export * from "./migrations" +export * from "./datasources" +export * from "./search" diff --git a/packages/types/src/sdk/search.ts b/packages/types/src/sdk/search.ts new file mode 100644 index 0000000000..6721fe6b55 --- /dev/null +++ b/packages/types/src/sdk/search.ts @@ -0,0 +1,91 @@ +import { Operation, SortDirection } from "./datasources" +import { Row, Table } from "../documents" + +export interface SearchFilters { + allOr?: boolean + string?: { + [key: string]: string + } + fuzzy?: { + [key: string]: string + } + range?: { + [key: string]: { + high: number | string + low: number | string + } + } + equal?: { + [key: string]: any + } + notEqual?: { + [key: string]: any + } + empty?: { + [key: string]: any + } + notEmpty?: { + [key: string]: any + } + oneOf?: { + [key: string]: any[] + } + contains?: { + [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 + tableName: string + column: string +} + +export interface QueryJson { + endpoint: { + datasourceId: string + entityId: string + operation: Operation + schema?: string + } + resource: { + fields: string[] + } + filters?: SearchFilters + sort?: SortJson + paginate?: PaginationJson + body?: Row | Row[] + table?: Table + meta?: { + table?: Table + tables?: Record + renamed: RenameColumn + } + extra?: { + idFilter?: SearchFilters + } + relationships?: RelationshipsJson[] +} + +export interface SqlQuery { + sql: string + bindings?: string[] +}