@budibase/server 2.0.30-alpha.14 → 2.0.30-alpha.16

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 (228) hide show
  1. package/builder/assets/backups-default.8c011f1b.png +0 -0
  2. package/builder/assets/{index.099ad307.js → index.7ebb4fb6.js} +333 -329
  3. package/builder/assets/{index.acdbfe62.css → index.b15ffe95.css} +1 -1
  4. package/builder/index.html +2 -2
  5. package/coverage/clover.xml +254 -313
  6. package/coverage/coverage-final.json +15 -17
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/cloud.js.html +74 -62
  10. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/index.html +17 -32
  13. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  19. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
  30. package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
  31. package/coverage/lcov-report/api/controllers/table/index.html +16 -16
  32. package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
  33. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/index.js.html +3 -3
  38. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  41. package/coverage/lcov-report/api/index.html +1 -1
  42. package/coverage/lcov-report/api/index.js.html +3 -3
  43. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  44. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  45. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/index.html +5 -20
  52. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  66. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  69. package/coverage/lcov-report/automations/actions.js.html +1 -1
  70. package/coverage/lcov-report/automations/automationUtils.js.html +6 -6
  71. package/coverage/lcov-report/automations/bullboard.js.html +17 -92
  72. package/coverage/lcov-report/automations/index.html +18 -18
  73. package/coverage/lcov-report/automations/index.js.html +5 -5
  74. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  75. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  76. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  77. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/index.html +1 -1
  81. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  91. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  92. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  93. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  94. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggers.js.html +5 -5
  100. package/coverage/lcov-report/constants/index.html +5 -5
  101. package/coverage/lcov-report/constants/index.js.html +6 -18
  102. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  103. package/coverage/lcov-report/constants/screens.js.html +1 -1
  104. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  105. package/coverage/lcov-report/db/index.html +19 -19
  106. package/coverage/lcov-report/db/index.js.html +1 -1
  107. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  108. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  109. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  110. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  111. package/coverage/lcov-report/db/newid.js.html +2 -2
  112. package/coverage/lcov-report/db/utils.js.html +35 -308
  113. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  114. package/coverage/lcov-report/events/index.html +1 -1
  115. package/coverage/lcov-report/events/index.js.html +1 -1
  116. package/coverage/lcov-report/events/utils.js.html +1 -1
  117. package/coverage/lcov-report/index.html +62 -62
  118. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  119. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  120. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  121. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  122. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  123. package/coverage/lcov-report/middleware/index.html +1 -1
  124. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  125. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  126. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  127. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  128. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  129. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  130. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  131. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  132. package/coverage/lcov-report/utilities/global.js.html +1 -1
  133. package/coverage/lcov-report/utilities/index.html +1 -1
  134. package/coverage/lcov-report/utilities/index.js.html +1 -1
  135. package/coverage/lcov-report/utilities/plugins.js.html +1 -1
  136. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
  137. package/coverage/lcov-report/utilities/queue/index.html +21 -21
  138. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  139. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  140. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  141. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  142. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  143. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  144. package/coverage/lcov-report/utilities/security.js.html +2 -2
  145. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  146. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  147. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  148. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  149. package/coverage/lcov-report/utilities/users.js.html +1 -1
  150. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  151. package/coverage/lcov.info +451 -564
  152. package/dist/api/controllers/application.js +2 -5
  153. package/dist/api/controllers/backup.js +19 -13
  154. package/dist/api/controllers/cloud.js +38 -35
  155. package/dist/api/controllers/deploy/index.js +11 -2
  156. package/dist/api/controllers/static/index.js +2 -2
  157. package/dist/api/controllers/table/bulkFormula.js +4 -3
  158. package/dist/api/controllers/table/external.js +5 -4
  159. package/dist/api/controllers/table/index.js +4 -4
  160. package/dist/api/controllers/table/internal.js +2 -1
  161. package/dist/api/controllers/table/utils.js +4 -48
  162. package/dist/api/controllers/view/index.js +2 -2
  163. package/dist/api/routes/backup.js +34 -7
  164. package/dist/api/routes/index.js +9 -4
  165. package/dist/app.js +14 -0
  166. package/dist/automations/automationUtils.js +2 -2
  167. package/dist/automations/bullboard.js +5 -33
  168. package/dist/automations/index.js +4 -4
  169. package/dist/automations/triggers.js +4 -4
  170. package/dist/automations/utils.js +13 -9
  171. package/dist/constants/index.js +2 -5
  172. package/dist/db/utils.js +10 -75
  173. package/dist/migrations/functions/backfill/app/tables.js +5 -8
  174. package/dist/package.json +11 -11
  175. package/dist/sdk/app/backups/constants.js +5 -0
  176. package/dist/sdk/app/backups/exports.js +172 -0
  177. package/dist/sdk/app/backups/imports.js +162 -0
  178. package/dist/sdk/app/backups/index.js +29 -0
  179. package/dist/sdk/app/backups/statistics.js +73 -0
  180. package/dist/sdk/app/tables/index.js +61 -0
  181. package/dist/sdk/index.js +15 -0
  182. package/dist/tests/utilities/TestConfiguration.js +4 -2
  183. package/dist/threads/automation.js +12 -17
  184. package/dist/tsconfig.build.tsbuildinfo +1 -1
  185. package/dist/utilities/fileSystem/index.js +3 -95
  186. package/dist/utilities/fileSystem/utilities.js +2 -1
  187. package/package.json +12 -12
  188. package/src/api/controllers/application.ts +3 -10
  189. package/src/api/controllers/{backup.js → backup.ts} +7 -7
  190. package/src/api/controllers/cloud.js +44 -40
  191. package/src/api/controllers/deploy/index.ts +20 -7
  192. package/src/api/controllers/static/index.ts +2 -2
  193. package/src/api/controllers/table/bulkFormula.js +4 -3
  194. package/src/api/controllers/table/external.js +4 -4
  195. package/src/api/controllers/table/index.js +4 -4
  196. package/src/api/controllers/table/internal.ts +3 -7
  197. package/src/api/controllers/table/utils.ts +1 -52
  198. package/src/api/controllers/view/index.js +2 -2
  199. package/src/api/routes/backup.ts +10 -0
  200. package/src/api/routes/index.ts +11 -5
  201. package/src/api/routes/tests/backup.spec.js +1 -1
  202. package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
  203. package/src/app.ts +15 -0
  204. package/src/automations/automationUtils.js +2 -2
  205. package/src/automations/bullboard.js +8 -33
  206. package/src/automations/index.js +4 -4
  207. package/src/automations/triggers.js +4 -4
  208. package/src/automations/utils.ts +12 -8
  209. package/src/constants/index.js +2 -6
  210. package/src/db/utils.js +17 -108
  211. package/src/definitions/automations.ts +0 -12
  212. package/src/migrations/functions/backfill/app/tables.ts +6 -13
  213. package/src/sdk/app/backups/constants.ts +2 -0
  214. package/src/sdk/app/backups/exports.ts +171 -0
  215. package/src/sdk/app/backups/imports.ts +168 -0
  216. package/src/sdk/app/backups/index.ts +9 -0
  217. package/src/sdk/app/backups/statistics.ts +77 -0
  218. package/src/sdk/app/tables/index.ts +60 -0
  219. package/src/sdk/index.ts +13 -0
  220. package/src/tests/utilities/TestConfiguration.js +5 -2
  221. package/src/threads/automation.ts +20 -27
  222. package/src/utilities/fileSystem/index.js +2 -119
  223. package/src/utilities/fileSystem/utilities.js +2 -0
  224. package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
  225. package/coverage/lcov-report/api/routes/backup.js.html +0 -115
  226. package/dist/automations/listeners.js +0 -102
  227. package/src/api/routes/backup.js +0 -10
  228. package/src/automations/listeners.ts +0 -78
