@budibase/server 1.0.49-alpha.9 → 1.0.49

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 (379) hide show
  1. package/__mocks__/arangojs.ts +1 -1
  2. package/__mocks__/aws-sdk.ts +4 -4
  3. package/__mocks__/mongodb.ts +5 -4
  4. package/__mocks__/mssql.ts +3 -3
  5. package/__mocks__/node-fetch.ts +1 -2
  6. package/__mocks__/pg.ts +5 -3
  7. package/builder/assets/{index.ad5370ae.js → index.2c37968e.js} +246 -249
  8. package/builder/assets/index.39e01193.css +1 -0
  9. package/builder/assets/{vendor.d526bfe8.js → vendor.f9faf6ab.js} +12 -12
  10. package/builder/index.html +3 -3
  11. package/coverage/clover.xml +2827 -3117
  12. package/coverage/coverage-final.json +101 -106
  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 +152 -257
  16. package/coverage/lcov-report/api/controllers/auth.js.html +13 -22
  17. package/coverage/lcov-report/api/controllers/automation.js.html +69 -39
  18. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -8
  20. package/coverage/lcov-report/api/controllers/component.js.html +16 -13
  21. package/coverage/lcov-report/api/controllers/datasource.js.html +51 -81
  22. package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
  23. package/coverage/lcov-report/{utilities/usageQuota/usageQuoteReset.js.html → api/controllers/hosting.js.html} +48 -36
  24. package/coverage/lcov-report/api/controllers/index.html +76 -76
  25. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
  27. package/coverage/lcov-report/api/controllers/metadata.js.html +21 -6
  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 +35 -38
  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 +10 -7
  34. package/coverage/lcov-report/api/controllers/row/external.js.html +141 -48
  35. package/coverage/lcov-report/api/controllers/row/index.html +40 -55
  36. package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
  37. package/coverage/lcov-report/api/controllers/row/internal.js.html +226 -118
  38. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +34 -52
  39. package/coverage/lcov-report/api/controllers/row/utils.js.html +62 -47
  40. package/coverage/lcov-report/api/controllers/screen.js.html +21 -15
  41. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  42. package/coverage/lcov-report/api/controllers/table/external.js.html +34 -25
  43. package/coverage/lcov-report/api/controllers/table/index.html +43 -58
  44. package/coverage/lcov-report/api/controllers/table/index.js.html +82 -58
  45. package/coverage/lcov-report/api/controllers/table/internal.js.html +66 -81
  46. package/coverage/lcov-report/api/controllers/table/utils.js.html +110 -218
  47. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  48. package/coverage/lcov-report/api/controllers/user.js.html +50 -47
  49. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  50. package/coverage/lcov-report/api/controllers/view/index.html +16 -16
  51. package/coverage/lcov-report/api/controllers/view/index.js.html +33 -27
  52. package/coverage/lcov-report/api/controllers/view/utils.js.html +20 -35
  53. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  54. package/coverage/lcov-report/api/controllers/webhook.js.html +28 -34
  55. package/coverage/lcov-report/api/index.html +1 -1
  56. package/coverage/lcov-report/api/index.js.html +8 -8
  57. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/{migrations.js.html → hosting.js.html} +14 -17
  69. package/coverage/lcov-report/api/routes/index.html +18 -18
  70. package/coverage/lcov-report/api/routes/index.js.html +3 -3
  71. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/static.js.html +2 -17
  82. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  83. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  84. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  85. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  86. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  87. package/coverage/lcov-report/automations/actions.js.html +24 -24
  88. package/coverage/lcov-report/automations/automationUtils.js.html +10 -7
  89. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  90. package/coverage/lcov-report/automations/index.html +18 -18
  91. package/coverage/lcov-report/automations/index.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  93. package/coverage/lcov-report/automations/steps/createRow.js.html +22 -13
  94. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  95. package/coverage/lcov-report/automations/steps/deleteRow.js.html +20 -11
  96. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  97. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  98. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  99. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  100. package/coverage/lcov-report/automations/steps/index.html +13 -13
  101. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  102. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  103. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  104. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  105. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  106. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  107. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  108. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  109. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  110. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  113. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  114. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  115. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  116. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  117. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  118. package/coverage/lcov-report/automations/triggers.js.html +55 -61
  119. package/coverage/lcov-report/automations/utils.js.html +42 -54
  120. package/coverage/lcov-report/constants/index.html +5 -5
  121. package/coverage/lcov-report/constants/index.js.html +26 -53
  122. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  123. package/coverage/lcov-report/constants/screens.js.html +4 -4
  124. package/coverage/lcov-report/db/client.js.html +18 -18
  125. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  126. package/coverage/lcov-report/db/index.html +15 -15
  127. package/coverage/lcov-report/db/index.js.html +3 -3
  128. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +37 -25
  129. package/coverage/lcov-report/db/linkedRows/index.html +27 -27
  130. package/coverage/lcov-report/db/linkedRows/index.js.html +96 -51
  131. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
  132. package/coverage/lcov-report/db/newid.js.html +4 -4
  133. package/coverage/lcov-report/db/utils.js.html +87 -87
  134. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  135. package/coverage/lcov-report/events/index.html +1 -1
  136. package/coverage/lcov-report/events/index.js.html +5 -5
  137. package/coverage/lcov-report/events/utils.js.html +3 -3
  138. package/coverage/lcov-report/index.html +120 -135
  139. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  140. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  141. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  142. package/coverage/lcov-report/middleware/authorized.js.html +65 -173
  143. package/coverage/lcov-report/middleware/builder.js.html +10 -10
  144. package/coverage/lcov-report/middleware/currentapp.js.html +83 -95
  145. package/coverage/lcov-report/middleware/index.html +38 -38
  146. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  147. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  148. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  149. package/coverage/lcov-report/middleware/usageQuota.js.html +53 -281
  150. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  151. package/coverage/lcov-report/threads/automation.js.html +24 -30
  152. package/coverage/lcov-report/threads/index.html +26 -26
  153. package/coverage/lcov-report/threads/index.js.html +10 -10
  154. package/coverage/lcov-report/threads/query.js.html +24 -39
  155. package/coverage/lcov-report/threads/utils.js.html +14 -14
  156. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  157. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  158. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  159. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  160. package/coverage/lcov-report/utilities/global.js.html +49 -58
  161. package/coverage/lcov-report/utilities/index.html +37 -37
  162. package/coverage/lcov-report/utilities/index.js.html +73 -43
  163. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  164. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  165. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  166. package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
  167. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  168. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +103 -97
  169. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +27 -75
  170. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  171. package/coverage/lcov-report/utilities/security.js.html +8 -8
  172. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  173. package/coverage/lcov-report/utilities/users.js.html +9 -9
  174. package/coverage/lcov-report/utilities/workerRequests.js.html +112 -43
  175. package/coverage/lcov.info +4431 -5013
  176. package/dist/api/controllers/application.js +60 -90
  177. package/dist/api/controllers/auth.js +5 -8
  178. package/dist/api/controllers/automation.js +19 -14
  179. package/dist/api/controllers/cloud.js +3 -2
  180. package/dist/api/controllers/component.js +4 -3
  181. package/dist/api/controllers/datasource.js +10 -20
  182. package/dist/api/controllers/deploy/Deployment.js +6 -3
  183. package/dist/api/controllers/deploy/index.js +13 -12
  184. package/dist/api/controllers/dev.js +5 -5
  185. package/dist/api/controllers/hosting.js +30 -0
  186. package/dist/api/controllers/layout.js +3 -3
  187. package/dist/api/controllers/metadata.js +4 -4
  188. package/dist/api/controllers/permission.js +4 -4
  189. package/dist/api/controllers/query/import/index.js +6 -4
  190. package/dist/api/controllers/query/index.js +10 -11
  191. package/dist/api/controllers/role.js +5 -5
  192. package/dist/api/controllers/routing.js +6 -5
  193. package/dist/api/controllers/row/ExternalRequest.js +67 -90
  194. package/dist/api/controllers/row/external.js +22 -14
  195. package/dist/api/controllers/row/internal.js +93 -55
  196. package/dist/api/controllers/row/internalSearch.js +17 -23
  197. package/dist/api/controllers/row/utils.js +14 -13
  198. package/dist/api/controllers/screen.js +7 -5
  199. package/dist/api/controllers/static/index.js +12 -61
  200. package/dist/api/controllers/table/external.js +10 -7
  201. package/dist/api/controllers/table/index.js +13 -16
  202. package/dist/api/controllers/table/internal.js +16 -22
  203. package/dist/api/controllers/table/utils.js +35 -62
  204. package/dist/api/controllers/user.js +20 -18
  205. package/dist/api/controllers/view/index.js +10 -8
  206. package/dist/api/controllers/view/utils.js +4 -9
  207. package/dist/api/controllers/webhook.js +8 -10
  208. package/dist/api/routes/hosting.js +11 -0
  209. package/dist/api/routes/index.js +2 -2
  210. package/dist/api/routes/static.js +1 -2
  211. package/dist/api/routes/tests/utilities/TestFunctions.js +17 -37
  212. package/dist/app.js +5 -35
  213. package/dist/automations/automationUtils.js +3 -2
  214. package/dist/automations/steps/createRow.js +5 -3
  215. package/dist/automations/steps/deleteRow.js +4 -1
  216. package/dist/automations/steps/updateRow.js +1 -1
  217. package/dist/automations/triggers.js +25 -27
  218. package/dist/automations/utils.js +5 -10
  219. package/dist/constants/index.js +0 -7
  220. package/dist/db/linkedRows/LinkController.js +7 -3
  221. package/dist/db/linkedRows/index.js +27 -16
  222. package/dist/db/linkedRows/linkUtils.js +6 -6
  223. package/dist/db/views/staticViews.js +10 -9
  224. package/dist/definitions/datasource.js +0 -1
  225. package/dist/environment.js +1 -4
  226. package/dist/integrations/base/sql.js +14 -56
  227. package/dist/integrations/index.js +0 -3
  228. package/dist/integrations/utils.js +9 -60
  229. package/dist/middleware/authorized.js +30 -57
  230. package/dist/middleware/builder.js +2 -2
  231. package/dist/middleware/currentapp.js +37 -41
  232. package/dist/middleware/usageQuota.js +15 -82
  233. package/dist/package.json +5 -8
  234. package/dist/tests/utilities/TestConfiguration.js +50 -80
  235. package/dist/threads/automation.js +11 -13
  236. package/dist/threads/query.js +11 -15
  237. package/dist/tsconfig.tsbuildinfo +1 -1
  238. package/dist/utilities/fileSystem/index.js +3 -4
  239. package/dist/utilities/global.js +12 -15
  240. package/dist/utilities/index.js +17 -7
  241. package/dist/utilities/routing/index.js +5 -5
  242. package/dist/utilities/rowProcessor/index.js +17 -23
  243. package/dist/utilities/rowProcessor/utils.js +4 -14
  244. package/dist/utilities/{usageQuota/index.js → usageQuota.js} +31 -45
  245. package/dist/utilities/users.js +3 -3
  246. package/dist/utilities/workerRequests.js +24 -4
  247. package/nodemon.json +1 -1
  248. package/package.json +6 -9
  249. package/scripts/integrations/postgres/init.sql +6 -11
  250. package/scripts/likeCypress.ts +1 -1
  251. package/src/api/controllers/application.js +50 -85
  252. package/src/api/controllers/auth.js +5 -8
  253. package/src/api/controllers/automation.js +23 -13
  254. package/src/api/controllers/cloud.js +3 -2
  255. package/src/api/controllers/component.js +4 -3
  256. package/src/api/controllers/datasource.js +11 -21
  257. package/src/api/controllers/deploy/Deployment.js +7 -3
  258. package/src/api/controllers/deploy/index.js +13 -20
  259. package/src/api/controllers/dev.js +5 -5
  260. package/src/api/controllers/hosting.js +22 -0
  261. package/src/api/controllers/layout.js +3 -3
  262. package/src/api/controllers/metadata.js +9 -4
  263. package/src/api/controllers/permission.js +4 -4
  264. package/src/api/controllers/query/import/index.ts +6 -4
  265. package/src/api/controllers/query/import/tests/index.spec.js +1 -2
  266. package/src/api/controllers/query/index.js +10 -11
  267. package/src/api/controllers/role.js +5 -5
  268. package/src/api/controllers/routing.js +6 -5
  269. package/src/api/controllers/row/ExternalRequest.ts +43 -67
  270. package/src/api/controllers/row/external.js +58 -27
  271. package/src/api/controllers/row/internal.js +90 -54
  272. package/src/api/controllers/row/internalSearch.js +17 -23
  273. package/src/api/controllers/row/utils.js +18 -13
  274. package/src/api/controllers/screen.js +7 -5
  275. package/src/api/controllers/static/index.js +12 -65
  276. package/src/api/controllers/table/external.js +10 -7
  277. package/src/api/controllers/table/index.js +28 -20
  278. package/src/api/controllers/table/internal.js +19 -24
  279. package/src/api/controllers/table/utils.js +42 -78
  280. package/src/api/controllers/user.js +20 -19
  281. package/src/api/controllers/view/index.js +10 -8
  282. package/src/api/controllers/view/utils.js +4 -9
  283. package/src/api/controllers/webhook.js +8 -10
  284. package/src/api/routes/hosting.js +13 -0
  285. package/src/api/routes/index.js +2 -2
  286. package/src/api/routes/static.js +0 -5
  287. package/src/api/routes/tests/application.spec.js +2 -2
  288. package/src/api/routes/tests/auth.spec.js +2 -1
  289. package/src/api/routes/tests/automation.spec.js +0 -1
  290. package/src/api/routes/tests/hosting.spec.js +36 -0
  291. package/src/api/routes/tests/misc.spec.js +1 -0
  292. package/src/api/routes/tests/routing.spec.js +12 -21
  293. package/src/api/routes/tests/row.spec.js +4 -7
  294. package/src/api/routes/tests/utilities/TestFunctions.js +17 -39
  295. package/src/app.ts +5 -18
  296. package/src/automations/automationUtils.js +3 -2
  297. package/src/automations/steps/createRow.js +5 -2
  298. package/src/automations/steps/deleteRow.js +4 -1
  299. package/src/automations/steps/updateRow.js +1 -1
  300. package/src/automations/triggers.js +31 -33
  301. package/src/automations/utils.js +5 -9
  302. package/src/constants/index.js +0 -9
  303. package/src/db/linkedRows/LinkController.js +7 -3
  304. package/src/db/linkedRows/index.js +31 -16
  305. package/src/db/linkedRows/linkUtils.js +6 -6
  306. package/src/db/tests/linkController.spec.js +1 -0
  307. package/src/db/tests/linkTests.spec.js +6 -5
  308. package/src/db/views/staticViews.js +10 -8
  309. package/src/definitions/common.ts +0 -3
  310. package/src/definitions/datasource.ts +0 -3
  311. package/src/environment.js +1 -4
  312. package/src/integrations/base/sql.ts +21 -69
  313. package/src/integrations/index.ts +0 -3
  314. package/src/integrations/tests/sql.spec.js +0 -16
  315. package/src/integrations/utils.ts +12 -75
  316. package/src/middleware/authorized.js +30 -66
  317. package/src/middleware/builder.js +2 -2
  318. package/src/middleware/currentapp.js +46 -50
  319. package/src/middleware/tests/authorized.spec.js +6 -13
  320. package/src/middleware/tests/currentapp.spec.js +0 -6
  321. package/src/middleware/tests/usageQuota.spec.js +24 -18
  322. package/src/middleware/usageQuota.js +17 -93
  323. package/src/tests/utilities/TestConfiguration.js +55 -82
  324. package/src/threads/automation.js +15 -17
  325. package/src/threads/query.js +12 -17
  326. package/src/utilities/fileSystem/index.js +3 -4
  327. package/src/utilities/global.js +12 -15
  328. package/src/utilities/index.js +17 -7
  329. package/src/utilities/routing/index.js +5 -5
  330. package/src/utilities/rowProcessor/index.js +27 -25
  331. package/src/utilities/rowProcessor/utils.js +7 -23
  332. package/src/utilities/usageQuota.js +73 -0
  333. package/src/utilities/users.js +3 -3
  334. package/src/utilities/workerRequests.js +27 -4
  335. package/tsconfig.json +1 -2
  336. package/builder/assets/index.83c0944f.css +0 -1
  337. package/coverage/lcov-report/api/controllers/migrations.js.html +0 -119
  338. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +0 -548
  339. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +0 -599
  340. package/coverage/lcov-report/utilities/usageQuota/index.html +0 -141
  341. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
  342. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +0 -305
  343. package/dist/api/controllers/migrations.js +0 -21
  344. package/dist/api/controllers/row/staticFormula.js +0 -147
  345. package/dist/api/controllers/table/bulkFormula.js +0 -159
  346. package/dist/api/routes/migrations.js +0 -9
  347. package/dist/integrations/googlesheets.js +0 -340
  348. package/dist/migrations/functions/appUrls.js +0 -46
  349. package/dist/migrations/functions/quotas1.js +0 -50
  350. package/dist/migrations/functions/usageQuotas/index.js +0 -20
  351. package/dist/migrations/functions/usageQuotas/syncApps.js +0 -29
  352. package/dist/migrations/functions/usageQuotas/syncRows.js +0 -33
  353. package/dist/migrations/functions/userEmailViewCasing.js +0 -24
  354. package/dist/migrations/index.js +0 -62
  355. package/dist/utilities/usageQuota/rows.js +0 -78
  356. package/dist/utilities/usageQuota/usageQuoteReset.js +0 -16
  357. package/src/api/controllers/migrations.js +0 -13
  358. package/src/api/controllers/row/staticFormula.js +0 -156
  359. package/src/api/controllers/table/bulkFormula.js +0 -173
  360. package/src/api/routes/migrations.js +0 -14
  361. package/src/api/routes/tests/static.spec.js +0 -98
  362. package/src/integrations/googlesheets.ts +0 -353
  363. package/src/migrations/functions/appUrls.ts +0 -34
  364. package/src/migrations/functions/quotas1.ts +0 -20
  365. package/src/migrations/functions/tests/appUrls.spec.js +0 -29
  366. package/src/migrations/functions/tests/quotas1.spec.js +0 -27
  367. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +0 -25
  368. package/src/migrations/functions/usageQuotas/index.ts +0 -8
  369. package/src/migrations/functions/usageQuotas/syncApps.ts +0 -18
  370. package/src/migrations/functions/usageQuotas/syncRows.ts +0 -22
  371. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -37
  372. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -43
  373. package/src/migrations/functions/userEmailViewCasing.ts +0 -13
  374. package/src/migrations/index.ts +0 -56
  375. package/src/module.d.ts +0 -3
  376. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  377. package/src/utilities/usageQuota/index.js +0 -93
  378. package/src/utilities/usageQuota/rows.js +0 -75
  379. package/src/utilities/usageQuota/usageQuoteReset.js +0 -18
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ const CouchDB = require("../../../db");
11
12
  const { buildExternalTableId, breakExternalTableId, } = require("../../../integrations/utils");
