@budibase/server 1.0.49-alpha.0 → 1.0.49-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.
Files changed (357) hide show
  1. package/__mocks__/arangojs.ts +1 -1
  2. package/__mocks__/aws-sdk.ts +4 -4
  3. package/__mocks__/mongodb.ts +4 -5
  4. package/__mocks__/mssql.ts +3 -3
  5. package/__mocks__/node-fetch.ts +2 -1
  6. package/__mocks__/pg.ts +3 -5
  7. package/builder/assets/{index.8184eed9.js → index.0bdf1cad.js} +195 -194
  8. package/builder/assets/{index.dd9e386f.css → index.83c0944f.css} +1 -1
  9. package/builder/assets/{vendor.3bd2f661.js → vendor.d526bfe8.js} +1 -1
  10. package/builder/index.html +3 -3
  11. package/coverage/clover.xml +2927 -2819
  12. package/coverage/coverage-final.json +104 -103
  13. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/application.js.html +157 -136
  16. package/coverage/lcov-report/api/controllers/auth.js.html +11 -14
  17. package/coverage/lcov-report/api/controllers/automation.js.html +39 -69
  18. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/cloud.js.html +8 -11
  20. package/coverage/lcov-report/api/controllers/component.js.html +10 -13
  21. package/coverage/lcov-report/api/controllers/datasource.js.html +31 -37
  22. package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
  23. package/coverage/lcov-report/api/controllers/index.html +69 -54
  24. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
  26. package/coverage/lcov-report/api/controllers/metadata.js.html +6 -21
  27. package/coverage/lcov-report/{migrations/usageQuotas/syncApps.js.html → api/controllers/migrations.js.html} +30 -45
  28. package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
  29. package/coverage/lcov-report/api/controllers/query/index.html +10 -10
  30. package/coverage/lcov-report/api/controllers/query/index.js.html +38 -35
  31. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  32. package/coverage/lcov-report/api/controllers/role.js.html +16 -16
  33. package/coverage/lcov-report/api/controllers/routing.js.html +7 -10
  34. package/coverage/lcov-report/api/controllers/row/external.js.html +48 -141
  35. package/coverage/lcov-report/api/controllers/row/index.html +52 -37
  36. package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
  37. package/coverage/lcov-report/api/controllers/row/internal.js.html +108 -216
  38. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +52 -34
  39. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +548 -0
  40. package/coverage/lcov-report/api/controllers/row/utils.js.html +27 -24
  41. package/coverage/lcov-report/api/controllers/screen.js.html +15 -21
  42. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  43. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +599 -0
  44. package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
  45. package/coverage/lcov-report/api/controllers/table/index.html +57 -42
  46. package/coverage/lcov-report/api/controllers/table/index.js.html +28 -70
  47. package/coverage/lcov-report/api/controllers/table/internal.js.html +56 -47
  48. package/coverage/lcov-report/api/controllers/table/utils.js.html +169 -85
  49. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  50. package/coverage/lcov-report/api/controllers/user.js.html +43 -52
  51. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  52. package/coverage/lcov-report/api/controllers/view/index.html +16 -16
  53. package/coverage/lcov-report/api/controllers/view/index.js.html +27 -33
  54. package/coverage/lcov-report/api/controllers/view/utils.js.html +35 -20
  55. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  56. package/coverage/lcov-report/api/controllers/webhook.js.html +34 -28
  57. package/coverage/lcov-report/api/index.html +1 -1
  58. package/coverage/lcov-report/api/index.js.html +3 -3
  59. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/index.html +22 -7
  71. package/coverage/lcov-report/api/routes/index.js.html +10 -4
  72. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  75. package/coverage/lcov-report/{migrations/usageQuotas/index.js.html → api/routes/migrations.js.html} +25 -55
  76. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  82. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  83. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  84. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  85. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  86. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  87. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  88. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  89. package/coverage/lcov-report/automations/actions.js.html +24 -24
  90. package/coverage/lcov-report/automations/automationUtils.js.html +7 -10
  91. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  92. package/coverage/lcov-report/automations/index.html +18 -18
  93. package/coverage/lcov-report/automations/index.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -10
  96. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  97. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  98. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  99. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  100. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  101. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  102. package/coverage/lcov-report/automations/steps/index.html +1 -1
  103. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  104. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  105. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  106. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  107. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  108. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  109. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  110. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  111. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  112. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  115. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  116. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  117. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  118. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  119. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  120. package/coverage/lcov-report/automations/triggers.js.html +61 -55
  121. package/coverage/lcov-report/automations/utils.js.html +54 -42
  122. package/coverage/lcov-report/constants/index.html +5 -5
  123. package/coverage/lcov-report/constants/index.js.html +42 -27
  124. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  125. package/coverage/lcov-report/constants/screens.js.html +4 -4
  126. package/coverage/lcov-report/db/client.js.html +18 -18
  127. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  128. package/coverage/lcov-report/db/index.html +1 -1
  129. package/coverage/lcov-report/db/index.js.html +3 -3
  130. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +15 -27
  131. package/coverage/lcov-report/db/linkedRows/index.html +27 -27
  132. package/coverage/lcov-report/db/linkedRows/index.js.html +40 -85
  133. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +40 -40
  134. package/coverage/lcov-report/db/newid.js.html +4 -4
  135. package/coverage/lcov-report/db/utils.js.html +75 -75
  136. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  137. package/coverage/lcov-report/events/index.html +1 -1
  138. package/coverage/lcov-report/events/index.js.html +5 -5
  139. package/coverage/lcov-report/events/utils.js.html +3 -3
  140. package/coverage/lcov-report/index.html +107 -122
  141. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  142. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  143. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  144. package/coverage/lcov-report/middleware/authorized.js.html +21 -15
  145. package/coverage/lcov-report/middleware/builder.js.html +3 -3
  146. package/coverage/lcov-report/middleware/currentapp.js.html +72 -60
  147. package/coverage/lcov-report/middleware/index.html +28 -28
  148. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  149. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  150. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  151. package/coverage/lcov-report/middleware/usageQuota.js.html +29 -35
  152. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  153. package/coverage/lcov-report/threads/automation.js.html +30 -24
  154. package/coverage/lcov-report/threads/index.html +25 -25
  155. package/coverage/lcov-report/threads/index.js.html +10 -10
  156. package/coverage/lcov-report/threads/query.js.html +26 -47
  157. package/coverage/lcov-report/threads/utils.js.html +14 -14
  158. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  159. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  160. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  161. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  162. package/coverage/lcov-report/utilities/global.js.html +57 -48
  163. package/coverage/lcov-report/utilities/index.html +27 -27
  164. package/coverage/lcov-report/utilities/index.js.html +42 -72
  165. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  166. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  167. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  168. package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
  169. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  170. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +65 -71
  171. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
  172. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  173. package/coverage/lcov-report/utilities/security.js.html +8 -8
  174. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  175. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  176. package/coverage/lcov-report/utilities/usageQuota/index.js.html +13 -10
  177. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +5 -2
  178. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  179. package/coverage/lcov-report/utilities/users.js.html +9 -9
  180. package/coverage/lcov-report/utilities/workerRequests.js.html +16 -16
  181. package/coverage/lcov.info +4620 -4358
  182. package/dist/api/controllers/application.js +49 -48
  183. package/dist/api/controllers/auth.js +4 -5
  184. package/dist/api/controllers/automation.js +14 -19
  185. package/dist/api/controllers/cloud.js +2 -3
  186. package/dist/api/controllers/component.js +3 -4
  187. package/dist/api/controllers/datasource.js +9 -10
  188. package/dist/api/controllers/deploy/Deployment.js +3 -6
  189. package/dist/api/controllers/deploy/index.js +12 -13
  190. package/dist/api/controllers/dev.js +5 -5
  191. package/dist/api/controllers/layout.js +3 -3
  192. package/dist/api/controllers/metadata.js +4 -4
  193. package/dist/api/controllers/migrations.js +21 -0
  194. package/dist/api/controllers/permission.js +4 -4
  195. package/dist/api/controllers/query/import/index.js +4 -6
  196. package/dist/api/controllers/query/index.js +11 -10
  197. package/dist/api/controllers/role.js +5 -5
  198. package/dist/api/controllers/routing.js +5 -6
  199. package/dist/api/controllers/row/ExternalRequest.js +90 -67
  200. package/dist/api/controllers/row/external.js +14 -22
  201. package/dist/api/controllers/row/internal.js +55 -93
  202. package/dist/api/controllers/row/internalSearch.js +23 -17
  203. package/dist/api/controllers/row/staticFormula.js +147 -0
  204. package/dist/api/controllers/row/utils.js +7 -6
  205. package/dist/api/controllers/screen.js +5 -7
  206. package/dist/api/controllers/static/index.js +4 -4
  207. package/dist/api/controllers/table/bulkFormula.js +159 -0
  208. package/dist/api/controllers/table/external.js +7 -10
  209. package/dist/api/controllers/table/index.js +7 -10
  210. package/dist/api/controllers/table/internal.js +20 -16
  211. package/dist/api/controllers/table/utils.js +54 -34
  212. package/dist/api/controllers/user.js +16 -20
  213. package/dist/api/controllers/view/index.js +8 -10
  214. package/dist/api/controllers/view/utils.js +9 -4
  215. package/dist/api/controllers/webhook.js +10 -8
  216. package/dist/api/routes/index.js +2 -0
  217. package/dist/api/routes/migrations.js +9 -0
  218. package/dist/api/routes/tests/utilities/TestFunctions.js +37 -17
  219. package/dist/app.js +35 -5
  220. package/dist/automations/automationUtils.js +2 -3
  221. package/dist/automations/steps/createRow.js +1 -1
  222. package/dist/automations/steps/updateRow.js +1 -1
  223. package/dist/automations/triggers.js +27 -25
  224. package/dist/automations/utils.js +10 -5
  225. package/dist/constants/index.js +4 -0
  226. package/dist/db/linkedRows/LinkController.js +3 -7
  227. package/dist/db/linkedRows/index.js +16 -27
  228. package/dist/db/linkedRows/linkUtils.js +6 -6
  229. package/dist/db/views/staticViews.js +9 -10
  230. package/dist/environment.js +3 -1
  231. package/dist/integrations/base/sql.js +43 -8
  232. package/dist/integrations/utils.js +3 -0
  233. package/dist/middleware/authorized.js +5 -3
  234. package/dist/middleware/builder.js +2 -2
  235. package/dist/middleware/currentapp.js +41 -37
  236. package/dist/middleware/usageQuota.js +2 -4
  237. package/dist/migrations/functions/appUrls.js +46 -0
  238. package/dist/migrations/functions/quotas1.js +50 -0
  239. package/dist/migrations/{usageQuotas → functions/usageQuotas}/index.js +6 -10
  240. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncApps.js +12 -9
  241. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncRows.js +16 -12
  242. package/dist/migrations/functions/userEmailViewCasing.js +24 -0
  243. package/dist/migrations/index.js +62 -0
  244. package/dist/package.json +4 -4
  245. package/dist/tests/utilities/TestConfiguration.js +70 -44
  246. package/dist/threads/automation.js +13 -11
  247. package/dist/threads/query.js +13 -19
  248. package/dist/tsconfig.tsbuildinfo +1 -1
  249. package/dist/utilities/fileSystem/index.js +4 -3
  250. package/dist/utilities/global.js +15 -12
  251. package/dist/utilities/index.js +7 -17
  252. package/dist/utilities/routing/index.js +5 -5
  253. package/dist/utilities/rowProcessor/index.js +23 -17
  254. package/dist/utilities/rowProcessor/utils.js +14 -4
  255. package/dist/utilities/usageQuota/index.js +1 -0
  256. package/dist/utilities/usageQuota/rows.js +1 -0
  257. package/dist/utilities/users.js +3 -3
  258. package/dist/utilities/workerRequests.js +4 -4
  259. package/package.json +5 -5
  260. package/scripts/integrations/postgres/init.sql +11 -6
  261. package/scripts/likeCypress.ts +1 -1
  262. package/src/api/controllers/application.js +38 -31
  263. package/src/api/controllers/auth.js +4 -5
  264. package/src/api/controllers/automation.js +13 -23
  265. package/src/api/controllers/cloud.js +2 -3
  266. package/src/api/controllers/component.js +3 -4
  267. package/src/api/controllers/datasource.js +9 -11
  268. package/src/api/controllers/deploy/Deployment.js +3 -7
  269. package/src/api/controllers/deploy/index.js +20 -13
  270. package/src/api/controllers/dev.js +5 -5
  271. package/src/api/controllers/layout.js +3 -3
  272. package/src/api/controllers/metadata.js +4 -9
  273. package/src/api/controllers/migrations.js +13 -0
  274. package/src/api/controllers/permission.js +4 -4
  275. package/src/api/controllers/query/import/index.ts +4 -6
  276. package/src/api/controllers/query/import/tests/index.spec.js +2 -1
  277. package/src/api/controllers/query/index.js +11 -10
  278. package/src/api/controllers/role.js +5 -5
  279. package/src/api/controllers/routing.js +5 -6
  280. package/src/api/controllers/row/ExternalRequest.ts +67 -43
  281. package/src/api/controllers/row/external.js +27 -58
  282. package/src/api/controllers/row/internal.js +54 -90
  283. package/src/api/controllers/row/internalSearch.js +23 -17
  284. package/src/api/controllers/row/staticFormula.js +156 -0
  285. package/src/api/controllers/row/utils.js +7 -6
  286. package/src/api/controllers/screen.js +5 -7
  287. package/src/api/controllers/static/index.js +4 -4
  288. package/src/api/controllers/table/bulkFormula.js +173 -0
  289. package/src/api/controllers/table/external.js +7 -10
  290. package/src/api/controllers/table/index.js +7 -21
  291. package/src/api/controllers/table/internal.js +22 -19
  292. package/src/api/controllers/table/utils.js +70 -42
  293. package/src/api/controllers/user.js +17 -20
  294. package/src/api/controllers/view/index.js +8 -10
  295. package/src/api/controllers/view/utils.js +9 -4
  296. package/src/api/controllers/webhook.js +10 -8
  297. package/src/api/routes/index.js +2 -0
  298. package/src/api/routes/migrations.js +14 -0
  299. package/src/api/routes/tests/automation.spec.js +1 -0
  300. package/src/api/routes/tests/misc.spec.js +0 -1
  301. package/src/api/routes/tests/routing.spec.js +21 -12
  302. package/src/api/routes/tests/row.spec.js +7 -4
  303. package/src/api/routes/tests/utilities/TestFunctions.js +39 -17
  304. package/src/app.ts +18 -5
  305. package/src/automations/automationUtils.js +2 -3
  306. package/src/automations/steps/createRow.js +0 -1
  307. package/src/automations/steps/updateRow.js +1 -1
  308. package/src/automations/triggers.js +33 -31
  309. package/src/automations/utils.js +9 -5
  310. package/src/constants/index.js +5 -0
  311. package/src/db/linkedRows/LinkController.js +3 -7
  312. package/src/db/linkedRows/index.js +16 -31
  313. package/src/db/linkedRows/linkUtils.js +6 -6
  314. package/src/db/tests/linkController.spec.js +0 -1
  315. package/src/db/tests/linkTests.spec.js +5 -6
  316. package/src/db/views/staticViews.js +8 -10
  317. package/src/definitions/common.ts +3 -0
  318. package/src/environment.js +3 -1
  319. package/src/integrations/base/sql.ts +55 -14
  320. package/src/integrations/utils.ts +4 -1
  321. package/src/middleware/authorized.js +5 -3
  322. package/src/middleware/builder.js +2 -2
  323. package/src/middleware/currentapp.js +50 -46
  324. package/src/middleware/tests/authorized.spec.js +7 -2
  325. package/src/middleware/tests/currentapp.spec.js +6 -0
  326. package/src/middleware/usageQuota.js +2 -4
  327. package/src/migrations/functions/appUrls.ts +34 -0
  328. package/src/migrations/functions/quotas1.ts +20 -0
  329. package/src/migrations/functions/tests/appUrls.spec.js +29 -0
  330. package/src/migrations/{tests/usageQuotas/index.spec.js → functions/tests/quotas1.spec.js} +5 -5
  331. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
  332. package/src/migrations/functions/usageQuotas/index.ts +8 -0
  333. package/src/migrations/{usageQuotas/syncApps.js → functions/usageQuotas/syncApps.ts} +6 -6
  334. package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
  335. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncApps.spec.js +4 -4
  336. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncRows.spec.js +4 -4
  337. package/src/migrations/functions/userEmailViewCasing.ts +13 -0
  338. package/src/migrations/index.ts +56 -0
  339. package/src/module.d.ts +3 -0
  340. package/src/tests/utilities/TestConfiguration.js +73 -50
  341. package/src/threads/automation.js +17 -15
  342. package/src/threads/query.js +14 -21
  343. package/src/utilities/fileSystem/index.js +4 -3
  344. package/src/utilities/global.js +15 -12
  345. package/src/utilities/index.js +7 -17
  346. package/src/utilities/routing/index.js +5 -5
  347. package/src/utilities/rowProcessor/index.js +25 -27
  348. package/src/utilities/rowProcessor/utils.js +23 -7
  349. package/src/utilities/usageQuota/index.js +1 -0
  350. package/src/utilities/usageQuota/rows.js +1 -0
  351. package/src/utilities/users.js +3 -3
  352. package/src/utilities/workerRequests.js +4 -4
  353. package/tsconfig.json +2 -1
  354. package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
  355. package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +0 -143
  356. package/src/migrations/usageQuotas/index.js +0 -24
  357. package/src/migrations/usageQuotas/syncRows.js +0 -21