@@ -1,11 +1,5 @@
1
1
  import { transform } from "../../../utilities/csvParser"
2
- import {
3
- getRowParams,
4
- generateRowID,
5
- InternalTables,
6
- getTableParams,
7
- BudibaseInternalDB,
8
- } from "../../../db/utils"
2
+ import { getRowParams, generateRowID, InternalTables } from "../../../db/utils"
9
3
  import { isEqual } from "lodash"
10
4
  import { AutoFieldSubTypes, FieldTypes } from "../../../constants"
11
5
  import {
@@ -17,11 +11,6 @@ import {
17
11
  SwitchableTypes,
18
12
  CanSwitchTypes,
19
13
  } from "../../../constants"
20
- import {
21
- isExternalTable,
22
- breakExternalTableId,
23
- isSQL,
24
- } from "../../../integrations/utils"
25
14
  import { getViews, saveView } from "../view/utils"
26
15
  import viewTemplate from "../view/viewBuilder"
27
16
  const { getAppDB } = require("@budibase/backend-core/context")
@@ -256,46 +245,6 @@ class TableSaveFunctions {
256
245
  }
257
246
  }
258
247
 
259
- export async function getAllInternalTables() {
260
- const db = getAppDB()
261
- const internalTables = await db.allDocs(
262
- getTableParams(null, {
263
- include_docs: true,
264
- })
265
- )
266
- return internalTables.rows.map((tableDoc: any) => ({
267
- ...tableDoc.doc,
268
- type: "internal",
269
- sourceId: BudibaseInternalDB._id,
270
- }))
271
- }
272
-
273
- export async function getAllExternalTables(datasourceId: any) {
274
- const db = getAppDB()
275
- const datasource = await db.get(datasourceId)
276
- if (!datasource || !datasource.entities) {
277
- throw "Datasource is not configured fully."
278
- }
279
- return datasource.entities
280
- }
281
-
282
- export async function getExternalTable(datasourceId: any, tableName: any) {
283
- const entities = await getAllExternalTables(datasourceId)
284
- return entities[tableName]
285
- }
286
-
287
- export async function getTable(tableId: any) {
288
- const db = getAppDB()
289
- if (isExternalTable(tableId)) {
290
- let { datasourceId, tableName } = breakExternalTableId(tableId)
291
- const datasource = await db.get(datasourceId)
292
- const table = await getExternalTable(datasourceId, tableName)
293
- return { ...table, sql: isSQL(datasource) }
294
- } else {
295
- return db.get(tableId)
296
- }
297
- }
298
-
299
248
  export async function checkForViewUpdates(
300
249
  table: any,
301
250
  rename: any,
@@ -3,12 +3,12 @@ const { apiFileReturn } = require("../../../utilities/fileSystem")
3
3
  const exporters = require("./exporters")
4
4
  const { saveView, getView, getViews, deleteView } = require("./utils")
5
5
  const { fetchView } = require("../row")
6
- const { getTable } = require("../table/utils")
7
6
  const { FieldTypes } = require("../../../constants")
8
7
  const { getAppDB } = require("@budibase/backend-core/context")
9
8
  const { events } = require("@budibase/backend-core")
10
9
  const { DocumentType } = require("../../../db/utils")
11
10
  const { cloneDeep, isEqual } = require("lodash")
11
+ const sdk = require("../../../sdk")
12
12
 
13
13
  exports.fetch = async ctx => {
14
14
  ctx.body = await getViews()
@@ -144,7 +144,7 @@ exports.exportView = async ctx => {
144
144
 
145
145
  let schema = view && view.meta && view.meta.schema
146
146
  const tableId = ctx.params.tableId || view.meta.tableId
147
- const table = await getTable(tableId)
147
+ const table = await sdk.tables.getTable(tableId)
148
148
  if (!schema) {
149
149
  schema = table.schema
150
150
  }
@@ -0,0 +1,10 @@
1
+ import Router from "@koa/router"
2
+ import * as controller from "../controllers/backup"
3
+ import authorized from "../../middleware/authorized"
4
+ import { BUILDER } from "@budibase/backend-core/permissions"
5
+
6
+ const router = new Router()
7
+
8
+ router.get("/api/backups/export", authorized(BUILDER), controller.exportAppDump)
9
+
10
+ export default router
@@ -25,11 +25,17 @@ import devRoutes from "./dev"
25
25
  import cloudRoutes from "./cloud"
26
26
  import migrationRoutes from "./migrations"
27
27
  import pluginRoutes from "./plugin"
28
+ import Router from "@koa/router"
29
+ import { api } from "@budibase/pro"
28
30
 
29
31
  export { default as staticRoutes } from "./static"
30
32
  export { default as publicRoutes } from "./public"
31
33
 
32
- export const mainRoutes = [
34
+ const appBackupRoutes = api.appBackups
35
+ const scheduleRoutes = api.schedules
36
+ export const mainRoutes: Router[] = [
37
+ appBackupRoutes,
38
+ backupRoutes,
33
39
  authRoutes,
34
40
  deployRoutes,
35
41
  layoutRoutes,
@@ -49,14 +55,14 @@ export const mainRoutes = [
49
55
  permissionRoutes,
50
56
  datasourceRoutes,
51
57
  queryRoutes,
52
- backupRoutes,
53
58
  metadataRoutes,
54
59
  devRoutes,
55
60
  cloudRoutes,
56
- // these need to be handled last as they still use /api/:tableId
57
- // this could be breaking as koa may recognise other routes as this
58
- tableRoutes,
59
61
  rowRoutes,
60
62
  migrationRoutes,
61
63
  pluginRoutes,
64
+ scheduleRoutes,
65
+ // these need to be handled last as they still use /api/:tableId
66
+ // this could be breaking as koa may recognise other routes as this
67
+ tableRoutes,
62
68
  ]
@@ -21,7 +21,7 @@ describe("/backups", () => {
21
21
  .set(config.defaultHeaders())
22
22
  .expect(200)
23
23
  expect(res.text).toBeDefined()
24
- expect(res.text.includes(`"db_name":"${config.getAppId()}"`)).toEqual(true)
24
+ expect(res.headers["content-type"]).toEqual("application/gzip")
25
25
  expect(events.app.exported.mock.calls.length).toBe(1)
26
26
  })
27
27
 
@@ -1,5 +1,5 @@
1
- const setup = require("./utilities")
2
- const { events } = require("@budibase/backend-core")
1
+ import setup from "./utilities"
2
+ import { events } from "@budibase/backend-core"
3
3
 
4
4
  describe("/deployments", () => {
5
5
  let request = setup.getRequest()
@@ -19,7 +19,7 @@ describe("/deployments", () => {
19
19
  .set(config.defaultHeaders())
20
20
  .expect("Content-Type", /json/)
21
21
  .expect(200)
22
- expect(events.app.published.mock.calls.length).toBe(1)
22
+ expect((events.app.published as jest.Mock).mock.calls.length).toBe(1)
23
23
  })
24
24
  })
25
- })
25
+ })
package/src/app.ts CHANGED
@@ -37,6 +37,8 @@ import {
37
37
  } from "./utilities/workerRequests"
38
38
  import { watch } from "./watch"
39
39
  import { initialise as initialiseWebsockets } from "./websocket"
40
+ import sdk from "./sdk"
41
+ import * as pro from "@budibase/pro"
40
42
 
41
43
  const app = new Koa()
42
44
 
@@ -102,12 +104,25 @@ server.on("close", async () => {
102
104
  }
103
105
  })
