@budibase/server 1.0.25 → 1.0.27-alpha.10
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 +21 -0
- package/builder/assets/bb-spaceship.8f6e81e1.svg +227 -0
- package/builder/assets/{index.4fb3f887.css → index.0dce895b.css} +1 -1
- package/builder/assets/index.39751e34.js +1348 -0
- package/builder/assets/{vendor.470042a4.js → vendor.f9faf6ab.js} +88 -88
- package/builder/index.html +3 -3
- package/coverage/clover.xml +1263 -1036
- package/coverage/coverage-final.json +36 -35
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +54 -54
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +22 -10
- 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 +62 -62
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +39 -54
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +126 -0
- package/coverage/lcov-report/api/controllers/{query.js.html → query/index.js.html} +225 -114
- package/coverage/lcov-report/api/controllers/query/validation.js.html +206 -0
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +22 -22
- 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 +7 -4
- package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -20
- package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
- 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 +108 -9
- 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 +18 -6
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +5 -5
- 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 +1 -1
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +9 -9
- 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 +19 -85
- 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 +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +1 -1
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +32 -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 +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +20 -20
- 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 +31 -7
- 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 +5 -8
- 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 +48 -15
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +22 -22
- 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 +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- 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 +4 -4
- package/coverage/lcov-report/db/utils.js.html +107 -80
- 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 +99 -84
- 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 +10 -10
- package/coverage/lcov-report/middleware/builder.js.html +8 -8
- package/coverage/lcov-report/middleware/currentapp.js.html +28 -28
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +11 -11
- package/coverage/lcov-report/middleware/resourceId.js.html +17 -17
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +31 -31
- package/coverage/lcov-report/threads/index.js.html +11 -11
- package/coverage/lcov-report/threads/query.js.html +394 -67
- package/coverage/lcov-report/threads/utils.js.html +356 -11
- 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 +1 -1
- package/coverage/lcov-report/utilities/global.js.html +13 -13
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +68 -35
- 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 +235 -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 +2 -2
- 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 +1 -1
- package/coverage/lcov.info +2117 -1728
- package/dist/api/controllers/automation.js +7 -5
- package/dist/api/controllers/query/import/index.js +79 -0
- package/dist/api/controllers/query/import/sources/base/index.js +64 -0
- package/dist/api/controllers/query/import/sources/base/openapi.js +42 -0
- package/dist/api/controllers/query/import/sources/curl.js +96 -0
- package/dist/api/controllers/query/import/sources/openapi2.js +142 -0
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
- package/dist/api/controllers/{query.js → query/index.js} +86 -52
- package/dist/api/controllers/query/validation.js +38 -0
- package/dist/api/controllers/row/internal.js +14 -6
- package/dist/api/controllers/row/internalSearch.js +2 -1
- package/dist/api/controllers/row/utils.js +13 -6
- package/dist/api/controllers/user.js +37 -1
- package/dist/api/controllers/webhook.js +4 -0
- package/dist/api/routes/query.js +5 -33
- package/dist/api/routes/user.js +3 -1
- package/dist/automations/steps/executeQuery.js +8 -1
- package/dist/automations/steps/outgoingWebhook.js +2 -3
- package/dist/automations/utils.js +10 -0
- package/dist/db/utils.js +8 -0
- package/dist/definitions/datasource.js +6 -1
- package/dist/integrations/base/sqlTable.js +1 -1
- package/dist/integrations/rest.js +207 -117
- package/dist/package.json +11 -4
- package/dist/tests/utilities/TestConfiguration.js +7 -0
- package/dist/threads/query.js +148 -40
- package/dist/threads/utils.js +105 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/index.js +10 -0
- package/dist/utilities/rowProcessor/index.js +76 -0
- package/package.json +12 -5
- package/src/api/controllers/automation.js +8 -4
- package/src/api/controllers/query/import/index.ts +85 -0
- package/src/api/controllers/query/import/sources/base/index.ts +87 -0
- package/src/api/controllers/query/import/sources/base/openapi.ts +24 -0
- package/src/api/controllers/query/import/sources/curl.ts +102 -0
- package/src/api/controllers/query/import/sources/openapi2.ts +163 -0
- package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +103 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +3 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +2 -0
- package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +1 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +253 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +160 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +1054 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +711 -0
- package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +238 -0
- package/src/api/controllers/query/import/tests/index.spec.js +109 -0
- package/src/api/controllers/query/index.js +195 -0
- package/src/api/controllers/query/validation.js +42 -0
- package/src/api/controllers/row/internal.js +14 -5
- package/src/api/controllers/row/internalSearch.js +2 -1
- package/src/api/controllers/row/utils.js +11 -8
- package/src/api/controllers/user.js +33 -0
- package/src/api/controllers/webhook.js +4 -0
- package/src/api/routes/query.js +13 -35
- package/src/api/routes/tests/query.spec.js +88 -0
- package/src/api/routes/user.js +10 -0
- package/src/automations/steps/executeQuery.js +9 -1
- package/src/automations/steps/outgoingWebhook.js +2 -3
- package/src/automations/utils.js +11 -0
- package/src/db/utils.js +9 -0
- package/src/definitions/common.ts +2 -16
- package/src/definitions/datasource.ts +83 -1
- package/src/integrations/base/IntegrationBase.ts +4 -4
- package/src/integrations/base/sqlTable.ts +1 -1
- package/src/integrations/oracle.ts +1 -1
- package/src/integrations/rest.ts +230 -137
- package/src/integrations/tests/rest.spec.js +167 -19
- package/src/tests/utilities/TestConfiguration.js +10 -0
- package/src/threads/query.js +149 -40
- package/src/threads/utils.js +115 -0
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/src/utilities/index.js +11 -0
- package/src/utilities/rowProcessor/index.js +75 -0
- package/builder/assets/index.f01106f0.js +0 -1316
- package/src/api/controllers/query.js +0 -158
|
@@ -10,18 +10,54 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
const datasource_1 = require("../definitions/datasource");
|
|
13
|
+
const BodyTypes = {
|
|
14
|
+
NONE: "none",
|
|
15
|
+
FORM_DATA: "form",
|
|
16
|
+
XML: "xml",
|
|
17
|
+
ENCODED: "encoded",
|
|
18
|
+
JSON: "json",
|
|
19
|
+
TEXT: "text",
|
|
20
|
+
};
|
|
21
|
+
const coreFields = {
|
|
22
|
+
path: {
|
|
23
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
24
|
+
display: "URL",
|
|
25
|
+
},
|
|
26
|
+
queryString: {
|
|
27
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
28
|
+
},
|
|
29
|
+
headers: {
|
|
30
|
+
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
31
|
+
},
|
|
32
|
+
enabledHeaders: {
|
|
33
|
+
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
34
|
+
},
|
|
35
|
+
requestBody: {
|
|
36
|
+
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
37
|
+
},
|
|
38
|
+
bodyType: {
|
|
39
|
+
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
40
|
+
enum: Object.values(BodyTypes),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
13
43
|
var RestModule;
|
|
14
44
|
(function (RestModule) {
|
|
15
45
|
const fetch = require("node-fetch");
|
|
46
|
+
const { formatBytes } = require("../utilities");
|
|
47
|
+
const { performance } = require("perf_hooks");
|
|
48
|
+
const FormData = require("form-data");
|
|
49
|
+
const { URLSearchParams } = require("url");
|
|
50
|
+
const { parseStringPromise: xmlParser, Builder: XmlBuilder, } = require("xml2js");
|
|
16
51
|
const SCHEMA = {
|
|
17
52
|
docs: "https://github.com/node-fetch/node-fetch",
|
|
18
|
-
description: "
|
|
53
|
+
description: "With the REST API datasource, you can connect, query and pull data from multiple REST APIs. You can then use the retrieved data to build apps.",
|
|
19
54
|
friendlyName: "REST API",
|
|
20
55
|
datasource: {
|
|
21
56
|
url: {
|
|
22
57
|
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
23
|
-
default: "
|
|
24
|
-
required:
|
|
58
|
+
default: "",
|
|
59
|
+
required: false,
|
|
60
|
+
deprecated: true,
|
|
25
61
|
},
|
|
26
62
|
defaultHeaders: {
|
|
27
63
|
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
@@ -34,174 +70,228 @@ var RestModule;
|
|
|
34
70
|
readable: true,
|
|
35
71
|
displayName: "POST",
|
|
36
72
|
type: datasource_1.QueryTypes.FIELDS,
|
|
37
|
-
|
|
38
|
-
fields: {
|
|
39
|
-
path: {
|
|
40
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
41
|
-
},
|
|
42
|
-
queryString: {
|
|
43
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
44
|
-
},
|
|
45
|
-
headers: {
|
|
46
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
47
|
-
},
|
|
48
|
-
requestBody: {
|
|
49
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
50
|
-
},
|
|
51
|
-
},
|
|
73
|
+
fields: coreFields,
|
|
52
74
|
},
|
|
53
75
|
read: {
|
|
54
76
|
displayName: "GET",
|
|
55
77
|
readable: true,
|
|
56
78
|
type: datasource_1.QueryTypes.FIELDS,
|
|
57
|
-
|
|
58
|
-
fields: {
|
|
59
|
-
path: {
|
|
60
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
61
|
-
},
|
|
62
|
-
queryString: {
|
|
63
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
64
|
-
},
|
|
65
|
-
headers: {
|
|
66
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
67
|
-
},
|
|
68
|
-
},
|
|
79
|
+
fields: coreFields,
|
|
69
80
|
},
|
|
70
81
|
update: {
|
|
71
82
|
displayName: "PUT",
|
|
72
83
|
readable: true,
|
|
73
84
|
type: datasource_1.QueryTypes.FIELDS,
|
|
74
|
-
|
|
75
|
-
fields: {
|
|
76
|
-
path: {
|
|
77
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
78
|
-
},
|
|
79
|
-
queryString: {
|
|
80
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
81
|
-
},
|
|
82
|
-
headers: {
|
|
83
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
84
|
-
},
|
|
85
|
-
requestBody: {
|
|
86
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
85
|
+
fields: coreFields,
|
|
89
86
|
},
|
|
90
87
|
patch: {
|
|
91
88
|
displayName: "PATCH",
|
|
92
89
|
readable: true,
|
|
93
90
|
type: datasource_1.QueryTypes.FIELDS,
|
|
94
|
-
|
|
95
|
-
fields: {
|
|
96
|
-
path: {
|
|
97
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
98
|
-
},
|
|
99
|
-
queryString: {
|
|
100
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
101
|
-
},
|
|
102
|
-
headers: {
|
|
103
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
104
|
-
},
|
|
105
|
-
requestBody: {
|
|
106
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
91
|
+
fields: coreFields,
|
|
109
92
|
},
|
|
110
93
|
delete: {
|
|
111
94
|
displayName: "DELETE",
|
|
112
95
|
type: datasource_1.QueryTypes.FIELDS,
|
|
113
|
-
|
|
114
|
-
fields: {
|
|
115
|
-
path: {
|
|
116
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
117
|
-
},
|
|
118
|
-
queryString: {
|
|
119
|
-
type: datasource_1.DatasourceFieldTypes.STRING,
|
|
120
|
-
},
|
|
121
|
-
headers: {
|
|
122
|
-
type: datasource_1.DatasourceFieldTypes.OBJECT,
|
|
123
|
-
},
|
|
124
|
-
requestBody: {
|
|
125
|
-
type: datasource_1.DatasourceFieldTypes.JSON,
|
|
126
|
-
},
|
|
127
|
-
},
|
|
96
|
+
fields: coreFields,
|
|
128
97
|
},
|
|
129
98
|
},
|
|
130
99
|
};
|
|
131
100
|
class RestIntegration {
|
|
132
101
|
constructor(config) {
|
|
133
102
|
this.headers = {};
|
|
103
|
+
this.startTimeMs = performance.now();
|
|
134
104
|
this.config = config;
|
|
135
105
|
}
|
|
136
106
|
parseResponse(response) {
|
|
137
107
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
108
|
+
let data, raw, headers;
|
|
109
|
+
const contentType = response.headers.get("content-type") || "";
|
|
110
|
+
try {
|
|
111
|
+
if (contentType.includes("application/json")) {
|
|
112
|
+
data = yield response.json();
|
|
113
|
+
raw = JSON.stringify(data);
|
|
114
|
+
}
|
|
115
|
+
else if (contentType.includes("text/xml") ||
|
|
116
|
+
contentType.includes("application/xml")) {
|
|
117
|
+
const rawXml = yield response.text();
|
|
118
|
+
data =
|
|
119
|
+
(yield xmlParser(rawXml, {
|
|
120
|
+
explicitArray: false,
|
|
121
|
+
trim: true,
|
|
122
|
+
explicitRoot: false,
|
|
123
|
+
})) || {};
|
|
124
|
+
// there is only one structure, its an array, return the array so it appears as rows
|
|
125
|
+
const keys = Object.keys(data);
|
|
126
|
+
if (keys.length === 1 && Array.isArray(data[keys[0]])) {
|
|
127
|
+
data = data[keys[0]];
|
|
128
|
+
}
|
|
129
|
+
raw = rawXml;
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
data = yield response.text();
|
|
133
|
+
raw = data;
|
|
134
|
+
}
|
|
141
135
|
}
|
|
142
|
-
|
|
143
|
-
|
|
136
|
+
catch (err) {
|
|
137
|
+
throw "Failed to parse response body.";
|
|
144
138
|
}
|
|
139
|
+
const size = formatBytes(response.headers.get("content-length") || Buffer.byteLength(raw, "utf8"));
|
|
140
|
+
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`;
|
|
141
|
+
headers = response.headers.raw();
|
|
142
|
+
for (let [key, value] of Object.entries(headers)) {
|
|
143
|
+
headers[key] = Array.isArray(value) ? value[0] : value;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
data,
|
|
147
|
+
info: {
|
|
148
|
+
code: response.status,
|
|
149
|
+
size,
|
|
150
|
+
time,
|
|
151
|
+
},
|
|
152
|
+
extra: {
|
|
153
|
+
raw,
|
|
154
|
+
headers,
|
|
155
|
+
},
|
|
156
|
+
};
|
|
145
157
|
});
|
|
146
158
|
}
|
|
147
159
|
getUrl(path, queryString) {
|
|
148
|
-
|
|
160
|
+
const main = `${path}?${queryString}`;
|
|
161
|
+
let complete = main;
|
|
162
|
+
if (this.config.url && !main.startsWith("http")) {
|
|
163
|
+
complete = !this.config.url ? main : `${this.config.url}/${main}`;
|
|
164
|
+
}
|
|
165
|
+
if (!complete.startsWith("http")) {
|
|
166
|
+
complete = `http://${complete}`;
|
|
167
|
+
}
|
|
168
|
+
return complete;
|
|
169
|
+
}
|
|
170
|
+
addBody(bodyType, body, input) {
|
|
171
|
+
let error, object, string;
|
|
172
|
+
try {
|
|
173
|
+
string = typeof body !== "string" ? JSON.stringify(body) : body;
|
|
174
|
+
object = typeof body === "object" ? body : JSON.parse(body);
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
error = err;
|
|
178
|
+
}
|
|
179
|
+
if (!input.headers) {
|
|
180
|
+
input.headers = {};
|
|
181
|
+
}
|
|
182
|
+
switch (bodyType) {
|
|
183
|
+
case BodyTypes.NONE:
|
|
184
|
+
break;
|
|
185
|
+
case BodyTypes.TEXT:
|
|
186
|
+
// content type defaults to plaintext
|
|
187
|
+
input.body = string;
|
|
188
|
+
break;
|
|
189
|
+
case BodyTypes.ENCODED:
|
|
190
|
+
const params = new URLSearchParams();
|
|
191
|
+
for (let [key, value] of Object.entries(object)) {
|
|
192
|
+
params.append(key, value);
|
|
193
|
+
}
|
|
194
|
+
input.body = params;
|
|
195
|
+
break;
|
|
196
|
+
case BodyTypes.FORM_DATA:
|
|
197
|
+
const form = new FormData();
|
|
198
|
+
for (let [key, value] of Object.entries(object)) {
|
|
199
|
+
form.append(key, value);
|
|
200
|
+
}
|
|
201
|
+
input.body = form;
|
|
202
|
+
break;
|
|
203
|
+
case BodyTypes.XML:
|
|
204
|
+
if (object != null) {
|
|
205
|
+
string = new XmlBuilder().buildObject(object);
|
|
206
|
+
}
|
|
207
|
+
input.body = string;
|
|
208
|
+
input.headers["Content-Type"] = "application/xml";
|
|
209
|
+
break;
|
|
210
|
+
default:
|
|
211
|
+
case BodyTypes.JSON:
|
|
212
|
+
// if JSON error, throw it
|
|
213
|
+
if (error) {
|
|
214
|
+
throw "Invalid JSON for request body";
|
|
215
|
+
}
|
|
216
|
+
input.body = string;
|
|
217
|
+
input.headers["Content-Type"] = "application/json";
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return input;
|
|
221
|
+
}
|
|
222
|
+
getAuthHeaders(authConfigId) {
|
|
223
|
+
let headers = {};
|
|
224
|
+
if (this.config.authConfigs && authConfigId) {
|
|
225
|
+
const authConfig = this.config.authConfigs.filter(c => c._id === authConfigId)[0];
|
|
226
|
+
// check the config still exists before proceeding
|
|
227
|
+
// if not - do nothing
|
|
228
|
+
if (authConfig) {
|
|
229
|
+
let config;
|
|
230
|
+
switch (authConfig.type) {
|
|
231
|
+
case datasource_1.AuthType.BASIC:
|
|
232
|
+
config = authConfig.config;
|
|
233
|
+
headers.Authorization = `Basic ${Buffer.from(`${config.username}:${config.password}`).toString("base64")}`;
|
|
234
|
+
break;
|
|
235
|
+
case datasource_1.AuthType.BEARER:
|
|
236
|
+
config = authConfig.config;
|
|
237
|
+
headers.Authorization = `Bearer ${config.token}`;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return headers;
|
|
149
243
|
}
|
|
150
|
-
|
|
244
|
+
_req(query) {
|
|
151
245
|
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
246
|
+
const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody, authConfigId, } = query;
|
|
247
|
+
const authHeaders = this.getAuthHeaders(authConfigId);
|
|
248
|
+
this.headers = Object.assign(Object.assign(Object.assign({}, this.config.defaultHeaders), headers), authHeaders);
|
|
249
|
+
if (disabledHeaders) {
|
|
250
|
+
for (let headerKey of Object.keys(this.headers)) {
|
|
251
|
+
if (disabledHeaders[headerKey]) {
|
|
252
|
+
delete this.headers[headerKey];
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
let input = { method, headers: this.headers };
|
|
257
|
+
if (requestBody) {
|
|
258
|
+
input = this.addBody(bodyType, requestBody, input);
|
|
259
|
+
}
|
|
260
|
+
this.startTimeMs = performance.now();
|
|
261
|
+
const url = this.getUrl(path, queryString);
|
|
262
|
+
const response = yield fetch(url, input);
|
|
158
263
|
return yield this.parseResponse(response);
|
|
159
264
|
});
|
|
160
265
|
}
|
|
161
|
-
|
|
266
|
+
create(opts) {
|
|
162
267
|
return __awaiter(this, void 0, void 0, function* () {
|
|
163
|
-
this.
|
|
164
|
-
const response = yield fetch(this.getUrl(path, queryString), {
|
|
165
|
-
headers: this.headers,
|
|
166
|
-
});
|
|
167
|
-
return yield this.parseResponse(response);
|
|
268
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "POST" }));
|
|
168
269
|
});
|
|
169
270
|
}
|
|
170
|
-
|
|
271
|
+
read(opts) {
|
|
171
272
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
this.
|
|
173
|
-
const response = yield fetch(this.getUrl(path, queryString), {
|
|
174
|
-
method: "PUT",
|
|
175
|
-
headers: this.headers,
|
|
176
|
-
body: JSON.stringify(json),
|
|
177
|
-
});
|
|
178
|
-
return yield this.parseResponse(response);
|
|
273
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "GET" }));
|
|
179
274
|
});
|
|
180
275
|
}
|
|
181
|
-
|
|
276
|
+
update(opts) {
|
|
182
277
|
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
this.
|
|
184
|
-
const response = yield fetch(this.getUrl(path, queryString), {
|
|
185
|
-
method: "PATCH",
|
|
186
|
-
headers: this.headers,
|
|
187
|
-
body: JSON.stringify(json),
|
|
188
|
-
});
|
|
189
|
-
return yield this.parseResponse(response);
|
|
278
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "PUT" }));
|
|
190
279
|
});
|
|
191
280
|
}
|
|
192
|
-
|
|
281
|
+
patch(opts) {
|
|
193
282
|
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
-
this.
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return
|
|
283
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "PATCH" }));
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
delete(opts) {
|
|
287
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
+
return this._req(Object.assign(Object.assign({}, opts), { method: "DELETE" }));
|
|
200
289
|
});
|
|
201
290
|
}
|
|
202
291
|
}
|
|
203
292
|
module.exports = {
|
|
204
293
|
schema: SCHEMA,
|
|
205
294
|
integration: RestIntegration,
|
|
295
|
+
AuthType: datasource_1.AuthType,
|
|
206
296
|
};
|
|
207
297
|
})(RestModule || (RestModule = {}));
|
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.
|
|
4
|
+
"version": "1.0.27-alpha.9",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -69,9 +69,10 @@
|
|
|
69
69
|
"author": "Budibase",
|
|
70
70
|
"license": "GPL-3.0",
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@
|
|
73
|
-
"@budibase/
|
|
74
|
-
"@budibase/
|
|
72
|
+
"@apidevtools/swagger-parser": "^10.0.3",
|
|
73
|
+
"@budibase/auth": "^1.0.27-alpha.9",
|
|
74
|
+
"@budibase/client": "^1.0.27-alpha.9",
|
|
75
|
+
"@budibase/string-templates": "^1.0.27-alpha.9",
|
|
75
76
|
"@bull-board/api": "^3.7.0",
|
|
76
77
|
"@bull-board/koa": "^3.7.0",
|
|
77
78
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -85,12 +86,15 @@
|
|
|
85
86
|
"bull": "^3.22.4",
|
|
86
87
|
"chmodr": "1.2.0",
|
|
87
88
|
"csvtojson": "2.0.10",
|
|
89
|
+
"curlconverter": "^3.21.0",
|
|
88
90
|
"dotenv": "8.2.0",
|
|
89
91
|
"download": "8.0.0",
|
|
90
92
|
"fix-path": "3.0.0",
|
|
93
|
+
"form-data": "^4.0.0",
|
|
91
94
|
"fs-extra": "8.1.0",
|
|
92
95
|
"jimp": "0.16.1",
|
|
93
96
|
"joi": "17.2.1",
|
|
97
|
+
"js-yaml": "^4.1.0",
|
|
94
98
|
"jsonschema": "1.4.0",
|
|
95
99
|
"knex": "^0.95.6",
|
|
96
100
|
"koa": "2.7.0",
|
|
@@ -118,11 +122,13 @@
|
|
|
118
122
|
"pouchdb-replication-stream": "1.2.9",
|
|
119
123
|
"server-destroy": "1.0.1",
|
|
120
124
|
"svelte": "^3.38.2",
|
|
125
|
+
"swagger-parser": "^10.0.3",
|
|
121
126
|
"to-json-schema": "0.2.5",
|
|
122
127
|
"uuid": "3.3.2",
|
|
123
128
|
"validate.js": "0.13.1",
|
|
124
129
|
"vm2": "^3.9.3",
|
|
125
130
|
"worker-farm": "^1.7.0",
|
|
131
|
+
"xml2js": "^0.4.23",
|
|
126
132
|
"yargs": "13.2.4",
|
|
127
133
|
"zlib": "1.0.5"
|
|
128
134
|
},
|
|
@@ -146,6 +152,7 @@
|
|
|
146
152
|
"eslint": "^6.8.0",
|
|
147
153
|
"jest": "^27.0.5",
|
|
148
154
|
"nodemon": "^2.0.4",
|
|
155
|
+
"openapi-types": "^9.3.1",
|
|
149
156
|
"path-to-regexp": "^6.2.0",
|
|
150
157
|
"prettier": "^2.3.1",
|
|
151
158
|
"rimraf": "^3.0.2",
|
|
@@ -294,6 +294,13 @@ 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
|
+
}
|
|
297
304
|
createQuery(config = null) {
|
|
298
305
|
return __awaiter(this, void 0, void 0, function* () {
|
|
299
306
|
if (!this.datasource && !config) {
|
package/dist/threads/query.js
CHANGED
|
@@ -8,51 +8,159 @@ 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
|
+
class QueryRunner {
|
|
18
|
+
constructor(input, flags = { noRecursiveQuery: false }) {
|
|
19
|
+
this.appId = input.appId;
|
|
20
|
+
this.datasource = input.datasource;
|
|
21
|
+
this.queryVerb = input.queryVerb;
|
|
22
|
+
this.fields = input.fields;
|
|
23
|
+
this.parameters = input.parameters;
|
|
24
|
+
this.transformer = input.transformer;
|
|
25
|
+
this.queryId = input.queryId;
|
|
26
|
+
this.noRecursiveQuery = flags.noRecursiveQuery;
|
|
27
|
+
this.cachedVariables = [];
|
|
28
|
+
// allows the response from a query to be stored throughout this
|
|
29
|
+
// execution so that if it needs to be re-used for another variable
|
|
30
|
+
// it can be
|
|
31
|
+
this.queryResponse = {};
|
|
32
|
+
this.hasRerun = false;
|
|
33
|
+
}
|
|
34
|
+
execute() {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
let { datasource, fields, queryVerb, transformer } = this;
|
|
37
|
+
// pre-query, make sure datasource variables are added to parameters
|
|
38
|
+
const parameters = yield this.addDatasourceVariables();
|
|
39
|
+
const query = threadUtils.enrichQueryFields(fields, parameters);
|
|
40
|
+
const Integration = integrations[datasource.source];
|
|
41
|
+
if (!Integration) {
|
|
42
|
+
throw "Integration type does not exist.";
|
|
43
|
+
}
|
|
44
|
+
const integration = new Integration(datasource.config);
|
|
45
|
+
let output = threadUtils.formatResponse(yield integration[queryVerb](query));
|
|
46
|
+
let rows = output, info = undefined, extra = undefined;
|
|
47
|
+
if (threadUtils.hasExtraData(output)) {
|
|
48
|
+
rows = output.data;
|
|
49
|
+
info = output.info;
|
|
50
|
+
extra = output.extra;
|
|
51
|
+
}
|
|
52
|
+
// transform as required
|
|
53
|
+
if (transformer) {
|
|
54
|
+
const runner = new ScriptRunner(transformer, {
|
|
55
|
+
data: rows,
|
|
56
|
+
params: parameters,
|
|
57
|
+
});
|
|
58
|
+
rows = runner.execute();
|
|
59
|
+
}
|
|
60
|
+
// if the request fails we retry once, invalidating the cached value
|
|
61
|
+
if (info &&
|
|
62
|
+
info.code >= 400 &&
|
|
63
|
+
this.cachedVariables.length > 0 &&
|
|
64
|
+
!this.hasRerun) {
|
|
65
|
+
this.hasRerun = true;
|
|
66
|
+
// invalidate the cache value
|
|
67
|
+
yield threadUtils.invalidateDynamicVariables(this.cachedVariables);
|
|
68
|
+
return this.execute();
|
|
69
|
+
}
|
|
70
|
+
// needs to an array for next step
|
|
71
|
+
if (!Array.isArray(rows)) {
|
|
72
|
+
rows = [rows];
|
|
73
|
+
}
|
|
74
|
+
// map into JSON if just raw primitive here
|
|
75
|
+
if (rows.find(row => typeof row !== "object")) {
|
|
76
|
+
rows = rows.map(value => ({ value }));
|
|
77
|
+
}
|
|
78
|
+
// get all the potential fields in the schema
|
|
79
|
+
let keys = rows.flatMap(Object.keys);
|
|
80
|
+
if (integration.end) {
|
|
81
|
+
integration.end();
|
|
82
|
+
}
|
|
83
|
+
return { rows, keys, info, extra };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
runAnotherQuery(queryId, parameters) {
|
|
87
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
88
|
+
const db = new CouchDB(this.appId);
|
|
89
|
+
const query = yield db.get(queryId);
|
|
90
|
+
const datasource = yield db.get(query.datasourceId);
|
|
91
|
+
return new QueryRunner({
|
|
92
|
+
appId: this.appId,
|
|
93
|
+
datasource,
|
|
94
|
+
queryVerb: query.queryVerb,
|
|
95
|
+
fields: query.fields,
|
|
96
|
+
parameters,
|
|
97
|
+
transformer: query.transformer,
|
|
98
|
+
}, { noRecursiveQuery: true }).execute();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
getDynamicVariable(variable) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
let { parameters } = this;
|
|
104
|
+
const queryId = variable.queryId, name = variable.name;
|
|
105
|
+
let value = yield threadUtils.checkCacheForDynamicVariable(queryId, name);
|
|
106
|
+
if (!value) {
|
|
107
|
+
value = this.queryResponse[queryId]
|
|
108
|
+
? this.queryResponse[queryId]
|
|
109
|
+
: yield this.runAnotherQuery(queryId, parameters);
|
|
110
|
+
// store incase this query is to be called again
|
|
111
|
+
this.queryResponse[queryId] = value;
|
|
112
|
+
yield threadUtils.storeDynamicVariable(queryId, name, value);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.cachedVariables.push({ queryId, name });
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
addDatasourceVariables() {
|
|
121
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
122
|
+
let { datasource, parameters, fields } = this;
|
|
123
|
+
if (!datasource || !datasource.config) {
|
|
124
|
+
return parameters;
|
|
125
|
+
}
|
|
126
|
+
const staticVars = datasource.config.staticVariables || {};
|
|
127
|
+
const dynamicVars = datasource.config.dynamicVariables || [];
|
|
128
|
+
for (let [key, value] of Object.entries(staticVars)) {
|
|
129
|
+
if (!parameters[key]) {
|
|
130
|
+
parameters[key] = value;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (!this.noRecursiveQuery) {
|
|
134
|
+
// need to see if this uses any variables
|
|
135
|
+
const stringFields = JSON.stringify(fields);
|
|
136
|
+
const foundVars = dynamicVars.filter(variable => {
|
|
137
|
+
// don't allow a query to use its own dynamic variable (loop)
|
|
138
|
+
if (variable.queryId === this.queryId) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
// look for {{ variable }} but allow spaces between handlebars
|
|
142
|
+
const regex = new RegExp(`{{[ ]*${variable.name}[ ]*}}`);
|
|
143
|
+
return regex.test(stringFields);
|
|
144
|
+
});
|
|
145
|
+
const dynamics = foundVars.map(dynVar => this.getDynamicVariable(dynVar));
|
|
146
|
+
const responses = yield Promise.all(dynamics);
|
|
147
|
+
for (let i = 0; i < foundVars.length; i++) {
|
|
148
|
+
const variable = foundVars[i];
|
|
149
|
+
parameters[variable.name] = processStringSync(variable.value, {
|
|
150
|
+
data: responses[i].rows,
|
|
151
|
+
info: responses[i].extra,
|
|
152
|
+
});
|
|
153
|
+
// make sure its known that this uses dynamic variables in case it fails
|
|
154
|
+
this.hasDynamicVariables = true;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return parameters;
|
|
158
|
+
});
|
|
22
159
|
}
|
|
23
|
-
return resp;
|
|
24
|
-
}
|
|
25
|
-
function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
26
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
-
const Integration = integrations[datasource.source];
|
|
28
|
-
if (!Integration) {
|
|
29
|
-
throw "Integration type does not exist.";
|
|
30
|
-
}
|
|
31
|
-
const integration = new Integration(datasource.config);
|
|
32
|
-
let rows = formatResponse(yield integration[queryVerb](query));
|
|
33
|
-
// transform as required
|
|
34
|
-
if (transformer) {
|
|
35
|
-
const runner = new ScriptRunner(transformer, { data: rows });
|
|
36
|
-
rows = runner.execute();
|
|
37
|
-
}
|
|
38
|
-
// needs to an array for next step
|
|
39
|
-
if (!Array.isArray(rows)) {
|
|
40
|
-
rows = [rows];
|
|
41
|
-
}
|
|
42
|
-
// map into JSON if just raw primitive here
|
|
43
|
-
if (rows.find(row => typeof row !== "object")) {
|
|
44
|
-
rows = rows.map(value => ({ value }));
|
|
45
|
-
}
|
|
46
|
-
// get all the potential fields in the schema
|
|
47
|
-
let keys = rows.flatMap(Object.keys);
|
|
48
|
-
if (integration.end) {
|
|
49
|
-
integration.end();
|
|
50
|
-
}
|
|
51
|
-
return { rows, keys };
|
|
52
|
-
});
|
|
53
160
|
}
|
|
54
161
|
module.exports = (input, callback) => {
|
|
55
|
-
|
|
162
|
+
const Runner = new QueryRunner(input);
|
|
163
|
+
Runner.execute()
|
|
56
164
|
.then(response => {
|
|
57
165
|
callback(null, response);
|
|
58
166
|
})
|