From 62bc2f2be345296491878250f33d27ff8a876971 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 25 May 2022 10:52:19 +0100 Subject: [PATCH] Moving table, datasource and datasource plus document types into the backend core. --- packages/backend-core/src/db/constants.js | 4 ++++ packages/backend-core/src/db/utils.js | 22 ++++++++++++++++++++++ packages/server/src/db/utils.js | 6 +++--- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/packages/backend-core/src/db/constants.js b/packages/backend-core/src/db/constants.js index 271d4f412d..221f51264b 100644 --- a/packages/backend-core/src/db/constants.js +++ b/packages/backend-core/src/db/constants.js @@ -15,6 +15,10 @@ exports.DocumentTypes = { ROLE: "role", MIGRATIONS: "migrations", DEV_INFO: "devinfo", + TABLE: "ta", + ROW: "ro", + DATASOURCE: "datasource", + DATASOURCE_PLUS: "datasource_plus", } exports.StaticDatabases = { diff --git a/packages/backend-core/src/db/utils.js b/packages/backend-core/src/db/utils.js index d6eb0aa89e..7f0857acc1 100644 --- a/packages/backend-core/src/db/utils.js +++ b/packages/backend-core/src/db/utils.js @@ -79,6 +79,28 @@ function getDocParams(docType, docId = null, otherProps = {}) { } exports.getDocParams = getDocParams +/** + * Check if a given ID is that of a table. + * @returns {boolean} + */ +exports.isTableId = id => { + // this includes datasource plus tables + return ( + id && + (id.startsWith(`${DocumentTypes.TABLE}${SEPARATOR}`) || + id.startsWith(`${DocumentTypes.DATASOURCE_PLUS}${SEPARATOR}`)) + ) +} + +/** + * Check if a given ID is that of a datasource or datasource plus. + * @returns {boolean} + */ +exports.isDatasourceId = id => { + // this covers both datasources and datasource plus + return id && id.startsWith(`${DocumentTypes.DATASOURCE}${SEPARATOR}`) +} + /** * Generates a new workspace ID. * @returns {string} The new workspace ID which the workspace doc can be stored under. diff --git a/packages/server/src/db/utils.js b/packages/server/src/db/utils.js index 280596928b..d1ea6a4ebd 100644 --- a/packages/server/src/db/utils.js +++ b/packages/server/src/db/utils.js @@ -27,7 +27,9 @@ const DocumentTypes = { APP_DEV: CoreDocTypes.APP_DEV, APP_METADATA: CoreDocTypes.APP_METADATA, ROLE: CoreDocTypes.ROLE, - TABLE: "ta", + TABLE: CoreDocTypes.TABLE, + DATASOURCE: CoreDocTypes.DATASOURCE, + DATASOURCE_PLUS: CoreDocTypes.DATASOURCE_PLUS, ROW: "ro", USER: "us", AUTOMATION: "au", @@ -36,8 +38,6 @@ const DocumentTypes = { INSTANCE: "inst", LAYOUT: "layout", SCREEN: "screen", - DATASOURCE: "datasource", - DATASOURCE_PLUS: "datasource_plus", QUERY: "query", DEPLOYMENTS: "deployments", METADATA: "metadata",