@budibase/server 0.9.188 → 0.9.190-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +7 -1
- package/__mocks__/mssql.ts +1 -1
- package/__mocks__/oracledb.ts +31 -0
- package/__mocks__/pg.ts +3 -0
- package/builder/assets/bb-space-man.5be51a45.svg +290 -0
- package/builder/assets/index.7d405e74.css +1 -0
- package/builder/assets/index.edea4fa5.js +1316 -0
- package/builder/assets/oracle.66592424.png +0 -0
- package/builder/assets/vendor.470042a4.js +152 -0
- package/builder/assets/vendor.5e1fe644.css +1 -0
- package/builder/index.html +4 -4
- package/coverage/clover.xml +1507 -1081
- package/coverage/coverage-final.json +93 -89
- package/coverage/lcov-report/api/controllers/analytics.js.html +2 -2
- package/coverage/lcov-report/api/controllers/apikeys.js.html +2 -2
- package/coverage/lcov-report/api/controllers/application.js.html +64 -13
- package/coverage/lcov-report/api/controllers/auth.js.html +19 -10
- package/coverage/lcov-report/api/controllers/automation.js.html +3 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +232 -28
- package/coverage/lcov-report/api/controllers/dev.js.html +16 -7
- package/coverage/lcov-report/api/controllers/hosting.js.html +10 -10
- package/coverage/lcov-report/api/controllers/index.html +91 -91
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +3 -3
- package/coverage/lcov-report/api/controllers/metadata.js.html +3 -3
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
- package/coverage/lcov-report/api/controllers/query.js.html +53 -209
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +3 -3
- package/coverage/lcov-report/api/controllers/row/external.js.html +17 -8
- package/coverage/lcov-report/api/controllers/row/index.html +26 -26
- package/coverage/lcov-report/api/controllers/row/index.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/internal.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/utils.js.html +21 -30
- package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
- package/coverage/lcov-report/api/controllers/script.js.html +3 -3
- package/coverage/lcov-report/api/controllers/table/external.js.html +1001 -0
- package/coverage/lcov-report/api/controllers/table/index.html +56 -26
- package/coverage/lcov-report/api/controllers/table/index.js.html +80 -350
- package/coverage/lcov-report/api/controllers/table/internal.js.html +545 -0
- package/coverage/lcov-report/api/controllers/table/utils.js.html +175 -52
- package/coverage/lcov-report/api/controllers/templates.js.html +4 -4
- package/coverage/lcov-report/api/controllers/user.js.html +390 -33
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +19 -4
- package/coverage/lcov-report/api/controllers/view/index.html +22 -22
- package/coverage/lcov-report/api/controllers/view/index.js.html +52 -13
- package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -3
- package/coverage/lcov-report/api/controllers/webhook.js.html +4 -4
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +2 -2
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +4 -4
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +5 -2
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +2 -2
- package/coverage/lcov-report/api/routes/table.js.html +35 -2
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +17 -2
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +2 -2
- package/coverage/lcov-report/automations/automationUtils.js.html +4 -4
- package/coverage/lcov-report/automations/bullboard.js.html +71 -20
- package/coverage/lcov-report/automations/index.html +35 -50
- package/coverage/lcov-report/automations/index.js.html +2 -2
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +3 -3
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -3
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +14 -14
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +3 -3
- package/coverage/lcov-report/automations/steps/queryRows.js.html +3 -3
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +7 -7
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +22 -10
- package/coverage/lcov-report/automations/utils.js.html +42 -12
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +87 -21
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/client.js.html +2 -2
- package/coverage/lcov-report/db/inMemoryView.js.html +2 -2
- package/coverage/lcov-report/db/index.html +2 -2
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +6 -6
- package/coverage/lcov-report/db/linkedRows/index.html +10 -10
- package/coverage/lcov-report/db/linkedRows/index.js.html +5 -5
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +6 -6
- package/coverage/lcov-report/db/newid.js.html +3 -3
- package/coverage/lcov-report/db/utils.js.html +57 -57
- package/coverage/lcov-report/events/AutomationEmitter.js.html +6 -6
- package/coverage/lcov-report/events/index.html +6 -6
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +5 -5
- package/coverage/lcov-report/index.html +106 -91
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +2 -2
- package/coverage/lcov-report/middleware/authorized.js.html +11 -8
- package/coverage/lcov-report/middleware/builder.js.html +16 -7
- package/coverage/lcov-report/middleware/currentapp.js.html +6 -6
- package/coverage/lcov-report/middleware/index.html +23 -23
- package/coverage/lcov-report/middleware/joi-validator.js.html +2 -2
- package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
- package/coverage/lcov-report/middleware/selfhost.js.html +2 -2
- package/coverage/lcov-report/middleware/usageQuota.js.html +4 -4
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/{automations/thread.js.html → threads/automation.js.html} +90 -33
- package/coverage/lcov-report/threads/index.html +141 -0
- package/coverage/lcov-report/threads/index.js.html +278 -0
- package/coverage/lcov-report/threads/query.js.html +278 -0
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +144 -15
- package/coverage/lcov-report/utilities/global.js.html +26 -11
- package/coverage/lcov-report/utilities/index.html +48 -48
- package/coverage/lcov-report/utilities/index.js.html +47 -14
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +30 -9
- package/coverage/lcov-report/utilities/queue/index.html +14 -14
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +4 -4
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +2 -2
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +3 -3
- package/coverage/lcov-report/utilities/scriptRunner.js.html +16 -7
- package/coverage/lcov-report/utilities/security.js.html +3 -3
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +5 -5
- package/coverage/lcov.info +2495 -1737
- package/dist/api/controllers/application.js +15 -1
- package/dist/api/controllers/auth.js +3 -3
- package/dist/api/controllers/datasource.js +67 -16
- package/dist/api/controllers/deploy/index.js +2 -0
- package/dist/api/controllers/dev.js +4 -1
- package/dist/api/controllers/query.js +30 -58
- package/dist/api/controllers/row/ExternalRequest.js +78 -34
- package/dist/api/controllers/row/external.js +3 -1
- package/dist/api/controllers/row/utils.js +6 -12
- package/dist/api/controllers/table/external.js +249 -0
- package/dist/api/controllers/table/index.js +49 -123
- package/dist/api/controllers/table/internal.js +150 -0
- package/dist/api/controllers/table/utils.js +62 -28
- package/dist/api/controllers/user.js +123 -11
- package/dist/api/controllers/view/exporters.js +4 -0
- package/dist/api/controllers/view/index.js +14 -2
- package/dist/api/routes/query.js +1 -1
- package/dist/api/routes/table.js +7 -1
- package/dist/api/routes/user.js +2 -1
- package/dist/app.js +2 -11
- package/dist/automations/bullboard.js +37 -10
- package/dist/automations/triggers.js +7 -3
- package/dist/automations/utils.js +11 -2
- package/dist/constants/index.js +19 -0
- package/dist/definitions/datasource.js +5 -0
- package/dist/environment.js +13 -0
- package/dist/integrations/base/IntegrationBase.js +2 -0
- package/dist/integrations/base/datasourcePlus.js +2 -0
- package/dist/integrations/base/sql.js +353 -177
- package/dist/integrations/base/sqlTable.js +143 -0
- package/dist/integrations/base/utils.js +30 -0
- package/dist/integrations/index.js +6 -0
- package/dist/integrations/microsoftSqlServer.js +117 -9
- package/dist/integrations/mysql.js +16 -85
- package/dist/integrations/oracle.js +347 -0
- package/dist/integrations/postgres.js +35 -28
- package/dist/integrations/utils.js +71 -9
- package/dist/middleware/authorized.js +2 -1
- package/dist/middleware/builder.js +4 -1
- package/dist/package.json +12 -7
- package/dist/tests/utilities/TestConfiguration.js +2 -1
- package/dist/{automations/thread.js → threads/automation.js} +26 -8
- package/dist/threads/index.js +64 -0
- package/dist/threads/query.js +64 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +46 -5
- package/dist/utilities/global.js +6 -2
- package/dist/utilities/index.js +11 -0
- package/dist/utilities/queue/inMemoryQueue.js +8 -0
- package/dist/utilities/scriptRunner.js +4 -1
- package/package.json +13 -8
- package/scripts/dev/manage.js +1 -0
- package/scripts/integrations/mssql/data/Dockerfile +9 -0
- package/scripts/integrations/mssql/data/entrypoint.sh +24 -0
- package/scripts/integrations/mssql/data/setup.sql +54 -0
- package/scripts/integrations/mssql/docker-compose.yaml +12 -0
- package/scripts/integrations/mssql/reset.sh +3 -0
- package/scripts/integrations/oracle/docker-compose.yml +19 -0
- package/scripts/integrations/oracle/instantclient/linux/x86-64/basiclite-21.4.zip +0 -0
- package/scripts/integrations/oracle/instantclient/linux/x86-64/install.sh +23 -0
- package/scripts/integrations/oracle/oracle.md +90 -0
- package/scripts/integrations/postgres/docker-compose.yml +3 -3
- package/scripts/likeCypress.ts +33 -0
- package/src/api/controllers/application.js +18 -1
- package/src/api/controllers/auth.js +3 -0
- package/src/api/controllers/datasource.js +84 -16
- package/src/api/controllers/deploy/index.js +2 -0
- package/src/api/controllers/dev.js +4 -1
- package/src/api/controllers/query.js +29 -81
- package/src/api/controllers/row/ExternalRequest.ts +91 -36
- package/src/api/controllers/row/external.js +4 -1
- package/src/api/controllers/row/utils.js +8 -11
- package/src/api/controllers/table/external.js +307 -0
- package/src/api/controllers/table/index.js +47 -137
- package/src/api/controllers/table/internal.js +155 -0
- package/src/api/controllers/table/utils.js +74 -33
- package/src/api/controllers/user.js +132 -13
- package/src/api/controllers/view/exporters.js +5 -0
- package/src/api/controllers/view/index.js +15 -2
- package/src/api/routes/query.js +1 -0
- package/src/api/routes/table.js +11 -0
- package/src/api/routes/tests/datasource.spec.js +2 -2
- package/src/api/routes/tests/misc.spec.js +5 -1
- package/src/api/routes/tests/query.spec.js +0 -1
- package/src/api/routes/user.js +5 -0
- package/src/app.ts +2 -10
- package/src/automations/bullboard.js +28 -11
- package/src/automations/tests/automation.spec.js +3 -4
- package/src/automations/triggers.js +7 -3
- package/src/automations/utils.js +12 -2
- package/src/constants/index.js +22 -0
- package/src/definitions/common.ts +7 -1
- package/src/definitions/datasource.ts +10 -3
- package/src/environment.js +15 -0
- package/src/integrations/airtable.ts +2 -1
- package/src/integrations/arangodb.ts +2 -1
- package/src/integrations/base/IntegrationBase.ts +6 -0
- package/src/integrations/base/datasourcePlus.ts +9 -0
- package/src/integrations/base/sql.ts +377 -218
- package/src/integrations/base/sqlTable.ts +180 -0
- package/src/integrations/base/utils.ts +22 -0
- package/src/integrations/couchdb.ts +2 -1
- package/src/integrations/dynamodb.ts +2 -1
- package/src/integrations/elasticsearch.ts +2 -1
- package/src/integrations/index.ts +7 -0
- package/src/integrations/microsoftSqlServer.ts +145 -13
- package/src/integrations/mongodb.ts +2 -1
- package/src/integrations/mysql.ts +23 -95
- package/src/integrations/oracle.ts +458 -0
- package/src/integrations/postgres.ts +45 -35
- package/src/integrations/rest.ts +2 -1
- package/src/integrations/s3.ts +2 -1
- package/src/integrations/tests/microsoftSqlServer.spec.js +22 -15
- package/src/integrations/tests/oracle.spec.js +94 -0
- package/src/integrations/tests/postgres.spec.js +4 -0
- package/src/integrations/utils.ts +78 -8
- package/src/middleware/authorized.js +2 -1
- package/src/middleware/builder.js +4 -1
- package/src/tests/utilities/TestConfiguration.js +2 -1
- package/src/{automations/thread.js → threads/automation.js} +27 -8
- package/src/threads/index.js +66 -0
- package/src/threads/query.js +66 -0
- package/src/utilities/csvParser.js +48 -5
- package/src/utilities/global.js +7 -2
- package/src/utilities/index.js +11 -0
- package/src/utilities/queue/inMemoryQueue.js +7 -0
- package/src/utilities/scriptRunner.js +4 -1
- package/src/utilities/tests/__snapshots__/csvParser.spec.js.snap +0 -6
- package/src/utilities/tests/csvParser.spec.js +3 -0
- package/tsconfig.json +1 -1
- package/builder/assets/index.550fdba7.js +0 -201
- package/builder/assets/index.7469e1e4.css +0 -29
- package/builder/assets/vendor.278a305c.js +0 -9
- package/builder/assets/vendor.d75d5eb7.css +0 -1
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const datasource_1 = require("../definitions/datasource");
|
|
16
|
+
const utils_1 = require("./utils");
|
|
17
|
+
const oracledb_1 = __importDefault(require("oracledb"));
|
|
18
|
+
const sql_1 = __importDefault(require("./base/sql"));
|
|
19
|
+
const constants_1 = require("../constants");
|
|
20
|
+
var OracleModule;
|
|
21
|
+
(function (OracleModule) {
|
|
22
|
+
oracledb_1.default.outFormat = oracledb_1.default.OUT_FORMAT_OBJECT;
|
|
23
|
+
const SCHEMA = {
|
|
24
|
+
docs: "https://github.com/oracle/node-oracledb",
|
|
25
|
+
plus: true,
|
|
26
|
+
friendlyName: "Oracle",
|
|
27
|
+
description: "Oracle Database is an object-relational database management system developed by Oracle Corporation",
|
|
28
|
+
datasource: {
|
|
29
|
+
host: {
|
|
30
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
31
|
+
default: "localhost",
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
port: {
|
|
35
|
+
type: datasource_1.DatasourceFieldTypes.NUMBER,
|
|
36
|
+
required: true,
|
|
37
|
+
default: 1521,
|
|
38
|
+
},
|
|
39
|
+
database: {
|
|
40
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
41
|
+
required: true,
|
|
42
|
+
},
|
|
43
|
+
user: {
|
|
44
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
password: {
|
|
48
|
+
type: datasource_1.DatasourceFieldTypes.PASSWORD,
|
|
49
|
+
required: true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
query: {
|
|
53
|
+
create: {
|
|
54
|
+
type: datasource_1.QueryTypes.SQL,
|
|
55
|
+
},
|
|
56
|
+
read: {
|
|
57
|
+
type: datasource_1.QueryTypes.SQL,
|
|
58
|
+
},
|
|
59
|
+
update: {
|
|
60
|
+
type: datasource_1.QueryTypes.SQL,
|
|
61
|
+
},
|
|
62
|
+
delete: {
|
|
63
|
+
type: datasource_1.QueryTypes.SQL,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
const UNSUPPORTED_TYPES = ["BLOB", "CLOB", "NCLOB"];
|
|
68
|
+
const OracleContraintTypes = {
|
|
69
|
+
PRIMARY: "P",
|
|
70
|
+
NOT_NULL_OR_CHECK: "C",
|
|
71
|
+
FOREIGN_KEY: "R",
|
|
72
|
+
UNIQUE: "U",
|
|
73
|
+
};
|
|
74
|
+
class OracleIntegration extends sql_1.default {
|
|
75
|
+
constructor(config) {
|
|
76
|
+
super(utils_1.SqlClients.ORACLE);
|
|
77
|
+
this.tables = {};
|
|
78
|
+
this.schemaErrors = {};
|
|
79
|
+
this.COLUMNS_SQL = `
|
|
80
|
+
SELECT
|
|
81
|
+
tabs.table_name,
|
|
82
|
+
cols.column_name,
|
|
83
|
+
cols.data_type,
|
|
84
|
+
cols.data_default,
|
|
85
|
+
cols.column_id,
|
|
86
|
+
cons.constraint_name,
|
|
87
|
+
cons.constraint_type,
|
|
88
|
+
cons.r_constraint_name,
|
|
89
|
+
cons.search_condition
|
|
90
|
+
FROM
|
|
91
|
+
user_tables tabs
|
|
92
|
+
JOIN
|
|
93
|
+
user_tab_columns cols
|
|
94
|
+
ON tabs.table_name = cols.table_name
|
|
95
|
+
LEFT JOIN
|
|
96
|
+
user_cons_columns col_cons
|
|
97
|
+
ON cols.column_name = col_cons.column_name
|
|
98
|
+
AND cols.table_name = col_cons.table_name
|
|
99
|
+
LEFT JOIN
|
|
100
|
+
user_constraints cons
|
|
101
|
+
ON col_cons.constraint_name = cons.constraint_name
|
|
102
|
+
AND cons.table_name = cols.table_name
|
|
103
|
+
WHERE
|
|
104
|
+
(cons.status = 'ENABLED'
|
|
105
|
+
OR cons.status IS NULL)
|
|
106
|
+
`;
|
|
107
|
+
this.getConnection = () => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
//connectString : "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SID= ORCL)))"
|
|
109
|
+
const connectString = `${this.config.host}:${this.config.port || 1521}/${this.config.database}`;
|
|
110
|
+
const attributes = {
|
|
111
|
+
user: this.config.user,
|
|
112
|
+
password: this.config.user,
|
|
113
|
+
connectString,
|
|
114
|
+
};
|
|
115
|
+
return oracledb_1.default.getConnection(attributes);
|
|
116
|
+
});
|
|
117
|
+
this.config = config;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Map the flat tabular columns and constraints data into a nested object
|
|
121
|
+
*/
|
|
122
|
+
mapColumns(result) {
|
|
123
|
+
const oracleTables = {};
|
|
124
|
+
if (result.rows) {
|
|
125
|
+
result.rows.forEach(row => {
|
|
126
|
+
const tableName = row.TABLE_NAME;
|
|
127
|
+
const columnName = row.COLUMN_NAME;
|
|
128
|
+
const dataType = row.DATA_TYPE;
|
|
129
|
+
const dataDefault = row.DATA_DEFAULT;
|
|
130
|
+
const columnId = row.COLUMN_ID;
|
|
131
|
+
const constraintName = row.CONSTRAINT_NAME;
|
|
132
|
+
const constraintType = row.CONSTRAINT_TYPE;
|
|
133
|
+
const relatedConstraintName = row.R_CONSTRAINT_NAME;
|
|
134
|
+
const searchCondition = row.SEARCH_CONDITION;
|
|
135
|
+
let table = oracleTables[tableName];
|
|
136
|
+
if (!table) {
|
|
137
|
+
table = {
|
|
138
|
+
name: tableName,
|
|
139
|
+
columns: {},
|
|
140
|
+
};
|
|
141
|
+
oracleTables[tableName] = table;
|
|
142
|
+
}
|
|
143
|
+
let column = table.columns[columnName];
|
|
144
|
+
if (!column) {
|
|
145
|
+
column = {
|
|
146
|
+
name: columnName,
|
|
147
|
+
type: dataType,
|
|
148
|
+
default: dataDefault,
|
|
149
|
+
id: columnId,
|
|
150
|
+
constraints: {},
|
|
151
|
+
};
|
|
152
|
+
table.columns[columnName] = column;
|
|
153
|
+
}
|
|
154
|
+
if (constraintName && constraintType) {
|
|
155
|
+
let constraint = column.constraints[constraintName];
|
|
156
|
+
if (!constraint) {
|
|
157
|
+
constraint = {
|
|
158
|
+
name: constraintName,
|
|
159
|
+
type: constraintType,
|
|
160
|
+
relatedConstraintName: relatedConstraintName,
|
|
161
|
+
searchCondition: searchCondition,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
column.constraints[constraintName] = constraint;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
return oracleTables;
|
|
169
|
+
}
|
|
170
|
+
isSupportedColumn(column) {
|
|
171
|
+
if (UNSUPPORTED_TYPES.includes(column.type)) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
isAutoColumn(column) {
|
|
177
|
+
if (column.default && column.default.toLowerCase().includes("nextval")) {
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* No native boolean in oracle. Best we can do is to check if a manual 1 or 0 number constraint has been set up
|
|
184
|
+
* This matches the default behaviour for generating DDL used in knex.
|
|
185
|
+
*/
|
|
186
|
+
isBooleanType(column) {
|
|
187
|
+
if (column.type.toLowerCase() === "number" &&
|
|
188
|
+
Object.values(column.constraints).filter(c => {
|
|
189
|
+
if (c.type === OracleContraintTypes.NOT_NULL_OR_CHECK &&
|
|
190
|
+
c.searchCondition) {
|
|
191
|
+
const condition = c.searchCondition
|
|
192
|
+
.replace(/\s/g, "") // remove spaces
|
|
193
|
+
.replace(/[']+/g, ""); // remove quotes
|
|
194
|
+
if (condition.includes("in(0,1)") ||
|
|
195
|
+
condition.includes("in(1,0)")) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return false;
|
|
200
|
+
}).length > 0) {
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
internalConvertType(column) {
|
|
206
|
+
if (this.isBooleanType(column)) {
|
|
207
|
+
return constants_1.FieldTypes.BOOLEAN;
|
|
208
|
+
}
|
|
209
|
+
return utils_1.convertSqlType(column.type);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Fetches the tables from the oracle table and assigns them to the datasource.
|
|
213
|
+
* @param {*} datasourceId - datasourceId to fetch
|
|
214
|
+
* @param entities - the tables that are to be built
|
|
215
|
+
*/
|
|
216
|
+
buildSchema(datasourceId, entities) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
const columnsResponse = yield this.internalQuery({
|
|
219
|
+
sql: this.COLUMNS_SQL,
|
|
220
|
+
});
|
|
221
|
+
const oracleTables = this.mapColumns(columnsResponse);
|
|
222
|
+
const tables = {};
|
|
223
|
+
// iterate each table
|
|
224
|
+
Object.values(oracleTables).forEach(oracleTable => {
|
|
225
|
+
let table = tables[oracleTable.name];
|
|
226
|
+
if (!table) {
|
|
227
|
+
table = {
|
|
228
|
+
_id: utils_1.buildExternalTableId(datasourceId, oracleTable.name),
|
|
229
|
+
primary: [],
|
|
230
|
+
name: oracleTable.name,
|
|
231
|
+
schema: {},
|
|
232
|
+
};
|
|
233
|
+
tables[oracleTable.name] = table;
|
|
234
|
+
}
|
|
235
|
+
// iterate each column on the table
|
|
236
|
+
Object.values(oracleTable.columns)
|
|
237
|
+
// remove columns that we can't read / save
|
|
238
|
+
.filter(oracleColumn => this.isSupportedColumn(oracleColumn))
|
|
239
|
+
// match the order of the columns in the db
|
|
240
|
+
.sort((c1, c2) => c1.id - c2.id)
|
|
241
|
+
.forEach(oracleColumn => {
|
|
242
|
+
const columnName = oracleColumn.name;
|
|
243
|
+
let fieldSchema = table.schema[columnName];
|
|
244
|
+
if (!fieldSchema) {
|
|
245
|
+
fieldSchema = {
|
|
246
|
+
autocolumn: this.isAutoColumn(oracleColumn),
|
|
247
|
+
name: columnName,
|
|
248
|
+
type: this.internalConvertType(oracleColumn),
|
|
249
|
+
};
|
|
250
|
+
table.schema[columnName] = fieldSchema;
|
|
251
|
+
}
|
|
252
|
+
// iterate each constraint on the column
|
|
253
|
+
Object.values(oracleColumn.constraints).forEach(oracleConstraint => {
|
|
254
|
+
if (oracleConstraint.type === OracleContraintTypes.PRIMARY) {
|
|
255
|
+
table.primary.push(columnName);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
const final = utils_1.finaliseExternalTables(tables, entities);
|
|
261
|
+
this.tables = final.tables;
|
|
262
|
+
this.schemaErrors = final.errors;
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Knex default returning behaviour does not work with oracle
|
|
267
|
+
* Manually add the behaviour for the return column
|
|
268
|
+
*/
|
|
269
|
+
addReturning(query, bindings, returnColumn) {
|
|
270
|
+
if (bindings instanceof Array) {
|
|
271
|
+
bindings.push({ dir: oracledb_1.default.BIND_OUT });
|
|
272
|
+
query.sql =
|
|
273
|
+
query.sql + ` returning \"${returnColumn}\" into :${bindings.length}`;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
internalQuery(query, returnColum, operation) {
|
|
277
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
+
let connection;
|
|
279
|
+
try {
|
|
280
|
+
connection = yield this.getConnection();
|
|
281
|
+
const options = { autoCommit: true };
|
|
282
|
+
const bindings = query.bindings || [];
|
|
283
|
+
if (returnColum &&
|
|
284
|
+
(operation === datasource_1.Operation.CREATE || operation === datasource_1.Operation.UPDATE)) {
|
|
285
|
+
this.addReturning(query, bindings, returnColum);
|
|
286
|
+
}
|
|
287
|
+
const result = yield connection.execute(query.sql, bindings, options);
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
finally {
|
|
291
|
+
if (connection) {
|
|
292
|
+
try {
|
|
293
|
+
yield connection.close();
|
|
294
|
+
}
|
|
295
|
+
catch (err) {
|
|
296
|
+
console.error(err);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
create(query) {
|
|
303
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
304
|
+
const response = yield this.internalQuery(utils_1.getSqlQuery(query));
|
|
305
|
+
return response.rows && response.rows.length
|
|
306
|
+
? response.rows
|
|
307
|
+
: [{ created: true }];
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
read(query) {
|
|
311
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
312
|
+
const response = yield this.internalQuery(utils_1.getSqlQuery(query));
|
|
313
|
+
return response.rows ? response.rows : [];
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
update(query) {
|
|
317
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
318
|
+
const response = yield this.internalQuery(utils_1.getSqlQuery(query));
|
|
319
|
+
return response.rows && response.rows.length
|
|
320
|
+
? response.rows
|
|
321
|
+
: [{ updated: true }];
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
delete(query) {
|
|
325
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
326
|
+
const response = yield this.internalQuery(utils_1.getSqlQuery(query));
|
|
327
|
+
return response.rows && response.rows.length
|
|
328
|
+
? response.rows
|
|
329
|
+
: [{ deleted: true }];
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
query(json) {
|
|
333
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
334
|
+
const primaryKeys = json.meta.table.primary;
|
|
335
|
+
const primaryKey = primaryKeys ? primaryKeys[0] : undefined;
|
|
336
|
+
const queryFn = (query, operation) => this.internalQuery(query, primaryKey, operation);
|
|
337
|
+
const processFn = (response) => (response.rows ? response.rows : []);
|
|
338
|
+
const output = yield this.queryWithReturning(json, queryFn, processFn);
|
|
339
|
+
return output;
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
module.exports = {
|
|
344
|
+
schema: SCHEMA,
|
|
345
|
+
integration: OracleIntegration,
|
|
346
|
+
};
|
|
347
|
+
})(OracleModule || (OracleModule = {}));
|
|
@@ -15,8 +15,6 @@ var PostgresModule;
|
|
|
15
15
|
(function (PostgresModule) {
|
|
16
16
|
const { Pool } = require("pg");
|
|
17
17
|
const Sql = require("./base/sql");
|
|
18
|
-
const { FieldTypes } = require("../constants");
|
|
19
|
-
const { buildExternalTableId, convertType, copyExistingPropsOver, } = require("./utils");
|
|
20
18
|
const { escapeDangerousCharacters } = require("../utilities");
|
|
21
19
|
const JSON_REGEX = /'{.*}'::json/s;
|
|
22
20
|
const SCHEMA = {
|
|
@@ -50,6 +48,11 @@ var PostgresModule;
|
|
|
50
48
|
default: "root",
|
|
51
49
|
required: true,
|
|
52
50
|
},
|
|
51
|
+
schema: {
|
|
52
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
53
|
+
default: "public",
|
|
54
|
+
required: true,
|
|
55
|
+
},
|
|
53
56
|
ssl: {
|
|
54
57
|
type: datasource_1.DatasourceFieldTypes.BOOLEAN,
|
|
55
58
|
default: false,
|
|
@@ -81,21 +84,6 @@ var PostgresModule;
|
|
|
81
84
|
},
|
|
82
85
|
},
|
|
83
86
|
};
|
|
84
|
-
const TYPE_MAP = {
|
|
85
|
-
text: FieldTypes.LONGFORM,
|
|
86
|
-
varchar: FieldTypes.STRING,
|
|
87
|
-
integer: FieldTypes.NUMBER,
|
|
88
|
-
bigint: FieldTypes.NUMBER,
|
|
89
|
-
decimal: FieldTypes.NUMBER,
|
|
90
|
-
smallint: FieldTypes.NUMBER,
|
|
91
|
-
real: FieldTypes.NUMBER,
|
|
92
|
-
"double precision": FieldTypes.NUMBER,
|
|
93
|
-
timestamp: FieldTypes.DATETIME,
|
|
94
|
-
time: FieldTypes.DATETIME,
|
|
95
|
-
boolean: FieldTypes.BOOLEAN,
|
|
96
|
-
json: FieldTypes.JSON,
|
|
97
|
-
date: FieldTypes.DATETIME,
|
|
98
|
-
};
|
|
99
87
|
function internalQuery(client, query) {
|
|
100
88
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
89
|
// need to handle a specific issue with json data types in postgres,
|
|
@@ -120,8 +108,9 @@ var PostgresModule;
|
|
|
120
108
|
}
|
|
121
109
|
class PostgresIntegration extends Sql {
|
|
122
110
|
constructor(config) {
|
|
123
|
-
super(
|
|
124
|
-
this.
|
|
111
|
+
super(utils_1.SqlClients.POSTGRES);
|
|
112
|
+
this.tables = {};
|
|
113
|
+
this.schemaErrors = {};
|
|
125
114
|
this.PRIMARY_KEYS_SQL = `
|
|
126
115
|
select tc.table_schema, tc.table_name, kc.column_name as primary_key
|
|
127
116
|
from information_schema.table_constraints tc
|
|
@@ -142,6 +131,16 @@ var PostgresModule;
|
|
|
142
131
|
this.pool = new Pool(newConfig);
|
|
143
132
|
}
|
|
144
133
|
this.client = this.pool;
|
|
134
|
+
this.setSchema();
|
|
135
|
+
}
|
|
136
|
+
setSchema() {
|
|
137
|
+
if (!this.config.schema) {
|
|
138
|
+
this.config.schema = "public";
|
|
139
|
+
}
|
|
140
|
+
this.client.on("connect", (client) => {
|
|
141
|
+
client.query(`SET search_path TO ${this.config.schema}`);
|
|
142
|
+
});
|
|
143
|
+
this.COLUMNS_SQL = `select * from information_schema.columns where table_schema = '${this.config.schema}'`;
|
|
145
144
|
}
|
|
146
145
|
/**
|
|
147
146
|
* Fetches the tables from the postgres table and assigns them to the datasource.
|
|
@@ -176,13 +175,13 @@ var PostgresModule;
|
|
|
176
175
|
// table key doesn't exist yet
|
|
177
176
|
if (!tables[tableName] || !tables[tableName].schema) {
|
|
178
177
|
tables[tableName] = {
|
|
179
|
-
_id: buildExternalTableId(datasourceId, tableName),
|
|
180
|
-
primary: tableKeys[tableName] || [
|
|
178
|
+
_id: utils_1.buildExternalTableId(datasourceId, tableName),
|
|
179
|
+
primary: tableKeys[tableName] || [],
|
|
181
180
|
name: tableName,
|
|
182
181
|
schema: {},
|
|
183
182
|
};
|
|
184
183
|
}
|
|
185
|
-
const type =
|
|
184
|
+
const type = utils_1.convertSqlType(column.data_type);
|
|
186
185
|
const identity = !!(column.identity_generation ||
|
|
187
186
|
column.identity_start ||
|
|
188
187
|
column.identity_increment);
|
|
@@ -196,10 +195,9 @@ var PostgresModule;
|
|
|
196
195
|
type,
|
|
197
196
|
};
|
|
198
197
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.tables = tables;
|
|
198
|
+
const final = utils_1.finaliseExternalTables(tables, entities);
|
|
199
|
+
this.tables = final.tables;
|
|
200
|
+
this.schemaErrors = final.errors;
|
|
203
201
|
});
|
|
204
202
|
}
|
|
205
203
|
create(query) {
|
|
@@ -230,8 +228,17 @@ var PostgresModule;
|
|
|
230
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
231
229
|
const operation = this._operation(json).toLowerCase();
|
|
232
230
|
const input = this._query(json);
|
|
233
|
-
|
|
234
|
-
|
|
231
|
+
if (Array.isArray(input)) {
|
|
232
|
+
const responses = [];
|
|
233
|
+
for (let query of input) {
|
|
234
|
+
responses.push(yield internalQuery(this.client, query));
|
|
235
|
+
}
|
|
236
|
+
return responses;
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
const response = yield internalQuery(this.client, input);
|
|
240
|
+
return response.rows.length ? response.rows : [{ [operation]: true }];
|
|
241
|
+
}
|
|
235
242
|
});
|
|
236
243
|
}
|
|
237
244
|
}
|
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.finaliseExternalTables = exports.isIsoDateString = exports.isSQL = exports.getSqlQuery = exports.convertSqlType = exports.breakRowIdField = exports.convertRowId = exports.isRowId = exports.generateRowIdField = exports.breakExternalTableId = exports.buildExternalTableId = exports.isExternalTable = exports.SqlClients = void 0;
|
|
4
4
|
const datasource_1 = require("../definitions/datasource");
|
|
5
5
|
const { DocumentTypes, SEPARATOR } = require("../db/utils");
|
|
6
|
-
const { FieldTypes } = require("../constants");
|
|
6
|
+
const { FieldTypes, BuildSchemaErrors, InvalidColumns, } = require("../constants");
|
|
7
7
|
const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`;
|
|
8
8
|
const ROW_ID_REGEX = /^\[.*]$/g;
|
|
9
|
+
const SQL_TYPE_MAP = {
|
|
10
|
+
text: FieldTypes.LONGFORM,
|
|
11
|
+
varchar: FieldTypes.STRING,
|
|
12
|
+
integer: FieldTypes.NUMBER,
|
|
13
|
+
bigint: FieldTypes.NUMBER,
|
|
14
|
+
decimal: FieldTypes.NUMBER,
|
|
15
|
+
smallint: FieldTypes.NUMBER,
|
|
16
|
+
real: FieldTypes.NUMBER,
|
|
17
|
+
"double precision": FieldTypes.NUMBER,
|
|
18
|
+
timestamp: FieldTypes.DATETIME,
|
|
19
|
+
time: FieldTypes.DATETIME,
|
|
20
|
+
boolean: FieldTypes.BOOLEAN,
|
|
21
|
+
json: FieldTypes.JSON,
|
|
22
|
+
date: FieldTypes.DATETIME,
|
|
23
|
+
blob: FieldTypes.LONGFORM,
|
|
24
|
+
enum: FieldTypes.STRING,
|
|
25
|
+
float: FieldTypes.NUMBER,
|
|
26
|
+
int: FieldTypes.NUMBER,
|
|
27
|
+
numeric: FieldTypes.NUMBER,
|
|
28
|
+
mediumint: FieldTypes.NUMBER,
|
|
29
|
+
dec: FieldTypes.NUMBER,
|
|
30
|
+
double: FieldTypes.NUMBER,
|
|
31
|
+
fixed: FieldTypes.NUMBER,
|
|
32
|
+
datetime: FieldTypes.DATETIME,
|
|
33
|
+
tinyint: FieldTypes.BOOLEAN,
|
|
34
|
+
long: FieldTypes.LONGFORM,
|
|
35
|
+
number: FieldTypes.NUMBER,
|
|
36
|
+
binary_float: FieldTypes.NUMBER,
|
|
37
|
+
binary_double: FieldTypes.NUMBER,
|
|
38
|
+
};
|
|
39
|
+
var SqlClients;
|
|
40
|
+
(function (SqlClients) {
|
|
41
|
+
SqlClients["MS_SQL"] = "mssql";
|
|
42
|
+
SqlClients["POSTGRES"] = "pg";
|
|
43
|
+
SqlClients["MY_SQL"] = "mysql";
|
|
44
|
+
SqlClients["ORACLE"] = "oracledb";
|
|
45
|
+
})(SqlClients = exports.SqlClients || (exports.SqlClients = {}));
|
|
9
46
|
function isExternalTable(tableId) {
|
|
10
47
|
return tableId.includes(DocumentTypes.DATASOURCE);
|
|
11
48
|
}
|
|
@@ -66,15 +103,15 @@ function breakRowIdField(_id) {
|
|
|
66
103
|
}
|
|
67
104
|
}
|
|
68
105
|
exports.breakRowIdField = breakRowIdField;
|
|
69
|
-
function
|
|
70
|
-
for (let [external, internal] of Object.entries(
|
|
106
|
+
function convertSqlType(type) {
|
|
107
|
+
for (let [external, internal] of Object.entries(SQL_TYPE_MAP)) {
|
|
71
108
|
if (type.toLowerCase().includes(external)) {
|
|
72
109
|
return internal;
|
|
73
110
|
}
|
|
74
111
|
}
|
|
75
112
|
return FieldTypes.STRING;
|
|
76
113
|
}
|
|
77
|
-
exports.
|
|
114
|
+
exports.convertSqlType = convertSqlType;
|
|
78
115
|
function getSqlQuery(query) {
|
|
79
116
|
if (typeof query === "string") {
|
|
80
117
|
return { sql: query };
|
|
@@ -101,10 +138,10 @@ function isIsoDateString(str) {
|
|
|
101
138
|
}
|
|
102
139
|
exports.isIsoDateString = isIsoDateString;
|
|
103
140
|
// add the existing relationships from the entities if they exist, to prevent them from being overridden
|
|
104
|
-
function copyExistingPropsOver(tableName,
|
|
141
|
+
function copyExistingPropsOver(tableName, table, entities) {
|
|
105
142
|
if (entities && entities[tableName]) {
|
|
106
143
|
if (entities[tableName].primaryDisplay) {
|
|
107
|
-
|
|
144
|
+
table.primaryDisplay = entities[tableName].primaryDisplay;
|
|
108
145
|
}
|
|
109
146
|
const existingTableSchema = entities[tableName].schema;
|
|
110
147
|
for (let key in existingTableSchema) {
|
|
@@ -112,9 +149,34 @@ function copyExistingPropsOver(tableName, tables, entities) {
|
|
|
112
149
|
continue;
|
|
113
150
|
}
|
|
114
151
|
if (existingTableSchema[key].type === "link") {
|
|
115
|
-
|
|
152
|
+
table.schema[key] = existingTableSchema[key];
|
|
116
153
|
}
|
|
117
154
|
}
|
|
118
155
|
}
|
|
156
|
+
return table;
|
|
119
157
|
}
|
|
120
|
-
|
|
158
|
+
function finaliseExternalTables(tables, entities) {
|
|
159
|
+
const invalidColumns = Object.values(InvalidColumns);
|
|
160
|
+
let finalTables = {};
|
|
161
|
+
const errors = {};
|
|
162
|
+
for (let [name, table] of Object.entries(tables)) {
|
|
163
|
+
const schemaFields = Object.keys(table.schema);
|
|
164
|
+
// make sure every table has a key
|
|
165
|
+
if (table.primary == null || table.primary.length === 0) {
|
|
166
|
+
errors[name] = BuildSchemaErrors.NO_KEY;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
else if (schemaFields.find(field => invalidColumns.includes(field))) {
|
|
170
|
+
errors[name] = BuildSchemaErrors.INVALID_COLUMN;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
// make sure all previous props have been added back
|
|
174
|
+
finalTables[name] = copyExistingPropsOver(name, table, entities);
|
|
175
|
+
}
|
|
176
|
+
// sort the tables by name
|
|
177
|
+
finalTables = Object.entries(finalTables)
|
|
178
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
179
|
+
.reduce((r, [k, v]) => (Object.assign(Object.assign({}, r), { [k]: v })), {});
|
|
180
|
+
return { tables: finalTables, errors };
|
|
181
|
+
}
|
|
182
|
+
exports.finaliseExternalTables = finaliseExternalTables;
|
|
@@ -18,7 +18,8 @@ function hasResource(ctx) {
|
|
|
18
18
|
module.exports =
|
|
19
19
|
(permType, permLevel = null) => (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
20
|
// webhooks don't need authentication, each webhook unique
|
|
21
|
-
|
|
21
|
+
// also internal requests (between services) don't need authorized
|
|
22
|
+
if (isWebhookEndpoint(ctx) || ctx.internal) {
|
|
22
23
|
return next();
|
|
23
24
|
}
|
|
24
25
|
if (!ctx.user) {
|
|
@@ -13,6 +13,7 @@ const { doesUserHaveLock, updateLock, checkDebounce, setDebounce, } = require(".
|
|
|
13
13
|
const CouchDB = require("../db");
|
|
14
14
|
const { DocumentTypes } = require("../db/utils");
|
|
15
15
|
const { PermissionTypes } = require("@budibase/auth/permissions");
|
|
16
|
+
const { app: appCache } = require("@budibase/auth/cache");
|
|
16
17
|
const DEBOUNCE_TIME_SEC = 30;
|
|
17
18
|
/************************************************** *
|
|
18
19
|
* This middleware has been broken out of the *
|
|
@@ -51,7 +52,9 @@ function updateAppUpdatedAt(ctx) {
|
|
|
51
52
|
const db = new CouchDB(appId);
|
|
52
53
|
const metadata = yield db.get(DocumentTypes.APP_METADATA);
|
|
53
54
|
metadata.updatedAt = new Date().toISOString();
|
|
54
|
-
yield db.put(metadata);
|
|
55
|
+
const response = yield db.put(metadata);
|
|
56
|
+
metadata._rev = response.rev;
|
|
57
|
+
yield appCache.invalidateAppMetadata(appId, metadata);
|
|
55
58
|
// set a new debounce record with a short TTL
|
|
56
59
|
yield setDebounce(appId, DEBOUNCE_TIME_SEC);
|
|
57
60
|
});
|