12
13
  const { getTable, generateForeignKey, generateJunctionTableName, foreignKeyStructure, hasTypeChanged, } = require("./utils");
13
14
  const { DataSourceOperation, FieldTypes, RelationshipTypes, } = require("../../../constants");
@@ -15,7 +16,6 @@ const { makeExternalQuery } = require("../../../integrations/base/utils");
15
16
  const { cloneDeep } = require("lodash/fp");
16
17
  const csvParser = require("../../../utilities/csvParser");
17
18
  const { handleRequest } = require("../row/external");
18
- const { getAppDB } = require("@budibase/backend-core/context");
19
19
  function makeTableRequest(datasource, operation, table, tables, oldTable = null) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  const json = {
@@ -134,6 +134,7 @@ function isRelationshipSetup(column) {
134
134
  }
135
135
  exports.save = function (ctx) {
136
136
  return __awaiter(this, void 0, void 0, function* () {
137
+ const appId = ctx.appId;
137
138
  const table = ctx.request.body;
138
139
  // can't do this right now
139
140
  delete table.dataImport;
@@ -145,12 +146,12 @@ exports.save = function (ctx) {
145
146
  let tableToSave = Object.assign({ type: "table", _id: buildExternalTableId(datasourceId, table.name) }, table);
146
147
  let oldTable;
147
148
  if (ctx.request.body && ctx.request.body._id) {
148
- oldTable = yield getTable(ctx.request.body._id);
149
+ oldTable = yield getTable(appId, ctx.request.body._id);
149
150
  }
150
151
  if (hasTypeChanged(tableToSave, oldTable)) {
151
152
  ctx.throw(400, "A column type has changed.");
152
153
  }
153
- const db = getAppDB();
154
+ const db = new CouchDB(appId);
154
155
  const datasource = yield db.get(datasourceId);
155
156
  const oldTables = cloneDeep(datasource.entities);
156
157
  const tables = datasource.entities;
@@ -214,12 +215,13 @@ exports.save = function (ctx) {
214
215
  };
215
216
  exports.destroy = function (ctx) {
216
217
  return __awaiter(this, void 0, void 0, function* () {
217
- const tableToDelete = yield getTable(ctx.params.tableId);
218
+ const appId = ctx.appId;
219
+ const tableToDelete = yield getTable(appId, ctx.params.tableId);
218
220
  if (!tableToDelete || !tableToDelete.created) {
219
221
  ctx.throw(400, "Cannot delete tables which weren't created in Budibase.");
220
222
  }
221
223
  const datasourceId = getDatasourceId(tableToDelete);
222
- const db = getAppDB();
224
+ const db = new CouchDB(appId);
223
225
  const datasource = yield db.get(datasourceId);
224
226
  const tables = datasource.entities;
225
227
  const operation = DataSourceOperation.DELETE_TABLE;
@@ -232,13 +234,14 @@ exports.destroy = function (ctx) {
232
234
  };
233
235
  exports.bulkImport = function (ctx) {
234
236
  return __awaiter(this, void 0, void 0, function* () {
235
- const table = yield getTable(ctx.params.tableId);
237
+ const appId = ctx.appId;
238
+ const table = yield getTable(appId, ctx.params.tableId);
236
239
  const { dataImport } = ctx.request.body;
237
240
  if (!dataImport || !dataImport.schema || !dataImport.csvString) {
238
241
  ctx.throw(400, "Provided data import information is invalid.");
239
242
  }
240
243
  const rows = yield csvParser.transform(Object.assign(Object.assign({}, dataImport), { existingTable: table }));
241
- yield handleRequest(DataSourceOperation.BULK_CREATE, table._id, {
244
+ yield handleRequest(appId, DataSourceOperation.BULK_CREATE, table._id, {
242
245
  rows,
243
246
  });
244
247
  return table;
@@ -8,13 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ const CouchDB = require("../../../db");
11
12
  const internal = require("./internal");
12
13
  const external = require("./external");
13
14
  const csvParser = require("../../../utilities/csvParser");
14
- const { isExternalTable, isSQL } = require("../../../integrations/utils");
15
- const { getDatasourceParams } = require("../../../db/utils");
16
- const { getAppDB } = require("@budibase/backend-core/context");
17
- const { getTable, getAllInternalTables } = require("./utils");
15
+ const { isExternalTable } = require("../../../integrations/utils");
16
+ const { getTableParams, getDatasourceParams, BudibaseInternalDB, } = require("../../../db/utils");
17
+ const { getTable } = require("./utils");
18
18
  function pickApi({ tableId, table }) {
19
19
  if (table && !tableId) {
20
20
  tableId = table._id;
@@ -30,19 +30,16 @@ function pickApi({ tableId, table }) {
30
30
  // covers both internal and external
31
31
  exports.fetch = function (ctx) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- const db = getAppDB();
34
- const internal = yield getAllInternalTables();
33
+ const db = new CouchDB(ctx.appId);
34
+ const internalTables = yield db.allDocs(getTableParams(null, {
35
+ include_docs: true,
36
+ }));
37
+ const internal = internalTables.rows.map(row => (Object.assign(Object.assign({}, row.doc), { type: "internal", sourceId: BudibaseInternalDB._id })));
35
38
  const externalTables = yield db.allDocs(getDatasourceParams("plus", {
36
39
  include_docs: true,
37
40
  }));
38
- const external = externalTables.rows.flatMap(tableDoc => {
39
- let entities = tableDoc.doc.entities;
40
- if (entities) {
41
- return Object.values(entities).map(entity => (Object.assign(Object.assign({}, entity), { type: "external", sourceId: tableDoc.doc._id, sql: isSQL(tableDoc.doc) })));
42
- }
43
- else {
44
- return [];
45
- }
41
+ const external = externalTables.rows.flatMap(row => {
42
+ return Object.values(row.doc.entities || {}).map(entity => (Object.assign(Object.assign({}, entity), { type: "external", sourceId: row.doc._id })));
46
43
  });
47
44
  ctx.body = [...internal, ...external];
48
45
  });
@@ -50,7 +47,7 @@ exports.fetch = function (ctx) {
50
47
  exports.find = function (ctx) {
51
48
  return __awaiter(this, void 0, void 0, function* () {
52
49
  const tableId = ctx.params.id;
53
- ctx.body = yield getTable(tableId);
50
+ ctx.body = yield getTable(ctx.appId, tableId);
54
51
  });
55
52
  };
56
53
  exports.save = function (ctx) {
@@ -93,7 +90,7 @@ exports.validateCSVSchema = function (ctx) {
93
90
  const { csvString, schema = {}, tableId } = ctx.request.body;
94
91
  let existingTable;
95
92
  if (tableId) {
96
- existingTable = yield getTable(tableId);
93
+ existingTable = yield getTable(ctx.appId, tableId);
97
94
  }
98
95
  let result = yield csvParser.parse(csvString, schema);
99
96
  if (existingTable) {
@@ -19,18 +19,15 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ const CouchDB = require("../../../db");
22
23
  const linkRows = require("../../../db/linkedRows");
23
24
  const { getRowParams, generateTableID } = require("../../../db/utils");
24
25
  const { FieldTypes } = require("../../../constants");
25
26
  const { TableSaveFunctions, hasTypeChanged, getTable, handleDataImport, } = require("./utils");
26
- const usageQuota = require("../../../utilities/usageQuota");
27
- const { getAppDB } = require("@budibase/backend-core/context");
28
- const env = require("../../../environment");
29
- const { cleanupAttachments } = require("../../../utilities/rowProcessor");
30
- const { runStaticFormulaChecks } = require("./bulkFormula");
31
27
  exports.save = function (ctx) {
32
28
  return __awaiter(this, void 0, void 0, function* () {
33
- const db = getAppDB();
29
+ const appId = ctx.appId;
30
+ const db = new CouchDB(appId);
34
31
  const _a = ctx.request.body, { dataImport } = _a, rest = __rest(_a, ["dataImport"]);
35
32
  let tableToSave = Object.assign({ type: "table", _id: generateTableID(), views: {} }, rest);
36
33
  // if the table obj had an _id then it will have been retrieved
@@ -44,7 +41,8 @@ exports.save = function (ctx) {
44
41
  // saving a table is a complex operation, involving many different steps, this
45
42
  // has been broken out into a utility to make it more obvious/easier to manipulate
46
43
  const tableSaveFunctions = new TableSaveFunctions({
47
- user: ctx.user,
44
+ db,
45
+ ctx,
48
46
  oldTable,
49
47
  dataImport,
50
48
  });
@@ -84,6 +82,7 @@ exports.save = function (ctx) {
84
82
  // update linked rows
85
83
  try {
86
84
  const linkResp = yield linkRows.updateLinks({
85
+ appId,
87
86
  eventType: oldTable
88
87
  ? linkRows.EventType.TABLE_UPDATED
89
88
  : linkRows.EventType.TABLE_SAVE,
@@ -106,47 +105,42 @@ exports.save = function (ctx) {
106
105
  const result = yield db.put(tableToSave);
107
106
  tableToSave._rev = result.rev;
108
107
  tableToSave = yield tableSaveFunctions.after(tableToSave);
109
- // has to run after, make sure it has _id
110
- yield runStaticFormulaChecks(tableToSave, { oldTable });
111
108
  return tableToSave;
112
109
  });
113
110
  };
114
111
  exports.destroy = function (ctx) {
115
112
  return __awaiter(this, void 0, void 0, function* () {
116
- const db = getAppDB();
113
+ const appId = ctx.appId;
114
+ const db = new CouchDB(appId);
117
115
  const tableToDelete = yield db.get(ctx.params.tableId);
118
116
  // Delete all rows for that table
119
117
  const rows = yield db.allDocs(getRowParams(ctx.params.tableId, null, {
120
118
  include_docs: true,
121
119
  }));
122
120
  yield db.bulkDocs(rows.rows.map(row => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
123
- yield usageQuota.update(usageQuota.Properties.ROW, -rows.rows.length);
124
121
  // update linked rows
125
122
  yield linkRows.updateLinks({
123
+ appId,
126
124
  eventType: linkRows.EventType.TABLE_DELETE,
127
125
  table: tableToDelete,
128
126
  });
129
127
  // don't remove the table itself until very end
130
128
  yield db.remove(tableToDelete);
131
129
  // remove table search index
132
- if (!env.isTest()) {
133
- const currentIndexes = yield db.getIndexes();
134
- const existingIndex = currentIndexes.indexes.find(existing => existing.name === `search:${ctx.params.tableId}`);
135
- if (existingIndex) {
136
- yield db.deleteIndex(existingIndex);
137
- }
130
+ const currentIndexes = yield db.getIndexes();
131
+ const existingIndex = currentIndexes.indexes.find(existing => existing.name === `search:${ctx.params.tableId}`);
132
+ if (existingIndex) {
133
+ yield db.deleteIndex(existingIndex);
138
134
  }
139
- // has to run after, make sure it has _id
140
- yield runStaticFormulaChecks(tableToDelete, { deletion: true });
141
- yield cleanupAttachments(tableToDelete, { rows });
142
135
  return tableToDelete;
143
136
  });
144
137
  };
145
138
  exports.bulkImport = function (ctx) {
146
139
  return __awaiter(this, void 0, void 0, function* () {
147
- const table = yield getTable(ctx.params.tableId);
140
+ const appId = ctx.appId;
141
+ const table = yield getTable(appId, ctx.params.tableId);
148
142
  const { dataImport } = ctx.request.body;
149
- yield handleDataImport(ctx.user, table, dataImport);
143
+ yield handleDataImport(appId, ctx.user, table, dataImport);
150
144
  return table;
151
145
  });
152
146
  };
@@ -8,30 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ const CouchDB = require("../../../db");
11
12
  const csvParser = require("../../../utilities/csvParser");
12
- const { getRowParams, generateRowID, InternalTables, getTableParams, BudibaseInternalDB, } = require("../../../db/utils");
13
- const { isEqual } = require("lodash");
13
+ const { getRowParams, generateRowID, InternalTables, } = require("../../../db/utils");
14
+ const { isEqual } = require("lodash/fp");
14
15
  const { AutoFieldSubTypes, FieldTypes } = require("../../../constants");
15
- const { inputProcessing, cleanupAttachments, } = require("../../../utilities/rowProcessor");
16
+ const { inputProcessing } = require("../../../utilities/rowProcessor");
16
17
  const { USERS_TABLE_SCHEMA, SwitchableTypes, CanSwitchTypes, } = require("../../../constants");
17
- const { isExternalTable, breakExternalTableId, isSQL, } = require("../../../integrations/utils");
18
+ const { isExternalTable, breakExternalTableId, } = require("../../../integrations/utils");
18
19
  const { getViews, saveView } = require("../view/utils");
19
20
  const viewTemplate = require("../view/viewBuilder");
20
- const usageQuota = require("../../../utilities/usageQuota");
21
- const { getAppDB } = require("@budibase/backend-core/context");
22
- const { cloneDeep } = require("lodash/fp");
23
- exports.clearColumns = (table, columnNames) => __awaiter(void 0, void 0, void 0, function* () {
24
- const db = getAppDB();
25
- const rows = yield db.allDocs(getRowParams(table._id, null, {
26
- include_docs: true,
27
- }));
28
- return db.bulkDocs(rows.rows.map(({ doc }) => {
29
- columnNames.forEach(colName => delete doc[colName]);
30
- return doc;
31
- }));
32
- });
33
- exports.checkForColumnUpdates = (oldTable, updatedTable) => __awaiter(void 0, void 0, void 0, function* () {
34
- const db = getAppDB();
21
+ exports.checkForColumnUpdates = (db, oldTable, updatedTable) => __awaiter(void 0, void 0, void 0, function* () {
35
22
  let updatedRows = [];
36
23
  const rename = updatedTable._rename;
37
24
  let deletedColumns = [];
@@ -44,22 +31,18 @@ exports.checkForColumnUpdates = (oldTable, updatedTable) => __awaiter(void 0, vo
44
31
  const rows = yield db.allDocs(getRowParams(updatedTable._id, null, {
45
32
  include_docs: true,
46
33
  }));
47
- const rawRows = rows.rows.map(({ doc }) => doc);
48
- updatedRows = rawRows.map(row => {
49
- row = cloneDeep(row);
34
+ updatedRows = rows.rows.map(({ doc }) => {
50
35
  if (rename) {
51
- row[rename.updated] = row[rename.old];
52
- delete row[rename.old];
36
+ doc[rename.updated] = doc[rename.old];
37
+ delete doc[rename.old];
53
38
  }
54
39
  else if (deletedColumns.length !== 0) {
55
- deletedColumns.forEach(colName => delete row[colName]);
40
+ deletedColumns.forEach(colName => delete doc[colName]);
56
41
  }
57
- return row;
42
+ return doc;
58
43
  });
59
- // cleanup any attachments from object storage for deleted attachment columns
60
- yield cleanupAttachments(updatedTable, { oldTable, rows: rawRows });
61
44
  // Update views
62
- yield exports.checkForViewUpdates(updatedTable, rename, deletedColumns);
45
+ yield exports.checkForViewUpdates(db, updatedTable, rename, deletedColumns);
63
46
  delete updatedTable._rename;
64
47
  }
65
48
  return { rows: updatedRows, table: updatedTable };
@@ -82,11 +65,11 @@ exports.makeSureTableUpToDate = (table, tableToSave) => {
82
65
  }
83
66
  return tableToSave;
84
67
  };
85
- exports.handleDataImport = (user, table, dataImport) => __awaiter(void 0, void 0, void 0, function* () {
68
+ exports.handleDataImport = (appId, user, table, dataImport) => __awaiter(void 0, void 0, void 0, function* () {
86
69
  if (!dataImport || !dataImport.csvString) {
87
70
  return table;
88
71
  }
89
- const db = getAppDB();
72
+ const db = new CouchDB(appId);
90
73
  // Populate the table with rows imported from CSV in a bulk update
91
74
  const data = yield csvParser.transform(Object.assign(Object.assign({}, dataImport), { existingTable: table }));
92
75
  let finalData = [];
@@ -112,17 +95,13 @@ exports.handleDataImport = (user, table, dataImport) => __awaiter(void 0, void 0
112
95
  }
113
96
  finalData.push(row);
114
97
  }
115
- yield usageQuota.update(usageQuota.Properties.ROW, finalData.length, {
116
- dryRun: true,
117
- });
118
98
  yield db.bulkDocs(finalData);
119
- yield usageQuota.update(usageQuota.Properties.ROW, finalData.length);
120
99
  let response = yield db.put(table);
121
100
  table._rev = response._rev;
122
101
  return table;
123
102
  });
124
- exports.handleSearchIndexes = (table) => __awaiter(void 0, void 0, void 0, function* () {
125
- const db = getAppDB();
103
+ exports.handleSearchIndexes = (appId, table) => __awaiter(void 0, void 0, void 0, function* () {
104
+ const db = new CouchDB(appId);
126
105
  // create relevant search indexes
127
106
  if (table.indexes && table.indexes.length > 0) {
128
107
  const currentIndexes = yield db.getIndexes();
@@ -171,9 +150,12 @@ exports.checkStaticTables = table => {
171
150
  return table;
172
151
  };
173
152
  class TableSaveFunctions {
174
- constructor({ user, oldTable, dataImport }) {
175
- this.db = getAppDB();
176
- this.user = user;
153
+ constructor({ db, ctx, oldTable, dataImport }) {
154
+ this.db = db;
155
+ this.ctx = ctx;
156
+ if (this.ctx && this.ctx.user) {
157
+ this.appId = this.ctx.appId;
158
+ }
177
159
  this.oldTable = oldTable;
178
160
  this.dataImport = dataImport;
179
161
  // any rows that need updated
@@ -192,7 +174,7 @@ class TableSaveFunctions {
192
174
  // when confirmed valid
193
175
  mid(table) {
194
176
  return __awaiter(this, void 0, void 0, function* () {
195
- let response = yield exports.checkForColumnUpdates(this.oldTable, table);
177
+ let response = yield exports.checkForColumnUpdates(this.db, this.oldTable, table);
196
178
  this.rows = this.rows.concat(response.rows);
197
179
  return table;
198
180
  });
@@ -200,8 +182,8 @@ class TableSaveFunctions {
200
182
  // after saving
201
183
  after(table) {
202
184
  return __awaiter(this, void 0, void 0, function* () {
203
- table = yield exports.handleSearchIndexes(table);
204
- table = yield exports.handleDataImport(this.user, table, this.dataImport);
185
+ table = yield exports.handleSearchIndexes(this.appId, table);
186
+ table = yield exports.handleDataImport(this.appId, this.ctx.user, table, this.dataImport);
205
187
  return table;
206
188
  });
207
189
  }
@@ -209,39 +191,30 @@ class TableSaveFunctions {
209
191
  return this.rows;
210
192
  }
211
193
  }
212
- exports.getAllInternalTables = () => __awaiter(void 0, void 0, void 0, function* () {
213
- const db = getAppDB();
214
- const internalTables = yield db.allDocs(getTableParams(null, {
215
- include_docs: true,
216
- }));
217
- return internalTables.rows.map(tableDoc => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: BudibaseInternalDB._id })));
218
- });
219
- exports.getAllExternalTables = (datasourceId) => __awaiter(void 0, void 0, void 0, function* () {
220
- const db = getAppDB();
194
+ exports.getAllExternalTables = (appId, datasourceId) => __awaiter(void 0, void 0, void 0, function* () {
195
+ const db = new CouchDB(appId);
221
196
  const datasource = yield db.get(datasourceId);
222
197
  if (!datasource || !datasource.entities) {
223
198
  throw "Datasource is not configured fully.";
224
199
  }
225
200
  return datasource.entities;
226
201
  });
227
- exports.getExternalTable = (datasourceId, tableName) => __awaiter(void 0, void 0, void 0, function* () {
228
- const entities = yield exports.getAllExternalTables(datasourceId);
202
+ exports.getExternalTable = (appId, datasourceId, tableName) => __awaiter(void 0, void 0, void 0, function* () {
203
+ const entities = yield exports.getAllExternalTables(appId, datasourceId);
229
204
  return entities[tableName];
230
205
  });
231
- exports.getTable = (tableId) => __awaiter(void 0, void 0, void 0, function* () {
232
- const db = getAppDB();
206
+ exports.getTable = (appId, tableId) => __awaiter(void 0, void 0, void 0, function* () {
207
+ const db = new CouchDB(appId);
233
208
  if (isExternalTable(tableId)) {
234
209
  let { datasourceId, tableName } = breakExternalTableId(tableId);
235
- const datasource = yield db.get(datasourceId);
236
- const table = yield exports.getExternalTable(datasourceId, tableName);
237
- return Object.assign(Object.assign({}, table), { sql: isSQL(datasource) });
210
+ return exports.getExternalTable(appId, datasourceId, tableName);
238
211
  }
239
212
  else {
240
213
  return db.get(tableId);
241
214
  }
242
215
  });
243
- exports.checkForViewUpdates = (table, rename, deletedColumns) => __awaiter(void 0, void 0, void 0, function* () {
244
- const views = yield getViews();
216
+ exports.checkForViewUpdates = (db, table, rename, deletedColumns) => __awaiter(void 0, void 0, void 0, function* () {
217
+ const views = yield getViews(db);
245
218
  const tableViews = views.filter(view => view.meta.tableId === table._id);
246
219
  // Check each table view to see if impacted by this table action
247
220
  for (let view of tableViews) {
@@ -297,7 +270,7 @@ exports.checkForViewUpdates = (table, rename, deletedColumns) => __awaiter(void
297
270
  // Update view if required
298
271
  if (needsUpdated) {
299
272
  const newViewTemplate = viewTemplate(view.meta);
300
- yield saveView(null, view.name, newViewTemplate);
273
+ yield saveView(db, null, view.name, newViewTemplate);
301
274
  if (!newViewTemplate.meta.schema) {
302
275
  newViewTemplate.meta.schema = table.schema;
303
276
  }
@@ -8,18 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ const CouchDB = require("../../db");
11
12
  const { generateUserMetadataID, getUserMetadataParams, generateUserFlagID, } = require("../../db/utils");
12
13
  const { InternalTables } = require("../../db/utils");
13
14
  const { getGlobalUsers, getRawGlobalUser } = require("../../utilities/global");
14
15
  const { getFullUser } = require("../../utilities/users");
15
16
  const { isEqual } = require("lodash");
16
17
  const { BUILTIN_ROLE_IDS } = require("@budibase/backend-core/roles");
17
- const { getDevelopmentAppID, getProdAppIDs, dbExists, } = require("@budibase/backend-core/db");
18
+ const { getDevelopmentAppID, getDeployedAppIDs, } = require("@budibase/backend-core/db");
19
+ const { doesDatabaseExist } = require("../../utilities");
18
20
  const { UserStatus } = require("@budibase/backend-core/constants");
19
- const { getAppDB } = require("@budibase/backend-core/context");
20
- function rawMetadata() {
21
+ function rawMetadata(db) {
21
22
  return __awaiter(this, void 0, void 0, function* () {
22
- const db = getAppDB();
23
23
  return (yield db.allDocs(getUserMetadataParams(null, {
24
24
  include_docs: true,
25
25
  }))).rows.map(row => row.doc);
@@ -45,10 +45,13 @@ function combineMetadataAndUser(user, metadata) {
45
45
  }
46
46
  return null;
47
47
  }
48
- exports.syncGlobalUsers = () => __awaiter(void 0, void 0, void 0, function* () {
48
+ exports.syncGlobalUsers = (appId) => __awaiter(void 0, void 0, void 0, function* () {
49
49
  // sync user metadata
50
- const db = getAppDB();
51
- const [users, metadata] = yield Promise.all([getGlobalUsers(), rawMetadata()]);
50
+ const db = new CouchDB(appId);
51
+ const [users, metadata] = yield Promise.all([
52
+ getGlobalUsers(appId),
53
+ rawMetadata(db),
54
+ ]);
52
55
  const toWrite = [];
53
56
  for (let user of users) {
54
57
  const combined = yield combineMetadataAndUser(user, metadata);
@@ -83,7 +86,7 @@ exports.syncUser = function (ctx) {
83
86
  let prodAppIds;
84
87
  // if they are a builder then get all production app IDs
85
88
  if ((user.builder && user.builder.global) || deleting) {
86
- prodAppIds = yield getProdAppIDs();
89
+ prodAppIds = yield getDeployedAppIDs(CouchDB);
87
90
  }
88
91
  else {
89
92
  prodAppIds = Object.entries(roles)
@@ -94,10 +97,10 @@ exports.syncUser = function (ctx) {
94
97
  const roleId = roles[prodAppId];
95
98
  const devAppId = getDevelopmentAppID(prodAppId);
96
99
  for (let appId of [prodAppId, devAppId]) {
97
- if (!(yield dbExists(appId))) {
100
+ if (!(yield doesDatabaseExist(appId))) {
98
101
  continue;
99
102
  }
100
- const db = getAppDB();
103
+ const db = new CouchDB(appId);
101
104
  const metadataId = generateUserMetadataID(userId);
102
105
  let metadata;
103
106
  try {
@@ -131,8 +134,8 @@ exports.syncUser = function (ctx) {
131
134
  };
132
135
  exports.fetchMetadata = function (ctx) {
133
136
  return __awaiter(this, void 0, void 0, function* () {
134
- const database = getAppDB();
135
- const global = yield getGlobalUsers();
137
+ const database = new CouchDB(ctx.appId);
138
+ const global = yield getGlobalUsers(ctx.appId);
136
139
  const metadata = yield rawMetadata(database);
137
140
  const users = [];
138
141
  for (let user of global) {
@@ -152,14 +155,13 @@ exports.updateSelfMetadata = function (ctx) {
152
155
  ctx.request.body._id = ctx.user._id;
153
156
  // make sure no stale rev
154
157
  delete ctx.request.body._rev;
155
- // make sure no csrf token
156
- delete ctx.request.body.csrfToken;
157
158
  yield exports.updateMetadata(ctx);
158
159
  });
159
160
  };
160
161
  exports.updateMetadata = function (ctx) {
161
162
  return __awaiter(this, void 0, void 0, function* () {
162
- const db = getAppDB();
163
+ const appId = ctx.appId;
164
+ const db = new CouchDB(appId);
163
165
  const user = ctx.request.body;
164
166
  // this isn't applicable to the user
165
167
  delete user.roles;
@@ -169,7 +171,7 @@ exports.updateMetadata = function (ctx) {
169
171
  };
170
172
  exports.destroyMetadata = function (ctx) {
171
173
  return __awaiter(this, void 0, void 0, function* () {
172
- const db = getAppDB();
174
+ const db = new CouchDB(ctx.appId);
173
175
  try {
174
176
  const dbUser = yield db.get(ctx.params.id);
175
177
  yield db.remove(dbUser._id, dbUser._rev);
@@ -195,7 +197,7 @@ exports.setFlag = function (ctx) {
195
197
  ctx.throw(400, "Must supply a 'flag' field in request body.");
196
198
  }
197
199
  const flagDocId = generateUserFlagID(userId);
198
- const db = getAppDB();
200
+ const db = new CouchDB(ctx.appId);
199
201
  let doc;
200
202
  try {
201
203
  doc = yield db.get(flagDocId);
@@ -212,7 +214,7 @@ exports.getFlags = function (ctx) {
212
214
  return __awaiter(this, void 0, void 0, function* () {
213
215
  const userId = ctx.user._id;
214
216
  const docId = generateUserFlagID(userId);
215
- const db = getAppDB();
217
+ const db = new CouchDB(ctx.appId);
216
218
  let doc;
217
219
  try {
218
220
  doc = yield db.get(docId);
@@ -19,6 +19,7 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ const CouchDB = require("../../../db");
22
23
  const viewTemplate = require("./viewBuilder");
23
24
  const { apiFileReturn } = require("../../../utilities/fileSystem");
24
25
  const exporters = require("./exporters");
@@ -26,18 +27,18 @@ const { saveView, getView, getViews, deleteView } = require("./utils");
26
27
  const { fetchView } = require("../row");
27
28
  const { getTable } = require("../table/utils");
28
29
  const { FieldTypes } = require("../../../constants");
29
- const { getAppDB } = require("@budibase/backend-core/context");
30
30
  exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
31
- ctx.body = yield getViews();
31
+ const db = new CouchDB(ctx.appId);
32
+ ctx.body = yield getViews(db);
32
33
  });
33
34
  exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
34
- const db = getAppDB();
35
+ const db = new CouchDB(ctx.appId);
35
36
  const _a = ctx.request.body, { originalName } = _a, viewToSave = __rest(_a, ["originalName"]);
36
37
  const view = viewTemplate(viewToSave);
37
38
  if (!viewToSave.name) {
38
39
  ctx.throw(400, "Cannot create view without a name");
39
40
  }
40
- yield saveView(originalName, viewToSave.name, view);
41
+ yield saveView(db, originalName, viewToSave.name, view);
41
42
  // add views to table document
42
43
  const table = yield db.get(ctx.request.body.tableId);
43
44
  if (!table.views)
@@ -53,17 +54,18 @@ exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
53
54
  ctx.body = Object.assign(Object.assign({}, table.views[viewToSave.name]), { name: viewToSave.name });
54
55
  });
55
56
  exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
56
- const db = getAppDB();
57
+ const db = new CouchDB(ctx.appId);
57
58
  const viewName = decodeURI(ctx.params.viewName);
58
- const view = yield deleteView(viewName);
59
+ const view = yield deleteView(db, viewName);
59
60
  const table = yield db.get(view.meta.tableId);
60
61
  delete table.views[viewName];
61
62
  yield db.put(table);
62
63
  ctx.body = view;
63
64
  });
64
65
  exports.exportView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
66
+ const db = new CouchDB(ctx.appId);
65
67
  const viewName = decodeURI(ctx.query.view);
66
- const view = yield getView(viewName);
68
+ const view = yield getView(db, viewName);
67
69
  const format = ctx.query.format;
68
70
  if (!format || !Object.values(exporters.ExportFormats).includes(format)) {
69
71
  ctx.throw(400, "Format must be specified, either csv or json");
@@ -88,7 +90,7 @@ exports.exportView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
88
90
  let schema = view && view.meta && view.meta.schema;
89
91
  if (!schema) {
90
92
  const tableId = ctx.params.tableId || view.meta.tableId;
91
- const table = yield getTable(tableId);
93
+ const table = yield getTable(ctx.appId, tableId);
92
94
  schema = table.schema;
93
95
  }
94
96
  // remove any relationships
@@ -10,9 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const { ViewNames, generateMemoryViewID, getMemoryViewParams, DocumentTypes, SEPARATOR, } = require("../../../db/utils");
12
12
  const env = require("../../../environment");
13
- const { getAppDB } = require("@budibase/backend-core/context");
14
- exports.getView = (viewName) => __awaiter(void 0, void 0, void 0, function* () {
15
- const db = getAppDB();
13
+ exports.getView = (db, viewName) => __awaiter(void 0, void 0, void 0, function* () {
16
14
  if (env.SELF_HOSTED) {
17
15
  const designDoc = yield db.get("_design/database");
18
16
  return designDoc.views[viewName];
@@ -26,8 +24,7 @@ exports.getView = (viewName) => __awaiter(void 0, void 0, void 0, function* () {
26
24
  return viewDoc.view;
27
25
  }
28
26
  });
29
- exports.getViews = () => __awaiter(void 0, void 0, void 0, function* () {
30
- const db = getAppDB();
27
+ exports.getViews = (db) => __awaiter(void 0, void 0, void 0, function* () {
31
28
  const response = [];
32
29
  if (env.SELF_HOSTED) {
33
30
  const designDoc = yield db.get("_design/database");
@@ -49,8 +46,7 @@ exports.getViews = () => __awaiter(void 0, void 0, void 0, function* () {
49
46
  }
50
47
  return response;
51
48
  });
52
- exports.saveView = (originalName, viewName, viewTemplate) => __awaiter(void 0, void 0, void 0, function* () {
53
- const db = getAppDB();
49
+ exports.saveView = (db, originalName, viewName, viewTemplate) => __awaiter(void 0, void 0, void 0, function* () {
54
50
  if (env.SELF_HOSTED) {
55
51
  const designDoc = yield db.get("_design/database");
56
52
  designDoc.views = Object.assign(Object.assign({}, designDoc.views), { [viewName]: viewTemplate });
@@ -85,8 +81,7 @@ exports.saveView = (originalName, viewName, viewTemplate) => __awaiter(void 0, v
85
81
  yield db.put(viewDoc);
86
82
  }
87
83
  });
88
- exports.deleteView = (viewName) => __awaiter(void 0, void 0, void 0, function* () {
89
- const db = getAppDB();
84
+ exports.deleteView = (db, viewName) => __awaiter(void 0, void 0, void 0, function* () {
90
85
  if (env.SELF_HOSTED) {
91
86
  const designDoc = yield db.get("_design/database");
92
87
  const view = designDoc.views[viewName];