@budibase/server 1.0.115 → 1.0.118
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.dae9f8cf.js → index.b1f26359.js} +2 -2
- package/builder/index.html +1 -1
- package/coverage/clover.xml +1113 -1125
- package/coverage/coverage-final.json +85 -86
- 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 +46 -46
- 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 +10 -10
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +1 -1
- 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 +1392 -1404
- 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/ExternalRequest.js +18 -7
- 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/mysql.js +13 -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/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/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/ExternalRequest.ts +25 -7
- 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/mysql.ts +17 -1
- 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/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
|
@@ -12,7 +12,7 @@ const { budibaseTempDir } = require("../budibaseDir");
|
|
|
12
12
|
const fs = require("fs");
|
|
13
13
|
const { join } = require("path");
|
|
14
14
|
const uuid = require("uuid/v4");
|
|
15
|
-
const
|
|
15
|
+
const { doWithDB } = require("@budibase/backend-core/db");
|
|
16
16
|
const { ObjectStoreBuckets } = require("../../constants");
|
|
17
17
|
const { upload, retrieve, retrieveToTmp, streamUpload, deleteFolder, downloadTarball, } = require("./utilities");
|
|
18
18
|
const { updateClientLibrary } = require("./clientLibrary");
|
|
@@ -135,32 +135,33 @@ exports.streamBackup = (appId) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
135
135
|
* @return {*} either a readable stream or a string
|
|
136
136
|
*/
|
|
137
137
|
exports.exportDB = (dbName, { stream, filter, exportName } = {}) => __awaiter(void 0, void 0, void 0, function* () {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
// Write the dump to file if required
|
|
146
|
-
if (exportName) {
|
|
147
|
-
const path = join(budibaseTempDir(), exportName);
|
|
148
|
-
const writeStream = fs.createWriteStream(path);
|
|
149
|
-
yield instanceDb.dump(writeStream, { filter });
|
|
150
|
-
// Upload the dump to the object store if self hosted
|
|
151
|
-
if (env.SELF_HOSTED) {
|
|
152
|
-
yield streamUpload(ObjectStoreBuckets.BACKUPS, join(dbName, exportName), fs.createReadStream(path));
|
|
138
|
+
return doWithDB(dbName, (db) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
+
// Stream the dump if required
|
|
140
|
+
if (stream) {
|
|
141
|
+
const memStream = new MemoryStream();
|
|
142
|
+
db.dump(memStream, { filter });
|
|
143
|
+
return memStream;
|
|
153
144
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
145
|
+
// Write the dump to file if required
|
|
146
|
+
if (exportName) {
|
|
147
|
+
const path = join(budibaseTempDir(), exportName);
|
|
148
|
+
const writeStream = fs.createWriteStream(path);
|
|
149
|
+
yield db.dump(writeStream, { filter });
|
|
150
|
+
// Upload the dump to the object store if self hosted
|
|
151
|
+
if (env.SELF_HOSTED) {
|
|
152
|
+
yield streamUpload(ObjectStoreBuckets.BACKUPS, join(dbName, exportName), fs.createReadStream(path));
|
|
153
|
+
}
|
|
154
|
+
return fs.createReadStream(path);
|
|
155
|
+
}
|
|
156
|
+
// Stringify the dump in memory if required
|
|
157
|
+
const memStream = new MemoryStream();
|
|
158
|
+
let appString = "";
|
|
159
|
+
memStream.on("data", chunk => {
|
|
160
|
+
appString += chunk.toString();
|
|
161
|
+
});
|
|
162
|
+
yield db.dump(memStream, { filter });
|
|
163
|
+
return appString;
|
|
164
|
+
}));
|
|
164
165
|
});
|
|
165
166
|
/**
|
|
166
167
|
* Writes the provided contents to a temporary file, which can be used briefly.
|
|
@@ -9,8 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { getRowParams, USER_METDATA_PREFIX } = require("../../db/utils");
|
|
12
|
-
const
|
|
13
|
-
const { isDevAppID, getDevelopmentAppID } = require("@budibase/backend-core/db");
|
|
12
|
+
const { isDevAppID, getDevelopmentAppID, doWithDB, } = require("@budibase/backend-core/db");
|
|
14
13
|
const ROW_EXCLUSIONS = [USER_METDATA_PREFIX];
|
|
15
14
|
const getAppPairs = appIds => {
|
|
16
15
|
// collect the app ids into dev / prod pairs
|
|
@@ -32,20 +31,21 @@ const getAppPairs = appIds => {
|
|
|
32
31
|
};
|
|
33
32
|
const getAppRows = (appId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
33
|
// need to specify the app ID, as this is used for different apps in one call
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
return doWithDB(appId, (db) => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
|
+
const response = yield db.allDocs(getRowParams(null, null, {
|
|
36
|
+
include_docs: false,
|
|
37
|
+
}));
|
|
38
|
+
return response.rows
|
|
39
|
+
.map(r => r.id)
|
|
40
|
+
.filter(id => {
|
|
41
|
+
for (let exclusion of ROW_EXCLUSIONS) {
|
|
42
|
+
if (id.startsWith(exclusion)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
46
|
+
return true;
|
|
47
|
+
});
|
|
48
|
+
}));
|
|
49
49
|
});
|
|
50
50
|
/**
|
|
51
51
|
* Return a set of all rows in the given app ids.
|
|
@@ -62,7 +62,7 @@ exports.getUniqueRows = (appIds) => __awaiter(void 0, void 0, void 0, function*
|
|
|
62
62
|
continue;
|
|
63
63
|
}
|
|
64
64
|
try {
|
|
65
|
-
appRows.
|
|
65
|
+
appRows = appRows.concat(yield getAppRows(appId));
|
|
66
66
|
}
|
|
67
67
|
catch (e) {
|
|
68
68
|
console.error(e);
|
package/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.118",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"license": "GPL-3.0",
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@apidevtools/swagger-parser": "^10.0.3",
|
|
71
|
-
"@budibase/backend-core": "^1.0.
|
|
72
|
-
"@budibase/client": "^1.0.
|
|
73
|
-
"@budibase/string-templates": "^1.0.
|
|
71
|
+
"@budibase/backend-core": "^1.0.118",
|
|
72
|
+
"@budibase/client": "^1.0.118",
|
|
73
|
+
"@budibase/string-templates": "^1.0.118",
|
|
74
74
|
"@bull-board/api": "^3.7.0",
|
|
75
75
|
"@bull-board/koa": "^3.7.0",
|
|
76
76
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"pg": "8.5.1",
|
|
118
118
|
"pino-pretty": "4.0.0",
|
|
119
119
|
"posthog-node": "^1.1.4",
|
|
120
|
-
"pouchdb": "7.
|
|
120
|
+
"pouchdb": "7.3.0",
|
|
121
121
|
"pouchdb-adapter-memory": "^7.2.1",
|
|
122
122
|
"pouchdb-all-dbs": "1.0.2",
|
|
123
123
|
"pouchdb-find": "^7.2.2",
|
|
@@ -174,5 +174,5 @@
|
|
|
174
174
|
"optionalDependencies": {
|
|
175
175
|
"oracledb": "^5.3.0"
|
|
176
176
|
},
|
|
177
|
-
"gitHead": "
|
|
177
|
+
"gitHead": "ef0d516dcb713a215b5bfcc008b3fe9d9145b693"
|
|
178
178
|
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
const yargs = require("yargs")
|
|
3
3
|
const fs = require("fs")
|
|
4
4
|
const { join } = require("path")
|
|
5
|
-
|
|
5
|
+
require("../src/db").init()
|
|
6
|
+
const { doWithDB } = require("@budibase/backend-core/db")
|
|
6
7
|
// load environment
|
|
7
8
|
const env = require("../src/environment")
|
|
8
9
|
const {
|
|
@@ -47,13 +48,14 @@ yargs
|
|
|
47
48
|
const writeStream = fs.createWriteStream(join(exportPath, "dump.text"))
|
|
48
49
|
// perform couch dump
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
await doWithDB(appId, async db => {
|
|
52
|
+
return db.dump(writeStream, {
|
|
53
|
+
filter: doc =>
|
|
54
|
+
!(
|
|
55
|
+
doc._id.includes(USER_METDATA_PREFIX) ||
|
|
56
|
+
doc.includes(LINK_USER_METADATA_PREFIX)
|
|
57
|
+
),
|
|
58
|
+
})
|
|
57
59
|
})
|
|
58
60
|
console.log(`Template ${name} exported to ${exportPath}`)
|
|
59
61
|
}
|
|
@@ -123,7 +123,7 @@ async function createInstance(template) {
|
|
|
123
123
|
const tenantId = isMultiTenant() ? getTenantId() : null
|
|
124
124
|
const baseAppId = generateAppID(tenantId)
|
|
125
125
|
const appId = generateDevAppID(baseAppId)
|
|
126
|
-
updateAppId(appId)
|
|
126
|
+
await updateAppId(appId)
|
|
127
127
|
|
|
128
128
|
const db = getAppDB()
|
|
129
129
|
await db.put({
|
|
@@ -404,6 +404,8 @@ exports.sync = async (ctx, next) => {
|
|
|
404
404
|
})
|
|
405
405
|
} catch (err) {
|
|
406
406
|
error = err
|
|
407
|
+
} finally {
|
|
408
|
+
await replication.close()
|
|
407
409
|
}
|
|
408
410
|
|
|
409
411
|
// sync the users
|
|
@@ -94,18 +94,16 @@ async function initDeployedApp(prodAppId) {
|
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
async function deployApp(deployment) {
|
|
97
|
+
let replication
|
|
97
98
|
try {
|
|
98
99
|
const appId = getAppId()
|
|
99
100
|
const devAppId = getDevelopmentAppID(appId)
|
|
100
101
|
const productionAppId = getProdAppID(appId)
|
|
101
|
-
|
|
102
|
-
const replication = new Replication({
|
|
102
|
+
replication = new Replication({
|
|
103
103
|
source: devAppId,
|
|
104
104
|
target: productionAppId,
|
|
105
105
|
})
|
|
106
|
-
|
|
107
106
|
console.log("Replication object created")
|
|
108
|
-
|
|
109
107
|
await replication.replicate()
|
|
110
108
|
console.log("replication complete.. replacing app meta doc")
|
|
111
109
|
const db = getProdAppDB()
|
|
@@ -126,6 +124,8 @@ async function deployApp(deployment) {
|
|
|
126
124
|
...err,
|
|
127
125
|
message: `Deployment Failed: ${err.message}`,
|
|
128
126
|
}
|
|
127
|
+
} finally {
|
|
128
|
+
await replication.close()
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
|
|
@@ -83,7 +83,9 @@ exports.revert = async ctx => {
|
|
|
83
83
|
try {
|
|
84
84
|
const db = getProdAppDB({ skip_setup: true })
|
|
85
85
|
const info = await db.info()
|
|
86
|
-
if (info.error)
|
|
86
|
+
if (info.error) {
|
|
87
|
+
throw info.error
|
|
88
|
+
}
|
|
87
89
|
const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
|
|
88
90
|
if (
|
|
89
91
|
!deploymentDoc.history ||
|
|
@@ -95,12 +97,11 @@ exports.revert = async ctx => {
|
|
|
95
97
|
return ctx.throw(400, "App has not yet been deployed")
|
|
96
98
|
}
|
|
97
99
|
|
|
100
|
+
const replication = new Replication({
|
|
101
|
+
source: productionAppId,
|
|
102
|
+
target: appId,
|
|
103
|
+
})
|
|
98
104
|
try {
|
|
99
|
-
const replication = new Replication({
|
|
100
|
-
source: productionAppId,
|
|
101
|
-
target: appId,
|
|
102
|
-
})
|
|
103
|
-
|
|
104
105
|
await replication.rollback()
|
|
105
106
|
// update appID in reverted app to be dev version again
|
|
106
107
|
const db = getAppDB()
|
|
@@ -114,6 +115,8 @@ exports.revert = async ctx => {
|
|
|
114
115
|
}
|
|
115
116
|
} catch (err) {
|
|
116
117
|
ctx.throw(400, `Unable to revert. ${err}`)
|
|
118
|
+
} finally {
|
|
119
|
+
await replication.close()
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const bulkDocs = jest.fn()
|
|
3
|
-
const db = jest.fn(() => {
|
|
4
|
-
return {
|
|
5
|
-
bulkDocs
|
|
6
|
-
}
|
|
7
|
-
})
|
|
8
|
-
jest.mock("../../../../../db", () => db)
|
|
9
|
-
require("@budibase/backend-core").init(require("../../../../../db"))
|
|
1
|
+
const TestConfig = require("../../../../../tests/utilities/TestConfiguration")
|
|
10
2
|
|
|
11
3
|
const { RestImporter } = require("../index")
|
|
12
4
|
|
|
@@ -48,6 +40,12 @@ const datasets = {
|
|
|
48
40
|
}
|
|
49
41
|
|
|
50
42
|
describe("Rest Importer", () => {
|
|
43
|
+
const config = new TestConfig(false)
|
|
44
|
+
|
|
45
|
+
beforeEach(async () => {
|
|
46
|
+
await config.init()
|
|
47
|
+
})
|
|
48
|
+
|
|
51
49
|
let restImporter
|
|
52
50
|
|
|
53
51
|
const init = async (data) => {
|
|
@@ -105,11 +103,9 @@ describe("Rest Importer", () => {
|
|
|
105
103
|
|
|
106
104
|
const testImportQueries = async (key, data, assertions) => {
|
|
107
105
|
await init(data)
|
|
108
|
-
bulkDocs.mockReturnValue([])
|
|
109
106
|
const importResult = await restImporter.importQueries("datasourceId")
|
|
110
107
|
expect(importResult.errorQueries.length).toBe(0)
|
|
111
108
|
expect(importResult.queries.length).toBe(assertions[key].count)
|
|
112
|
-
expect(bulkDocs).toHaveBeenCalledTimes(1)
|
|
113
109
|
jest.clearAllMocks()
|
|
114
110
|
}
|
|
115
111
|
|
|
@@ -323,6 +323,28 @@ module External {
|
|
|
323
323
|
return { row: newRow, manyRelationships }
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
+
squashRelationshipColumns(
|
|
327
|
+
table: Table,
|
|
328
|
+
row: Row,
|
|
329
|
+
relationships: RelationshipsJson[]
|
|
330
|
+
): Row {
|
|
331
|
+
for (let relationship of relationships) {
|
|
332
|
+
const linkedTable = this.tables[relationship.tableName]
|
|
333
|
+
if (!linkedTable) {
|
|
334
|
+
continue
|
|
335
|
+
}
|
|
336
|
+
const display = linkedTable.primaryDisplay
|
|
337
|
+
for (let key of Object.keys(row[relationship.column])) {
|
|
338
|
+
const related: Row = row[relationship.column][key]
|
|
339
|
+
row[relationship.column][key] = {
|
|
340
|
+
primaryDisplay: display ? related[display] : undefined,
|
|
341
|
+
_id: related._id,
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return row
|
|
346
|
+
}
|
|
347
|
+
|
|
326
348
|
/**
|
|
327
349
|
* This iterates through the returned rows and works out what elements of the rows
|
|
328
350
|
* actually match up to another row (based on primary keys) - this is pretty specific
|
|
@@ -354,12 +376,6 @@ module External {
|
|
|
354
376
|
if (!linked._id) {
|
|
355
377
|
continue
|
|
356
378
|
}
|
|
357
|
-
// if not returning full docs then get the minimal links out
|
|
358
|
-
const display = linkedTable.primaryDisplay
|
|
359
|
-
linked = {
|
|
360
|
-
primaryDisplay: display ? linked[display] : undefined,
|
|
361
|
-
_id: linked._id,
|
|
362
|
-
}
|
|
363
379
|
columns[relationship.column] = linked
|
|
364
380
|
}
|
|
365
381
|
for (let [column, related] of Object.entries(columns)) {
|
|
@@ -417,7 +433,9 @@ module External {
|
|
|
417
433
|
relationships
|
|
418
434
|
)
|
|
419
435
|
}
|
|
420
|
-
return processFormulas(table, Object.values(finalRows))
|
|
436
|
+
return processFormulas(table, Object.values(finalRows)).map((row: Row) =>
|
|
437
|
+
this.squashRelationshipColumns(table, row, relationships)
|
|
438
|
+
)
|
|
421
439
|
}
|
|
422
440
|
|
|
423
441
|
/**
|
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
DocumentTypes,
|
|
7
7
|
InternalTables,
|
|
8
8
|
} = require("../../../db/utils")
|
|
9
|
+
const { dangerousGetDB } = require("@budibase/backend-core/db")
|
|
9
10
|
const userController = require("../user")
|
|
10
11
|
const {
|
|
11
12
|
inputProcessing,
|
|
@@ -250,7 +251,7 @@ exports.fetch = async ctx => {
|
|
|
250
251
|
}
|
|
251
252
|
|
|
252
253
|
exports.find = async ctx => {
|
|
253
|
-
const db =
|
|
254
|
+
const db = dangerousGetDB(ctx.appId)
|
|
254
255
|
const table = await db.get(ctx.params.tableId)
|
|
255
256
|
let row = await findRow(ctx, ctx.params.tableId, ctx.params.rowId)
|
|
256
257
|
row = await outputProcessing(table, row)
|
|
@@ -54,7 +54,7 @@ exports.destroy = async ctx => {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
exports.buildSchema = async ctx => {
|
|
57
|
-
updateAppId(ctx.params.instance)
|
|
57
|
+
await updateAppId(ctx.params.instance)
|
|
58
58
|
const db = getAppDB()
|
|
59
59
|
const webhook = await db.get(ctx.params.id)
|
|
60
60
|
webhook.bodySchema = toJsonSchema(ctx.request.body)
|
|
@@ -80,7 +80,7 @@ exports.buildSchema = async ctx => {
|
|
|
80
80
|
|
|
81
81
|
exports.trigger = async ctx => {
|
|
82
82
|
const prodAppId = getProdAppID(ctx.params.instance)
|
|
83
|
-
updateAppId(prodAppId)
|
|
83
|
+
await updateAppId(prodAppId)
|
|
84
84
|
try {
|
|
85
85
|
const db = getAppDB()
|
|
86
86
|
const webhook = await db.get(ctx.params.id)
|
|
@@ -2,6 +2,7 @@ const { outputProcessing } = require("../../../utilities/rowProcessor")
|
|
|
2
2
|
const setup = require("./utilities")
|
|
3
3
|
const { basicRow } = setup.structures
|
|
4
4
|
const { doInAppContext } = require("@budibase/backend-core/context")
|
|
5
|
+
const { doInTenant } = require("@budibase/backend-core/tenancy")
|
|
5
6
|
|
|
6
7
|
// mock the fetch for the search system
|
|
7
8
|
jest.mock("node-fetch")
|
|
@@ -340,17 +341,20 @@ describe("/rows", () => {
|
|
|
340
341
|
|
|
341
342
|
describe("fetchEnrichedRows", () => {
|
|
342
343
|
it("should allow enriching some linked rows", async () => {
|
|
343
|
-
const table = await
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
344
|
+
const { table, firstRow, secondRow } = await doInTenant(setup.structures.TENANT_ID, async () => {
|
|
345
|
+
const table = await config.createLinkedTable()
|
|
346
|
+
const firstRow = await config.createRow({
|
|
347
|
+
name: "Test Contact",
|
|
348
|
+
description: "original description",
|
|
349
|
+
tableId: table._id
|
|
350
|
+
})
|
|
351
|
+
const secondRow = await config.createRow({
|
|
352
|
+
name: "Test 2",
|
|
353
|
+
description: "og desc",
|
|
354
|
+
link: [{_id: firstRow._id}],
|
|
355
|
+
tableId: table._id,
|
|
356
|
+
})
|
|
357
|
+
return { table, firstRow, secondRow }
|
|
354
358
|
})
|
|
355
359
|
|
|
356
360
|
// test basic enrichment
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
const { checkBuilderEndpoint
|
|
1
|
+
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
|
2
|
+
const { getAppDB } = require("@budibase/backend-core/context")
|
|
2
3
|
const setup = require("./utilities")
|
|
3
4
|
const { basicTable } = setup.structures
|
|
4
5
|
|
|
@@ -122,7 +123,7 @@ describe("/tables", () => {
|
|
|
122
123
|
|
|
123
124
|
describe("indexing", () => {
|
|
124
125
|
it("should be able to create a table with indexes", async () => {
|
|
125
|
-
const db =
|
|
126
|
+
const db = getAppDB(config)
|
|
126
127
|
const indexCount = (await db.getIndexes()).total_rows
|
|
127
128
|
const table = basicTable()
|
|
128
129
|
table.indexes = ["name"]
|
|
@@ -3,7 +3,7 @@ const appController = require("../../../controllers/application")
|
|
|
3
3
|
const { AppStatus } = require("../../../../db/utils")
|
|
4
4
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
|
|
5
5
|
const { TENANT_ID } = require("../../../../tests/utilities/structures")
|
|
6
|
-
const {
|
|
6
|
+
const { doInAppContext } = require("@budibase/backend-core/context")
|
|
7
7
|
const env = require("../../../../environment")
|
|
8
8
|
|
|
9
9
|
function Request(appId, params) {
|
|
@@ -106,10 +106,6 @@ exports.checkPermissionsEndpoint = async ({
|
|
|
106
106
|
.expect(403)
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
exports.getDB = () => {
|
|
110
|
-
return getAppDB()
|
|
111
|
-
}
|
|
112
|
-
|
|
113
109
|
exports.testAutomation = async (config, automation) => {
|
|
114
110
|
return runRequest(automation.appId, async () => {
|
|
115
111
|
return await config.request
|
package/src/app.ts
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import { ExtendableContext } from "koa"
|
|
3
3
|
|
|
4
4
|
import * as env from "./environment"
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import db from "./db"
|
|
6
|
+
db.init()
|
|
7
7
|
const Koa = require("koa")
|
|
8
8
|
const destroyable = require("server-destroy")
|
|
9
9
|
const koaBody = require("koa-body")
|
package/src/automations/utils.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
const { Thread, ThreadType } = require("../threads")
|
|
2
2
|
const { definitions } = require("./triggerInfo")
|
|
3
3
|
const webhooks = require("../api/controllers/webhook")
|
|
4
|
-
const CouchDB = require("../db")
|
|
5
4
|
const { queue } = require("./bullboard")
|
|
6
5
|
const newid = require("../db/newid")
|
|
7
6
|
const { updateEntityMetadata } = require("../utilities")
|
|
8
7
|
const { MetadataTypes, WebhookType } = require("../constants")
|
|
9
8
|
const { getProdAppID } = require("@budibase/backend-core/db")
|
|
10
9
|
const { cloneDeep } = require("lodash/fp")
|
|
10
|
+
const { doWithDB } = require("@budibase/backend-core/db")
|
|
11
11
|
const { getAppDB, getAppId } = require("@budibase/backend-core/context")
|
|
12
12
|
|
|
13
13
|
const WH_STEP_ID = definitions.WEBHOOK.stepId
|
|
@@ -101,10 +101,11 @@ exports.enableCronTrigger = async (appId, automation) => {
|
|
|
101
101
|
// can't use getAppDB here as this is likely to be called from dev app,
|
|
102
102
|
// but this call could be for dev app or prod app, need to just use what
|
|
103
103
|
// was passed in
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
await doWithDB(appId, async db => {
|
|
105
|
+
const response = await db.put(automation)
|
|
106
|
+
automation._id = response.id
|
|
107
|
+
automation._rev = response.rev
|
|
108
|
+
})
|
|
108
109
|
}
|
|
109
110
|
return automation
|
|
110
111
|
}
|
package/src/db/inMemoryView.js
CHANGED
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
const PouchDB = require("pouchdb")
|
|
2
|
-
const memory = require("pouchdb-adapter-memory")
|
|
3
1
|
const newid = require("./newid")
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})
|
|
3
|
+
// bypass the main application db config
|
|
4
|
+
// use in memory pouchdb directly
|
|
5
|
+
const { getPouch, closeDB } = require("@budibase/backend-core/db")
|
|
6
|
+
const Pouch = getPouch({ inMemory: true })
|
|
10
7
|
|
|
11
8
|
exports.runView = async (view, calculation, group, data) => {
|
|
12
9
|
// use a different ID each time for the DB, make sure they
|
|
13
10
|
// are always unique for each query, don't want overlap
|
|
14
11
|
// which could cause 409s
|
|
15
12
|
const db = new Pouch(newid())
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const response = await db.query(queryFns, {
|
|
33
|
-
include_docs: !calculation,
|
|
34
|
-
group: !!group,
|
|
35
|
-
})
|
|
36
|
-
// need to fix the revs to be totally accurate
|
|
37
|
-
for (let row of response.rows) {
|
|
38
|
-
if (!row._rev || !row._id) {
|
|
39
|
-
continue
|
|
13
|
+
try {
|
|
14
|
+
// write all the docs to the in memory Pouch (remove revs)
|
|
15
|
+
await db.bulkDocs(
|
|
16
|
+
data.map(row => ({
|
|
17
|
+
...row,
|
|
18
|
+
_rev: undefined,
|
|
19
|
+
}))
|
|
20
|
+
)
|
|
21
|
+
let fn = (doc, emit) => emit(doc._id)
|
|
22
|
+
eval("fn = " + view.map.replace("function (doc)", "function (doc, emit)"))
|
|
23
|
+
const queryFns = {
|
|
24
|
+
meta: view.meta,
|
|
25
|
+
map: fn,
|
|
26
|
+
}
|
|
27
|
+
if (view.reduce) {
|
|
28
|
+
queryFns.reduce = view.reduce
|
|
40
29
|
}
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
const response = await db.query(queryFns, {
|
|
31
|
+
include_docs: !calculation,
|
|
32
|
+
group: !!group,
|
|
33
|
+
})
|
|
34
|
+
// need to fix the revs to be totally accurate
|
|
35
|
+
for (let row of response.rows) {
|
|
36
|
+
if (!row._rev || !row._id) {
|
|
37
|
+
continue
|
|
38
|
+
}
|
|
39
|
+
const found = data.find(possible => possible._id === row._id)
|
|
40
|
+
if (found) {
|
|
41
|
+
row._rev = found._rev
|
|
42
|
+
}
|
|
44
43
|
}
|
|
44
|
+
return response
|
|
45
|
+
} finally {
|
|
46
|
+
await db.destroy()
|
|
47
|
+
await closeDB(db)
|
|
45
48
|
}
|
|
46
|
-
await db.destroy()
|
|
47
|
-
return response
|
|
48
49
|
}
|
package/src/db/index.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
const
|
|
1
|
+
const core = require("@budibase/backend-core")
|
|
2
|
+
const env = require("../environment")
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
exports.init = () => {
|
|
5
|
+
const dbConfig = {
|
|
6
|
+
replication: true,
|
|
7
|
+
find: true,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (env.isTest()) {
|
|
11
|
+
dbConfig.inMemory = true
|
|
12
|
+
dbConfig.allDbs = true
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
core.init({ db: dbConfig })
|
|
16
|
+
}
|