@budibase/server 2.0.30-alpha.14 → 2.0.30-alpha.15
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/backups-default.8c011f1b.png +0 -0
- package/builder/assets/{index.acdbfe62.css → index.b15ffe95.css} +1 -1
- package/builder/assets/{index.099ad307.js → index.e50f636c.js} +320 -316
- package/builder/index.html +2 -2
- package/coverage/clover.xml +254 -313
- package/coverage/coverage-final.json +15 -17
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +74 -62
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +17 -32
- 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/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/index.html +16 -16
- package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- 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 +3 -3
- 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 +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +3 -3
- 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/automation.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 +5 -20
- 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/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.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 +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
- package/coverage/lcov-report/automations/bullboard.js.html +17 -92
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +5 -5
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +5 -5
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +6 -18
- 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/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +19 -19
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +35 -308
- 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 +62 -62
- 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/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +1 -1
- 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/utils.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 +1 -1
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +1 -1
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
- package/coverage/lcov-report/utilities/queue/index.html +21 -21
- 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 +1 -1
- 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/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.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 +451 -564
- package/dist/api/controllers/application.js +2 -5
- package/dist/api/controllers/backup.js +19 -13
- package/dist/api/controllers/cloud.js +38 -35
- package/dist/api/controllers/deploy/index.js +11 -2
- package/dist/api/controllers/static/index.js +2 -2
- package/dist/api/controllers/table/bulkFormula.js +4 -3
- package/dist/api/controllers/table/external.js +5 -4
- package/dist/api/controllers/table/index.js +4 -4
- package/dist/api/controllers/table/internal.js +2 -1
- package/dist/api/controllers/table/utils.js +4 -48
- package/dist/api/controllers/view/index.js +2 -2
- package/dist/api/routes/backup.js +34 -7
- package/dist/api/routes/index.js +9 -4
- package/dist/app.js +14 -0
- package/dist/automations/automationUtils.js +2 -2
- package/dist/automations/bullboard.js +5 -33
- package/dist/automations/index.js +4 -4
- package/dist/automations/triggers.js +4 -4
- package/dist/automations/utils.js +13 -9
- package/dist/constants/index.js +2 -5
- package/dist/db/utils.js +10 -75
- package/dist/migrations/functions/backfill/app/tables.js +5 -8
- package/dist/package.json +11 -11
- package/dist/sdk/app/backups/constants.js +5 -0
- package/dist/sdk/app/backups/exports.js +172 -0
- package/dist/sdk/app/backups/imports.js +162 -0
- package/dist/sdk/app/backups/index.js +29 -0
- package/dist/sdk/app/backups/statistics.js +73 -0
- package/dist/sdk/app/tables/index.js +61 -0
- package/dist/sdk/index.js +15 -0
- package/dist/tests/utilities/TestConfiguration.js +4 -2
- package/dist/threads/automation.js +12 -17
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +3 -95
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/package.json +12 -12
- package/src/api/controllers/application.ts +3 -10
- package/src/api/controllers/{backup.js → backup.ts} +7 -7
- package/src/api/controllers/cloud.js +44 -40
- package/src/api/controllers/deploy/index.ts +20 -7
- package/src/api/controllers/static/index.ts +2 -2
- package/src/api/controllers/table/bulkFormula.js +4 -3
- package/src/api/controllers/table/external.js +4 -4
- package/src/api/controllers/table/index.js +4 -4
- package/src/api/controllers/table/internal.ts +3 -7
- package/src/api/controllers/table/utils.ts +1 -52
- package/src/api/controllers/view/index.js +2 -2
- package/src/api/routes/backup.ts +10 -0
- package/src/api/routes/index.ts +11 -5
- package/src/api/routes/tests/backup.spec.js +1 -1
- package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
- package/src/app.ts +15 -0
- package/src/automations/automationUtils.js +2 -2
- package/src/automations/bullboard.js +8 -33
- package/src/automations/index.js +4 -4
- package/src/automations/triggers.js +4 -4
- package/src/automations/utils.ts +12 -8
- package/src/constants/index.js +2 -6
- package/src/db/utils.js +17 -108
- package/src/definitions/automations.ts +0 -12
- package/src/migrations/functions/backfill/app/tables.ts +6 -13
- package/src/sdk/app/backups/constants.ts +2 -0
- package/src/sdk/app/backups/exports.ts +171 -0
- package/src/sdk/app/backups/imports.ts +168 -0
- package/src/sdk/app/backups/index.ts +9 -0
- package/src/sdk/app/backups/statistics.ts +77 -0
- package/src/sdk/app/tables/index.ts +60 -0
- package/src/sdk/index.ts +13 -0
- package/src/tests/utilities/TestConfiguration.js +5 -2
- package/src/threads/automation.ts +20 -27
- package/src/utilities/fileSystem/index.js +2 -119
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
- package/coverage/lcov-report/api/routes/backup.js.html +0 -115
- package/dist/automations/listeners.js +0 -102
- package/src/api/routes/backup.js +0 -10
- package/src/automations/listeners.ts +0 -78
|
@@ -11,34 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
const { createBullBoard } = require("@bull-board/api");
|
|
12
12
|
const { BullAdapter } = require("@bull-board/api/bullAdapter");
|
|
13
13
|
const { KoaAdapter } = require("@bull-board/koa");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
: require("bull");
|
|
18
|
-
const { JobQueues } = require("../constants");
|
|
19
|
-
const { utils } = require("@budibase/backend-core/redis");
|
|
20
|
-
const { opts, redisProtocolUrl } = utils.getRedisOptions();
|
|
21
|
-
const listeners = require("./listeners");
|
|
22
|
-
const CLEANUP_PERIOD_MS = 60 * 1000;
|
|
23
|
-
const queueConfig = redisProtocolUrl || { redis: opts };
|
|
24
|
-
let cleanupInternal = null;
|
|
25
|
-
let automationQueue = new Queue(JobQueues.AUTOMATIONS, queueConfig);
|
|
26
|
-
listeners.addListeners(automationQueue);
|
|
27
|
-
function cleanup() {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
yield automationQueue.clean(CLEANUP_PERIOD_MS, "completed");
|
|
30
|
-
});
|
|
31
|
-
}
|
|
14
|
+
const { queue } = require("@budibase/backend-core");
|
|
15
|
+
const automation = require("../threads/automation");
|
|
16
|
+
let automationQueue = queue.createQueue(queue.JobQueue.AUTOMATION, automation.removeStalled);
|
|
32
17
|
const PATH_PREFIX = "/bulladmin";
|
|
33
18
|
exports.init = () => {
|
|
34
|
-
// cleanup the events every 5 minutes
|
|
35
|
-
if (!cleanupInternal) {
|
|
36
|
-
cleanupInternal = setInterval(cleanup, CLEANUP_PERIOD_MS);
|
|
37
|
-
// fire off an initial cleanup
|
|
38
|
-
cleanup().catch(err => {
|
|
39
|
-
console.error(`Unable to cleanup automation queue initially - ${err}`);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
19
|
// Set up queues for bull board admin
|
|
43
20
|
const queues = [automationQueue];
|
|
44
21
|
const adapters = [];
|
|
@@ -54,11 +31,6 @@ exports.init = () => {
|
|
|
54
31
|
return serverAdapter.registerPlugin();
|
|
55
32
|
};
|
|
56
33
|
exports.shutdown = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
|
|
58
|
-
clearInterval(cleanupInternal);
|
|
59
|
-
yield automationQueue.close();
|
|
60
|
-
automationQueue = null;
|
|
61
|
-
}
|
|
62
|
-
console.log("Bull shutdown");
|
|
34
|
+
yield queue.shutdown();
|
|
63
35
|
});
|
|
64
|
-
exports.
|
|
36
|
+
exports.automationQueue = automationQueue;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
const { processEvent } = require("./utils");
|
|
12
|
-
const {
|
|
12
|
+
const { automationQueue, shutdown } = require("./bullboard");
|
|
13
13
|
const { TRIGGER_DEFINITIONS, rebootTrigger } = require("./triggers");
|
|
14
14
|
const { ACTION_DEFINITIONS } = require("./actions");
|
|
15
15
|
/**
|
|
@@ -18,7 +18,7 @@ const { ACTION_DEFINITIONS } = require("./actions");
|
|
|
18
18
|
exports.init = function () {
|
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
20
|
// this promise will not complete
|
|
21
|
-
const promise =
|
|
21
|
+
const promise = automationQueue.process((job) => __awaiter(this, void 0, void 0, function* () {
|
|
22
22
|
yield processEvent(job);
|
|
23
23
|
}));
|
|
24
24
|
// on init we need to trigger any reboot automations
|
|
@@ -27,11 +27,11 @@ exports.init = function () {
|
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
exports.getQueues = () => {
|
|
30
|
-
return [
|
|
30
|
+
return [automationQueue];
|
|
31
31
|
};
|
|
32
32
|
exports.shutdown = () => {
|
|
33
33
|
return shutdown();
|
|
34
34
|
};
|
|
35
|
-
exports.
|
|
35
|
+
exports.automationQueue = automationQueue;
|
|
36
36
|
exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS;
|
|
37
37
|
exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS;
|
|
@@ -14,7 +14,7 @@ const { coerce } = require("../utilities/rowProcessor");
|
|
|
14
14
|
const { definitions } = require("./triggerInfo");
|
|
15
15
|
const { isDevAppID } = require("../db/utils");
|
|
16
16
|
// need this to call directly, so we can get a response
|
|
17
|
-
const {
|
|
17
|
+
const { automationQueue } = require("./bullboard");
|
|
18
18
|
const { checkTestFlag } = require("../utilities/redis");
|
|
19
19
|
const utils = require("./utils");
|
|
20
20
|
const env = require("../environment");
|
|
@@ -57,7 +57,7 @@ function queueRelevantRowAutomations(event, eventType) {
|
|
|
57
57
|
}
|
|
58
58
|
if (automationTrigger.inputs &&
|
|
59
59
|
automationTrigger.inputs.tableId === event.row.tableId) {
|
|
60
|
-
yield
|
|
60
|
+
yield automationQueue.add({ automation, event }, JOB_OPTS);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}));
|
|
@@ -110,7 +110,7 @@ exports.externalTrigger = function (automation, params, { getResponses } = {}) {
|
|
|
110
110
|
return utils.processEvent({ data });
|
|
111
111
|
}
|
|
112
112
|
else {
|
|
113
|
-
return
|
|
113
|
+
return automationQueue.add(data, JOB_OPTS);
|
|
114
114
|
}
|
|
115
115
|
});
|
|
116
116
|
};
|
|
@@ -136,7 +136,7 @@ exports.rebootTrigger = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
136
136
|
timestamp: Date.now(),
|
|
137
137
|
},
|
|
138
138
|
};
|
|
139
|
-
rebootEvents.push(
|
|
139
|
+
rebootEvents.push(automationQueue.add(job, JOB_OPTS));
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
yield Promise.all(rebootEvents);
|
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.isErrorInOutput = exports.isRecurring = exports.cleanupAutomations = exports.checkForWebhooks = exports.enableCronTrigger = exports.isRebootTrigger = exports.isCronTrigger = exports.clearMetadata = exports.
|
|
38
|
+
exports.isErrorInOutput = exports.isRecurring = exports.cleanupAutomations = exports.checkForWebhooks = exports.enableCronTrigger = exports.isRebootTrigger = exports.isCronTrigger = exports.clearMetadata = exports.disableCronById = exports.disableAllCrons = exports.removeDeprecated = exports.updateTestHistory = exports.processEvent = void 0;
|
|
39
39
|
const threads_1 = require("../threads");
|
|
40
40
|
const triggerInfo_1 = require("./triggerInfo");
|
|
41
41
|
const webhooks = __importStar(require("../api/controllers/webhook"));
|
|
@@ -108,12 +108,12 @@ exports.removeDeprecated = removeDeprecated;
|
|
|
108
108
|
function disableAllCrons(appId) {
|
|
109
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
110
110
|
const promises = [];
|
|
111
|
-
const jobs = yield bullboard_1.
|
|
111
|
+
const jobs = yield bullboard_1.automationQueue.getRepeatableJobs();
|
|
112
112
|
for (let job of jobs) {
|
|
113
113
|
if (job.key.includes(`${appId}_cron`)) {
|
|
114
|
-
promises.push(bullboard_1.
|
|
114
|
+
promises.push(bullboard_1.automationQueue.removeRepeatableByKey(job.key));
|
|
115
115
|
if (job.id) {
|
|
116
|
-
promises.push(bullboard_1.
|
|
116
|
+
promises.push(bullboard_1.automationQueue.removeJobs(job.id));
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -121,14 +121,18 @@ function disableAllCrons(appId) {
|
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
exports.disableAllCrons = disableAllCrons;
|
|
124
|
-
function
|
|
124
|
+
function disableCronById(jobId) {
|
|
125
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
yield bullboard_1.
|
|
127
|
-
|
|
126
|
+
const repeatJobs = yield bullboard_1.automationQueue.getRepeatableJobs();
|
|
127
|
+
for (let repeatJob of repeatJobs) {
|
|
128
|
+
if (repeatJob.id === jobId) {
|
|
129
|
+
yield bullboard_1.automationQueue.removeRepeatableByKey(repeatJob.key);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
128
132
|
console.log(`jobId=${jobId} disabled`);
|
|
129
133
|
});
|
|
130
134
|
}
|
|
131
|
-
exports.
|
|
135
|
+
exports.disableCronById = disableCronById;
|
|
132
136
|
function clearMetadata() {
|
|
133
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
134
138
|
const db = (0, context_1.getProdAppDB)();
|
|
@@ -167,7 +171,7 @@ function enableCronTrigger(appId, automation) {
|
|
|
167
171
|
(trigger === null || trigger === void 0 ? void 0 : trigger.inputs.cron)) {
|
|
168
172
|
// make a job id rather than letting Bull decide, makes it easier to handle on way out
|
|
169
173
|
const jobId = `${appId}_cron_${(0, newid_1.default)()}`;
|
|
170
|
-
const job = yield bullboard_1.
|
|
174
|
+
const job = yield bullboard_1.automationQueue.add({
|
|
171
175
|
automation,
|
|
172
176
|
event: { appId, timestamp: Date.now() },
|
|
173
177
|
}, { repeat: { cron: trigger.inputs.cron }, jobId });
|
package/dist/constants/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
|
|
3
3
|
const { UserStatus } = require("@budibase/backend-core/constants");
|
|
4
|
-
const {
|
|
5
|
-
exports.JobQueues = {
|
|
6
|
-
AUTOMATIONS: "automationQueue",
|
|
7
|
-
};
|
|
4
|
+
const { objectStore } = require("@budibase/backend-core");
|
|
8
5
|
const FilterTypes = {
|
|
9
6
|
STRING: "string",
|
|
10
7
|
FUZZY: "fuzzy",
|
|
@@ -188,5 +185,5 @@ exports.AutomationErrors = {
|
|
|
188
185
|
FAILURE_CONDITION: "FAILURE_CONDITION_MET",
|
|
189
186
|
};
|
|
190
187
|
// pass through the list from the auth/core lib
|
|
191
|
-
exports.ObjectStoreBuckets = ObjectStoreBuckets;
|
|
188
|
+
exports.ObjectStoreBuckets = objectStore.ObjectStoreBuckets;
|
|
192
189
|
exports.MAX_AUTOMATION_RECURRING_ERRORS = 5;
|
package/dist/db/utils.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
const newid = require("./newid");
|
|
3
|
-
const { DocumentType:
|
|
3
|
+
const { DocumentType: CoreDocType, InternalTable, getRoleParams, generateRoleID, APP_DEV_PREFIX, APP_PREFIX, SEPARATOR, StaticDatabases, isDevAppID, isProdAppID, getDevelopmentAppID, generateAppID, getQueryIndex, ViewName, getDocParams, getRowParams, generateRowID, getUserMetadataParams, generateUserMetadataID, getGlobalIDFromUserMetadataID, } = require("@budibase/backend-core/db");
|
|
4
4
|
const UNICODE_MAX = "\ufff0";
|
|
5
5
|
const AppStatus = {
|
|
6
6
|
DEV: "development",
|
|
7
7
|
ALL: "all",
|
|
8
8
|
DEPLOYED: "published",
|
|
9
9
|
};
|
|
10
|
-
const DocumentType =
|
|
11
|
-
const InternalTables = {
|
|
12
|
-
USER_METADATA: "ta_users",
|
|
13
|
-
};
|
|
10
|
+
const DocumentType = CoreDocType;
|
|
14
11
|
const SearchIndexes = {
|
|
15
12
|
ROWS: "rows",
|
|
16
13
|
};
|
|
@@ -26,11 +23,11 @@ exports.APP_PREFIX = APP_PREFIX;
|
|
|
26
23
|
exports.APP_DEV_PREFIX = APP_DEV_PREFIX;
|
|
27
24
|
exports.isDevAppID = isDevAppID;
|
|
28
25
|
exports.isProdAppID = isProdAppID;
|
|
29
|
-
exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${
|
|
30
|
-
exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${
|
|
26
|
+
exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`;
|
|
27
|
+
exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`;
|
|
31
28
|
exports.TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`;
|
|
32
29
|
exports.ViewName = ViewName;
|
|
33
|
-
exports.InternalTables =
|
|
30
|
+
exports.InternalTables = InternalTable;
|
|
34
31
|
exports.DocumentType = DocumentType;
|
|
35
32
|
exports.SEPARATOR = SEPARATOR;
|
|
36
33
|
exports.UNICODE_MAX = UNICODE_MAX;
|
|
@@ -42,25 +39,12 @@ exports.generateDevAppID = getDevelopmentAppID;
|
|
|
42
39
|
exports.generateRoleID = generateRoleID;
|
|
43
40
|
exports.getRoleParams = getRoleParams;
|
|
44
41
|
exports.getQueryIndex = getQueryIndex;
|
|
45
|
-
/**
|
|
46
|
-
* If creating DB allDocs/query params with only a single top level ID this can be used, this
|
|
47
|
-
* is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
|
|
48
|
-
* More complex cases such as link docs and rows which have multiple levels of IDs that their
|
|
49
|
-
* ID consists of need their own functions to build the allDocs parameters.
|
|
50
|
-
* @param {string} docType The type of document which input params are being built for, e.g. user,
|
|
51
|
-
* link, app, table and so on.
|
|
52
|
-
* @param {string|null} docId The ID of the document minus its type - this is only needed if looking
|
|
53
|
-
* for a singular document.
|
|
54
|
-
* @param {object} otherProps Add any other properties onto the request, e.g. include_docs.
|
|
55
|
-
* @returns {object} Parameters which can then be used with an allDocs request.
|
|
56
|
-
*/
|
|
57
|
-
function getDocParams(docType, docId = null, otherProps = {}) {
|
|
58
|
-
if (docId == null) {
|
|
59
|
-
docId = "";
|
|
60
|
-
}
|
|
61
|
-
return Object.assign(Object.assign({}, otherProps), { startkey: `${docType}${SEPARATOR}${docId}`, endkey: `${docType}${SEPARATOR}${docId}${UNICODE_MAX}` });
|
|
62
|
-
}
|
|
63
42
|
exports.getDocParams = getDocParams;
|
|
43
|
+
exports.getRowParams = getRowParams;
|
|
44
|
+
exports.generateRowID = generateRowID;
|
|
45
|
+
exports.getUserMetadataParams = getUserMetadataParams;
|
|
46
|
+
exports.generateUserMetadataID = generateUserMetadataID;
|
|
47
|
+
exports.getGlobalIDFromUserMetadataID = getGlobalIDFromUserMetadataID;
|
|
64
48
|
/**
|
|
65
49
|
* Gets parameters for retrieving tables, this is a utility function for the getDocParams function.
|
|
66
50
|
*/
|
|
@@ -74,21 +58,6 @@ exports.getTableParams = (tableId = null, otherProps = {}) => {
|
|
|
74
58
|
exports.generateTableID = () => {
|
|
75
59
|
return `${DocumentType.TABLE}${SEPARATOR}${newid()}`;
|
|
76
60
|
};
|
|
77
|
-
/**
|
|
78
|
-
* Gets the DB allDocs/query params for retrieving a row.
|
|
79
|
-
* @param {string|null} tableId The table in which the rows have been stored.
|
|
80
|
-
* @param {string|null} rowId The ID of the row which is being specifically queried for. This can be
|
|
81
|
-
* left null to get all the rows in the table.
|
|
82
|
-
* @param {object} otherProps Any other properties to add to the request.
|
|
83
|
-
* @returns {object} Parameters which can then be used with an allDocs request.
|
|
84
|
-
*/
|
|
85
|
-
exports.getRowParams = (tableId = null, rowId = null, otherProps = {}) => {
|
|
86
|
-
if (tableId == null) {
|
|
87
|
-
return getDocParams(DocumentType.ROW, null, otherProps);
|
|
88
|
-
}
|
|
89
|
-
const endOfKey = rowId == null ? `${tableId}${SEPARATOR}` : rowId;
|
|
90
|
-
return getDocParams(DocumentType.ROW, endOfKey, otherProps);
|
|
91
|
-
};
|
|
92
61
|
/**
|
|
93
62
|
* Given a row ID this will find the table ID within it (only works for internal tables).
|
|
94
63
|
* @param {string} rowId The ID of the row.
|
|
@@ -100,40 +69,6 @@ exports.getTableIDFromRowID = rowId => {
|
|
|
100
69
|
.split(SEPARATOR);
|
|
101
70
|
return `${DocumentType.TABLE}${SEPARATOR}${components[0]}`;
|
|
102
71
|
};
|
|
103
|
-
/**
|
|
104
|
-
* Gets a new row ID for the specified table.
|
|
105
|
-
* @param {string} tableId The table which the row is being created for.
|
|
106
|
-
* @param {string|null} id If an ID is to be used then the UUID can be substituted for this.
|
|
107
|
-
* @returns {string} The new ID which a row doc can be stored under.
|
|
108
|
-
*/
|
|
109
|
-
exports.generateRowID = (tableId, id = null) => {
|
|
110
|
-
id = id || newid();
|
|
111
|
-
return `${DocumentType.ROW}${SEPARATOR}${tableId}${SEPARATOR}${id}`;
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Gets parameters for retrieving users, this is a utility function for the getDocParams function.
|
|
115
|
-
*/
|
|
116
|
-
exports.getUserMetadataParams = (userId = null, otherProps = {}) => {
|
|
117
|
-
return exports.getRowParams(InternalTables.USER_METADATA, userId, otherProps);
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Generates a new user ID based on the passed in global ID.
|
|
121
|
-
* @param {string} globalId The ID of the global user.
|
|
122
|
-
* @returns {string} The new user ID which the user doc can be stored under.
|
|
123
|
-
*/
|
|
124
|
-
exports.generateUserMetadataID = globalId => {
|
|
125
|
-
return exports.generateRowID(InternalTables.USER_METADATA, globalId);
|
|
126
|
-
};
|
|
127
|
-
/**
|
|
128
|
-
* Breaks up the ID to get the global ID.
|
|
129
|
-
*/
|
|
130
|
-
exports.getGlobalIDFromUserMetadataID = id => {
|
|
131
|
-
const prefix = `${DocumentType.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`;
|
|
132
|
-
if (!id || !id.includes(prefix)) {
|
|
133
|
-
return id;
|
|
134
|
-
}
|
|
135
|
-
return id.split(prefix)[1];
|
|
136
|
-
};
|
|
137
72
|
/**
|
|
138
73
|
* Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
|
|
139
74
|
*/
|
|
@@ -8,19 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.backfill = void 0;
|
|
13
16
|
const backend_core_1 = require("@budibase/backend-core");
|
|
14
|
-
const
|
|
15
|
-
const getTables = (appDb) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
-
const response = yield appDb.allDocs((0, utils_1.getTableParams)(null, {
|
|
17
|
-
include_docs: true,
|
|
18
|
-
}));
|
|
19
|
-
return response.rows.map((row) => row.doc);
|
|
20
|
-
});
|
|
17
|
+
const sdk_1 = __importDefault(require("../../../../sdk"));
|
|
21
18
|
const backfill = (appDb, timestamp) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
19
|
var _a;
|
|
23
|
-
const tables = yield
|
|
20
|
+
const tables = yield sdk_1.default.tables.getAllInternalTables(appDb);
|
|
24
21
|
for (const table of tables) {
|
|
25
22
|
yield backend_core_1.events.table.created(table, timestamp);
|
|
26
23
|
if (table.views) {
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.0.30-alpha.
|
|
4
|
+
"version": "2.0.30-alpha.14",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -77,23 +77,23 @@
|
|
|
77
77
|
"license": "GPL-3.0",
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
80
|
-
"@budibase/backend-core": "2.0.30-alpha.
|
|
81
|
-
"@budibase/client": "2.0.30-alpha.
|
|
82
|
-
"@budibase/pro": "2.0.30-alpha.
|
|
83
|
-
"@budibase/string-templates": "2.0.30-alpha.
|
|
84
|
-
"@budibase/types": "2.0.30-alpha.
|
|
80
|
+
"@budibase/backend-core": "2.0.30-alpha.14",
|
|
81
|
+
"@budibase/client": "2.0.30-alpha.14",
|
|
82
|
+
"@budibase/pro": "2.0.30-alpha.14",
|
|
83
|
+
"@budibase/string-templates": "2.0.30-alpha.14",
|
|
84
|
+
"@budibase/types": "2.0.30-alpha.14",
|
|
85
85
|
"@bull-board/api": "3.7.0",
|
|
86
86
|
"@bull-board/koa": "3.9.4",
|
|
87
87
|
"@elastic/elasticsearch": "7.10.0",
|
|
88
88
|
"@google-cloud/firestore": "5.0.2",
|
|
89
|
-
"@koa/router": "8.0.
|
|
89
|
+
"@koa/router": "8.0.8",
|
|
90
90
|
"@sendgrid/mail": "7.1.1",
|
|
91
91
|
"@sentry/node": "6.17.7",
|
|
92
92
|
"airtable": "0.10.1",
|
|
93
93
|
"arangojs": "7.2.0",
|
|
94
94
|
"aws-sdk": "2.1030.0",
|
|
95
95
|
"bcryptjs": "2.4.3",
|
|
96
|
-
"bull": "4.
|
|
96
|
+
"bull": "4.10.1",
|
|
97
97
|
"chmodr": "1.2.0",
|
|
98
98
|
"chokidar": "3.5.3",
|
|
99
99
|
"csvtojson": "2.0.10",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"js-yaml": "4.1.0",
|
|
113
113
|
"jsonschema": "1.4.0",
|
|
114
114
|
"knex": "0.95.15",
|
|
115
|
-
"koa": "2.
|
|
115
|
+
"koa": "2.13.4",
|
|
116
116
|
"koa-body": "4.2.0",
|
|
117
117
|
"koa-compress": "4.0.1",
|
|
118
118
|
"koa-connect": "2.1.0",
|
|
@@ -159,12 +159,12 @@
|
|
|
159
159
|
"@jest/test-sequencer": "24.9.0",
|
|
160
160
|
"@types/apidoc": "0.50.0",
|
|
161
161
|
"@types/bson": "4.2.0",
|
|
162
|
-
"@types/bull": "3.15.8",
|
|
163
162
|
"@types/global-agent": "2.1.1",
|
|
164
163
|
"@types/google-spreadsheet": "3.1.5",
|
|
164
|
+
"@types/ioredis": "4.28.10",
|
|
165
165
|
"@types/jest": "27.5.1",
|
|
166
166
|
"@types/koa": "2.13.4",
|
|
167
|
-
"@types/koa__router": "8.0.
|
|
167
|
+
"@types/koa__router": "8.0.11",
|
|
168
168
|
"@types/lodash": "4.14.180",
|
|
169
169
|
"@types/node": "14.18.20",
|
|
170
170
|
"@types/node-fetch": "2.6.1",
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.streamExportApp = exports.exportMultipleApps = exports.exportApp = exports.exportDB = void 0;
|
|
16
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
17
|
+
const budibaseDir_1 = require("../../../utilities/budibaseDir");
|
|
18
|
+
const utilities_1 = require("../../../utilities/fileSystem/utilities");
|
|
19
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
20
|
+
const constants_1 = require("../../../constants");
|
|
21
|
+
const utils_1 = require("../../../db/utils");
|
|
22
|
+
const constants_2 = require("./constants");
|
|
23
|
+
const fs_1 = __importDefault(require("fs"));
|
|
24
|
+
const path_1 = require("path");
|
|
25
|
+
const environment_1 = __importDefault(require("../../../environment"));
|
|
26
|
+
const uuid = require("uuid/v4");
|
|
27
|
+
const tar = require("tar");
|
|
28
|
+
const MemoryStream = require("memorystream");
|
|
29
|
+
function tarFilesToTmp(tmpDir, files) {
|
|
30
|
+
const exportFile = (0, path_1.join)((0, budibaseDir_1.budibaseTempDir)(), `${uuid()}.tar.gz`);
|
|
31
|
+
tar.create({
|
|
32
|
+
sync: true,
|
|
33
|
+
gzip: true,
|
|
34
|
+
file: exportFile,
|
|
35
|
+
recursive: true,
|
|
36
|
+
cwd: tmpDir,
|
|
37
|
+
}, files);
|
|
38
|
+
return exportFile;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Exports a DB to either file or a variable (memory).
|
|
42
|
+
* @param {string} dbName the DB which is to be exported.
|
|
43
|
+
* @param {object} opts various options for the export, e.g. whether to stream,
|
|
44
|
+
* a filter function or the name of the export.
|
|
45
|
+
* @return {*} either a readable stream or a string
|
|
46
|
+
*/
|
|
47
|
+
function exportDB(dbName, opts = {}) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return backend_core_1.db.doWithDB(dbName, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
// Write the dump to file if required
|
|
51
|
+
if (opts === null || opts === void 0 ? void 0 : opts.exportPath) {
|
|
52
|
+
const path = opts === null || opts === void 0 ? void 0 : opts.exportPath;
|
|
53
|
+
const writeStream = fs_1.default.createWriteStream(path);
|
|
54
|
+
yield db.dump(writeStream, { filter: opts === null || opts === void 0 ? void 0 : opts.filter });
|
|
55
|
+
return path;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// Stringify the dump in memory if required
|
|
59
|
+
const memStream = new MemoryStream();
|
|
60
|
+
let appString = "";
|
|
61
|
+
memStream.on("data", (chunk) => {
|
|
62
|
+
appString += chunk.toString();
|
|
63
|
+
});
|
|
64
|
+
yield db.dump(memStream, { filter: opts === null || opts === void 0 ? void 0 : opts.filter });
|
|
65
|
+
return appString;
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.exportDB = exportDB;
|
|
71
|
+
function defineFilter(excludeRows) {
|
|
72
|
+
const ids = [utils_1.USER_METDATA_PREFIX, utils_1.LINK_USER_METADATA_PREFIX];
|
|
73
|
+
if (excludeRows) {
|
|
74
|
+
ids.push(utils_1.TABLE_ROW_PREFIX);
|
|
75
|
+
}
|
|
76
|
+
return (doc) => !ids.map(key => doc._id.includes(key)).reduce((prev, curr) => prev || curr);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Local utility to back up the database state for an app, excluding global user
|
|
80
|
+
* data or user relationships.
|
|
81
|
+
* @param {string} appId The app to back up
|
|
82
|
+
* @param {object} config Config to send to export DB/attachment export
|
|
83
|
+
* @returns {*} either a string or a stream of the backup
|
|
84
|
+
*/
|
|
85
|
+
function exportApp(appId, config) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const prodAppId = backend_core_1.db.getProdAppID(appId);
|
|
88
|
+
const appPath = `${prodAppId}/`;
|
|
89
|
+
// export bucket contents
|
|
90
|
+
let tmpPath;
|
|
91
|
+
if (!environment_1.default.isTest()) {
|
|
92
|
+
tmpPath = yield (0, utilities_1.retrieveDirectory)(constants_1.ObjectStoreBuckets.APPS, appPath);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
tmpPath = (0, fileSystem_1.createTempFolder)(uuid());
|
|
96
|
+
}
|
|
97
|
+
const downloadedPath = (0, path_1.join)(tmpPath, appPath);
|
|
98
|
+
if (fs_1.default.existsSync(downloadedPath)) {
|
|
99
|
+
const allFiles = fs_1.default.readdirSync(downloadedPath);
|
|
100
|
+
for (let file of allFiles) {
|
|
101
|
+
const path = (0, path_1.join)(downloadedPath, file);
|
|
102
|
+
// move out of app directory, simplify structure
|
|
103
|
+
fs_1.default.renameSync(path, (0, path_1.join)(downloadedPath, "..", file));
|
|
104
|
+
}
|
|
105
|
+
// remove the old app directory created by object export
|
|
106
|
+
fs_1.default.rmdirSync(downloadedPath);
|
|
107
|
+
}
|
|
108
|
+
// enforce an export of app DB to the tmp path
|
|
109
|
+
const dbPath = (0, path_1.join)(tmpPath, constants_2.DB_EXPORT_FILE);
|
|
110
|
+
yield exportDB(appId, Object.assign(Object.assign({}, config), { filter: defineFilter(config === null || config === void 0 ? void 0 : config.excludeRows), exportPath: dbPath }));
|
|
111
|
+
// if tar requested, return where the tarball is
|
|
112
|
+
if (config === null || config === void 0 ? void 0 : config.tar) {
|
|
113
|
+
// now the tmpPath contains both the DB export and attachments, tar this
|
|
114
|
+
const tarPath = tarFilesToTmp(tmpPath, fs_1.default.readdirSync(tmpPath));
|
|
115
|
+
// cleanup the tmp export files as tarball returned
|
|
116
|
+
fs_1.default.rmSync(tmpPath, { recursive: true, force: true });
|
|
117
|
+
return tarPath;
|
|
118
|
+
}
|
|
119
|
+
// tar not requested, turn the directory where export is
|
|
120
|
+
else {
|
|
121
|
+
return tmpPath;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
exports.exportApp = exportApp;
|
|
126
|
+
/**
|
|
127
|
+
* Export all apps + global DB (if supplied) to a single tarball, this includes
|
|
128
|
+
* the attachments for each app as well.
|
|
129
|
+
* @param {object[]} appMetadata The IDs and names of apps to export.
|
|
130
|
+
* @param {string} globalDbContents The contents of the global DB to export as well.
|
|
131
|
+
* @return {string} The path to the tarball.
|
|
132
|
+
*/
|
|
133
|
+
function exportMultipleApps(appMetadata, globalDbContents) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const tmpPath = (0, path_1.join)((0, budibaseDir_1.budibaseTempDir)(), uuid());
|
|
136
|
+
fs_1.default.mkdirSync(tmpPath);
|
|
137
|
+
let exportPromises = [];
|
|
138
|
+
// export each app to a directory, then move it into the complete export
|
|
139
|
+
const exportAndMove = (appId, appName) => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const path = yield exportApp(appId);
|
|
141
|
+
yield fs_1.default.promises.rename(path, (0, path_1.join)(tmpPath, appName));
|
|
142
|
+
});
|
|
143
|
+
for (let metadata of appMetadata) {
|
|
144
|
+
exportPromises.push(exportAndMove(metadata.appId, metadata.name));
|
|
145
|
+
}
|
|
146
|
+
// wait for all exports to finish
|
|
147
|
+
yield Promise.all(exportPromises);
|
|
148
|
+
// add the global DB contents
|
|
149
|
+
if (globalDbContents) {
|
|
150
|
+
fs_1.default.writeFileSync((0, path_1.join)(tmpPath, constants_2.GLOBAL_DB_EXPORT_FILE), globalDbContents);
|
|
151
|
+
}
|
|
152
|
+
const appNames = appMetadata.map(metadata => metadata.name);
|
|
153
|
+
const tarPath = tarFilesToTmp(tmpPath, [...appNames, constants_2.GLOBAL_DB_EXPORT_FILE]);
|
|
154
|
+
// clear up the tmp path now tarball generated
|
|
155
|
+
fs_1.default.rmSync(tmpPath, { recursive: true, force: true });
|
|
156
|
+
return tarPath;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.exportMultipleApps = exportMultipleApps;
|
|
160
|
+
/**
|
|
161
|
+
* Streams a backup of the database state for an app
|
|
162
|
+
* @param {string} appId The ID of the app which is to be backed up.
|
|
163
|
+
* @param {boolean} excludeRows Flag to state whether the export should include data.
|
|
164
|
+
* @returns {*} a readable stream of the backup which is written in real time
|
|
165
|
+
*/
|
|
166
|
+
function streamExportApp(appId, excludeRows) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const tmpPath = yield exportApp(appId, { excludeRows, tar: true });
|
|
169
|
+
return (0, fileSystem_1.streamFile)(tmpPath);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
exports.streamExportApp = streamExportApp;
|