@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
@@ -19,19 +19,6 @@ import {
19
19
  isRowId,
20
20
  convertRowId,
21
21
  } from "../../../integrations/utils"
22
- import { getDatasourceAndQuery } from "./utils"
23
- import {
24
- DataSourceOperation,
25
- FieldTypes,
26
- RelationshipTypes,
27
- } from "../../../constants"
28
- import { breakExternalTableId, isSQL } from "../../../integrations/utils"
29
- import { processObjectSync } from "@budibase/string-templates"
30
- // @ts-ignore
31
- import { cloneDeep } from "lodash/fp"
32
- import { processFormulas } from "../../../utilities/rowProcessor/utils"
33
- // @ts-ignore
34
- import { getAppDB } from "@budibase/backend-core/context"
35
22
 
36
23
  interface ManyRelationship {
37
24
  tableId?: string
@@ -51,6 +38,18 @@ interface RunConfig {
51
38
  }
52
39
 
53
40
  module External {
41
+ const { getDatasourceAndQuery } = require("./utils")
42
+ const {
43
+ DataSourceOperation,
44
+ FieldTypes,
45
+ RelationshipTypes,
46
+ } = require("../../../constants")
47
+ const { breakExternalTableId, isSQL } = require("../../../integrations/utils")
48
+ const { processObjectSync } = require("@budibase/string-templates")
49
+ const { cloneDeep } = require("lodash/fp")
50
+ const CouchDB = require("../../../db")
51
+ const { processFormulas } = require("../../../utilities/rowProcessor/utils")
52
+
54
53
  function buildFilters(
55
54
  id: string | undefined,
56
55
  filters: SearchFilters,
@@ -184,7 +183,7 @@ module External {
184
183
  thisRow._id = generateIdForRow(row, table)
185
184
  thisRow.tableId = table._id
186
185
  thisRow._rev = "rev"
187
- return processFormulas(table, thisRow)
186
+ return thisRow
188
187
  }
189
188
 
190
189
  function fixArrayTypes(row: Row, table: Table) {
@@ -211,12 +210,19 @@ module External {
211
210
  }
212
211
 
213
212
  class ExternalRequest {
213
+ private readonly appId: string
214
214
  private operation: Operation
215
215
  private tableId: string
216
216
  private datasource: Datasource
217
217
  private tables: { [key: string]: Table } = {}
218
218
 
219
- constructor(operation: Operation, tableId: string, datasource: Datasource) {
219
+ constructor(
220
+ appId: string,
221
+ operation: Operation,
222
+ tableId: string,
223
+ datasource: Datasource
224
+ ) {
225
+ this.appId = appId
220
226
  this.operation = operation
221
227
  this.tableId = tableId
222
228
  this.datasource = datasource
@@ -225,14 +231,12 @@ module External {
225
231
  }
226
232
  }
227
233
 
228
- getTable(tableId: string | undefined): Table | undefined {
234
+ getTable(tableId: string | undefined): Table {
229
235
  if (!tableId) {
230
236
  throw "Table ID is unknown, cannot find table"
231
237
  }
232
238
  const { tableName } = breakExternalTableId(tableId)
233
- if (tableName) {
234
- return this.tables[tableName]
235
- }
239
+ return this.tables[tableName]
236
240
  }
237
241
 
238
242
  inputProcessing(row: Row | undefined, table: Table) {
@@ -268,11 +272,9 @@ module External {
268
272
  newRow[key] = row[key]
269
273
  continue
270
274
  }
271
- const { tableName: linkTableName } = breakExternalTableId(
272
- field?.tableId
273
- )
275
+ const { tableName: linkTableName } = breakExternalTableId(field.tableId)
274
276
  // table has to exist for many to many
275
- if (!linkTableName || !this.tables[linkTableName]) {
277
+ if (!this.tables[linkTableName]) {
276
278
  continue
277
279
  }
278
280
  const linkTable = this.tables[linkTableName]
@@ -327,12 +329,8 @@ module External {
327
329
  * This iterates through the returned rows and works out what elements of the rows
328
330
  * actually match up to another row (based on primary keys) - this is pretty specific
329
331
  * to SQL and the way that SQL relationships are returned based on joins.
330
- * This is complicated, but the idea is that when a SQL query returns all the relations
331
- * will be separate rows, with all of the data in each row. We have to decipher what comes
332
- * from where (which tables) and how to convert that into budibase columns.
333
332
  */
334
333
  updateRelationshipColumns(
335
- table: Table,
336
334
  row: Row,
337
335
  rows: { [key: string]: Row },
338
336
  relationships: RelationshipsJson[]
@@ -343,13 +341,6 @@ module External {
343
341
  if (!linkedTable) {
344
342
  continue
345
343
  }
346
- const fromColumn = `${table.name}.${relationship.from}`
347
- const toColumn = `${linkedTable.name}.${relationship.to}`
348
- // this is important when working with multiple relationships
349
- // between the same tables, don't want to overlap/multiply the relations
350
- if (!relationship.through && row[fromColumn] !== row[toColumn]) {
351
- continue
352
- }
353
344
  let linked = basicProcessing(row, linkedTable)
354
345
  if (!linked._id) {
355
346
  continue
@@ -397,7 +388,6 @@ module External {
397
388
  // this is a relationship of some sort
398
389
  if (finalRows[rowId]) {
399
390
  finalRows = this.updateRelationshipColumns(
400
- table,
401
391
  row,
402
392
  finalRows,
403
393
  relationships
@@ -411,7 +401,6 @@ module External {
411
401
  finalRows[thisRow._id] = thisRow
412
402
  // do this at end once its been added to the final rows
413
403
  finalRows = this.updateRelationshipColumns(
414
- table,
415
404
  row,
416
405
  finalRows,
417
406
  relationships
@@ -433,7 +422,7 @@ module External {
433
422
  }
434
423
  const { tableName: linkTableName } = breakExternalTableId(field.tableId)
435
424
  // no table to link to, this is not a valid relationships
436
- if (!linkTableName || !this.tables[linkTableName]) {
425
+ if (!this.tables[linkTableName]) {
437
426
  continue
438
427
  }
439
428
  const linkTable = this.tables[linkTableName]
@@ -471,9 +460,6 @@ module External {
471
460
  async lookupRelations(tableId: string, row: Row) {
472
461
  const related: { [key: string]: any } = {}
473
462
  const { tableName } = breakExternalTableId(tableId)
474
- if (!tableName) {
475
- return related
476
- }
477
463
  const table = this.tables[tableName]
478
464
  // @ts-ignore
479
465
  const primaryKey = table.primary[0]
@@ -498,7 +484,7 @@ module External {
498
484
  if (!lookupField || !row[lookupField]) {
499
485
  continue
500
486
  }
501
- const response = await getDatasourceAndQuery({
487
+ const response = await getDatasourceAndQuery(this.appId, {
502
488
  endpoint: getEndpoint(tableId, DataSourceOperation.READ),
503
489
  filters: {
504
490
  equal: {
@@ -529,30 +515,28 @@ module External {
529
515
  row: Row,
530
516
  relationships: ManyRelationship[]
531
517
  ) {
518
+ const { appId } = this
532
519
  // if we're creating (in a through table) need to wipe the existing ones first
533
520
  const promises = []
534
521
  const related = await this.lookupRelations(mainTableId, row)
535
522
  for (let relationship of relationships) {
536
523
  const { key, tableId, isUpdate, id, ...rest } = relationship
537
- const body: { [key: string]: any } = processObjectSync(rest, row, {})
524
+ const body = processObjectSync(rest, row)
538
525
  const linkTable = this.getTable(tableId)
539
526
  // @ts-ignore
540
- const linkPrimary = linkTable?.primary[0]
541
- if (!linkTable || !linkPrimary) {
542
- return
543
- }
544
- const rows = related[key].rows || []
527
+ const linkPrimary = linkTable.primary[0]
528
+ const rows = related[key]?.rows || []
545
529
  const found = rows.find(
546
530
  (row: { [key: string]: any }) =>
547
531
  row[linkPrimary] === relationship.id ||
548
- row[linkPrimary] === body?.[linkPrimary]
532
+ row[linkPrimary] === body[linkPrimary]
549
533
  )
550
534
  const operation = isUpdate
551
535
  ? DataSourceOperation.UPDATE
552
536
  : DataSourceOperation.CREATE
553
537
  if (!found) {
554
538
  promises.push(
555
- getDatasourceAndQuery({
539
+ getDatasourceAndQuery(appId, {
556
540
  endpoint: getEndpoint(tableId, operation),
557
541
  // if we're doing many relationships then we're writing, only one response
558
542
  body,
@@ -568,12 +552,9 @@ module External {
568
552
  for (let [colName, { isMany, rows, tableId }] of Object.entries(
569
553
  related
570
554
  )) {
571
- const table: Table | undefined = this.getTable(tableId)
555
+ const table: Table = this.getTable(tableId)
572
556
  // if its not the foreign key skip it, nothing to do
573
- if (
574
- !table ||
575
- (table.primary && table.primary.indexOf(colName) !== -1)
576
- ) {
557
+ if (table.primary && table.primary.indexOf(colName) !== -1) {
577
558
  continue
578
559
  }
579
560
  for (let row of rows) {
@@ -585,7 +566,7 @@ module External {
585
566
  : DataSourceOperation.UPDATE
586
567
  const body = isMany ? null : { [colName]: null }
587
568
  promises.push(
588
- getDatasourceAndQuery({
569
+ getDatasourceAndQuery(this.appId, {
589
570
  endpoint: getEndpoint(tableId, op),
590
571
  body,
591
572
  filters,
@@ -624,25 +605,20 @@ module External {
624
605
  continue
625
606
  }
626
607
  const { tableName: linkTableName } = breakExternalTableId(field.tableId)
627
- if (linkTableName) {
628
- const linkTable = this.tables[linkTableName]
629
- if (linkTable) {
630
- const linkedFields = extractRealFields(linkTable, fields)
631
- fields = fields.concat(linkedFields)
632
- }
608
+ const linkTable = this.tables[linkTableName]
609
+ if (linkTable) {
610
+ const linkedFields = extractRealFields(linkTable, fields)
611
+ fields = fields.concat(linkedFields)
633
612
  }
634
613
  }
635
614
  return fields
636
615
  }
637
616
 
638
617
  async run(config: RunConfig) {
639
- const { operation, tableId } = this
618
+ const { appId, operation, tableId } = this
640
619
  let { datasourceId, tableName } = breakExternalTableId(tableId)
641
- if (!tableName) {
642
- throw "Unable to run without a table name"
643
- }
644
620
  if (!this.datasource) {
645
- const db = getAppDB()
621
+ const db = new CouchDB(appId)
646
622
  this.datasource = await db.get(datasourceId)
647
623
  if (!this.datasource || !this.datasource.entities) {
648
624
  throw "No tables found, fetch tables before query."
@@ -694,7 +670,7 @@ module External {
694
670
  },
695
671
  }
696
672
  // can't really use response right now
697
- const response = await getDatasourceAndQuery(json)
673
+ const response = await getDatasourceAndQuery(appId, json)
698
674
  // handle many to many relationships now if we know the ID (could be auto increment)
699
675
  if (
700
676
  operation !== DataSourceOperation.READ &&
@@ -9,9 +9,9 @@ const {
9
9
  breakRowIdField,
10
10
  } = require("../../../integrations/utils")
11
11
  const ExternalRequest = require("./ExternalRequest")
12
- const { getAppDB } = require("@budibase/backend-core/context")
12
+ const CouchDB = require("../../../db")
13
13
 
14
- async function handleRequest(operation, tableId, opts = {}) {
14
+ async function handleRequest(appId, operation, tableId, opts = {}) {
15
15
  // make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
16
16
  if (opts && opts.filters) {
17
17
  for (let filterField of NoEmptyFilterStrings) {
@@ -25,27 +25,31 @@ async function handleRequest(operation, tableId, opts = {}) {
25
25
  }
26
26
  }
27
27
  }
28
- return new ExternalRequest(operation, tableId, opts.datasource).run(opts)
28
+ return new ExternalRequest(appId, operation, tableId, opts.datasource).run(
29
+ opts
30
+ )
29
31
  }
30
32
 
31
33
  exports.handleRequest = handleRequest
32
34
 
33
35
  exports.patch = async ctx => {
36
+ const appId = ctx.appId
34
37
  const inputs = ctx.request.body
35
38
  const tableId = ctx.params.tableId
36
39
  const id = breakRowIdField(inputs._id)
37
40
  // don't save the ID to db
38
41
  delete inputs._id
39
- return handleRequest(DataSourceOperation.UPDATE, tableId, {
42
+ return handleRequest(appId, DataSourceOperation.UPDATE, tableId, {
40
43
  id,
41
44
  row: inputs,
42
45
  })
43
46
  }
44
47
 
45
48
  exports.save = async ctx => {
49
+ const appId = ctx.appId
46
50
  const inputs = ctx.request.body
47
51
  const tableId = ctx.params.tableId
48
- return handleRequest(DataSourceOperation.CREATE, tableId, {
52
+ return handleRequest(appId, DataSourceOperation.CREATE, tableId, {
49
53
  row: inputs,
50
54
  })
51
55
  }
@@ -59,35 +63,49 @@ exports.fetchView = async ctx => {
59
63
  }
60
64
 
61
65
  exports.fetch = async ctx => {
66
+ const appId = ctx.appId
62
67
  const tableId = ctx.params.tableId
63
- return handleRequest(DataSourceOperation.READ, tableId)
68
+ return handleRequest(appId, DataSourceOperation.READ, tableId)
64
69
  }
65
70
 
66
71
  exports.find = async ctx => {
72
+ const appId = ctx.appId
67
73
  const id = ctx.params.rowId
68
74
  const tableId = ctx.params.tableId
69
- const response = await handleRequest(DataSourceOperation.READ, tableId, {
70
- id,
71
- })
75
+ const response = await handleRequest(
76
+ appId,
77
+ DataSourceOperation.READ,
78
+ tableId,
79
+ {
80
+ id,
81
+ }
82
+ )
72
83
  return response ? response[0] : response
73
84
  }
74
85
 
75
86
  exports.destroy = async ctx => {
87
+ const appId = ctx.appId
76
88
  const tableId = ctx.params.tableId
77
89
  const id = ctx.request.body._id
78
- const { row } = await handleRequest(DataSourceOperation.DELETE, tableId, {
79
- id,
80
- })
90
+ const { row } = await handleRequest(
91
+ appId,
92
+ DataSourceOperation.DELETE,
93
+ tableId,
94
+ {
95
+ id,
96
+ }
97
+ )
81
98
  return { response: { ok: true }, row }
82
99
  }
83
100
 
84
101
  exports.bulkDestroy = async ctx => {
102
+ const appId = ctx.appId
85
103
  const { rows } = ctx.request.body
86
104
  const tableId = ctx.params.tableId
87
105
  let promises = []
88
106
  for (let row of rows) {
89
107
  promises.push(
90
- handleRequest(DataSourceOperation.DELETE, tableId, {
108
+ handleRequest(appId, DataSourceOperation.DELETE, tableId, {
91
109
  id: breakRowIdField(row._id),
92
110
  })
93
111
  )
@@ -97,6 +115,7 @@ exports.bulkDestroy = async ctx => {
97
115
  }
98
116
 
99
117
  exports.search = async ctx => {
118
+ const appId = ctx.appId
100
119
  const tableId = ctx.params.tableId
101
120
  const { paginate, query, ...params } = ctx.request.body
102
121
  let { bookmark, limit } = params
@@ -126,21 +145,26 @@ exports.search = async ctx => {
126
145
  [params.sort]: direction,
127
146
  }
128
147
  }
129
- const rows = await handleRequest(DataSourceOperation.READ, tableId, {
148
+ const rows = await handleRequest(appId, DataSourceOperation.READ, tableId, {
130
149
  filters: query,
131
150
  sort,
132
151
  paginate: paginateObj,
133
152
  })
134
153
  let hasNextPage = false
135
154
  if (paginate && rows.length === limit) {
136
- const nextRows = await handleRequest(DataSourceOperation.READ, tableId, {
137
- filters: query,
138
- sort,
139
- paginate: {
140
- limit: 1,
141
- page: bookmark * limit + 1,
142
- },
143
- })
155
+ const nextRows = await handleRequest(
156
+ appId,
157
+ DataSourceOperation.READ,
158
+ tableId,
159
+ {
160
+ filters: query,
161
+ sort,
162
+ paginate: {
163
+ limit: 1,
164
+ page: bookmark * limit + 1,
165
+ },
166
+ }
167
+ )
144
168
  hasNextPage = nextRows.length > 0
145
169
  }
146
170
  // need wrapper object for bookmarks etc when paginating
@@ -153,19 +177,25 @@ exports.validate = async () => {
153
177
  }
154
178
 
155
179
  exports.fetchEnrichedRow = async ctx => {
180
+ const appId = ctx.appId
156
181
  const id = ctx.params.rowId
157
182
  const tableId = ctx.params.tableId
158
183
  const { datasourceId, tableName } = breakExternalTableId(tableId)
159
- const db = getAppDB()
184
+ const db = new CouchDB(appId)
160
185
  const datasource = await db.get(datasourceId)
161
186
  if (!datasource || !datasource.entities) {
162
187
  ctx.throw(400, "Datasource has not been configured for plus API.")
163
188
  }
164
189
  const tables = datasource.entities
165
- const response = await handleRequest(DataSourceOperation.READ, tableId, {
166
- id,
167
- datasource,
168
- })
190
+ const response = await handleRequest(
191
+ appId,
192
+ DataSourceOperation.READ,
193
+ tableId,
194
+ {
195
+ id,
196
+ datasource,
197
+ }
198
+ )
169
199
  const table = tables[tableName]
170
200
  const row = response[0]
171
201
  // this seems like a lot of work, but basically we need to dig deeper for the enrich
@@ -184,6 +214,7 @@ exports.fetchEnrichedRow = async ctx => {
184
214
  // don't support composite keys right now
185
215
  const linkedIds = links.map(link => breakRowIdField(link._id)[0])
186
216
  row[fieldName] = await handleRequest(
217
+ appId,
187
218
  DataSourceOperation.READ,
188
219
  linkedTableId,
189
220
  {