@budibase/server 1.0.135 → 1.0.138

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.
Files changed (179) hide show
  1. package/builder/assets/{index.1a219cf7.js → index.a48ac266.js} +112 -112
  2. package/builder/index.html +1 -1
  3. package/coverage/clover.xml +13 -9
  4. package/coverage/coverage-final.json +2 -2
  5. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/index.html +1 -1
  15. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  44. package/coverage/lcov-report/api/index.html +1 -1
  45. package/coverage/lcov-report/api/index.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/index.html +1 -1
  57. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  71. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  74. package/coverage/lcov-report/automations/actions.js.html +1 -1
  75. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  76. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  77. package/coverage/lcov-report/automations/index.html +1 -1
  78. package/coverage/lcov-report/automations/index.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/index.html +1 -1
  86. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  105. package/coverage/lcov-report/constants/index.html +1 -1
  106. package/coverage/lcov-report/constants/index.js.html +1 -1
  107. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  108. package/coverage/lcov-report/constants/screens.js.html +1 -1
  109. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  110. package/coverage/lcov-report/db/index.html +1 -1
  111. package/coverage/lcov-report/db/index.js.html +1 -1
  112. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  116. package/coverage/lcov-report/db/newid.js.html +1 -1
  117. package/coverage/lcov-report/db/utils.js.html +1 -1
  118. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  119. package/coverage/lcov-report/events/index.html +1 -1
  120. package/coverage/lcov-report/events/index.js.html +1 -1
  121. package/coverage/lcov-report/events/utils.js.html +1 -1
  122. package/coverage/lcov-report/index.html +15 -15
  123. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  124. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  125. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  126. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  127. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  128. package/coverage/lcov-report/middleware/index.html +1 -1
  129. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  130. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  131. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  132. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  133. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  134. package/coverage/lcov-report/threads/automation.js.html +20 -26
  135. package/coverage/lcov-report/threads/index.html +22 -22
  136. package/coverage/lcov-report/threads/query.js.html +16 -19
  137. package/coverage/lcov-report/threads/utils.js.html +1 -1
  138. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  139. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  140. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  141. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  142. package/coverage/lcov-report/utilities/global.js.html +1 -1
  143. package/coverage/lcov-report/utilities/index.html +1 -1
  144. package/coverage/lcov-report/utilities/index.js.html +1 -1
  145. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  146. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  147. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  148. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  150. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  151. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  152. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  153. package/coverage/lcov-report/utilities/security.js.html +1 -1
  154. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  156. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  157. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  158. package/coverage/lcov-report/utilities/users.js.html +1 -1
  159. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  160. package/coverage/lcov.info +15 -19
  161. package/dist/integrations/microsoftSqlServer.js +1 -6
  162. package/dist/integrations/mysql.js +16 -14
  163. package/dist/integrations/oracle.js +2 -6
  164. package/dist/integrations/postgres.js +1 -6
  165. package/dist/integrations/utils.js +15 -5
  166. package/dist/package.json +5 -5
  167. package/dist/threads/automation.js +9 -10
  168. package/dist/threads/query.js +7 -7
  169. package/dist/tsconfig.build.tsbuildinfo +1 -1
  170. package/dist/utilities/fileSystem/index.js +11 -7
  171. package/package.json +6 -6
  172. package/src/integrations/microsoftSqlServer.ts +1 -3
  173. package/src/integrations/mysql.ts +18 -12
  174. package/src/integrations/oracle.ts +3 -3
  175. package/src/integrations/postgres.ts +1 -2
  176. package/src/integrations/utils.ts +16 -5
  177. package/src/threads/automation.js +9 -11
  178. package/src/threads/query.js +7 -8
  179. package/src/utilities/fileSystem/index.js +16 -8
@@ -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 { doWithDB } = require("@budibase/backend-core/db");
15
+ const { doWithDB, dangerousGetDB, closeDB, } = 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,13 +135,17 @@ 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
+ // streaming a DB dump is a bit more complicated, can't close DB
139
+ if (stream) {
140
+ const db = dangerousGetDB(dbName);
141
+ const memStream = new MemoryStream();
142
+ memStream.on("end", () => __awaiter(void 0, void 0, void 0, function* () {
143
+ yield closeDB(db);
144
+ }));
145
+ db.dump(memStream, { filter });
146
+ return memStream;
147
+ }
138
148
  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;