104
106
 
107
+ const initPro = async () => {
108
+ await pro.init({
109
+ backups: {
110
+ processing: {
111
+ exportAppFn: sdk.backups.exportApp,
112
+ importAppFn: sdk.backups.importApp,
113
+ statsFn: sdk.backups.calculateBackupStats,
114
+ },
115
+ },
116
+ })
117
+ }
118
+
105
119
  module.exports = server.listen(env.PORT || 0, async () => {
106
120
  console.log(`Budibase running on ${JSON.stringify(server.address())}`)
107
121
  env._set("PORT", server.address().port)
108
122
  eventEmitter.emitPort(env.PORT)
109
123
  fileSystem.init()
110
124
  await redis.init()
125
+ await initPro()
111
126
 
112
127
  // run migrations on startup if not done via http
113
128
  // not recommended in a clustered environment
@@ -1,10 +1,10 @@
1
- const { getTable } = require("../api/controllers/table/utils")
2
1
  const {
3
2
  findHBSBlocks,
4
3
  decodeJSBinding,
5
4
  isJSBinding,
6
5
  encodeJSBinding,
7
6
  } = require("@budibase/string-templates")
7
+ const sdk = require("../sdk")
8
8
 
9
9
  /**
10
10
  * When values are input to the system generally they will be of type string as this is required for template strings.
@@ -64,7 +64,7 @@ exports.cleanInputValues = (inputs, schema) => {
64
64
  * @returns {Promise<Object>} The cleaned up rows object, will should now have all the required primitive types.
65
65
  */
66
66
  exports.cleanUpRow = async (tableId, row) => {
67
- let table = await getTable(tableId)
67
+ let table = await sdk.tables.getTable(tableId)
68
68
  return exports.cleanInputValues(row, { properties: table.schema })
69
69
  }
70
70
 
@@ -1,37 +1,17 @@
1
1
  const { createBullBoard } = require("@bull-board/api")
2
2
  const { BullAdapter } = require("@bull-board/api/bullAdapter")
3
3
  const { KoaAdapter } = require("@bull-board/koa")
4
- const env = require("../environment")
5
- const Queue = env.isTest()
6
- ? require("../utilities/queue/inMemoryQueue")
7
- : require("bull")
8
- const { JobQueues } = require("../constants")
9
- const { utils } = require("@budibase/backend-core/redis")
10
- const { opts, redisProtocolUrl } = utils.getRedisOptions()
11
- const listeners = require("./listeners")
4
+ const { queue } = require("@budibase/backend-core")
5
+ const automation = require("../threads/automation")
12
6
 
13
- const CLEANUP_PERIOD_MS = 60 * 1000
14
- const queueConfig = redisProtocolUrl || { redis: opts }
15
- let cleanupInternal = null
16
-
17
- let automationQueue = new Queue(JobQueues.AUTOMATIONS, queueConfig)
18
- listeners.addListeners(automationQueue)
19
-
20
- async function cleanup() {
21
- await automationQueue.clean(CLEANUP_PERIOD_MS, "completed")
22
- }
7
+ let automationQueue = queue.createQueue(
8
+ queue.JobQueue.AUTOMATION,
9
+ automation.removeStalled
10
+ )
23
11
 
24
12
  const PATH_PREFIX = "/bulladmin"
25
13
 
26
14
  exports.init = () => {
27
- // cleanup the events every 5 minutes
28
- if (!cleanupInternal) {
29
- cleanupInternal = setInterval(cleanup, CLEANUP_PERIOD_MS)
30
- // fire off an initial cleanup
31
- cleanup().catch(err => {
32
- console.error(`Unable to cleanup automation queue initially - ${err}`)
33
- })
34
- }
35
15
  // Set up queues for bull board admin
36
16
  const queues = [automationQueue]
37
17
  const adapters = []
@@ -48,12 +28,7 @@ exports.init = () => {
48
28
  }
49
29
 
50
30
  exports.shutdown = async () => {
51
- if (automationQueue) {
52
- clearInterval(cleanupInternal)
53
- await automationQueue.close()
54
- automationQueue = null
55
- }
56
- console.log("Bull shutdown")
31
+ await queue.shutdown()
57
32
  }
58
33
 
59
- exports.queue = automationQueue
34
+ exports.automationQueue = automationQueue
@@ -1,5 +1,5 @@
1
1
  const { processEvent } = require("./utils")
2
- const { queue, shutdown } = require("./bullboard")
2
+ const { automationQueue, shutdown } = require("./bullboard")
3
3
  const { TRIGGER_DEFINITIONS, rebootTrigger } = require("./triggers")
4
4
  const { ACTION_DEFINITIONS } = require("./actions")
5
5
 
@@ -8,7 +8,7 @@ const { ACTION_DEFINITIONS } = require("./actions")
8
8
  */
9
9
  exports.init = async function () {
10
10
  // this promise will not complete
11
- const promise = queue.process(async job => {
11
+ const promise = automationQueue.process(async job => {
12
12
  await processEvent(job)
13
13
  })
14
14
  // on init we need to trigger any reboot automations
@@ -17,13 +17,13 @@ exports.init = async function () {
17
17
  }
18
18
 
19
19
  exports.getQueues = () => {
20
- return [queue]
20
+ return [automationQueue]
21
21
  }
22
22
 
23
23
  exports.shutdown = () => {
24
24
  return shutdown()
25
25
  }
26
26
 
27
- exports.queue = queue
27
+ exports.automationQueue = automationQueue
28
28
  exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS
29
29
  exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS
@@ -4,7 +4,7 @@ const { coerce } = require("../utilities/rowProcessor")
4
4
  const { definitions } = require("./triggerInfo")
5
5
  const { isDevAppID } = require("../db/utils")
6
6
  // need this to call directly, so we can get a response
7
- const { queue } = require("./bullboard")
7
+ const { automationQueue } = require("./bullboard")
8
8
  const { checkTestFlag } = require("../utilities/redis")
9
9
  const utils = require("./utils")
10
10
  const env = require("../environment")
@@ -56,7 +56,7 @@ async function queueRelevantRowAutomations(event, eventType) {
56
56
  automationTrigger.inputs &&
57
57
  automationTrigger.inputs.tableId === event.row.tableId
58
58
  ) {
59
- await queue.add({ automation, event }, JOB_OPTS)
59
+ await automationQueue.add({ automation, event }, JOB_OPTS)
60
60
  }
61
61
  }
62
62
  })
@@ -110,7 +110,7 @@ exports.externalTrigger = async function (
110
110
  if (getResponses) {
111
111
  return utils.processEvent({ data })
112
112
  } else {
113
- return queue.add(data, JOB_OPTS)
113
+ return automationQueue.add(data, JOB_OPTS)
114
114
  }
115
115
  }
116
116
 
@@ -136,7 +136,7 @@ exports.rebootTrigger = async () => {
136
136
  timestamp: Date.now(),
137
137
  },
138
138
  }
139
- rebootEvents.push(queue.add(job, JOB_OPTS))
139
+ rebootEvents.push(automationQueue.add(job, JOB_OPTS))
140
140
  }
141
141
  }
