@budibase/server 1.0.27-alpha.2 → 1.0.27-alpha.20
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/__mocks__/node-fetch.ts +18 -0
- package/builder/assets/{index.5522fcd5.css → index.39e01193.css} +1 -1
- package/builder/assets/{index.e9e2c4d7.js → index.c5bf8ef6.js} +247 -242
- package/builder/assets/{vendor.f9faf6ab.js → vendor.10e2ad1b.js} +12 -12
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1128 -968
- package/coverage/coverage-final.json +70 -70
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +3 -3
- package/coverage/lcov-report/api/controllers/application.js.html +73 -64
- package/coverage/lcov-report/api/controllers/auth.js.html +2 -2
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +13 -4
- package/coverage/lcov-report/api/controllers/component.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +150 -48
- package/coverage/lcov-report/api/controllers/dev.js.html +3 -3
- package/coverage/lcov-report/api/controllers/hosting.js.html +3 -3
- package/coverage/lcov-report/api/controllers/index.html +20 -20
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
- package/coverage/lcov-report/api/controllers/query/index.html +21 -21
- package/coverage/lcov-report/api/controllers/query/index.js.html +102 -120
- package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -3
- package/coverage/lcov-report/api/controllers/role.js.html +2 -2
- package/coverage/lcov-report/api/controllers/routing.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +11 -11
- package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +38 -11
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +14 -5
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +2 -2
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +6 -6
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +2 -2
- package/coverage/lcov-report/api/routes/application.js.html +2 -2
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +2 -2
- package/coverage/lcov-report/api/routes/backup.js.html +2 -2
- package/coverage/lcov-report/api/routes/cloud.js.html +2 -2
- package/coverage/lcov-report/api/routes/component.js.html +2 -2
- package/coverage/lcov-report/api/routes/datasource.js.html +2 -2
- package/coverage/lcov-report/api/routes/deploy.js.html +2 -2
- package/coverage/lcov-report/api/routes/dev.js.html +2 -2
- package/coverage/lcov-report/api/routes/hosting.js.html +2 -2
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +2 -2
- package/coverage/lcov-report/api/routes/layout.js.html +2 -2
- package/coverage/lcov-report/api/routes/metadata.js.html +2 -2
- package/coverage/lcov-report/api/routes/permission.js.html +12 -3
- package/coverage/lcov-report/api/routes/query.js.html +25 -4
- package/coverage/lcov-report/api/routes/role.js.html +2 -2
- package/coverage/lcov-report/api/routes/routing.js.html +2 -2
- package/coverage/lcov-report/api/routes/row.js.html +2 -2
- package/coverage/lcov-report/api/routes/screen.js.html +2 -2
- package/coverage/lcov-report/api/routes/script.js.html +2 -2
- package/coverage/lcov-report/api/routes/static.js.html +2 -2
- package/coverage/lcov-report/api/routes/table.js.html +2 -2
- package/coverage/lcov-report/api/routes/templates.js.html +2 -2
- package/coverage/lcov-report/api/routes/user.js.html +2 -2
- package/coverage/lcov-report/api/routes/view.js.html +2 -2
- package/coverage/lcov-report/api/routes/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +2 -2
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +32 -8
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +11 -11
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/automations/utils.js.html +6 -6
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +4 -4
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +2 -2
- package/coverage/lcov-report/db/client.js.html +2 -2
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +19 -19
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +69 -69
- 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 +1 -1
- package/coverage/lcov-report/middleware/authorized.js.html +12 -12
- package/coverage/lcov-report/middleware/builder.js.html +10 -10
- package/coverage/lcov-report/middleware/currentapp.js.html +79 -40
- package/coverage/lcov-report/middleware/index.html +10 -10
- package/coverage/lcov-report/middleware/joi-validator.js.html +9 -9
- package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +2 -2
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +3 -3
- package/coverage/lcov-report/threads/index.html +31 -31
- package/coverage/lcov-report/threads/index.js.html +12 -12
- package/coverage/lcov-report/threads/query.js.html +531 -87
- package/coverage/lcov-report/threads/utils.js.html +210 -15
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +2 -2
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +28 -19
- package/coverage/lcov-report/utilities/index.html +4 -4
- package/coverage/lcov-report/utilities/index.js.html +13 -13
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- 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 +19 -19
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +211 -10
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +13 -4
- 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 +22 -22
- package/coverage/lcov.info +1921 -1630
- package/dist/api/controllers/apikeys.js +2 -2
- package/dist/api/controllers/application.js +4 -4
- package/dist/api/controllers/auth.js +1 -1
- package/dist/api/controllers/cloud.js +2 -2
- package/dist/api/controllers/datasource.js +29 -0
- package/dist/api/controllers/deploy/index.js +2 -2
- package/dist/api/controllers/dev.js +2 -2
- package/dist/api/controllers/hosting.js +2 -2
- package/dist/api/controllers/permission.js +2 -2
- package/dist/api/controllers/query/import/sources/base/index.js +2 -1
- package/dist/api/controllers/query/import/sources/curl.js +11 -5
- package/dist/api/controllers/query/import/sources/openapi2.js +8 -5
- package/dist/api/controllers/query/index.js +46 -47
- package/dist/api/controllers/query/validation.js +2 -1
- package/dist/api/controllers/role.js +1 -1
- package/dist/api/controllers/routing.js +1 -1
- package/dist/api/controllers/row/internal.js +14 -6
- package/dist/api/controllers/row/internalSearch.js +1 -1
- package/dist/api/controllers/screen.js +1 -1
- package/dist/api/controllers/user.js +3 -3
- package/dist/api/controllers/webhook.js +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/routes/apikeys.js +1 -1
- package/dist/api/routes/application.js +1 -1
- package/dist/api/routes/automation.js +1 -1
- package/dist/api/routes/backup.js +1 -1
- package/dist/api/routes/cloud.js +1 -1
- package/dist/api/routes/component.js +1 -1
- package/dist/api/routes/datasource.js +1 -1
- package/dist/api/routes/deploy.js +1 -1
- package/dist/api/routes/dev.js +1 -1
- package/dist/api/routes/hosting.js +1 -1
- package/dist/api/routes/integration.js +1 -1
- package/dist/api/routes/layout.js +1 -1
- package/dist/api/routes/metadata.js +1 -1
- package/dist/api/routes/permission.js +1 -1
- package/dist/api/routes/query.js +4 -2
- package/dist/api/routes/role.js +1 -1
- package/dist/api/routes/routing.js +1 -1
- package/dist/api/routes/row.js +1 -1
- package/dist/api/routes/screen.js +1 -1
- package/dist/api/routes/script.js +1 -1
- package/dist/api/routes/static.js +1 -1
- package/dist/api/routes/table.js +1 -1
- package/dist/api/routes/templates.js +1 -1
- package/dist/api/routes/tests/utilities/TestFunctions.js +1 -1
- package/dist/api/routes/user.js +1 -1
- package/dist/api/routes/view.js +1 -1
- package/dist/api/routes/webhook.js +1 -1
- package/dist/app.js +1 -1
- package/dist/automations/bullboard.js +1 -1
- package/dist/automations/steps/executeQuery.js +9 -2
- package/dist/automations/utils.js +1 -1
- package/dist/constants/index.js +3 -3
- package/dist/constants/screens.js +1 -1
- package/dist/db/client.js +1 -1
- package/dist/db/utils.js +1 -1
- package/dist/environment.js +1 -0
- package/dist/integrations/base/sqlTable.js +1 -1
- package/dist/integrations/dynamodb.js +19 -0
- package/dist/integrations/rest.js +71 -22
- package/dist/integrations/s3.js +17 -8
- package/dist/integrations/utils.js +40 -37
- package/dist/middleware/authorized.js +2 -2
- package/dist/middleware/builder.js +2 -2
- package/dist/middleware/currentapp.js +15 -6
- package/dist/middleware/usageQuota.js +1 -1
- package/dist/package.json +5 -4
- package/dist/tests/utilities/TestConfiguration.js +55 -8
- package/dist/tests/utilities/structures.js +2 -2
- package/dist/threads/automation.js +2 -2
- package/dist/threads/query.js +195 -50
- package/dist/threads/utils.js +62 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/budibaseDir.js +1 -1
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/global.js +5 -5
- package/dist/utilities/index.js +2 -2
- package/dist/utilities/redis.js +1 -1
- package/dist/utilities/rowProcessor/index.js +63 -0
- package/dist/utilities/security.js +2 -2
- package/dist/utilities/usageQuota.js +2 -2
- package/dist/utilities/workerRequests.js +3 -3
- package/package.json +6 -5
- package/scripts/replicateApp.js +1 -1
- package/src/api/controllers/apikeys.js +2 -2
- package/src/api/controllers/application.js +7 -4
- package/src/api/controllers/auth.js +1 -1
- package/src/api/controllers/cloud.js +5 -2
- package/src/api/controllers/datasource.js +34 -0
- package/src/api/controllers/deploy/index.js +2 -2
- package/src/api/controllers/dev.js +2 -2
- package/src/api/controllers/hosting.js +2 -2
- package/src/api/controllers/permission.js +2 -2
- package/src/api/controllers/query/import/sources/base/index.ts +3 -1
- package/src/api/controllers/query/import/sources/curl.ts +12 -4
- package/src/api/controllers/query/import/sources/openapi2.ts +9 -5
- package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +2 -3
- package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +6 -7
- package/src/api/controllers/query/import/tests/index.spec.js +0 -6
- package/src/api/controllers/query/index.js +49 -55
- package/src/api/controllers/query/validation.js +2 -1
- package/src/api/controllers/role.js +1 -1
- package/src/api/controllers/routing.js +1 -1
- package/src/api/controllers/row/internal.js +14 -5
- package/src/api/controllers/row/internalSearch.js +1 -1
- package/src/api/controllers/screen.js +1 -1
- package/src/api/controllers/user.js +6 -3
- package/src/api/controllers/webhook.js +1 -1
- package/src/api/index.js +1 -1
- package/src/api/routes/apikeys.js +1 -1
- package/src/api/routes/application.js +1 -1
- package/src/api/routes/automation.js +1 -1
- package/src/api/routes/backup.js +1 -1
- package/src/api/routes/cloud.js +1 -1
- package/src/api/routes/component.js +1 -1
- package/src/api/routes/datasource.js +1 -1
- package/src/api/routes/deploy.js +1 -1
- package/src/api/routes/dev.js +1 -1
- package/src/api/routes/hosting.js +1 -1
- package/src/api/routes/integration.js +1 -1
- package/src/api/routes/layout.js +1 -1
- package/src/api/routes/metadata.js +1 -1
- package/src/api/routes/permission.js +4 -1
- package/src/api/routes/query.js +9 -2
- package/src/api/routes/role.js +1 -1
- package/src/api/routes/routing.js +1 -1
- package/src/api/routes/row.js +1 -1
- package/src/api/routes/screen.js +1 -1
- package/src/api/routes/script.js +1 -1
- package/src/api/routes/static.js +1 -1
- package/src/api/routes/table.js +1 -1
- package/src/api/routes/templates.js +1 -1
- package/src/api/routes/tests/datasource.spec.js +45 -0
- package/src/api/routes/tests/permissions.spec.js +1 -1
- package/src/api/routes/tests/query.spec.js +70 -1
- package/src/api/routes/tests/role.spec.js +2 -2
- package/src/api/routes/tests/routing.spec.js +1 -1
- package/src/api/routes/tests/user.spec.js +1 -1
- package/src/api/routes/tests/utilities/TestFunctions.js +1 -1
- package/src/api/routes/user.js +1 -1
- package/src/api/routes/view.js +1 -1
- package/src/api/routes/webhook.js +1 -1
- package/src/app.ts +1 -1
- package/src/automations/bullboard.js +1 -1
- package/src/automations/steps/executeQuery.js +10 -2
- package/src/automations/utils.js +1 -1
- package/src/constants/index.js +3 -3
- package/src/constants/screens.js +1 -1
- package/src/db/client.js +1 -1
- package/src/db/utils.js +1 -1
- package/src/definitions/datasource.ts +25 -0
- package/src/environment.js +1 -0
- package/src/integrations/base/sqlTable.ts +1 -1
- package/src/integrations/dynamodb.ts +18 -0
- package/src/integrations/rest.ts +103 -20
- package/src/integrations/s3.ts +18 -7
- package/src/integrations/tests/rest.spec.js +287 -24
- package/src/integrations/utils.ts +8 -7
- package/src/middleware/authorized.js +2 -2
- package/src/middleware/builder.js +2 -2
- package/src/middleware/currentapp.js +20 -7
- package/src/middleware/tests/authorized.spec.js +2 -2
- package/src/middleware/tests/currentapp.spec.js +35 -41
- package/src/middleware/tests/usageQuota.spec.js +1 -1
- package/src/middleware/usageQuota.js +1 -1
- package/src/tests/utilities/TestConfiguration.js +65 -8
- package/src/tests/utilities/structures.js +2 -2
- package/src/threads/automation.js +2 -2
- package/src/threads/query.js +203 -55
- package/src/threads/utils.js +66 -1
- package/src/utilities/budibaseDir.js +1 -1
- package/src/utilities/fileSystem/utilities.js +3 -1
- package/src/utilities/global.js +8 -5
- package/src/utilities/index.js +2 -2
- package/src/utilities/redis.js +1 -1
- package/src/utilities/rowProcessor/index.js +67 -0
- package/src/utilities/security.js +5 -2
- package/src/utilities/usageQuota.js +2 -2
- package/src/utilities/workerRequests.js +3 -3
|
@@ -2,39 +2,39 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
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
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`;
|
|
5
|
+
const utils_1 = require("../db/utils");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const DOUBLE_SEPARATOR = `${utils_1.SEPARATOR}${utils_1.SEPARATOR}`;
|
|
8
8
|
const ROW_ID_REGEX = /^\[.*]$/g;
|
|
9
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,
|
|
10
|
+
text: constants_1.FieldTypes.LONGFORM,
|
|
11
|
+
varchar: constants_1.FieldTypes.STRING,
|
|
12
|
+
integer: constants_1.FieldTypes.NUMBER,
|
|
13
|
+
bigint: constants_1.FieldTypes.NUMBER,
|
|
14
|
+
decimal: constants_1.FieldTypes.NUMBER,
|
|
15
|
+
smallint: constants_1.FieldTypes.NUMBER,
|
|
16
|
+
real: constants_1.FieldTypes.NUMBER,
|
|
17
|
+
"double precision": constants_1.FieldTypes.NUMBER,
|
|
18
|
+
timestamp: constants_1.FieldTypes.DATETIME,
|
|
19
|
+
time: constants_1.FieldTypes.DATETIME,
|
|
20
|
+
boolean: constants_1.FieldTypes.BOOLEAN,
|
|
21
|
+
json: constants_1.FieldTypes.JSON,
|
|
22
|
+
date: constants_1.FieldTypes.DATETIME,
|
|
23
|
+
blob: constants_1.FieldTypes.LONGFORM,
|
|
24
|
+
enum: constants_1.FieldTypes.STRING,
|
|
25
|
+
float: constants_1.FieldTypes.NUMBER,
|
|
26
|
+
int: constants_1.FieldTypes.NUMBER,
|
|
27
|
+
numeric: constants_1.FieldTypes.NUMBER,
|
|
28
|
+
mediumint: constants_1.FieldTypes.NUMBER,
|
|
29
|
+
dec: constants_1.FieldTypes.NUMBER,
|
|
30
|
+
double: constants_1.FieldTypes.NUMBER,
|
|
31
|
+
fixed: constants_1.FieldTypes.NUMBER,
|
|
32
|
+
datetime: constants_1.FieldTypes.DATETIME,
|
|
33
|
+
tinyint: constants_1.FieldTypes.BOOLEAN,
|
|
34
|
+
long: constants_1.FieldTypes.LONGFORM,
|
|
35
|
+
number: constants_1.FieldTypes.NUMBER,
|
|
36
|
+
binary_float: constants_1.FieldTypes.NUMBER,
|
|
37
|
+
binary_double: constants_1.FieldTypes.NUMBER,
|
|
38
38
|
};
|
|
39
39
|
var SqlClients;
|
|
40
40
|
(function (SqlClients) {
|
|
@@ -44,7 +44,7 @@ var SqlClients;
|
|
|
44
44
|
SqlClients["ORACLE"] = "oracledb";
|
|
45
45
|
})(SqlClients = exports.SqlClients || (exports.SqlClients = {}));
|
|
46
46
|
function isExternalTable(tableId) {
|
|
47
|
-
return tableId.includes(DocumentTypes.DATASOURCE);
|
|
47
|
+
return tableId.includes(utils_1.DocumentTypes.DATASOURCE);
|
|
48
48
|
}
|
|
49
49
|
exports.isExternalTable = isExternalTable;
|
|
50
50
|
function buildExternalTableId(datasourceId, tableName) {
|
|
@@ -109,7 +109,7 @@ function convertSqlType(type) {
|
|
|
109
109
|
return internal;
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
return FieldTypes.STRING;
|
|
112
|
+
return constants_1.FieldTypes.STRING;
|
|
113
113
|
}
|
|
114
114
|
exports.convertSqlType = convertSqlType;
|
|
115
115
|
function getSqlQuery(query) {
|
|
@@ -148,7 +148,10 @@ function copyExistingPropsOver(tableName, table, entities) {
|
|
|
148
148
|
if (!existingTableSchema.hasOwnProperty(key)) {
|
|
149
149
|
continue;
|
|
150
150
|
}
|
|
151
|
-
if (existingTableSchema[key].type ===
|
|
151
|
+
if (existingTableSchema[key].type === constants_1.FieldTypes.LINK ||
|
|
152
|
+
existingTableSchema[key].type === constants_1.FieldTypes.OPTIONS ||
|
|
153
|
+
((!table.schema[key] || table.schema[key].type === constants_1.FieldTypes.NUMBER) &&
|
|
154
|
+
existingTableSchema[key].type === constants_1.FieldTypes.BOOLEAN)) {
|
|
152
155
|
table.schema[key] = existingTableSchema[key];
|
|
153
156
|
}
|
|
154
157
|
}
|
|
@@ -156,18 +159,18 @@ function copyExistingPropsOver(tableName, table, entities) {
|
|
|
156
159
|
return table;
|
|
157
160
|
}
|
|
158
161
|
function finaliseExternalTables(tables, entities) {
|
|
159
|
-
const invalidColumns = Object.values(InvalidColumns);
|
|
162
|
+
const invalidColumns = Object.values(constants_1.InvalidColumns);
|
|
160
163
|
let finalTables = {};
|
|
161
164
|
const errors = {};
|
|
162
165
|
for (let [name, table] of Object.entries(tables)) {
|
|
163
166
|
const schemaFields = Object.keys(table.schema);
|
|
164
167
|
// make sure every table has a key
|
|
165
168
|
if (table.primary == null || table.primary.length === 0) {
|
|
166
|
-
errors[name] = BuildSchemaErrors.NO_KEY;
|
|
169
|
+
errors[name] = constants_1.BuildSchemaErrors.NO_KEY;
|
|
167
170
|
continue;
|
|
168
171
|
}
|
|
169
172
|
else if (schemaFields.find(field => invalidColumns.includes(field))) {
|
|
170
|
-
errors[name] = BuildSchemaErrors.INVALID_COLUMN;
|
|
173
|
+
errors[name] = constants_1.BuildSchemaErrors.INVALID_COLUMN;
|
|
171
174
|
continue;
|
|
172
175
|
}
|
|
173
176
|
// make sure all previous props have been added back
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { getUserRoleHierarchy, getRequiredResourceRole, BUILTIN_ROLE_IDS, } = require("@budibase/
|
|
12
|
-
const { PermissionTypes, doesHaveBasePermission, } = require("@budibase/
|
|
11
|
+
const { getUserRoleHierarchy, getRequiredResourceRole, BUILTIN_ROLE_IDS, } = require("@budibase/backend-core/roles");
|
|
12
|
+
const { PermissionTypes, doesHaveBasePermission, } = require("@budibase/backend-core/permissions");
|
|
13
13
|
const builderMiddleware = require("./builder");
|
|
14
14
|
const { isWebhookEndpoint } = require("./utils");
|
|
15
15
|
function hasResource(ctx) {
|
|
@@ -12,8 +12,8 @@ const { APP_DEV_PREFIX } = require("../db/utils");
|
|
|
12
12
|
const { doesUserHaveLock, updateLock, checkDebounce, setDebounce, } = require("../utilities/redis");
|
|
13
13
|
const CouchDB = require("../db");
|
|
14
14
|
const { DocumentTypes } = require("../db/utils");
|
|
15
|
-
const { PermissionTypes } = require("@budibase/
|
|
16
|
-
const { app: appCache } = require("@budibase/
|
|
15
|
+
const { PermissionTypes } = require("@budibase/backend-core/permissions");
|
|
16
|
+
const { app: appCache } = require("@budibase/backend-core/cache");
|
|
17
17
|
const DEBOUNCE_TIME_SEC = 30;
|
|
18
18
|
/************************************************** *
|
|
19
19
|
* This middleware has been broken out of the *
|
|
@@ -8,13 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { getAppId, setCookie, getCookie, clearCookie } = require("@budibase/
|
|
12
|
-
const { Cookies } = require("@budibase/
|
|
13
|
-
const { getRole } = require("@budibase/
|
|
14
|
-
const { BUILTIN_ROLE_IDS } = require("@budibase/
|
|
11
|
+
const { getAppId, setCookie, getCookie, clearCookie, } = require("@budibase/backend-core/utils");
|
|
12
|
+
const { Cookies } = require("@budibase/backend-core/constants");
|
|
13
|
+
const { getRole } = require("@budibase/backend-core/roles");
|
|
14
|
+
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
15
15
|
const { generateUserMetadataID, isDevAppID } = require("../db/utils");
|
|
16
|
-
const { dbExists } = require("@budibase/
|
|
17
|
-
const { isUserInAppTenant } = require("@budibase/
|
|
16
|
+
const { dbExists } = require("@budibase/backend-core/db");
|
|
17
|
+
const { isUserInAppTenant } = require("@budibase/backend-core/tenancy");
|
|
18
18
|
const { getCachedSelf } = require("../utilities/global");
|
|
19
19
|
const CouchDB = require("../db");
|
|
20
20
|
const env = require("../environment");
|
|
@@ -49,6 +49,15 @@ module.exports = (ctx, next) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
49
49
|
!isWebhookEndpoint(ctx) &&
|
|
50
50
|
(!ctx.user || !ctx.user.builder || !ctx.user.builder.global)) {
|
|
51
51
|
clearCookie(ctx, Cookies.CurrentApp);
|
|
52
|
+
// have to set the return url on the server side as client side is not available
|
|
53
|
+
setCookie(ctx, ctx.url, Cookies.RETURN_URL, {
|
|
54
|
+
// don't sign so the browser can easily read
|
|
55
|
+
sign: false,
|
|
56
|
+
// use the request domain to match how ui handles the return url cookie.
|
|
57
|
+
// it's important we don't use the shared domain here as the builder
|
|
58
|
+
// can't delete from it without awareness of the domain.
|
|
59
|
+
requestDomain: true,
|
|
60
|
+
});
|
|
52
61
|
return ctx.redirect("/");
|
|
53
62
|
}
|
|
54
63
|
let appId, roleId = BUILTIN_ROLE_IDS.PUBLIC;
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const CouchDB = require("../db");
|
|
12
12
|
const usageQuota = require("../utilities/usageQuota");
|
|
13
13
|
const env = require("../environment");
|
|
14
|
-
const { getTenantId } = require("@budibase/
|
|
14
|
+
const { getTenantId } = require("@budibase/backend-core/tenancy");
|
|
15
15
|
const { isExternalTable, isRowId: isExternalRowId, } = require("../integrations/utils");
|
|
16
16
|
// tenants without limits
|
|
17
17
|
const EXCLUDED_TENANTS = ["bb", "default", "bbtest", "bbstaging"];
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "1.0.27-alpha.
|
|
4
|
+
"version": "1.0.27-alpha.19",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"license": "GPL-3.0",
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@apidevtools/swagger-parser": "^10.0.3",
|
|
73
|
-
"@budibase/
|
|
74
|
-
"@budibase/client": "^1.0.27-alpha.
|
|
75
|
-
"@budibase/string-templates": "^1.0.27-alpha.
|
|
73
|
+
"@budibase/backend-core": "^1.0.27-alpha.19",
|
|
74
|
+
"@budibase/client": "^1.0.27-alpha.19",
|
|
75
|
+
"@budibase/string-templates": "^1.0.27-alpha.19",
|
|
76
76
|
"@bull-board/api": "^3.7.0",
|
|
77
77
|
"@bull-board/koa": "^3.7.0",
|
|
78
78
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -122,6 +122,7 @@
|
|
|
122
122
|
"pouchdb-replication-stream": "1.2.9",
|
|
123
123
|
"server-destroy": "1.0.1",
|
|
124
124
|
"svelte": "^3.38.2",
|
|
125
|
+
"swagger-parser": "^10.0.3",
|
|
125
126
|
"to-json-schema": "0.2.5",
|
|
126
127
|
"uuid": "3.3.2",
|
|
127
128
|
"validate.js": "0.13.1",
|
|
@@ -8,20 +8,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const { BUILTIN_ROLE_IDS } = require("@budibase/
|
|
11
|
+
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
12
12
|
const env = require("../../environment");
|
|
13
13
|
const { basicTable, basicRow, basicRole, basicAutomation, basicDatasource, basicQuery, basicScreen, basicLayout, basicWebhook, TENANT_ID, } = require("./structures");
|
|
14
14
|
const controllers = require("./controllers");
|
|
15
15
|
const supertest = require("supertest");
|
|
16
16
|
const { cleanup } = require("../../utilities/fileSystem");
|
|
17
|
-
const { Cookies, Headers } = require("@budibase/
|
|
18
|
-
const { jwt } = require("@budibase/auth")
|
|
19
|
-
const
|
|
20
|
-
const { getGlobalDB } = require("@budibase/
|
|
21
|
-
const { createASession } = require("@budibase/
|
|
22
|
-
const { user: userCache } = require("@budibase/
|
|
17
|
+
const { Cookies, Headers } = require("@budibase/backend-core/constants");
|
|
18
|
+
const { jwt } = require("@budibase/backend-core/auth");
|
|
19
|
+
const core = require("@budibase/backend-core");
|
|
20
|
+
const { getGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
21
|
+
const { createASession } = require("@budibase/backend-core/sessions");
|
|
22
|
+
const { user: userCache } = require("@budibase/backend-core/cache");
|
|
23
23
|
const CouchDB = require("../../db");
|
|
24
|
-
|
|
24
|
+
core.init(CouchDB);
|
|
25
25
|
const GLOBAL_USER_ID = "us_uuid1";
|
|
26
26
|
const EMAIL = "babs@babs.com";
|
|
27
27
|
class TestConfiguration {
|
|
@@ -294,6 +294,53 @@ class TestConfiguration {
|
|
|
294
294
|
return this.datasource;
|
|
295
295
|
});
|
|
296
296
|
}
|
|
297
|
+
updateDatasource(datasource) {
|
|
298
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
299
|
+
const response = yield this._req(datasource, { datasourceId: datasource._id }, controllers.datasource.update);
|
|
300
|
+
this.datasource = response.datasource;
|
|
301
|
+
return this.datasource;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
restDatasource(cfg) {
|
|
305
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
306
|
+
return this.createDatasource({
|
|
307
|
+
datasource: Object.assign(Object.assign({}, basicDatasource().datasource), { source: "REST", config: cfg || {} }),
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
dynamicVariableDatasource() {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
let datasource = yield this.restDatasource();
|
|
314
|
+
const basedOnQuery = yield this.createQuery(Object.assign(Object.assign({}, basicQuery(datasource._id)), { fields: {
|
|
315
|
+
path: "www.google.com",
|
|
316
|
+
} }));
|
|
317
|
+
datasource = yield this.updateDatasource(Object.assign(Object.assign({}, datasource), { config: {
|
|
318
|
+
dynamicVariables: [
|
|
319
|
+
{
|
|
320
|
+
queryId: basedOnQuery._id,
|
|
321
|
+
name: "variable3",
|
|
322
|
+
value: "{{ data.0.[value] }}",
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
} }));
|
|
326
|
+
return { datasource, query: basedOnQuery };
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
previewQuery(request, config, datasource, fields) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
return request
|
|
332
|
+
.post(`/api/queries/preview`)
|
|
333
|
+
.send({
|
|
334
|
+
datasourceId: datasource._id,
|
|
335
|
+
parameters: {},
|
|
336
|
+
fields,
|
|
337
|
+
queryVerb: "read",
|
|
338
|
+
})
|
|
339
|
+
.set(config.defaultHeaders())
|
|
340
|
+
.expect("Content-Type", /json/)
|
|
341
|
+
.expect(200);
|
|
342
|
+
});
|
|
343
|
+
}
|
|
297
344
|
createQuery(config = null) {
|
|
298
345
|
return __awaiter(this, void 0, void 0, function* () {
|
|
299
346
|
if (!this.datasource && !config) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const { BUILTIN_ROLE_IDS } = require("@budibase/
|
|
3
|
-
const { BUILTIN_PERMISSION_IDS } = require("@budibase/
|
|
2
|
+
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
3
|
+
const { BUILTIN_PERMISSION_IDS } = require("@budibase/backend-core/permissions");
|
|
4
4
|
const { createHomeScreen } = require("../../constants/screens");
|
|
5
5
|
const { EMPTY_LAYOUT } = require("../../constants/layouts");
|
|
6
6
|
const { cloneDeep } = require("lodash/fp");
|
|
@@ -14,10 +14,10 @@ const actions = require("../automations/actions");
|
|
|
14
14
|
const automationUtils = require("../automations/automationUtils");
|
|
15
15
|
const AutomationEmitter = require("../events/AutomationEmitter");
|
|
16
16
|
const { processObject } = require("@budibase/string-templates");
|
|
17
|
-
const { DEFAULT_TENANT_ID } = require("@budibase/
|
|
17
|
+
const { DEFAULT_TENANT_ID } = require("@budibase/backend-core/constants");
|
|
18
18
|
const CouchDB = require("../db");
|
|
19
19
|
const { DocumentTypes, isDevAppID } = require("../db/utils");
|
|
20
|
-
const { doInTenant } = require("@budibase/
|
|
20
|
+
const { doInTenant } = require("@budibase/backend-core/tenancy");
|
|
21
21
|
const usage = require("../utilities/usageQuota");
|
|
22
22
|
const { definitions: triggerDefs } = require("../automations/triggerInfo");
|
|
23
23
|
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId;
|
package/dist/threads/query.js
CHANGED
|
@@ -8,63 +8,208 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
require("./utils")
|
|
11
|
+
const threadUtils = require("./utils");
|
|
12
|
+
threadUtils.threadSetup();
|
|
12
13
|
const ScriptRunner = require("../utilities/scriptRunner");
|
|
13
14
|
const { integrations } = require("../integrations");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
const { processStringSync } = require("@budibase/string-templates");
|
|
16
|
+
const CouchDB = require("../db");
|
|
17
|
+
const IS_TRIPLE_BRACE = new RegExp(/^{{3}.*}{3}$/);
|
|
18
|
+
const IS_HANDLEBARS = new RegExp(/^{{2}.*}{2}$/);
|
|
19
|
+
class QueryRunner {
|
|
20
|
+
constructor(input, flags = { noRecursiveQuery: false }) {
|
|
21
|
+
this.appId = input.appId;
|
|
22
|
+
this.datasource = input.datasource;
|
|
23
|
+
this.queryVerb = input.queryVerb;
|
|
24
|
+
this.fields = input.fields;
|
|
25
|
+
this.parameters = input.parameters;
|
|
26
|
+
this.pagination = input.pagination;
|
|
27
|
+
this.transformer = input.transformer;
|
|
28
|
+
this.queryId = input.queryId;
|
|
29
|
+
this.noRecursiveQuery = flags.noRecursiveQuery;
|
|
30
|
+
this.cachedVariables = [];
|
|
31
|
+
// allows the response from a query to be stored throughout this
|
|
32
|
+
// execution so that if it needs to be re-used for another variable
|
|
33
|
+
// it can be
|
|
34
|
+
this.queryResponse = {};
|
|
35
|
+
this.hasRerun = false;
|
|
22
36
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
execute() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
let { datasource, fields, queryVerb, transformer } = this;
|
|
40
|
+
// pre-query, make sure datasource variables are added to parameters
|
|
41
|
+
const parameters = yield this.addDatasourceVariables();
|
|
42
|
+
let query = this.enrichQueryFields(fields, parameters);
|
|
43
|
+
// Add pagination values for REST queries
|
|
44
|
+
if (this.pagination) {
|
|
45
|
+
query.paginationValues = this.pagination;
|
|
46
|
+
}
|
|
47
|
+
const Integration = integrations[datasource.source];
|
|
48
|
+
if (!Integration) {
|
|
49
|
+
throw "Integration type does not exist.";
|
|
50
|
+
}
|
|
51
|
+
const integration = new Integration(datasource.config);
|
|
52
|
+
let output = threadUtils.formatResponse(yield integration[queryVerb](query));
|
|
53
|
+
let rows = output, info = undefined, extra = undefined, pagination = undefined;
|
|
54
|
+
if (threadUtils.hasExtraData(output)) {
|
|
55
|
+
rows = output.data;
|
|
56
|
+
info = output.info;
|
|
57
|
+
extra = output.extra;
|
|
58
|
+
pagination = output.pagination;
|
|
59
|
+
}
|
|
60
|
+
// transform as required
|
|
61
|
+
if (transformer) {
|
|
62
|
+
const runner = new ScriptRunner(transformer, {
|
|
63
|
+
data: rows,
|
|
64
|
+
params: parameters,
|
|
65
|
+
});
|
|
66
|
+
rows = runner.execute();
|
|
67
|
+
}
|
|
68
|
+
// if the request fails we retry once, invalidating the cached value
|
|
69
|
+
if (info &&
|
|
70
|
+
info.code >= 400 &&
|
|
71
|
+
this.cachedVariables.length > 0 &&
|
|
72
|
+
!this.hasRerun) {
|
|
73
|
+
this.hasRerun = true;
|
|
74
|
+
// invalidate the cache value
|
|
75
|
+
yield threadUtils.invalidateDynamicVariables(this.cachedVariables);
|
|
76
|
+
return this.execute();
|
|
77
|
+
}
|
|
78
|
+
// needs to an array for next step
|
|
79
|
+
if (!Array.isArray(rows)) {
|
|
80
|
+
rows = [rows];
|
|
81
|
+
}
|
|
82
|
+
// map into JSON if just raw primitive here
|
|
83
|
+
if (rows.find(row => typeof row !== "object")) {
|
|
84
|
+
rows = rows.map(value => ({ value }));
|
|
85
|
+
}
|
|
86
|
+
// get all the potential fields in the schema
|
|
87
|
+
let keys = rows.flatMap(Object.keys);
|
|
88
|
+
if (integration.end) {
|
|
89
|
+
integration.end();
|
|
90
|
+
}
|
|
91
|
+
return { rows, keys, info, extra, pagination };
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
runAnotherQuery(queryId, parameters) {
|
|
95
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
+
const db = new CouchDB(this.appId);
|
|
97
|
+
const query = yield db.get(queryId);
|
|
98
|
+
const datasource = yield db.get(query.datasourceId);
|
|
99
|
+
return new QueryRunner({
|
|
100
|
+
appId: this.appId,
|
|
101
|
+
datasource,
|
|
102
|
+
queryVerb: query.queryVerb,
|
|
103
|
+
fields: query.fields,
|
|
104
|
+
parameters,
|
|
105
|
+
transformer: query.transformer,
|
|
106
|
+
}, { noRecursiveQuery: true }).execute();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
getDynamicVariable(variable) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
let { parameters } = this;
|
|
112
|
+
const queryId = variable.queryId, name = variable.name;
|
|
113
|
+
let value = yield threadUtils.checkCacheForDynamicVariable(queryId, name);
|
|
114
|
+
if (!value) {
|
|
115
|
+
value = this.queryResponse[queryId]
|
|
116
|
+
? this.queryResponse[queryId]
|
|
117
|
+
: yield this.runAnotherQuery(queryId, parameters);
|
|
118
|
+
// store incase this query is to be called again
|
|
119
|
+
this.queryResponse[queryId] = value;
|
|
120
|
+
yield threadUtils.storeDynamicVariable(queryId, name, value);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.cachedVariables.push({ queryId, name });
|
|
124
|
+
}
|
|
125
|
+
return value;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
addDatasourceVariables() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
130
|
+
let { datasource, parameters, fields } = this;
|
|
131
|
+
if (!datasource || !datasource.config) {
|
|
132
|
+
return parameters;
|
|
133
|
+
}
|
|
134
|
+
const staticVars = datasource.config.staticVariables || {};
|
|
135
|
+
const dynamicVars = datasource.config.dynamicVariables || [];
|
|
136
|
+
for (let [key, value] of Object.entries(staticVars)) {
|
|
137
|
+
if (!parameters[key]) {
|
|
138
|
+
parameters[key] = value;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (!this.noRecursiveQuery) {
|
|
142
|
+
// need to see if this uses any variables
|
|
143
|
+
const stringFields = JSON.stringify(fields);
|
|
144
|
+
const foundVars = dynamicVars.filter(variable => {
|
|
145
|
+
// don't allow a query to use its own dynamic variable (loop)
|
|
146
|
+
if (variable.queryId === this.queryId) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
// look for {{ variable }} but allow spaces between handlebars
|
|
150
|
+
const regex = new RegExp(`{{[ ]*${variable.name}[ ]*}}`);
|
|
151
|
+
return regex.test(stringFields);
|
|
152
|
+
});
|
|
153
|
+
const dynamics = foundVars.map(dynVar => this.getDynamicVariable(dynVar));
|
|
154
|
+
const responses = yield Promise.all(dynamics);
|
|
155
|
+
for (let i = 0; i < foundVars.length; i++) {
|
|
156
|
+
const variable = foundVars[i];
|
|
157
|
+
parameters[variable.name] = processStringSync(variable.value, {
|
|
158
|
+
data: responses[i].rows,
|
|
159
|
+
info: responses[i].extra,
|
|
160
|
+
});
|
|
161
|
+
// make sure its known that this uses dynamic variables in case it fails
|
|
162
|
+
this.hasDynamicVariables = true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return parameters;
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
enrichQueryFields(fields, parameters = {}) {
|
|
169
|
+
const enrichedQuery = {};
|
|
170
|
+
// enrich the fields with dynamic parameters
|
|
171
|
+
for (let key of Object.keys(fields)) {
|
|
172
|
+
if (fields[key] == null) {
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (typeof fields[key] === "object") {
|
|
176
|
+
// enrich nested fields object
|
|
177
|
+
enrichedQuery[key] = this.enrichQueryFields(fields[key], parameters);
|
|
178
|
+
}
|
|
179
|
+
else if (typeof fields[key] === "string") {
|
|
180
|
+
// enrich string value as normal
|
|
181
|
+
let value = fields[key];
|
|
182
|
+
// add triple brace to avoid escaping e.g. '=' in cookie header
|
|
183
|
+
if (IS_HANDLEBARS.test(value) && !IS_TRIPLE_BRACE.test(value)) {
|
|
184
|
+
value = `{${value}}`;
|
|
185
|
+
}
|
|
186
|
+
enrichedQuery[key] = processStringSync(value, parameters, {
|
|
187
|
+
noHelpers: true,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
enrichedQuery[key] = fields[key];
|
|
192
|
+
}
|
|
57
193
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
194
|
+
if (enrichedQuery.json ||
|
|
195
|
+
enrichedQuery.customData ||
|
|
196
|
+
enrichedQuery.requestBody) {
|
|
197
|
+
try {
|
|
198
|
+
enrichedQuery.json = JSON.parse(enrichedQuery.json ||
|
|
199
|
+
enrichedQuery.customData ||
|
|
200
|
+
enrichedQuery.requestBody);
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
// no json found, ignore
|
|
204
|
+
}
|
|
205
|
+
delete enrichedQuery.customData;
|
|
62
206
|
}
|
|
63
|
-
return
|
|
64
|
-
}
|
|
207
|
+
return enrichedQuery;
|
|
208
|
+
}
|
|
65
209
|
}
|
|
66
210
|
module.exports = (input, callback) => {
|
|
67
|
-
|
|
211
|
+
const Runner = new QueryRunner(input);
|
|
212
|
+
Runner.execute()
|
|
68
213
|
.then(response => {
|
|
69
214
|
callback(null, response);
|
|
70
215
|
})
|