144
- }
145
149
  // Write the dump to file if required
146
150
  if (exportName) {
147
151
  const path = join(budibaseTempDir(), exportName);
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.135",
4
+ "version": "1.0.138",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -68,10 +68,10 @@
68
68
  "license": "GPL-3.0",
69
69
  "dependencies": {
70
70
  "@apidevtools/swagger-parser": "^10.0.3",
71
- "@budibase/backend-core": "^1.0.135",
72
- "@budibase/client": "^1.0.135",
73
- "@budibase/pro": "1.0.134",
74
- "@budibase/string-templates": "^1.0.135",
71
+ "@budibase/backend-core": "^1.0.138",
72
+ "@budibase/client": "^1.0.138",
73
+ "@budibase/pro": "1.0.137",
74
+ "@budibase/string-templates": "^1.0.138",
75
75
  "@bull-board/api": "^3.7.0",
76
76
  "@bull-board/koa": "^3.7.0",
77
77
  "@elastic/elasticsearch": "7.10.0",
@@ -180,5 +180,5 @@
180
180
  "optionalDependencies": {
181
181
  "oracledb": "^5.3.0"
182
182
  },
183
- "gitHead": "eae6a0110baea43dc1d735dc2d7db36732d52da7"
183
+ "gitHead": "fed8c77bce51a555cf057df219b913e66467442e"
184
184
  }
@@ -242,12 +242,10 @@ module MSSQLModule {
242
242
  if (typeof name !== "string") {
243
243
  continue
244
244
  }
245
- const type: string = convertSqlType(def.DATA_TYPE)
246
-
247
245
  schema[name] = {
248
246
  autocolumn: !!autoColumns.find((col: string) => col === name),
249
247
  name: name,
250
- type,
248
+ ...convertSqlType(def.DATA_TYPE),
251
249
  }
252
250
  }
253
251
  tables[tableName] = {
@@ -15,6 +15,7 @@ import {
15
15
  } from "./utils"
16
16
  import { DatasourcePlus } from "./base/datasourcePlus"
17
17
  import dayjs from "dayjs"
18
+ import { FieldTypes } from "../constants"
18
19
  const { NUMBER_REGEX } = require("../utilities")
19
20
 
20
21
  module MySQLModule {
@@ -101,7 +102,7 @@ module MySQLModule {
101
102
  }
102
103
  // if not a number, see if it is a date - important to do in this order as any
103
104
  // integer will be considered a valid date
104
- else if (dayjs(binding).isValid()) {
105
+ else if (/^\d/.test(binding) && dayjs(binding).isValid()) {
105
106
  bindings[i] = dayjs(binding).toDate()
106
107
  }
107
108
  }
@@ -151,20 +152,24 @@ module MySQLModule {
151
152
 
152
153
  async internalQuery(
153
154
  query: SqlQuery,
154
- connect: boolean = true
155
+ opts: { connect?: boolean; disableCoercion?: boolean } = {
156
+ connect: true,
157
+ disableCoercion: false,
158
+ }
155
159
  ): Promise<any[] | any> {
156
160
  try {
157
- if (connect) {
161
+ if (opts?.connect) {
158
162
  await this.connect()
159
163
  }
164
+ const baseBindings = query.bindings || []
165
+ const bindings = opts?.disableCoercion
166
+ ? baseBindings
167
+ : bindingTypeCoerce(baseBindings)
160
168
  // Node MySQL is callback based, so we must wrap our call in a promise
161
- const response = await this.client.query(
162
- query.sql,
163
- bindingTypeCoerce(query.bindings || [])
164
- )
169
+ const response = await this.client.query(query.sql, bindings)
165
170
  return response[0]
166
171
  } finally {
167
- if (connect) {
172
+ if (opts?.connect) {
168
173
  await this.disconnect()
169
174
  }
170
175
  }
@@ -179,7 +184,7 @@ module MySQLModule {
179
184
  // get the tables first
180
185
  const tablesResp = await this.internalQuery(
181
186
  { sql: "SHOW TABLES;" },
182
- false
187
+ { connect: false }
183
188
  )
184
189
  const tableNames = tablesResp.map(
185
190
  (obj: any) =>
@@ -191,7 +196,7 @@ module MySQLModule {
191
196
  const schema: TableSchema = {}
192
197
  const descResp = await this.internalQuery(
193
198
  { sql: `DESCRIBE \`${tableName}\`;` },
194
- false
199
+ { connect: false }
195
200
  )
196
201
  for (let column of descResp) {
197
202
  const columnName = column.Field
@@ -211,8 +216,8 @@ module MySQLModule {
211
216
  schema[columnName] = {
212
217
  name: columnName,
213
218
  autocolumn: isAuto,
214
- type: convertSqlType(column.Type),
215
219
  constraints,
220
+ ...convertSqlType(column.Type),
216
221
  }
217
222
  }
218
223
  if (!tables[tableName]) {
@@ -254,7 +259,8 @@ module MySQLModule {
254
259
  async query(json: QueryJson) {
255
260
  await this.connect()
256
261
  try {
257
- const queryFn = (query: any) => this.internalQuery(query, false)
262
+ const queryFn = (query: any) =>
263
+ this.internalQuery(query, { connect: false, disableCoercion: true })
258
264
  return await this.queryWithReturning(json, queryFn)
259
265
  } finally {
260
266
  await this.disconnect()
@@ -279,9 +279,9 @@ module OracleModule {
279
279
  )
280
280
  }
281
281
 
282
- private internalConvertType(column: OracleColumn): string {
282
+ private internalConvertType(column: OracleColumn): { type: string } {
283
283
  if (this.isBooleanType(column)) {
284
- return FieldTypes.BOOLEAN
284
+ return { type: FieldTypes.BOOLEAN }
285
285
  }
286
286
 
287
287
  return convertSqlType(column.type)
@@ -328,7 +328,7 @@ module OracleModule {
328
328
  fieldSchema = {
329
329
  autocolumn: OracleIntegration.isAutoColumn(oracleColumn),
330
330
  name: columnName,
331
- type: this.internalConvertType(oracleColumn),
331
+ ...this.internalConvertType(oracleColumn),
332
332
  }
333
333
  table.schema[columnName] = fieldSchema
334
334
  }
@@ -227,7 +227,6 @@ module PostgresModule {
227
227
  }
228
228
  }
229
229
 
230
- const type: string = convertSqlType(column.data_type)
231
230
  const identity = !!(
232
231
  column.identity_generation ||
233
232
  column.identity_start ||
@@ -242,7 +241,7 @@ module PostgresModule {
242
241
  tables[tableName].schema[columnName] = {
243
242
  autocolumn: isAuto,
244
243
  name: columnName,
245
- type,
244
+ ...convertSqlType(column.data_type),
246
245
  }
247
246
  }
248
247
 
@@ -35,6 +35,9 @@ const SQL_DATE_TYPE_MAP = {
35
35
  date: FieldTypes.DATETIME,
36
36
  }
37
37
 
38
+ const SQL_DATE_ONLY_TYPES = ["date"]
39
+ const SQL_TIME_ONLY_TYPES = ["time"]
40
+
38
41
  const SQL_STRING_TYPE_MAP = {
39
42
  varchar: FieldTypes.STRING,
40
43
  char: FieldTypes.STRING,
@@ -85,9 +88,9 @@ export function breakExternalTableId(tableId: string | undefined) {
85
88
  return {}
86
89
  }
87
90
  const parts = tableId.split(DOUBLE_SEPARATOR)
88
- let tableName = parts.pop()
91
+ let datasourceId = parts.shift()
89
92
  // if they need joined
90
- let datasourceId = parts.join(DOUBLE_SEPARATOR)
93
+ let tableName = parts.join(DOUBLE_SEPARATOR)
91
94
  return { datasourceId, tableName }
92
95
  }
93
96
 
@@ -137,12 +140,20 @@ export function breakRowIdField(_id: string | { _id: string }): any[] {
137
140
  }
138
141
 
139
142
  export function convertSqlType(type: string) {
143
+ let foundType = FieldTypes.STRING
144
+ const lcType = type.toLowerCase()
140
145
  for (let [external, internal] of Object.entries(SQL_TYPE_MAP)) {
141
- if (type.toLowerCase().includes(external)) {
142
- return internal
146
+ if (lcType.includes(external)) {
147
+ foundType = internal
148
+ break
143
149
  }
144
150
  }
145
- return FieldTypes.STRING
151
+ const schema: any = { type: foundType }
152
+ if (foundType === FieldTypes.DATETIME) {
153
+ schema.dateOnly = SQL_DATE_ONLY_TYPES.includes(lcType)
154
+ schema.timeOnly = SQL_TIME_ONLY_TYPES.includes(lcType)
155
+ }
156
+ return schema
146
157
  }
147
158
 
148
159
  export function getSqlQuery(query: SqlQuery | string): SqlQuery {
@@ -100,10 +100,10 @@ class Orchestrator {
100
100
  let automation = this._automation
101
101
  const app = await this.getApp()
102
102
  let stopped = false
103
- let loopStep
103
+ let loopStep = null
104
104
 
105
105
  let stepCount = 0
106
- let loopStepNumber
106
+ let loopStepNumber = null
107
107
  let loopSteps = []
108
108
  for (let step of automation.definition.steps) {
109
109
  stepCount++
@@ -286,18 +286,16 @@ class Orchestrator {
286
286
 
287
287
  module.exports = (input, callback) => {
288
288
  const appId = input.data.event.appId
289
- doInAppContext(appId, () => {
289
+ doInAppContext(appId, async () => {
290
290
  const automationOrchestrator = new Orchestrator(
291
291
  input.data.automation,
292
292
  input.data.event
293
293
  )
294
- automationOrchestrator
295
- .execute()
296
- .then(response => {
297
- callback(null, response)
298
- })
299
- .catch(err => {
300
- callback(err)
301
- })
294
+ try {
295
+ const response = await automationOrchestrator.execute()
296
+ callback(null, response)
297
+ } catch (err) {
298
+ callback(err)
299
+ }
302
300
  })
303
301
  }
@@ -191,14 +191,13 @@ class QueryRunner {
191
191
  }
192
192
 
193
193
  module.exports = (input, callback) => {
194
- doInAppContext(input.appId, () => {
194
+ doInAppContext(input.appId, async () => {
195
195
  const Runner = new QueryRunner(input)
196
- Runner.execute()
197
- .then(response => {
198
- callback(null, response)
199
- })
200
- .catch(err => {
201
- callback(err)
202
- })
196
+ try {
197
+ const response = await Runner.execute()
198
+ callback(null, response)
199
+ } catch (err) {
200
+ callback(err)
201
+ }
203
202
  })
204
203
  }
@@ -2,7 +2,11 @@ const { budibaseTempDir } = require("../budibaseDir")
2
2
  const fs = require("fs")
3
3
  const { join } = require("path")
4
4
  const uuid = require("uuid/v4")
5
- const { doWithDB } = require("@budibase/backend-core/db")
5
+ const {
6
+ doWithDB,
7
+ dangerousGetDB,
8
+ closeDB,
9
+ } = require("@budibase/backend-core/db")
6
10
  const { ObjectStoreBuckets } = require("../../constants")
7
11
  const {
8
12
  upload,
@@ -151,14 +155,18 @@ exports.streamBackup = async appId => {
151
155
  * @return {*} either a readable stream or a string
152
156
  */
153
157
  exports.exportDB = async (dbName, { stream, filter, exportName } = {}) => {
154
- return doWithDB(dbName, async db => {
155
- // Stream the dump if required
156
- if (stream) {
157
- const memStream = new MemoryStream()
158
- db.dump(memStream, { filter })
159
- return memStream
160
- }
158
+ // streaming a DB dump is a bit more complicated, can't close DB
159
+ if (stream) {
160
+ const db = dangerousGetDB(dbName)
161
+ const memStream = new MemoryStream()
162
+ memStream.on("end", async () => {
163
+ await closeDB(db)
164
+ })
165
+ db.dump(memStream, { filter })
166
+ return memStream
167
+ }
161
168
 
169
+ return doWithDB(dbName, async db => {
162
170
  // Write the dump to file if required
163
171
  if (exportName) {
164
172
  const path = join(budibaseTempDir(), exportName)