@@ -1,4 +1,3 @@
1
- const CouchDB = require("../../db")
2
1
  const env = require("../../environment")
3
2
  const packageJson = require("../../../package.json")
4
3
  const {
@@ -29,7 +28,7 @@ const { processObject } = require("@budibase/string-templates")
29
28
  const {
30
29
  getAllApps,
31
30
  isDevAppID,
32
- getDeployedAppID,
31
+ getProdAppID,
33
32
  Replication,
34
33
  } = require("@budibase/backend-core/db")
35
34
  const { USERS_TABLE_SCHEMA } = require("../../constants")
@@ -45,11 +44,17 @@ const { getTenantId, isMultiTenant } = require("@budibase/backend-core/tenancy")
45
44
  const { syncGlobalUsers } = require("./user")
46
45
  const { app: appCache } = require("@budibase/backend-core/cache")
47
46
  const { cleanupAutomations } = require("../../automations/utils")
47
+ const {
48
+ getAppDB,
49
+ getProdAppDB,
50
+ updateAppId,
51
+ } = require("@budibase/backend-core/context")
48
52
 
49
53
  const URL_REGEX_SLASH = /\/|\\/g
50
54
 
51
55
  // utility function, need to do away with this
52
- async function getLayouts(db) {
56
+ async function getLayouts() {
57
+ const db = getAppDB()
53
58
  return (
54
59
  await db.allDocs(
55
60
  getLayoutParams(null, {
@@ -59,7 +64,8 @@ async function getLayouts(db) {
59
64
  ).rows.map(row => row.doc)
60
65
  }
61
66
 
62
- async function getScreens(db) {
67
+ async function getScreens() {
68
+ const db = getAppDB()
63
69
  return (
64
70
  await db.allDocs(
65
71
  getScreenParams(null, {
@@ -75,7 +81,7 @@ function getUserRoleId(ctx) {
75
81
  : ctx.user.role._id
76
82
  }
77
83
 
78
- async function getAppUrl(ctx) {
84
+ exports.getAppUrl = ctx => {
79
85
  // construct the url
80
86
  let url
81
87
  if (ctx.request.body.url) {
@@ -117,8 +123,9 @@ async function createInstance(template) {
117
123
  const tenantId = isMultiTenant() ? getTenantId() : null
118
124
  const baseAppId = generateAppID(tenantId)
119
125
  const appId = generateDevAppID(baseAppId)
126
+ updateAppId(appId)
120
127
 
121
- const db = new CouchDB(appId)
128
+ const db = getAppDB()
122
129
  await db.put({
123
130
  _id: "_design/database",
124
131
  // view collation information, read before writing any complex views:
@@ -128,9 +135,9 @@ async function createInstance(template) {
128
135
 
129
136
  // NOTE: indexes need to be created before any tables/templates
130
137
  // add view for linked rows
131
- await createLinkView(appId)
132
- await createRoutingView(appId)
133
- await createAllSearchIndex(appId)
138
+ await createLinkView()
139
+ await createRoutingView()
140
+ await createAllSearchIndex()
134
141
 
135
142
  // replicate the template data to the instance DB
136
143
  // this is currently very hard to test, downloading and importing template files
@@ -156,7 +163,7 @@ async function createInstance(template) {
156
163
  exports.fetch = async ctx => {
157
164
  const dev = ctx.query && ctx.query.status === AppStatus.DEV
158
165
  const all = ctx.query && ctx.query.status === AppStatus.ALL
159
- const apps = await getAllApps(CouchDB, { dev, all })
166
+ const apps = await getAllApps({ dev, all })
160
167
 
161
168
  // get the locks for all the dev apps
162
169
  if (dev || all) {
@@ -179,12 +186,11 @@ exports.fetch = async ctx => {
179
186
  }
180
187
 
181
188
  exports.fetchAppDefinition = async ctx => {
182
- const db = new CouchDB(ctx.params.appId)
183
- const layouts = await getLayouts(db)
189
+ const layouts = await getLayouts()
184
190
  const userRoleId = getUserRoleId(ctx)
185
- const accessController = new AccessController(ctx.params.appId)
191
+ const accessController = new AccessController()
186
192
  const screens = await accessController.checkScreensAccess(
187
- await getScreens(db),
193
+ await getScreens(),
188
194
  userRoleId
189
195
  )
190
196
  ctx.body = {
@@ -195,15 +201,15 @@ exports.fetchAppDefinition = async ctx => {
195
201
  }
196
202
 
197
203
  exports.fetchAppPackage = async ctx => {
198
- const db = new CouchDB(ctx.params.appId)
204
+ const db = getAppDB()
199
205
  const application = await db.get(DocumentTypes.APP_METADATA)
200
- const layouts = await getLayouts(db)
201
- let screens = await getScreens(db)
206
+ const layouts = await getLayouts()
207
+ let screens = await getScreens()
202
208
 
203
209
  // Only filter screens if the user is not a builder
204
210
  if (!(ctx.user.builder && ctx.user.builder.global)) {
205
211
  const userRoleId = getUserRoleId(ctx)
206
- const accessController = new AccessController(ctx.params.appId)
212
+ const accessController = new AccessController()
207
213
  screens = await accessController.checkScreensAccess(screens, userRoleId)
208
214
  }
209
215
 
@@ -216,10 +222,10 @@ exports.fetchAppPackage = async ctx => {
216
222
  }
217
223
 
218
224
  exports.create = async ctx => {
219
- const apps = await getAllApps(CouchDB, { dev: true })
225
+ const apps = await getAllApps({ dev: true })
220
226
  const name = ctx.request.body.name
221
227
  checkAppName(ctx, apps, name)
222
- const url = await getAppUrl(ctx)
228
+ const url = exports.getAppUrl(ctx)
223
229
  checkAppUrl(ctx, apps, url)
224
230
 
225
231
  const { useTemplate, templateKey, templateString } = ctx.request.body
@@ -234,7 +240,7 @@ exports.create = async ctx => {
234
240
  const instance = await createInstance(instanceConfig)
235
241
  const appId = instance._id
236
242
 
237
- const db = new CouchDB(appId)
243
+ const db = getAppDB()
238
244
  let _rev
239
245
  try {
240
246
  // if template there will be an existing doc
@@ -280,13 +286,13 @@ exports.create = async ctx => {
280
286
  // This endpoint currently operates as a PATCH rather than a PUT
281
287
  // Thus name and url fields are handled only if present
282
288
  exports.update = async ctx => {
283
- const apps = await getAllApps(CouchDB, { dev: true })
289
+ const apps = await getAllApps({ dev: true })
284
290
  // validation
285
291
  const name = ctx.request.body.name
286
292
  if (name) {
287
293
  checkAppName(ctx, apps, name, ctx.params.appId)
288
294
  }
289
- const url = await getAppUrl(ctx)
295
+ const url = await exports.getAppUrl(ctx)
290
296
  if (url) {
291
297
  checkAppUrl(ctx, apps, url, ctx.params.appId)
292
298
  ctx.request.body.url = url
@@ -299,7 +305,7 @@ exports.update = async ctx => {
299
305
 
300
306
  exports.updateClient = async ctx => {
301
307
  // Get current app version
302
- const db = new CouchDB(ctx.params.appId)
308
+ const db = getAppDB()
303
309
  const application = await db.get(DocumentTypes.APP_METADATA)
304
310
  const currentVersion = application.version
305
311
 
@@ -321,7 +327,7 @@ exports.updateClient = async ctx => {
321
327
 
322
328
  exports.revertClient = async ctx => {
323
329
  // Check app can be reverted
324
- const db = new CouchDB(ctx.params.appId)
330
+ const db = getAppDB()
325
331
  const application = await db.get(DocumentTypes.APP_METADATA)
326
332
  if (!application.revertableVersion) {
327
333
  ctx.throw(400, "There is no version to revert to")
@@ -343,7 +349,7 @@ exports.revertClient = async ctx => {
343
349
  }
344
350
 
345
351
  exports.delete = async ctx => {
346
- const db = new CouchDB(ctx.params.appId)
352
+ const db = getAppDB()
347
353
 
348
354
  const result = await db.destroy()
349
355
  /* istanbul ignore next */
@@ -368,10 +374,11 @@ exports.sync = async (ctx, next) => {
368
374
  }
369
375
 
370
376
  // replicate prod to dev
371
- const prodAppId = getDeployedAppID(appId)
377
+ const prodAppId = getProdAppID(appId)
372
378
 
373
379
  try {
374
- const prodDb = new CouchDB(prodAppId, { skip_setup: true })
380
+ // specific case, want to make sure setup is skipped
381
+ const prodDb = getProdAppDB({ skip_setup: true })
375
382
  const info = await prodDb.info()
376
383
  if (info.error) throw info.error
377
384
  } catch (err) {
@@ -399,7 +406,7 @@ exports.sync = async (ctx, next) => {
399
406
  }
400
407
 
401
408
  // sync the users
402
- await syncGlobalUsers(appId)
409
+ await syncGlobalUsers()
403
410
 
404
411
  if (error) {
405
412
  ctx.throw(400, error)
@@ -411,7 +418,7 @@ exports.sync = async (ctx, next) => {
411
418
  }
412
419
 
413
420
  const updateAppPackage = async (appPackage, appId) => {
414
- const db = new CouchDB(appId)
421
+ const db = getAppDB()
415
422
  const application = await db.get(DocumentTypes.APP_METADATA)
416
423
 
417
424
  const newAppPackage = { ...application, ...appPackage }
@@ -430,7 +437,7 @@ const updateAppPackage = async (appPackage, appId) => {
430
437
  }
431
438
 
432
439
  const createEmptyAppPackage = async (ctx, app) => {
433
- const db = new CouchDB(app.appId)
440
+ const db = getAppDB()
434
441
 
435
442
  let screensAndLayouts = []
436
443
  for (let layout of BASE_LAYOUTS) {
@@ -1,11 +1,10 @@
1
- const CouchDB = require("../../db")
2
1
  const { outputProcessing } = require("../../utilities/rowProcessor")
3
2
  const { InternalTables } = require("../../db/utils")
4
3
  const { getFullUser } = require("../../utilities/users")
5
4
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles")
5
+ const { getAppDB, getAppId } = require("@budibase/backend-core/context")
6
6
 
7
7
  exports.fetchSelf = async ctx => {
8
- const appId = ctx.appId
9
8
  let userId = ctx.user.userId || ctx.user._id
10
9
  /* istanbul ignore next */
11
10
  if (!userId) {
@@ -19,8 +18,8 @@ exports.fetchSelf = async ctx => {
19
18
  // forward the csrf token from the session
20
19
  user.csrfToken = ctx.user.csrfToken
21
20
 
22
- if (appId) {
23
- const db = new CouchDB(appId)
21
+ if (getAppId()) {
22
+ const db = getAppDB()
24
23
  // remove the full roles structure
25
24
  delete user.roles
26
25
  try {
@@ -29,7 +28,7 @@ exports.fetchSelf = async ctx => {
29
28
  // make sure there is never a stale csrf token
30
29
  delete metadata.csrfToken
31
30
  // specifically needs to make sure is enriched
32
- ctx.body = await outputProcessing(ctx, userTable, {
31
+ ctx.body = await outputProcessing(userTable, {
33
32
  ...user,
34
33
  ...metadata,
35
34
  })
@@ -1,4 +1,3 @@
1
- const CouchDB = require("../../db")
2
1
  const actions = require("../../automations/actions")
3
2
  const triggers = require("../../automations/triggers")
4
3
  const { getAutomationParams, generateAutomationID } = require("../../db/utils")
@@ -10,6 +9,7 @@ const {
10
9
  const { deleteEntityMetadata } = require("../../utilities")
11
10
  const { MetadataTypes } = require("../../constants")
12
11
  const { setTestFlag, clearTestFlag } = require("../../utilities/redis")
12
+ const { getAppDB } = require("@budibase/backend-core/context")
13
13
 
14
14
  const ACTION_DEFS = removeDeprecated(actions.ACTION_DEFINITIONS)
15
15
  const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS)
@@ -20,14 +20,9 @@ const TRIGGER_DEFS = removeDeprecated(triggers.TRIGGER_DEFINITIONS)
20
20
  * *
21
21
  *************************/
22
22
 
23
- async function cleanupAutomationMetadata(appId, automationId) {
23
+ async function cleanupAutomationMetadata(automationId) {
24
+ await deleteEntityMetadata(MetadataTypes.AUTOMATION_TEST_INPUT, automationId)
24
25
  await deleteEntityMetadata(
25
- appId,
26
- MetadataTypes.AUTOMATION_TEST_INPUT,
27
- automationId
28
- )
29
- await deleteEntityMetadata(
30
- appId,
31
26
  MetadataTypes.AUTOMATION_TEST_HISTORY,
32
27
  automationId
33
28
  )
@@ -58,7 +53,7 @@ function cleanAutomationInputs(automation) {
58
53
  }
59
54
 
60
55
  exports.create = async function (ctx) {
61
- const db = new CouchDB(ctx.appId)
56
+ const db = getAppDB()
62
57
  let automation = ctx.request.body
63
58
  automation.appId = ctx.appId
64
59
 
@@ -72,7 +67,6 @@ exports.create = async function (ctx) {
72
67
  automation.type = "automation"
73
68
  automation = cleanAutomationInputs(automation)
74
69
  automation = await checkForWebhooks({
75
- appId: ctx.appId,
76
70
  newAuto: automation,
77
71
  })
78
72
  const response = await db.put(automation)
@@ -89,13 +83,12 @@ exports.create = async function (ctx) {
89
83
  }
90
84
 
91
85
  exports.update = async function (ctx) {
92
- const db = new CouchDB(ctx.appId)
86
+ const db = getAppDB()
93
87
  let automation = ctx.request.body
94
88
  automation.appId = ctx.appId
95
89
  const oldAutomation = await db.get(automation._id)
96
90
  automation = cleanAutomationInputs(automation)
97
91
  automation = await checkForWebhooks({
98
- appId: ctx.appId,
99
92
  oldAuto: oldAutomation,
100
93
  newAuto: automation,
101
94
  })
@@ -131,7 +124,7 @@ exports.update = async function (ctx) {
131
124
  }
132
125
 
133
126
  exports.fetch = async function (ctx) {
134
- const db = new CouchDB(ctx.appId)
127
+ const db = getAppDB()
135
128
  const response = await db.allDocs(
136
129
  getAutomationParams(null, {
137
130
  include_docs: true,
@@ -141,20 +134,19 @@ exports.fetch = async function (ctx) {
141
134
  }
142
135
 
143
136
  exports.find = async function (ctx) {
144
- const db = new CouchDB(ctx.appId)
137
+ const db = getAppDB()
145
138
  ctx.body = await db.get(ctx.params.id)
146
139
  }
147
140
 
148
141
  exports.destroy = async function (ctx) {
149
- const db = new CouchDB(ctx.appId)
142
+ const db = getAppDB()
150
143
  const automationId = ctx.params.id
151
144
  const oldAutomation = await db.get(automationId)
152
145
  await checkForWebhooks({
153
- appId: ctx.appId,
154
146
  oldAuto: oldAutomation,
155
147
  })
156
148
  // delete metadata first
157
- await cleanupAutomationMetadata(ctx.appId, automationId)
149
+ await cleanupAutomationMetadata(automationId)
158
150
  ctx.body = await db.remove(automationId, ctx.params.rev)
159
151
  }
160
152
 
@@ -180,12 +172,11 @@ module.exports.getDefinitionList = async function (ctx) {
180
172
  *********************/
181
173
 
182
174
  exports.trigger = async function (ctx) {
183
- const appId = ctx.appId
184
- const db = new CouchDB(appId)
175
+ const db = getAppDB()
185
176
  let automation = await db.get(ctx.params.id)
186
177
  await triggers.externalTrigger(automation, {
187
178
  ...ctx.request.body,
188
- appId,
179
+ appId: ctx.appId,
189
180
  })
190
181
  ctx.body = {
191
182
  message: `Automation ${automation._id} has been triggered.`,
@@ -205,8 +196,7 @@ function prepareTestInput(input) {
205
196
  }
206
197
 
207
198
  exports.test = async function (ctx) {
208
- const appId = ctx.appId
209
- const db = new CouchDB(appId)
199
+ const db = getAppDB()
210
200
  let automation = await db.get(ctx.params.id)
211
201
  await setTestFlag(automation._id)
212
202
  const testInput = prepareTestInput(ctx.request.body)
@@ -214,7 +204,7 @@ exports.test = async function (ctx) {
214
204
  automation,
215
205
  {
216
206
  ...testInput,
217
- appId,
207
+ appId: ctx.appId,
218
208
  },
219
209
  { getResponses: true }
220
210
  )
@@ -1,6 +1,5 @@
1
1
  const env = require("../../environment")
2
2
  const { getAllApps } = require("@budibase/backend-core/db")
3
- const CouchDB = require("../../db")
4
3
  const {
5
4
  exportDB,
6
5
  sendTempFile,
@@ -30,7 +29,7 @@ exports.exportApps = async ctx => {
30
29
  if (env.SELF_HOSTED || !env.MULTI_TENANCY) {
31
30
  ctx.throw(400, "Exporting only allowed in multi-tenant cloud environments.")
32
31
  }
33
- const apps = await getAllApps(CouchDB, { all: true })
32
+ const apps = await getAllApps({ all: true })
34
33
  const globalDBString = await exportDB(getGlobalDBName(), {
35
34
  filter: doc => !doc._id.startsWith(DocumentTypes.USER),
36
35
  })
@@ -63,7 +62,7 @@ async function hasBeenImported() {
63
62
  if (!env.SELF_HOSTED || env.MULTI_TENANCY) {
64
63
  return true
65
64
  }
66
- const apps = await getAllApps(CouchDB, { all: true })
65
+ const apps = await getAllApps({ all: true })
67
66
  return apps.length !== 0
68
67
  }
69
68
 
@@ -1,15 +1,14 @@
1
- const CouchDB = require("../../db")
2
1
  const { DocumentTypes } = require("../../db/utils")
3
2
  const { getComponentLibraryManifest } = require("../../utilities/fileSystem")
3
+ const { getAppDB } = require("@budibase/backend-core/context")
4
4
 
5
5
  exports.fetchAppComponentDefinitions = async function (ctx) {
6
- const appId = ctx.params.appId || ctx.appId
7
- const db = new CouchDB(appId)
6
+ const db = getAppDB()
8
7
  const app = await db.get(DocumentTypes.APP_METADATA)
9
8
 
10
9
  let componentManifests = await Promise.all(
11
10
  app.componentLibraries.map(async library => {
12
- let manifest = await getComponentLibraryManifest(appId, library)
11
+ let manifest = await getComponentLibraryManifest(library)
13
12
 
14
13
  return {
15
14
  manifest,
@@ -1,4 +1,3 @@
1
- const CouchDB = require("../../db")
2
1
  const {
3
2
  generateDatasourceID,
4
3
  getDatasourceParams,
@@ -11,12 +10,11 @@ const { BuildSchemaErrors, InvalidColumns } = require("../../constants")
11
10
  const { integrations } = require("../../integrations")
12
11
  const { getDatasourceAndQuery } = require("./row/utils")
13
12
  const { invalidateDynamicVariables } = require("../../threads/utils")
13
+ const { getAppDB } = require("@budibase/backend-core/context")
14
14
 
15
15
  exports.fetch = async function (ctx) {
16
- const database = new CouchDB(ctx.appId)
17
-
18
16
  // Get internal tables
19
- const db = new CouchDB(ctx.appId)
17
+ const db = getAppDB()
20
18
  const internalTables = await db.allDocs(
21
19
  getTableParams(null, {
22
20
  include_docs: true,
@@ -31,7 +29,7 @@ exports.fetch = async function (ctx) {
31
29
 
32
30
  // Get external datasources
33
31
  const datasources = (
34
- await database.allDocs(
32
+ await db.allDocs(
35
33
  getDatasourceParams(null, {
36
34
  include_docs: true,
37
35
  })
@@ -49,7 +47,7 @@ exports.fetch = async function (ctx) {
49
47
  }
50
48
 
51
49
  exports.buildSchemaFromDb = async function (ctx) {
52
- const db = new CouchDB(ctx.appId)
50
+ const db = getAppDB()
53
51
  const datasource = await db.get(ctx.params.datasourceId)
54
52
 
55
53
  const { tables, error } = await buildSchemaHelper(datasource)
@@ -98,7 +96,7 @@ const invalidateVariables = async (existingDatasource, updatedDatasource) => {
98
96
  }
99
97
 
100
98
  exports.update = async function (ctx) {
101
- const db = new CouchDB(ctx.appId)
99
+ const db = getAppDB()
102
100
  const datasourceId = ctx.params.datasourceId
103
101
  let datasource = await db.get(datasourceId)
104
102
  const auth = datasource.config.auth
@@ -126,7 +124,7 @@ exports.update = async function (ctx) {
126
124
  }
127
125
 
128
126
  exports.save = async function (ctx) {
129
- const db = new CouchDB(ctx.appId)
127
+ const db = getAppDB()
130
128
  const plus = ctx.request.body.datasource.plus
131
129
  const fetchSchema = ctx.request.body.fetchSchema
132
130
 
@@ -162,7 +160,7 @@ exports.save = async function (ctx) {
162
160
  }
163
161
 
164
162
  exports.destroy = async function (ctx) {
165
- const db = new CouchDB(ctx.appId)
163
+ const db = getAppDB()
166
164
 
167
165
  // Delete all queries for the datasource
168
166
  const queries = await db.allDocs(
@@ -184,7 +182,7 @@ exports.destroy = async function (ctx) {
184
182
  }
185
183
 
186
184
  exports.find = async function (ctx) {
187
- const database = new CouchDB(ctx.appId)
185
+ const database = getAppDB()
188
186
  ctx.body = await database.get(ctx.params.datasourceId)
189
187
  }
190
188
 
@@ -192,7 +190,7 @@ exports.find = async function (ctx) {
192
190
  exports.query = async function (ctx) {
193
191
  const queryJson = ctx.request.body
194
192
  try {
195
- ctx.body = await getDatasourceAndQuery(ctx.appId, queryJson)
193
+ ctx.body = await getDatasourceAndQuery(queryJson)
196
194
  } catch (err) {
197
195
  ctx.throw(400, err)
198
196
  }
@@ -1,18 +1,14 @@
1
1
  const newid = require("../../../db/newid")
2
+ const { getAppId } = require("@budibase/backend-core/context")
2
3
 
3
4
  /**
4
5
  * This is used to pass around information about the deployment that is occurring
5
6
  */
6
7
  class Deployment {
7
- constructor(appId, id = null) {
8
- this.appId = appId
8
+ constructor(id = null) {
9
9
  this._id = id || newid()
10
10
  }
11
11
 
12
- getAppId() {
13
- return this.appId
14
- }
15
-
16
12
  setVerification(verification) {
17
13
  if (!verification) {
18
14
  return
@@ -43,7 +39,7 @@ class Deployment {
43
39
  getJSON() {
44
40
  const obj = {
45
41
  _id: this._id,
46
- appId: this.appId,
42
+ appId: getAppId(),
47
43
  status: this.status,
48
44
  }
49
45
  if (this.err) {
@@ -1,12 +1,20 @@
1
- const CouchDB = require("../../../db")
2
1
  const Deployment = require("./Deployment")
3
- const { Replication, getDeployedAppID } = require("@budibase/backend-core/db")
2
+ const {
3
+ Replication,
4
+ getProdAppID,
5
+ getDevelopmentAppID,
6
+ } = require("@budibase/backend-core/db")
4
7
  const { DocumentTypes, getAutomationParams } = require("../../../db/utils")
5
8
  const {
6
9
  disableAllCrons,
7
10
  enableCronTrigger,
8
11
  } = require("../../../automations/utils")
9
12
  const { app: appCache } = require("@budibase/backend-core/cache")
13
+ const {
14
+ getAppId,
15
+ getAppDB,
16
+ getProdAppDB,
17
+ } = require("@budibase/backend-core/context")
10
18
 
11
19
  // the max time we can wait for an invalidation to complete before considering it failed
12
20
  const MAX_PENDING_TIME_MS = 30 * 60000
@@ -34,9 +42,8 @@ async function checkAllDeployments(deployments) {
34
42
  }
35
43
 
36
44
  async function storeDeploymentHistory(deployment) {
37
- const appId = deployment.getAppId()
38
45
  const deploymentJSON = deployment.getJSON()
39
- const db = new CouchDB(appId)
46
+ const db = getAppDB()
40
47
 
41
48
  let deploymentDoc
42
49
  try {
@@ -64,7 +71,7 @@ async function storeDeploymentHistory(deployment) {
64
71
  }
65
72
 
66
73
  async function initDeployedApp(prodAppId) {
67
- const db = new CouchDB(prodAppId)
74
+ const db = getProdAppDB()
68
75
  console.log("Reading automation docs")
69
76
  const automations = (
70
77
  await db.allDocs(
@@ -88,10 +95,12 @@ async function initDeployedApp(prodAppId) {
88
95
 
89
96
  async function deployApp(deployment) {
90
97
  try {
91
- const productionAppId = getDeployedAppID(deployment.appId)
98
+ const appId = getAppId()
99
+ const devAppId = getDevelopmentAppID(appId)
100
+ const productionAppId = getProdAppID(appId)
92
101
 
93
102
  const replication = new Replication({
94
- source: deployment.appId,
103
+ source: devAppId,
95
104
  target: productionAppId,
96
105
  })
97
106
 
@@ -99,7 +108,7 @@ async function deployApp(deployment) {
99
108
 
100
109
  await replication.replicate()
101
110
  console.log("replication complete.. replacing app meta doc")
102
- const db = new CouchDB(productionAppId)
111
+ const db = getProdAppDB()
103
112
  const appDoc = await db.get(DocumentTypes.APP_METADATA)
104
113
  appDoc.appId = productionAppId
105
114
  appDoc.instance._id = productionAppId
@@ -122,8 +131,7 @@ async function deployApp(deployment) {
122
131
 
123
132
  exports.fetchDeployments = async function (ctx) {
124
133
  try {
125
- const appId = ctx.appId
126
- const db = new CouchDB(appId)
134
+ const db = getAppDB()
127
135
  const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
128
136
  const { updated, deployments } = await checkAllDeployments(
129
137
  deploymentDoc,
@@ -140,8 +148,7 @@ exports.fetchDeployments = async function (ctx) {
140
148
 
141
149
  exports.deploymentProgress = async function (ctx) {
142
150
  try {
143
- const appId = ctx.appId
144
- const db = new CouchDB(appId)
151
+ const db = getAppDB()
145
152
  const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
146
153
  ctx.body = deploymentDoc[ctx.params.deploymentId]
147
154
  } catch (err) {
@@ -153,7 +160,7 @@ exports.deploymentProgress = async function (ctx) {
153
160
  }
154
161
 
155
162
  exports.deployApp = async function (ctx) {
156
- let deployment = new Deployment(ctx.appId)
163
+ let deployment = new Deployment()
157
164
  console.log("Deployment object created")
158
165
  deployment.setStatus(DeploymentStatus.PENDING)
159
166
  console.log("Deployment object set to pending")
@@ -1,12 +1,12 @@
1
1
  const fetch = require("node-fetch")
2
- const CouchDB = require("../../db")
3
2
  const env = require("../../environment")
4
3
  const { checkSlashesInUrl } = require("../../utilities")
5
4
  const { request } = require("../../utilities/workerRequests")
6
5
  const { clearLock } = require("../../utilities/redis")
7
- const { Replication } = require("@budibase/backend-core/db")
6
+ const { Replication, getProdAppID } = require("@budibase/backend-core/db")
8
7
  const { DocumentTypes } = require("../../db/utils")
9
8
  const { app: appCache } = require("@budibase/backend-core/cache")
9
+ const { getProdAppDB, getAppDB } = require("@budibase/backend-core/context")
10
10
 
11
11
  async function redirect(ctx, method, path = "global") {
12
12
  const { devPath } = ctx.params
@@ -77,11 +77,11 @@ exports.clearLock = async ctx => {
77
77
 
78
78
  exports.revert = async ctx => {
79
79
  const { appId } = ctx.params
80
- const productionAppId = appId.replace("_dev", "")
80
+ const productionAppId = getProdAppID(appId)
81
81
 
82
82
  // App must have been deployed first
83
83
  try {
84
- const db = new CouchDB(productionAppId, { skip_setup: true })
84
+ const db = getProdAppDB({ skip_setup: true })
85
85
  const info = await db.info()
86
86
  if (info.error) throw info.error
87
87
  const deploymentDoc = await db.get(DocumentTypes.DEPLOYMENTS)
@@ -103,7 +103,7 @@ exports.revert = async ctx => {
103
103
 
104
104
  await replication.rollback()
105
105
  // update appID in reverted app to be dev version again
106
- const db = new CouchDB(appId)
106
+ const db = getAppDB()
107
107
  const appDoc = await db.get(DocumentTypes.APP_METADATA)
108
108
  appDoc.appId = appId
109
109
  appDoc.instance._id = appId