@budibase/server 1.0.113 → 1.0.116
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/builder/assets/{index.e3e5909b.js → index.28d8c64f.js} +4 -4
- package/builder/index.html +1 -1
- package/coverage/clover.xml +1212 -1269
- package/coverage/coverage-final.json +86 -87
- 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 +126 -120
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
- package/coverage/lcov-report/api/controllers/dev.js.html +23 -14
- package/coverage/lcov-report/api/controllers/index.html +17 -17
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
- package/coverage/lcov-report/api/controllers/row/index.html +10 -10
- package/coverage/lcov-report/api/controllers/row/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/row/internal.js.html +37 -34
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +10 -10
- package/coverage/lcov-report/api/controllers/row/utils.js.html +12 -12
- package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +9 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/table/internal.js.html +13 -13
- package/coverage/lcov-report/api/controllers/table/utils.js.html +30 -30
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +19 -19
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/view/utils.js.html +12 -12
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
- 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 +1 -1
- 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 +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/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- 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 +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +5 -5
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
- package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- 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 +18 -18
- package/coverage/lcov-report/automations/utils.js.html +43 -40
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +27 -27
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/inMemoryView.js.html +52 -49
- package/coverage/lcov-report/db/index.html +21 -36
- package/coverage/lcov-report/db/index.js.html +49 -10
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +7 -7
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +18 -18
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +13 -13
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +13 -13
- 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 +5 -5
- package/coverage/lcov-report/events/utils.js.html +3 -3
- package/coverage/lcov-report/index.html +52 -52
- 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 +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +15 -12
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +4 -4
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +34 -34
- package/coverage/lcov-report/threads/index.js.html +35 -17
- package/coverage/lcov-report/threads/query.js.html +20 -356
- package/coverage/lcov-report/threads/utils.js.html +19 -22
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +15 -15
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +26 -26
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
- 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 +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +18 -18
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +13 -13
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +8 -8
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +38 -26
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +5 -5
- package/coverage/lcov-report/utilities/workerRequests.js.html +28 -28
- package/coverage/lcov.info +1570 -1660
- package/dist/api/controllers/application.js +4 -1
- package/dist/api/controllers/deploy/index.js +5 -1
- package/dist/api/controllers/dev.js +9 -5
- package/dist/api/controllers/row/internal.js +2 -1
- package/dist/api/controllers/webhook.js +2 -2
- package/dist/api/routes/tests/utilities/TestFunctions.js +1 -4
- package/dist/app.js +5 -2
- package/dist/automations/utils.js +6 -5
- package/dist/db/inMemoryView.js +33 -31
- package/dist/db/index.js +13 -2
- package/dist/integrations/couchdb.js +19 -25
- package/dist/integrations/queries/sql.js +108 -0
- package/dist/middleware/builder.js +10 -9
- package/dist/migrations/index.js +1 -5
- package/dist/package.json +5 -5
- package/dist/tests/utilities/TestConfiguration.js +66 -59
- package/dist/threads/index.js +6 -1
- package/dist/threads/query.js +4 -103
- package/dist/threads/utils.js +2 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +27 -26
- package/dist/utilities/usageQuota/rows.js +16 -16
- package/package.json +6 -6
- package/scripts/exportAppTemplate.js +10 -8
- package/scripts/integrations/mysql/init.sql +1 -0
- package/src/api/controllers/application.js +3 -1
- package/src/api/controllers/deploy/index.js +4 -4
- package/src/api/controllers/dev.js +9 -6
- package/src/api/controllers/query/import/tests/index.spec.js +7 -11
- package/src/api/controllers/row/internal.js +2 -1
- package/src/api/controllers/webhook.js +2 -2
- package/src/api/routes/tests/row.spec.js +15 -11
- package/src/api/routes/tests/table.spec.js +3 -2
- package/src/api/routes/tests/utilities/TestFunctions.js +1 -5
- package/src/app.ts +2 -2
- package/src/automations/tests/deleteRow.spec.js +1 -1
- package/src/automations/utils.js +6 -5
- package/src/db/inMemoryView.js +37 -36
- package/src/db/index.js +15 -2
- package/src/db/tests/linkTests.spec.js +8 -7
- package/src/integrations/couchdb.ts +28 -24
- package/src/integrations/queries/sql.ts +125 -0
- package/src/integrations/tests/airtable.spec.js +3 -1
- package/src/integrations/tests/couchdb.spec.js +4 -1
- package/src/middleware/builder.js +10 -9
- package/src/middleware/tests/authorized.spec.js +0 -1
- package/src/middleware/tests/usageQuota.spec.js +6 -20
- package/src/migrations/functions/tests/appUrls.spec.js +8 -11
- package/src/migrations/functions/tests/userEmailViewCasing.spec.js +13 -10
- package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +25 -21
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +26 -24
- package/src/migrations/index.ts +1 -2
- package/src/module.d.ts +8 -0
- package/src/tests/utilities/TestConfiguration.js +62 -55
- package/src/threads/index.js +7 -1
- package/src/threads/query.js +7 -119
- package/src/threads/utils.js +2 -3
- package/src/utilities/fileSystem/index.js +30 -30
- package/src/utilities/usageQuota/rows.js +22 -18
- package/coverage/lcov-report/db/client.js.html +0 -173
- package/dist/db/client.js +0 -25
- package/scripts/replicateApp.js +0 -50
- package/src/db/client.js +0 -31
|
@@ -8,9 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
const CouchDB = require("../../db");
|
|
13
|
-
core.init(CouchDB);
|
|
11
|
+
require("../../db").init();
|
|
14
12
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
15
13
|
const env = require("../../environment");
|
|
16
14
|
const { basicTable, basicRow, basicRole, basicAutomation, basicDatasource, basicQuery, basicScreen, basicLayout, basicWebhook, TENANT_ID, } = require("./structures");
|
|
@@ -19,7 +17,7 @@ const supertest = require("supertest");
|
|
|
19
17
|
const { cleanup } = require("../../utilities/fileSystem");
|
|
20
18
|
const { Cookies, Headers } = require("@budibase/backend-core/constants");
|
|
21
19
|
const { jwt } = require("@budibase/backend-core/auth");
|
|
22
|
-
const {
|
|
20
|
+
const { doInTenant, doWithGlobalDB } = require("@budibase/backend-core/tenancy");
|
|
23
21
|
const { createASession } = require("@budibase/backend-core/sessions");
|
|
24
22
|
const { user: userCache } = require("@budibase/backend-core/cache");
|
|
25
23
|
const newid = require("../../db/newid");
|
|
@@ -50,8 +48,23 @@ class TestConfiguration {
|
|
|
50
48
|
getAppId() {
|
|
51
49
|
return this.appId;
|
|
52
50
|
}
|
|
53
|
-
|
|
54
|
-
return
|
|
51
|
+
doInContext(appId, task) {
|
|
52
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
+
if (!appId) {
|
|
54
|
+
appId = this.appId;
|
|
55
|
+
}
|
|
56
|
+
return doInTenant(TENANT_ID, () => {
|
|
57
|
+
// check if already in a context
|
|
58
|
+
if (context.getAppId() == null && appId !== null) {
|
|
59
|
+
return context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
return task();
|
|
61
|
+
}));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return task();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
55
68
|
}
|
|
56
69
|
_req(config, params, controlFunc) {
|
|
57
70
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -65,66 +78,57 @@ class TestConfiguration {
|
|
|
65
78
|
request.request = {
|
|
66
79
|
body: config,
|
|
67
80
|
};
|
|
68
|
-
function
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
// check if already in a context
|
|
78
|
-
if (context.getAppId() == null && this.appId !== null) {
|
|
79
|
-
return context.doInAppContext(this.appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
80
|
-
return run();
|
|
81
|
-
}));
|
|
82
|
-
}
|
|
83
|
-
else {
|
|
84
|
-
return run();
|
|
85
|
-
}
|
|
81
|
+
return this.doInContext(this.appId, () => __awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
if (params) {
|
|
83
|
+
request.params = params;
|
|
84
|
+
}
|
|
85
|
+
yield controlFunc(request);
|
|
86
|
+
return request.body;
|
|
87
|
+
}));
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
90
|
generateApiKey(userId = GLOBAL_USER_ID) {
|
|
89
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
return doWithGlobalDB(TENANT_ID, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const id = generateDevInfoID(userId);
|
|
94
|
+
let devInfo;
|
|
95
|
+
try {
|
|
96
|
+
devInfo = yield db.get(id);
|
|
97
|
+
}
|
|
98
|
+
catch (err) {
|
|
99
|
+
devInfo = { _id: id, userId };
|
|
100
|
+
}
|
|
101
|
+
devInfo.apiKey = encrypt(`${TENANT_ID}${SEPARATOR}${newid()}`);
|
|
102
|
+
yield db.put(devInfo);
|
|
103
|
+
return devInfo.apiKey;
|
|
104
|
+
}));
|
|
102
105
|
});
|
|
103
106
|
}
|
|
104
107
|
globalUser({ id = GLOBAL_USER_ID, builder = true, email = EMAIL, roles, } = {}) {
|
|
105
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
109
|
+
return doWithGlobalDB(TENANT_ID, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
let existing;
|
|
111
|
+
try {
|
|
112
|
+
existing = yield db.get(id);
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
existing = { email };
|
|
116
|
+
}
|
|
117
|
+
const user = Object.assign(Object.assign({ _id: id }, existing), { roles: roles || {}, tenantId: TENANT_ID });
|
|
118
|
+
yield createASession(id, {
|
|
119
|
+
sessionId: "sessionid",
|
|
120
|
+
tenantId: TENANT_ID,
|
|
121
|
+
csrfToken: CSRF_TOKEN,
|
|
122
|
+
});
|
|
123
|
+
if (builder) {
|
|
124
|
+
user.builder = { global: true };
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
user.builder = { global: false };
|
|
128
|
+
}
|
|
129
|
+
const resp = yield db.put(user);
|
|
130
|
+
return Object.assign({ _rev: resp._rev }, user);
|
|
131
|
+
}));
|
|
128
132
|
});
|
|
129
133
|
}
|
|
130
134
|
// use a new id as the name to avoid name collisions
|
|
@@ -182,9 +186,12 @@ class TestConfiguration {
|
|
|
182
186
|
createApp(appName) {
|
|
183
187
|
return __awaiter(this, void 0, void 0, function* () {
|
|
184
188
|
// create dev app
|
|
189
|
+
// clear any old app
|
|
190
|
+
this.appId = null;
|
|
191
|
+
yield context.updateAppId(null);
|
|
185
192
|
this.app = yield this._req({ name: appName }, null, controllers.app.create);
|
|
186
193
|
this.appId = this.app.appId;
|
|
187
|
-
context.updateAppId(this.appId);
|
|
194
|
+
yield context.updateAppId(this.appId);
|
|
188
195
|
// create production app
|
|
189
196
|
this.prodApp = yield this.deploy();
|
|
190
197
|
this.prodAppId = this.prodApp.appId;
|
package/dist/threads/index.js
CHANGED
|
@@ -34,12 +34,14 @@ class Thread {
|
|
|
34
34
|
maxConcurrentWorkers: this.count,
|
|
35
35
|
};
|
|
36
36
|
if (opts.timeoutMs) {
|
|
37
|
+
this.timeoutMs = opts.timeoutMs;
|
|
37
38
|
workerOpts.maxCallTime = opts.timeoutMs;
|
|
38
39
|
}
|
|
39
40
|
this.workers = workerFarm(workerOpts, typeToFile(type));
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
run(data) {
|
|
44
|
+
const timeoutMs = this.timeoutMs;
|
|
43
45
|
return new Promise((resolve, reject) => {
|
|
44
46
|
let fncToCall;
|
|
45
47
|
// if in test then don't use threading
|
|
@@ -50,7 +52,10 @@ class Thread {
|
|
|
50
52
|
fncToCall = this.workers;
|
|
51
53
|
}
|
|
52
54
|
fncToCall(data, (err, response) => {
|
|
53
|
-
if (err) {
|
|
55
|
+
if (err && err.type === "TimeoutError") {
|
|
56
|
+
reject(new Error(`Query response time exceeded ${timeoutMs}ms timeout.`));
|
|
57
|
+
}
|
|
58
|
+
else if (err) {
|
|
54
59
|
reject(err);
|
|
55
60
|
}
|
|
56
61
|
else {
|
package/dist/threads/query.js
CHANGED
|
@@ -12,10 +12,10 @@ const threadUtils = require("./utils");
|
|
|
12
12
|
threadUtils.threadSetup();
|
|
13
13
|
const ScriptRunner = require("../utilities/scriptRunner");
|
|
14
14
|
const { integrations } = require("../integrations");
|
|
15
|
-
const { processStringSync
|
|
15
|
+
const { processStringSync } = require("@budibase/string-templates");
|
|
16
16
|
const { doInAppContext, getAppDB } = require("@budibase/backend-core/context");
|
|
17
17
|
const { isSQL } = require("../integrations/utils");
|
|
18
|
-
const
|
|
18
|
+
const { enrichQueryFields, interpolateSQL, } = require("../integrations/queries/sql");
|
|
19
19
|
class QueryRunner {
|
|
20
20
|
constructor(input, flags = { noRecursiveQuery: false }) {
|
|
21
21
|
this.datasource = input.datasource;
|
|
@@ -33,67 +33,6 @@ class QueryRunner {
|
|
|
33
33
|
this.queryResponse = {};
|
|
34
34
|
this.hasRerun = false;
|
|
35
35
|
}
|
|
36
|
-
interpolateSQL(fields, parameters, integration) {
|
|
37
|
-
let sql = fields.sql;
|
|
38
|
-
if (!sql) {
|
|
39
|
-
return fields;
|
|
40
|
-
}
|
|
41
|
-
const bindings = findHBSBlocks(sql);
|
|
42
|
-
let variables = [], arrays = [];
|
|
43
|
-
for (let binding of bindings) {
|
|
44
|
-
// look for array/list operations in the SQL statement, which will need handled later
|
|
45
|
-
const listRegexMatch = sql.match(new RegExp(`(in|IN|In|iN)( )+[(]?${binding}[)]?`));
|
|
46
|
-
// check if the variable was used as part of a string concat e.g. 'Hello {{binding}}'
|
|
47
|
-
// start by finding all the instances of const character strings
|
|
48
|
-
const charConstMatch = sql.match(CONST_CHAR_REGEX) || [];
|
|
49
|
-
// now look within them to see if a binding is used
|
|
50
|
-
const charConstBindingMatch = charConstMatch.find(string => string.match(new RegExp(`'[^']*${binding}[^']*'`)));
|
|
51
|
-
if (charConstBindingMatch) {
|
|
52
|
-
let [part1, part2] = charConstBindingMatch.split(binding);
|
|
53
|
-
part1 = `'${part1.substring(1)}'`;
|
|
54
|
-
part2 = `'${part2.substring(0, part2.length - 1)}'`;
|
|
55
|
-
sql = sql.replace(charConstBindingMatch, integration.getStringConcat([
|
|
56
|
-
part1,
|
|
57
|
-
integration.getBindingIdentifier(),
|
|
58
|
-
part2,
|
|
59
|
-
]));
|
|
60
|
-
}
|
|
61
|
-
// generate SQL parameterised array
|
|
62
|
-
else if (listRegexMatch) {
|
|
63
|
-
arrays.push(binding);
|
|
64
|
-
// determine the length of the array
|
|
65
|
-
const value = this.enrichQueryFields([binding], parameters)[0].split(",");
|
|
66
|
-
// build a string like ($1, $2, $3)
|
|
67
|
-
let replacement = `${Array.apply(null, Array(value.length))
|
|
68
|
-
.map(() => integration.getBindingIdentifier())
|
|
69
|
-
.join(",")}`;
|
|
70
|
-
// check if parentheses are needed
|
|
71
|
-
if (!listRegexMatch[0].includes(`(${binding})`)) {
|
|
72
|
-
replacement = `(${replacement})`;
|
|
73
|
-
}
|
|
74
|
-
sql = sql.replace(binding, replacement);
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
sql = sql.replace(binding, integration.getBindingIdentifier());
|
|
78
|
-
}
|
|
79
|
-
variables.push(binding);
|
|
80
|
-
}
|
|
81
|
-
// replicate the knex structure
|
|
82
|
-
fields.sql = sql;
|
|
83
|
-
fields.bindings = this.enrichQueryFields(variables, parameters);
|
|
84
|
-
// check for arrays in the data
|
|
85
|
-
let updated = [];
|
|
86
|
-
for (let i = 0; i < variables.length; i++) {
|
|
87
|
-
if (arrays.includes(variables[i])) {
|
|
88
|
-
updated = updated.concat(fields.bindings[i].split(","));
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
updated.push(fields.bindings[i]);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
fields.bindings = updated;
|
|
95
|
-
return fields;
|
|
96
|
-
}
|
|
97
36
|
execute() {
|
|
98
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
99
38
|
let { datasource, fields, queryVerb, transformer } = this;
|
|
@@ -107,10 +46,10 @@ class QueryRunner {
|
|
|
107
46
|
let query;
|
|
108
47
|
// handle SQL injections by interpolating the variables
|
|
109
48
|
if (isSQL(datasource)) {
|
|
110
|
-
query =
|
|
49
|
+
query = interpolateSQL(fields, parameters, integration);
|
|
111
50
|
}
|
|
112
51
|
else {
|
|
113
|
-
query =
|
|
52
|
+
query = enrichQueryFields(fields, parameters);
|
|
114
53
|
}
|
|
115
54
|
// Add pagination values for REST queries
|
|
116
55
|
if (this.pagination) {
|
|
@@ -237,44 +176,6 @@ class QueryRunner {
|
|
|
237
176
|
return parameters;
|
|
238
177
|
});
|
|
239
178
|
}
|
|
240
|
-
enrichQueryFields(fields, parameters = {}) {
|
|
241
|
-
const enrichedQuery = Array.isArray(fields) ? [] : {};
|
|
242
|
-
// enrich the fields with dynamic parameters
|
|
243
|
-
for (let key of Object.keys(fields)) {
|
|
244
|
-
if (fields[key] == null) {
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (typeof fields[key] === "object") {
|
|
248
|
-
// enrich nested fields object
|
|
249
|
-
enrichedQuery[key] = this.enrichQueryFields(fields[key], parameters);
|
|
250
|
-
}
|
|
251
|
-
else if (typeof fields[key] === "string") {
|
|
252
|
-
// enrich string value as normal
|
|
253
|
-
enrichedQuery[key] = processStringSync(fields[key], parameters, {
|
|
254
|
-
noEscaping: true,
|
|
255
|
-
noHelpers: true,
|
|
256
|
-
escapeNewlines: true,
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
else {
|
|
260
|
-
enrichedQuery[key] = fields[key];
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
if (enrichedQuery.json ||
|
|
264
|
-
enrichedQuery.customData ||
|
|
265
|
-
enrichedQuery.requestBody) {
|
|
266
|
-
try {
|
|
267
|
-
enrichedQuery.json = JSON.parse(enrichedQuery.json ||
|
|
268
|
-
enrichedQuery.customData ||
|
|
269
|
-
enrichedQuery.requestBody);
|
|
270
|
-
}
|
|
271
|
-
catch (err) {
|
|
272
|
-
// no json found, ignore
|
|
273
|
-
}
|
|
274
|
-
delete enrichedQuery.customData;
|
|
275
|
-
}
|
|
276
|
-
return enrichedQuery;
|
|
277
|
-
}
|
|
278
179
|
}
|
|
279
180
|
module.exports = (input, callback) => {
|
|
280
181
|
doInAppContext(input.appId, () => {
|
package/dist/threads/utils.js
CHANGED
|
@@ -9,8 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const env = require("../environment");
|
|
12
|
-
const
|
|
13
|
-
const { init } = require("@budibase/backend-core");
|
|
12
|
+
const db = require("../db");
|
|
14
13
|
const redis = require("@budibase/backend-core/redis");
|
|
15
14
|
const { SEPARATOR } = require("@budibase/backend-core/db");
|
|
16
15
|
const VARIABLE_TTL_SECONDS = 3600;
|
|
@@ -34,7 +33,7 @@ exports.threadSetup = () => {
|
|
|
34
33
|
}
|
|
35
34
|
// when thread starts, make sure it is recorded
|
|
36
35
|
env.setInThread();
|
|
37
|
-
init(
|
|
36
|
+
db.init();
|
|
38
37
|
};
|
|
39
38
|
function makeVariableKey(queryId, variable) {
|
|
40
39
|
return `${queryId}${SEPARATOR}${variable}`;
|