@budibase/server 0.9.185-alpha.0 → 0.9.185-alpha.12
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/Dockerfile +1 -1
- package/builder/assets/bb-space-man.5be51a45.svg +290 -0
- package/builder/assets/index.4a7c5636.css +1 -0
- package/builder/assets/index.708945dd.js +1316 -0
- package/builder/assets/vendor.470042a4.js +152 -0
- package/builder/assets/vendor.5e1fe644.css +1 -0
- package/builder/index.html +4 -4
- package/coverage/clover.xml +1060 -928
- package/coverage/coverage-final.json +90 -88
- package/coverage/lcov-report/api/controllers/analytics.js.html +2 -2
- package/coverage/lcov-report/api/controllers/apikeys.js.html +2 -2
- package/coverage/lcov-report/api/controllers/application.js.html +43 -13
- package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
- package/coverage/lcov-report/api/controllers/automation.js.html +3 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +31 -7
- package/coverage/lcov-report/api/controllers/dev.js.html +16 -7
- package/coverage/lcov-report/api/controllers/hosting.js.html +10 -10
- package/coverage/lcov-report/api/controllers/index.html +75 -75
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +3 -3
- package/coverage/lcov-report/api/controllers/metadata.js.html +3 -3
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
- package/coverage/lcov-report/api/controllers/query.js.html +48 -210
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +3 -3
- package/coverage/lcov-report/api/controllers/row/external.js.html +12 -6
- package/coverage/lcov-report/api/controllers/row/index.html +18 -18
- package/coverage/lcov-report/api/controllers/row/index.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/internal.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/utils.js.html +2 -2
- package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
- package/coverage/lcov-report/api/controllers/script.js.html +3 -3
- package/coverage/lcov-report/api/controllers/table/external.js.html +65 -8
- package/coverage/lcov-report/api/controllers/table/index.html +42 -42
- package/coverage/lcov-report/api/controllers/table/index.js.html +66 -12
- package/coverage/lcov-report/api/controllers/table/internal.js.html +49 -10
- package/coverage/lcov-report/api/controllers/table/utils.js.html +57 -45
- package/coverage/lcov-report/api/controllers/templates.js.html +4 -4
- package/coverage/lcov-report/api/controllers/user.js.html +33 -18
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +9 -9
- package/coverage/lcov-report/api/controllers/view/index.js.html +5 -5
- package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -3
- package/coverage/lcov-report/api/controllers/webhook.js.html +4 -4
- 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 +2 -2
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +4 -4
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +5 -2
- 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 +2 -2
- package/coverage/lcov-report/api/routes/table.js.html +35 -2
- 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/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +2 -2
- package/coverage/lcov-report/automations/automationUtils.js.html +3 -3
- package/coverage/lcov-report/automations/bullboard.js.html +71 -20
- package/coverage/lcov-report/automations/index.html +33 -48
- package/coverage/lcov-report/automations/index.js.html +2 -2
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +3 -3
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -3
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +14 -14
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +3 -3
- package/coverage/lcov-report/automations/steps/queryRows.js.html +3 -3
- 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 +7 -7
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- 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 +22 -10
- package/coverage/lcov-report/automations/utils.js.html +42 -12
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +5 -2
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/client.js.html +2 -2
- package/coverage/lcov-report/db/inMemoryView.js.html +2 -2
- package/coverage/lcov-report/db/index.html +2 -2
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +6 -6
- package/coverage/lcov-report/db/linkedRows/index.html +10 -10
- package/coverage/lcov-report/db/linkedRows/index.js.html +5 -5
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +6 -6
- package/coverage/lcov-report/db/newid.js.html +1 -1
- package/coverage/lcov-report/db/utils.js.html +1 -1
- package/coverage/lcov-report/events/AutomationEmitter.js.html +6 -6
- package/coverage/lcov-report/events/index.html +6 -6
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +5 -5
- package/coverage/lcov-report/index.html +94 -79
- 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 +2 -2
- package/coverage/lcov-report/middleware/authorized.js.html +5 -5
- package/coverage/lcov-report/middleware/builder.js.html +16 -7
- package/coverage/lcov-report/middleware/currentapp.js.html +6 -6
- package/coverage/lcov-report/middleware/index.html +21 -21
- package/coverage/lcov-report/middleware/joi-validator.js.html +2 -2
- package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
- package/coverage/lcov-report/middleware/selfhost.js.html +2 -2
- package/coverage/lcov-report/middleware/usageQuota.js.html +4 -4
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/{automations/thread.js.html → threads/automation.js.html} +83 -32
- package/coverage/lcov-report/threads/index.html +141 -0
- package/coverage/lcov-report/threads/index.js.html +260 -0
- package/coverage/lcov-report/threads/query.js.html +269 -0
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +144 -15
- package/coverage/lcov-report/utilities/global.js.html +2 -2
- package/coverage/lcov-report/utilities/index.html +34 -34
- package/coverage/lcov-report/utilities/index.js.html +12 -9
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +30 -9
- package/coverage/lcov-report/utilities/queue/index.html +14 -14
- 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 +4 -4
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +2 -2
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +3 -3
- package/coverage/lcov-report/utilities/scriptRunner.js.html +16 -7
- package/coverage/lcov-report/utilities/security.js.html +3 -3
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +5 -5
- package/coverage/lcov.info +1753 -1527
- package/dist/api/controllers/application.js +11 -1
- package/dist/api/controllers/datasource.js +6 -2
- package/dist/api/controllers/deploy/index.js +2 -0
- package/dist/api/controllers/dev.js +4 -1
- package/dist/api/controllers/query.js +27 -57
- package/dist/api/controllers/row/ExternalRequest.js +2 -2
- package/dist/api/controllers/row/external.js +1 -0
- package/dist/api/controllers/table/external.js +17 -0
- package/dist/api/controllers/table/index.js +21 -2
- package/dist/api/controllers/table/internal.js +10 -1
- package/dist/api/controllers/table/utils.js +28 -27
- package/dist/api/controllers/user.js +10 -6
- package/dist/api/routes/query.js +1 -1
- package/dist/api/routes/table.js +7 -1
- package/dist/app.js +2 -11
- package/dist/automations/bullboard.js +37 -10
- package/dist/automations/triggers.js +7 -3
- package/dist/automations/utils.js +11 -2
- package/dist/constants/index.js +1 -0
- package/dist/definitions/datasource.js +1 -0
- package/dist/integrations/base/IntegrationBase.js +2 -0
- package/dist/integrations/base/sql.js +48 -8
- package/dist/integrations/base/sqlTable.js +1 -2
- package/dist/integrations/mysql.js +3 -1
- package/dist/integrations/postgres.js +2 -2
- package/dist/middleware/builder.js +4 -1
- package/dist/package.json +7 -6
- package/dist/{automations/thread.js → threads/automation.js} +23 -7
- package/dist/threads/index.js +58 -0
- package/dist/threads/query.js +61 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +46 -5
- package/dist/utilities/index.js +1 -0
- package/dist/utilities/queue/inMemoryQueue.js +8 -0
- package/dist/utilities/scriptRunner.js +4 -1
- package/package.json +8 -7
- package/scripts/likeCypress.ts +33 -0
- package/src/api/controllers/application.js +11 -1
- package/src/api/controllers/datasource.js +10 -2
- package/src/api/controllers/deploy/index.js +2 -0
- package/src/api/controllers/dev.js +4 -1
- package/src/api/controllers/query.js +26 -80
- package/src/api/controllers/row/ExternalRequest.ts +6 -2
- package/src/api/controllers/row/external.js +2 -0
- package/src/api/controllers/table/external.js +19 -0
- package/src/api/controllers/table/index.js +20 -2
- package/src/api/controllers/table/internal.js +14 -1
- package/src/api/controllers/table/utils.js +36 -32
- package/src/api/controllers/user.js +15 -10
- package/src/api/routes/query.js +1 -0
- package/src/api/routes/table.js +11 -0
- package/src/api/routes/tests/misc.spec.js +5 -1
- package/src/app.ts +2 -10
- package/src/automations/bullboard.js +28 -11
- package/src/automations/tests/automation.spec.js +3 -4
- package/src/automations/triggers.js +7 -3
- package/src/automations/utils.js +12 -2
- package/src/constants/index.js +1 -0
- package/src/definitions/datasource.ts +3 -2
- package/src/integrations/airtable.ts +2 -1
- package/src/integrations/arangodb.ts +2 -1
- package/src/integrations/base/IntegrationBase.ts +6 -0
- package/src/integrations/base/datasourcePlus.ts +2 -1
- package/src/integrations/base/sql.ts +51 -9
- package/src/integrations/base/sqlTable.ts +1 -4
- package/src/integrations/couchdb.ts +2 -1
- package/src/integrations/dynamodb.ts +2 -1
- package/src/integrations/elasticsearch.ts +2 -1
- package/src/integrations/mongodb.ts +2 -1
- package/src/integrations/mysql.ts +1 -1
- package/src/integrations/postgres.ts +5 -5
- package/src/integrations/rest.ts +2 -1
- package/src/integrations/s3.ts +2 -1
- package/src/middleware/builder.js +4 -1
- package/src/{automations/thread.js → threads/automation.js} +24 -7
- package/src/threads/index.js +60 -0
- package/src/threads/query.js +63 -0
- package/src/utilities/csvParser.js +48 -5
- package/src/utilities/index.js +1 -0
- package/src/utilities/queue/inMemoryQueue.js +7 -0
- package/src/utilities/scriptRunner.js +4 -1
- package/src/utilities/tests/__snapshots__/csvParser.spec.js.snap +0 -6
- package/src/utilities/tests/csvParser.spec.js +3 -0
- package/tsconfig.json +1 -1
- package/builder/assets/index.0e6a5c20.js +0 -201
- package/builder/assets/index.cf21e4d2.css +0 -29
- package/builder/assets/vendor.278a305c.js +0 -9
- package/builder/assets/vendor.d75d5eb7.css +0 -1
|
@@ -17,19 +17,46 @@ const datasource_1 = require("../../definitions/datasource");
|
|
|
17
17
|
const utils_1 = require("../utils");
|
|
18
18
|
const sqlTable_1 = __importDefault(require("./sqlTable"));
|
|
19
19
|
const BASE_LIMIT = 5000;
|
|
20
|
+
// these are invalid dates sent by the client, need to convert them to a real max date
|
|
21
|
+
const MIN_ISO_DATE = "0000-00-00T00:00:00.000Z";
|
|
22
|
+
const MAX_ISO_DATE = "9999-00-00T00:00:00.000Z";
|
|
23
|
+
function parse(input) {
|
|
24
|
+
if (Array.isArray(input)) {
|
|
25
|
+
return JSON.stringify(input);
|
|
26
|
+
}
|
|
27
|
+
if (typeof input !== "string") {
|
|
28
|
+
return input;
|
|
29
|
+
}
|
|
30
|
+
if (input === MAX_ISO_DATE) {
|
|
31
|
+
return new Date(8640000000000000);
|
|
32
|
+
}
|
|
33
|
+
if (input === MIN_ISO_DATE) {
|
|
34
|
+
return new Date(-8640000000000000);
|
|
35
|
+
}
|
|
36
|
+
if (utils_1.isIsoDateString(input)) {
|
|
37
|
+
return new Date(input);
|
|
38
|
+
}
|
|
39
|
+
return input;
|
|
40
|
+
}
|
|
20
41
|
function parseBody(body) {
|
|
21
42
|
for (let [key, value] of Object.entries(body)) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
body[key] = parse(value);
|
|
44
|
+
}
|
|
45
|
+
return body;
|
|
46
|
+
}
|
|
47
|
+
function parseFilters(filters) {
|
|
48
|
+
for (let [key, value] of Object.entries(filters)) {
|
|
49
|
+
let parsed;
|
|
50
|
+
if (typeof value === "object") {
|
|
51
|
+
parsed = parseFilters(value);
|
|
27
52
|
}
|
|
28
|
-
|
|
29
|
-
|
|
53
|
+
else {
|
|
54
|
+
parsed = parse(value);
|
|
30
55
|
}
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
filters[key] = parsed;
|
|
31
58
|
}
|
|
32
|
-
return
|
|
59
|
+
return filters;
|
|
33
60
|
}
|
|
34
61
|
class InternalBuilder {
|
|
35
62
|
constructor(client) {
|
|
@@ -45,6 +72,7 @@ class InternalBuilder {
|
|
|
45
72
|
if (!filters) {
|
|
46
73
|
return query;
|
|
47
74
|
}
|
|
75
|
+
filters = parseFilters(filters);
|
|
48
76
|
// if all or specified in filters, then everything is an or
|
|
49
77
|
const allOr = filters.allOr;
|
|
50
78
|
if (filters.oneOf) {
|
|
@@ -156,6 +184,15 @@ class InternalBuilder {
|
|
|
156
184
|
return query.insert(parsedBody).returning("*");
|
|
157
185
|
}
|
|
158
186
|
}
|
|
187
|
+
bulkCreate(knex, json) {
|
|
188
|
+
const { endpoint, body } = json;
|
|
189
|
+
let query = knex(endpoint.entityId);
|
|
190
|
+
if (!Array.isArray(body)) {
|
|
191
|
+
return query;
|
|
192
|
+
}
|
|
193
|
+
const parsedBody = body.map(row => parseBody(row));
|
|
194
|
+
return query.insert(parsedBody);
|
|
195
|
+
}
|
|
159
196
|
read(knex, json, limit) {
|
|
160
197
|
var _a, _b;
|
|
161
198
|
let { endpoint, resource, filters, sort, paginate, relationships } = json;
|
|
@@ -264,6 +301,9 @@ class SqlQueryBuilder extends sqlTable_1.default {
|
|
|
264
301
|
case datasource_1.Operation.DELETE:
|
|
265
302
|
query = builder.delete(client, json, opts);
|
|
266
303
|
break;
|
|
304
|
+
case datasource_1.Operation.BULK_CREATE:
|
|
305
|
+
query = builder.bulkCreate(client, json);
|
|
306
|
+
break;
|
|
267
307
|
case datasource_1.Operation.CREATE_TABLE:
|
|
268
308
|
case datasource_1.Operation.UPDATE_TABLE:
|
|
269
309
|
case datasource_1.Operation.DELETE_TABLE:
|
|
@@ -22,8 +22,7 @@ function generateSchema(schema, table, tables, oldTable = null) {
|
|
|
22
22
|
for (let [key, column] of Object.entries(table.schema)) {
|
|
23
23
|
// skip things that are already correct
|
|
24
24
|
const oldColumn = oldTable ? oldTable.schema[key] : null;
|
|
25
|
-
if ((oldColumn && oldColumn.type) ||
|
|
26
|
-
(primaryKey === key && !isJunction)) {
|
|
25
|
+
if ((oldColumn && oldColumn.type) || (primaryKey === key && !isJunction)) {
|
|
27
26
|
continue;
|
|
28
27
|
}
|
|
29
28
|
switch (column.type) {
|
|
@@ -147,7 +147,9 @@ var MySQLModule;
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
read(query) {
|
|
150
|
-
return
|
|
150
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
+
return internalQuery(this.client, utils_1.getSqlQuery(query));
|
|
152
|
+
});
|
|
151
153
|
}
|
|
152
154
|
update(query) {
|
|
153
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -135,9 +135,9 @@ var PostgresModule;
|
|
|
135
135
|
}
|
|
136
136
|
setSchema() {
|
|
137
137
|
if (!this.config.schema) {
|
|
138
|
-
this.config.schema =
|
|
138
|
+
this.config.schema = "public";
|
|
139
139
|
}
|
|
140
|
-
this.client.on(
|
|
140
|
+
this.client.on("connect", (client) => {
|
|
141
141
|
client.query(`SET search_path TO ${this.config.schema}`);
|
|
142
142
|
});
|
|
143
143
|
this.COLUMNS_SQL = `select * from information_schema.columns where table_schema = '${this.config.schema}'`;
|
|
@@ -13,6 +13,7 @@ const { doesUserHaveLock, updateLock, checkDebounce, setDebounce, } = require(".
|
|
|
13
13
|
const CouchDB = require("../db");
|
|
14
14
|
const { DocumentTypes } = require("../db/utils");
|
|
15
15
|
const { PermissionTypes } = require("@budibase/auth/permissions");
|
|
16
|
+
const { app: appCache } = require("@budibase/auth/cache");
|
|
16
17
|
const DEBOUNCE_TIME_SEC = 30;
|
|
17
18
|
/************************************************** *
|
|
18
19
|
* This middleware has been broken out of the *
|
|
@@ -51,7 +52,9 @@ function updateAppUpdatedAt(ctx) {
|
|
|
51
52
|
const db = new CouchDB(appId);
|
|
52
53
|
const metadata = yield db.get(DocumentTypes.APP_METADATA);
|
|
53
54
|
metadata.updatedAt = new Date().toISOString();
|
|
54
|
-
yield db.put(metadata);
|
|
55
|
+
const response = yield db.put(metadata);
|
|
56
|
+
metadata._rev = response.rev;
|
|
57
|
+
yield appCache.invalidateAppMetadata(appId, metadata);
|
|
55
58
|
// set a new debounce record with a short TTL
|
|
56
59
|
yield setDebounce(appId, DEBOUNCE_TIME_SEC);
|
|
57
60
|
});
|
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.185-alpha.11",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"repository": {
|
|
@@ -68,9 +68,11 @@
|
|
|
68
68
|
"author": "Budibase",
|
|
69
69
|
"license": "AGPL-3.0-or-later",
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@budibase/auth": "^0.9.
|
|
72
|
-
"@budibase/client": "^0.9.
|
|
73
|
-
"@budibase/string-templates": "^0.9.
|
|
71
|
+
"@budibase/auth": "^0.9.185-alpha.11",
|
|
72
|
+
"@budibase/client": "^0.9.185-alpha.11",
|
|
73
|
+
"@budibase/string-templates": "^0.9.185-alpha.11",
|
|
74
|
+
"@bull-board/api": "^3.7.0",
|
|
75
|
+
"@bull-board/koa": "^3.7.0",
|
|
74
76
|
"@elastic/elasticsearch": "7.10.0",
|
|
75
77
|
"@koa/router": "8.0.0",
|
|
76
78
|
"@sendgrid/mail": "7.1.1",
|
|
@@ -80,7 +82,6 @@
|
|
|
80
82
|
"aws-sdk": "^2.767.0",
|
|
81
83
|
"bcryptjs": "2.4.3",
|
|
82
84
|
"bull": "^3.22.4",
|
|
83
|
-
"bull-board": "^2.0.1",
|
|
84
85
|
"chmodr": "1.2.0",
|
|
85
86
|
"csvtojson": "2.0.10",
|
|
86
87
|
"dotenv": "8.2.0",
|
|
@@ -120,6 +121,7 @@
|
|
|
120
121
|
"uuid": "3.3.2",
|
|
121
122
|
"validate.js": "0.13.1",
|
|
122
123
|
"vm2": "^3.9.3",
|
|
124
|
+
"worker-farm": "^1.7.0",
|
|
123
125
|
"yargs": "13.2.4",
|
|
124
126
|
"zlib": "1.0.5"
|
|
125
127
|
},
|
|
@@ -138,7 +140,6 @@
|
|
|
138
140
|
"copyfiles": "^2.4.1",
|
|
139
141
|
"docker-compose": "^0.23.6",
|
|
140
142
|
"eslint": "^6.8.0",
|
|
141
|
-
"express": "^4.17.1",
|
|
142
143
|
"jest": "^27.0.5",
|
|
143
144
|
"nodemon": "^2.0.4",
|
|
144
145
|
"prettier": "^2.3.1",
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
const actions = require("
|
|
12
|
-
const automationUtils = require("
|
|
11
|
+
const actions = require("../automations/actions");
|
|
12
|
+
const automationUtils = require("../automations/automationUtils");
|
|
13
13
|
const AutomationEmitter = require("../events/AutomationEmitter");
|
|
14
14
|
const { processObject } = require("@budibase/string-templates");
|
|
15
15
|
const { DEFAULT_TENANT_ID } = require("@budibase/auth").constants;
|
|
@@ -18,7 +18,9 @@ const { DocumentTypes, isDevAppID } = require("../db/utils");
|
|
|
18
18
|
const { doInTenant } = require("@budibase/auth/tenancy");
|
|
19
19
|
const env = require("../environment");
|
|
20
20
|
const usage = require("../utilities/usageQuota");
|
|
21
|
+
const { definitions: triggerDefs } = require("../automations/triggerInfo");
|
|
21
22
|
const FILTER_STEP_ID = actions.ACTION_DEFINITIONS.FILTER.stepId;
|
|
23
|
+
const CRON_STEP_ID = triggerDefs.CRON.stepId;
|
|
22
24
|
const STOPPED_STATUS = { success: false, status: "STOPPED" };
|
|
23
25
|
/**
|
|
24
26
|
* The automation orchestrator is a class responsible for executing automations.
|
|
@@ -31,6 +33,8 @@ class Orchestrator {
|
|
|
31
33
|
this._chainCount = this._metadata ? this._metadata.automationChainCount : 0;
|
|
32
34
|
this._appId = triggerOutput.appId;
|
|
33
35
|
this._app = null;
|
|
36
|
+
const triggerStepId = automation.definition.trigger.stepId;
|
|
37
|
+
triggerOutput = this.cleanupTriggerOutputs(triggerStepId, triggerOutput);
|
|
34
38
|
// remove from context
|
|
35
39
|
delete triggerOutput.appId;
|
|
36
40
|
delete triggerOutput.metadata;
|
|
@@ -42,10 +46,15 @@ class Orchestrator {
|
|
|
42
46
|
this._emitter = new AutomationEmitter(this._chainCount + 1);
|
|
43
47
|
this.executionOutput = { trigger: {}, steps: [] };
|
|
44
48
|
// setup the execution output
|
|
45
|
-
const triggerStepId = automation.definition.trigger.stepId;
|
|
46
49
|
const triggerId = automation.definition.trigger.id;
|
|
47
50
|
this.updateExecutionOutput(triggerId, triggerStepId, null, triggerOutput);
|
|
48
51
|
}
|
|
52
|
+
cleanupTriggerOutputs(stepId, triggerOutput) {
|
|
53
|
+
if (stepId === CRON_STEP_ID) {
|
|
54
|
+
triggerOutput.timestamp = Date.now();
|
|
55
|
+
}
|
|
56
|
+
return triggerOutput;
|
|
57
|
+
}
|
|
49
58
|
getStepFunctionality(stepId) {
|
|
50
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
60
|
let step = yield actions.getAction(stepId);
|
|
@@ -122,7 +131,14 @@ class Orchestrator {
|
|
|
122
131
|
});
|
|
123
132
|
}
|
|
124
133
|
}
|
|
125
|
-
module.exports = (
|
|
126
|
-
const automationOrchestrator = new Orchestrator(
|
|
127
|
-
|
|
128
|
-
|
|
134
|
+
module.exports = (input, callback) => {
|
|
135
|
+
const automationOrchestrator = new Orchestrator(input.data.automation, input.data.event);
|
|
136
|
+
automationOrchestrator
|
|
137
|
+
.execute()
|
|
138
|
+
.then(response => {
|
|
139
|
+
callback(null, response);
|
|
140
|
+
})
|
|
141
|
+
.catch(err => {
|
|
142
|
+
callback(err);
|
|
143
|
+
});
|
|
144
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const workerFarm = require("worker-farm");
|
|
3
|
+
const env = require("../environment");
|
|
4
|
+
const ThreadType = {
|
|
5
|
+
QUERY: "query",
|
|
6
|
+
AUTOMATION: "automation",
|
|
7
|
+
};
|
|
8
|
+
function typeToFile(type) {
|
|
9
|
+
let filename = null;
|
|
10
|
+
switch (type) {
|
|
11
|
+
case ThreadType.QUERY:
|
|
12
|
+
filename = "./query";
|
|
13
|
+
break;
|
|
14
|
+
case ThreadType.AUTOMATION:
|
|
15
|
+
filename = "./automation";
|
|
16
|
+
break;
|
|
17
|
+
default:
|
|
18
|
+
throw "Unknown thread type";
|
|
19
|
+
}
|
|
20
|
+
return require.resolve(filename);
|
|
21
|
+
}
|
|
22
|
+
class Thread {
|
|
23
|
+
constructor(type, opts = { timeoutMs: null, count: 1 }) {
|
|
24
|
+
this.type = type;
|
|
25
|
+
if (!env.isTest()) {
|
|
26
|
+
const workerOpts = {
|
|
27
|
+
autoStart: true,
|
|
28
|
+
maxConcurrentWorkers: opts.count ? opts.count : 1,
|
|
29
|
+
};
|
|
30
|
+
if (opts.timeoutMs) {
|
|
31
|
+
workerOpts.maxCallTime = opts.timeoutMs;
|
|
32
|
+
}
|
|
33
|
+
this.workers = workerFarm(workerOpts, typeToFile(type));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
run(data) {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
let fncToCall;
|
|
39
|
+
// if in test then don't use threading
|
|
40
|
+
if (env.isTest()) {
|
|
41
|
+
fncToCall = require(typeToFile(this.type));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
fncToCall = this.workers;
|
|
45
|
+
}
|
|
46
|
+
fncToCall(data, (err, response) => {
|
|
47
|
+
if (err) {
|
|
48
|
+
reject(err);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
resolve(response);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
module.exports.Thread = Thread;
|
|
58
|
+
module.exports.ThreadType = ThreadType;
|
|
@@ -0,0 +1,61 @@
|
|
|
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
|
+
const ScriptRunner = require("../utilities/scriptRunner");
|
|
12
|
+
const { integrations } = require("../integrations");
|
|
13
|
+
function formatResponse(resp) {
|
|
14
|
+
if (typeof resp === "string") {
|
|
15
|
+
try {
|
|
16
|
+
resp = JSON.parse(resp);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
resp = { response: resp };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return resp;
|
|
23
|
+
}
|
|
24
|
+
function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const Integration = integrations[datasource.source];
|
|
27
|
+
if (!Integration) {
|
|
28
|
+
throw "Integration type does not exist.";
|
|
29
|
+
}
|
|
30
|
+
const integration = new Integration(datasource.config);
|
|
31
|
+
let rows = formatResponse(yield integration[queryVerb](query));
|
|
32
|
+
// transform as required
|
|
33
|
+
if (transformer) {
|
|
34
|
+
const runner = new ScriptRunner(transformer, { data: rows });
|
|
35
|
+
rows = runner.execute();
|
|
36
|
+
}
|
|
37
|
+
// needs to an array for next step
|
|
38
|
+
if (!Array.isArray(rows)) {
|
|
39
|
+
rows = [rows];
|
|
40
|
+
}
|
|
41
|
+
// map into JSON if just raw primitive here
|
|
42
|
+
if (rows.find(row => typeof row !== "object")) {
|
|
43
|
+
rows = rows.map(value => ({ value }));
|
|
44
|
+
}
|
|
45
|
+
// get all the potential fields in the schema
|
|
46
|
+
let keys = rows.flatMap(Object.keys);
|
|
47
|
+
if (integration.end) {
|
|
48
|
+
integration.end();
|
|
49
|
+
}
|
|
50
|
+
return { rows, keys };
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
module.exports = (input, callback) => {
|
|
54
|
+
runAndTransform(input.datasource, input.queryVerb, input.query, input.transformer)
|
|
55
|
+
.then(response => {
|
|
56
|
+
callback(null, response);
|
|
57
|
+
})
|
|
58
|
+
.catch(err => {
|
|
59
|
+
callback(err);
|
|
60
|
+
});
|
|
61
|
+
};
|