142
142
  await Promise.all(rebootEvents)
@@ -1,7 +1,7 @@
1
1
  import { Thread, ThreadType } from "../threads"
2
2
  import { definitions } from "./triggerInfo"
3
3
  import * as webhooks from "../api/controllers/webhook"
4
- import { queue } from "./bullboard"
4
+ import { automationQueue } from "./bullboard"
5
5
  import newid from "../db/newid"
6
6
  import { updateEntityMetadata } from "../utilities"
7
7
  import { MetadataTypes, WebhookType } from "../constants"
@@ -79,21 +79,25 @@ export function removeDeprecated(definitions: any) {
79
79
  // end the repetition and the job itself
80
80
  export async function disableAllCrons(appId: any) {
81
81
  const promises = []
82
- const jobs = await queue.getRepeatableJobs()
82
+ const jobs = await automationQueue.getRepeatableJobs()
83
83
  for (let job of jobs) {
84
84
  if (job.key.includes(`${appId}_cron`)) {
85
- promises.push(queue.removeRepeatableByKey(job.key))
85
+ promises.push(automationQueue.removeRepeatableByKey(job.key))
86
86
  if (job.id) {
87
- promises.push(queue.removeJobs(job.id))
87
+ promises.push(automationQueue.removeJobs(job.id))
88
88
  }
89
89
  }
90
90
  }
91
91
  return Promise.all(promises)
92
92
  }
93
93
 
94
- export async function disableCron(jobId: string, jobKey: string) {
95
- await queue.removeRepeatableByKey(jobKey)
96
- await queue.removeJobs(jobId)
94
+ export async function disableCronById(jobId: number | string) {
95
+ const repeatJobs = await automationQueue.getRepeatableJobs()
96
+ for (let repeatJob of repeatJobs) {
97
+ if (repeatJob.id === jobId) {
98
+ await automationQueue.removeRepeatableByKey(repeatJob.key)
99
+ }
100
+ }
97
101
  console.log(`jobId=${jobId} disabled`)
98
102
  }
99
103
 
@@ -141,7 +145,7 @@ export async function enableCronTrigger(appId: any, automation: Automation) {
141
145
  ) {
142
146
  // make a job id rather than letting Bull decide, makes it easier to handle on way out
143
147
  const jobId = `${appId}_cron_${newid()}`
144
- const job: any = await queue.add(
148
+ const job: any = await automationQueue.add(
145
149
  {
146
150
  automation,
147
151
  event: { appId, timestamp: Date.now() },
@@ -1,10 +1,6 @@
1
1
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
2
2
  const { UserStatus } = require("@budibase/backend-core/constants")
3
- const { ObjectStoreBuckets } = require("@budibase/backend-core/objectStore")
4
-
5
- exports.JobQueues = {
6
- AUTOMATIONS: "automationQueue",
7
- }
3
+ const { objectStore } = require("@budibase/backend-core")
8
4
 
9
5
  const FilterTypes = {
10
6
  STRING: "string",
@@ -211,6 +207,6 @@ exports.AutomationErrors = {
211
207
  }
212
208
 
213
209
  // pass through the list from the auth/core lib
214
- exports.ObjectStoreBuckets = ObjectStoreBuckets
210
+ exports.ObjectStoreBuckets = objectStore.ObjectStoreBuckets
215
211
 
216
212
  exports.MAX_AUTOMATION_RECURRING_ERRORS = 5
package/src/db/utils.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const newid = require("./newid")
2
2
  const {
3
- DocumentType: CoreDocTypes,
3
+ DocumentType: CoreDocType,
4
+ InternalTable,
4
5
  getRoleParams,
5
6
  generateRoleID,
6
7
  APP_DEV_PREFIX,
@@ -13,6 +14,12 @@ const {
13
14
  generateAppID,
14
15
  getQueryIndex,
15
16
  ViewName,
17
+ getDocParams,
18
+ getRowParams,
19
+ generateRowID,
20
+ getUserMetadataParams,
21
+ generateUserMetadataID,
22
+ getGlobalIDFromUserMetadataID,
16
23
  } = require("@budibase/backend-core/db")
17
24
 
18
25
  const UNICODE_MAX = "\ufff0"
@@ -23,28 +30,7 @@ const AppStatus = {
23
30
  DEPLOYED: "published",
24
31
  }
25
32
 
26
- const DocumentType = {
27
- ...CoreDocTypes,
28
- TABLE: "ta",
29
- ROW: "ro",
30
- USER: "us",
31
- AUTOMATION: "au",
32
- LINK: "li",
33
- WEBHOOK: "wh",
34
- INSTANCE: "inst",
35
- LAYOUT: "layout",
36
- SCREEN: "screen",
37
- QUERY: "query",
38
- DEPLOYMENTS: "deployments",
39
- METADATA: "metadata",
40
- MEM_VIEW: "view",
41
- USER_FLAG: "flag",
42
- AUTOMATION_METADATA: "meta_au",
43
- }
44
-
45
- const InternalTables = {
46
- USER_METADATA: "ta_users",
47
- }
33
+ const DocumentType = CoreDocType
48
34
 
49
35
  const SearchIndexes = {
50
36
  ROWS: "rows",
@@ -64,11 +50,11 @@ exports.APP_PREFIX = APP_PREFIX
64
50
  exports.APP_DEV_PREFIX = APP_DEV_PREFIX
65
51
  exports.isDevAppID = isDevAppID
66
52
  exports.isProdAppID = isProdAppID
67
- exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
68
- exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
53
+ exports.USER_METDATA_PREFIX = `${DocumentType.ROW}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`
54
+ exports.LINK_USER_METADATA_PREFIX = `${DocumentType.LINK}${SEPARATOR}${InternalTable.USER_METADATA}${SEPARATOR}`
69
55
  exports.TABLE_ROW_PREFIX = `${DocumentType.ROW}${SEPARATOR}${DocumentType.TABLE}`
70
56
  exports.ViewName = ViewName
71
- exports.InternalTables = InternalTables
57
+ exports.InternalTables = InternalTable
72
58
  exports.DocumentType = DocumentType
73
59
  exports.SEPARATOR = SEPARATOR
74
60
  exports.UNICODE_MAX = UNICODE_MAX
@@ -77,36 +63,15 @@ exports.AppStatus = AppStatus
77
63
  exports.BudibaseInternalDB = BudibaseInternalDB
78
64
  exports.generateAppID = generateAppID
79
65
  exports.generateDevAppID = getDevelopmentAppID
80
-
81
66
  exports.generateRoleID = generateRoleID
82
67
  exports.getRoleParams = getRoleParams
83
-
84
68
  exports.getQueryIndex = getQueryIndex
85
-
86
- /**
87
- * If creating DB allDocs/query params with only a single top level ID this can be used, this
88
- * is usually the case as most of our docs are top level e.g. tables, automations, users and so on.
89
- * More complex cases such as link docs and rows which have multiple levels of IDs that their
90
- * ID consists of need their own functions to build the allDocs parameters.
91
- * @param {string} docType The type of document which input params are being built for, e.g. user,
92
- * link, app, table and so on.
93
- * @param {string|null} docId The ID of the document minus its type - this is only needed if looking
94
- * for a singular document.
95
- * @param {object} otherProps Add any other properties onto the request, e.g. include_docs.
96
- * @returns {object} Parameters which can then be used with an allDocs request.
97
- */
98
- function getDocParams(docType, docId = null, otherProps = {}) {
99
- if (docId == null) {
100
- docId = ""
101
- }
102
- return {
103
- ...otherProps,
104
- startkey: `${docType}${SEPARATOR}${docId}`,
105
- endkey: `${docType}${SEPARATOR}${docId}${UNICODE_MAX}`,
106
- }
107
- }
108
-
109
69
  exports.getDocParams = getDocParams
70
+ exports.getRowParams = getRowParams
71
+ exports.generateRowID = generateRowID
72
+ exports.getUserMetadataParams = getUserMetadataParams
73
+ exports.generateUserMetadataID = generateUserMetadataID
74
+ exports.getGlobalIDFromUserMetadataID = getGlobalIDFromUserMetadataID
110
75
 
111
76
  /**
112
77
  * Gets parameters for retrieving tables, this is a utility function for the getDocParams function.
@@ -123,24 +88,6 @@ exports.generateTableID = () => {
123
88
  return `${DocumentType.TABLE}${SEPARATOR}${newid()}`
124
89
  }
125
90
 
126
- /**
127
- * Gets the DB allDocs/query params for retrieving a row.
128
- * @param {string|null} tableId The table in which the rows have been stored.
129
- * @param {string|null} rowId The ID of the row which is being specifically queried for. This can be
130
- * left null to get all the rows in the table.
131
- * @param {object} otherProps Any other properties to add to the request.
132
- * @returns {object} Parameters which can then be used with an allDocs request.
133
- */
134
- exports.getRowParams = (tableId = null, rowId = null, otherProps = {}) => {
135
- if (tableId == null) {
136
- return getDocParams(DocumentType.ROW, null, otherProps)
137
- }
138
-
139
- const endOfKey = rowId == null ? `${tableId}${SEPARATOR}` : rowId
140
-
141
- return getDocParams(DocumentType.ROW, endOfKey, otherProps)
142
- }
143
-
144
91
  /**
145
92
  * Given a row ID this will find the table ID within it (only works for internal tables).
146
93
  * @param {string} rowId The ID of the row.
@@ -153,44 +100,6 @@ exports.getTableIDFromRowID = rowId => {
153
100
  return `${DocumentType.TABLE}${SEPARATOR}${components[0]}`
154
101
  }
155
102
 
156
- /**
157
- * Gets a new row ID for the specified table.
158
- * @param {string} tableId The table which the row is being created for.
159
- * @param {string|null} id If an ID is to be used then the UUID can be substituted for this.
160
- * @returns {string} The new ID which a row doc can be stored under.
161
- */
162
- exports.generateRowID = (tableId, id = null) => {
163
- id = id || newid()
164
- return `${DocumentType.ROW}${SEPARATOR}${tableId}${SEPARATOR}${id}`
165
- }
166
-
167
- /**
168
- * Gets parameters for retrieving users, this is a utility function for the getDocParams function.
169
- */
170
- exports.getUserMetadataParams = (userId = null, otherProps = {}) => {
171
- return exports.getRowParams(InternalTables.USER_METADATA, userId, otherProps)
172
- }
173
-
174
- /**
175
- * Generates a new user ID based on the passed in global ID.
176
- * @param {string} globalId The ID of the global user.
177
- * @returns {string} The new user ID which the user doc can be stored under.
178
- */
179
- exports.generateUserMetadataID = globalId => {
180
- return exports.generateRowID(InternalTables.USER_METADATA, globalId)
181
- }
182
-
183
- /**
184
- * Breaks up the ID to get the global ID.
185
- */
186
- exports.getGlobalIDFromUserMetadataID = id => {
187
- const prefix = `${DocumentType.ROW}${SEPARATOR}${InternalTables.USER_METADATA}${SEPARATOR}`
188
- if (!id || !id.includes(prefix)) {
189
- return id
190
- }
191
- return id.split(prefix)[1]
192
- }
193
-
194
103
  /**
195
104
  * Gets parameters for retrieving automations, this is a utility function for the getDocParams function.
196
105
  */
@@ -27,18 +27,6 @@ export interface TriggerOutput {
27
27
  timestamp?: number
28
28
  }
29
29
 
30
- export interface AutomationEvent {
31
- data: {
32
- automation: Automation
33
- event: any
34
- }
35
- opts?: {
36
- repeat?: {
37
- jobId: string
38
- }
39
- }
40
- }
41
-
42
30
  export interface AutomationContext extends AutomationResults {
43
31
  steps: any[]
44
32
  trigger: any
@@ -1,18 +1,11 @@
1
1
  import { events } from "@budibase/backend-core"
2
- import { getTableParams } from "../../../../db/utils"
3
- import { Table } from "@budibase/types"
2
+ import sdk from "../../../../sdk"
4
3
 
5
- const getTables = async (appDb: any): Promise<Table[]> => {
6
- const response = await appDb.allDocs(
7
- getTableParams(null, {
8
- include_docs: true,
9
- })
10
- )
11
- return response.rows.map((row: any) => row.doc)
12
- }
13
-
14
- export const backfill = async (appDb: any, timestamp: string | number) => {
15
- const tables = await getTables(appDb)
4
+ export const backfill = async (
5
+ appDb: PouchDB.Database,
6
+ timestamp: string | number
7
+ ) => {
8
+ const tables = await sdk.tables.getAllInternalTables(appDb)
16
9
 
17
10
  for (const table of tables) {
18
11
  await events.table.created(table, timestamp)
@@ -0,0 +1,2 @@
1
+ export const DB_EXPORT_FILE = "db.txt"
2
+ export const GLOBAL_DB_EXPORT_FILE = "global.txt"