@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,11 +19,13 @@ 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
- const { generateRowID, getRowParams, DocumentTypes, InternalTables, } = require("../../../db/utils");
24
+ const { getRowParams, generateRowID, DocumentTypes, InternalTables, } = require("../../../db/utils");
24
25
  const userController = require("../user");
25
- const { inputProcessing, outputProcessing, cleanupAttachments, } = require("../../../utilities/rowProcessor");
26
+ const { inputProcessing, outputProcessing, processAutoColumn, cleanupAttachments, } = require("../../../utilities/rowProcessor");
26
27
  const { FieldTypes } = require("../../../constants");
28
+ const { isEqual } = require("lodash");
27
29
  const { validate, findRow } = require("./utils");
28
30
  const { fullSearch, paginatedSearch } = require("./internalSearch");
29
31
  const { getGlobalUsersFromMetadata } = require("../../../utilities/global");
@@ -31,13 +33,59 @@ const inMemoryViews = require("../../../db/inMemoryView");
31
33
  const env = require("../../../environment");
32
34
  const { migrateToInMemoryView, migrateToDesignView, getFromDesignDoc, getFromMemoryDoc, } = require("../view/utils");
33
35
  const { cloneDeep } = require("lodash/fp");
34
- const { getAppDB } = require("@budibase/backend-core/context");
35
- const { finaliseRow, updateRelatedFormula } = require("./staticFormula");
36
36
  const CALCULATION_TYPES = {
37
37
  SUM: "sum",
38
38
  COUNT: "count",
39
39
  STATS: "stats",
40
40
  };
41
+ function storeResponse(ctx, db, row, oldTable, table) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ row.type = "row";
44
+ // don't worry about rev, tables handle rev/lastID updates
45
+ // if another row has been written since processing this will
46
+ // handle the auto ID clash
47
+ if (!isEqual(oldTable, table)) {
48
+ try {
49
+ yield db.put(table);
50
+ }
51
+ catch (err) {
52
+ if (err.status === 409) {
53
+ const updatedTable = yield db.get(table._id);
54
+ let response = processAutoColumn(null, updatedTable, row, {
55
+ reprocessing: true,
56
+ });
57
+ yield db.put(response.table);
58
+ row = response.row;
59
+ }
60
+ else {
61
+ throw err;
62
+ }
63
+ }
64
+ }
65
+ const response = yield db.put(row);
66
+ row._rev = response.rev;
67
+ // process the row before return, to include relationships
68
+ row = yield outputProcessing(ctx, table, row, { squash: false });
69
+ return { row, table };
70
+ });
71
+ }
72
+ // doesn't do the outputProcessing
73
+ function getRawTableData(ctx, db, tableId) {
74
+ return __awaiter(this, void 0, void 0, function* () {
75
+ let rows;
76
+ if (tableId === InternalTables.USER_METADATA) {
77
+ yield userController.fetchMetadata(ctx);
78
+ rows = ctx.body;
79
+ }
80
+ else {
81
+ const response = yield db.allDocs(getRowParams(tableId, null, {
82
+ include_docs: true,
83
+ }));
84
+ rows = response.rows.map(row => row.doc);
85
+ }
86
+ return rows;
87
+ });
88
+ }
41
89
  function getView(db, viewName) {
42
90
  return __awaiter(this, void 0, void 0, function* () {
43
91
  let mainGetter = env.SELF_HOSTED ? getFromDesignDoc : getFromMemoryDoc;
@@ -66,24 +114,9 @@ function getView(db, viewName) {
66
114
  return viewInfo;
67
115
  });
68
116
  }
69
- function getRawTableData(ctx, db, tableId) {
70
- return __awaiter(this, void 0, void 0, function* () {
71
- let rows;
72
- if (tableId === InternalTables.USER_METADATA) {
73
- yield userController.fetchMetadata(ctx);
74
- rows = ctx.body;
75
- }
76
- else {
77
- const response = yield db.allDocs(getRowParams(tableId, null, {
78
- include_docs: true,
79
- }));
80
- rows = response.rows.map(row => row.doc);
81
- }
82
- return rows;
83
- });
84
- }
85
117
  exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
86
- const db = getAppDB();
118
+ const appId = ctx.appId;
119
+ const db = new CouchDB(appId);
87
120
  const inputs = ctx.request.body;
88
121
  const tableId = inputs.tableId;
89
122
  const isUserTable = tableId === InternalTables.USER_METADATA;
@@ -122,27 +155,26 @@ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
122
155
  }
123
156
  // returned row is cleaned and prepared for writing to DB
124
157
  row = yield linkRows.updateLinks({
158
+ appId,
125
159
  eventType: linkRows.EventType.ROW_UPDATE,
126
160
  row,
127
161
  tableId: row.tableId,
128
162
  table,
129
163
  });
130
164
  // check if any attachments removed
131
- yield cleanupAttachments(table, { oldRow, row });
165
+ yield cleanupAttachments(appId, table, { oldRow, row });
132
166
  if (isUserTable) {
133
167
  // the row has been updated, need to put it into the ctx
134
168
  ctx.request.body = row;
135
169
  yield userController.updateMetadata(ctx);
136
170
  return { row: ctx.body, table };
137
171
  }
138
- return finaliseRow(table, row, {
139
- oldTable: dbTable,
140
- updateFormula: true,
141
- });
172
+ return storeResponse(ctx, db, row, dbTable, table);
142
173
  });
143
174
  exports.save = function (ctx) {
144
175
  return __awaiter(this, void 0, void 0, function* () {
145
- const db = getAppDB();
176
+ const appId = ctx.appId;
177
+ const db = new CouchDB(appId);
146
178
  let inputs = ctx.request.body;
147
179
  inputs.tableId = ctx.params.tableId;
148
180
  if (!inputs._rev && !inputs._id) {
@@ -160,25 +192,24 @@ exports.save = function (ctx) {
160
192
  }
161
193
  // make sure link rows are up to date
162
194
  row = yield linkRows.updateLinks({
195
+ appId,
163
196
  eventType: linkRows.EventType.ROW_SAVE,
164
197
  row,
165
198
  tableId: row.tableId,
166
199
  table,
167
200
  });
168
- return finaliseRow(table, row, {
169
- oldTable: dbTable,
170
- updateFormula: true,
171
- });
201
+ return storeResponse(ctx, db, row, dbTable, table);
172
202
  });
173
203
  };
174
204
  exports.fetchView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
205
+ const appId = ctx.appId;
175
206
  const viewName = ctx.params.viewName;
176
207
  // if this is a table view being looked for just transfer to that
177
208
  if (viewName.startsWith(DocumentTypes.TABLE)) {
178
209
  ctx.params.tableId = viewName;
179
210
  return exports.fetch(ctx);
180
211
  }
181
- const db = getAppDB();
212
+ const db = new CouchDB(appId);
182
213
  const { calculation, group, field } = ctx.query;
183
214
  const viewInfo = yield getView(db, viewName);
184
215
  let response;
@@ -206,7 +237,7 @@ exports.fetchView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
206
237
  schema: {},
207
238
  };
208
239
  }
209
- rows = yield outputProcessing(table, response.rows);
240
+ rows = yield outputProcessing(ctx, table, response.rows);
210
241
  }
211
242
  if (calculation === CALCULATION_TYPES.STATS) {
212
243
  response.rows = response.rows.map(row => (Object.assign(Object.assign({ group: row.key, field }, row.value), { avg: row.value.sum / row.value.count })));
@@ -223,22 +254,25 @@ exports.fetchView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
223
254
  return rows;
224
255
  });
225
256
  exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
226
- const db = getAppDB();
257
+ const appId = ctx.appId;
258
+ const db = new CouchDB(appId);
227
259
  const tableId = ctx.params.tableId;
228
260
  let table = yield db.get(tableId);
229
261
  let rows = yield getRawTableData(ctx, db, tableId);
230
- return outputProcessing(table, rows);
262
+ return outputProcessing(ctx, table, rows);
231
263
  });
232
264
  exports.find = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
233
- const db = getAppDB();
265
+ const appId = ctx.appId;
266
+ const db = new CouchDB(appId);
234
267
  const table = yield db.get(ctx.params.tableId);
235
- let row = yield findRow(ctx, ctx.params.tableId, ctx.params.rowId);
236
- row = yield outputProcessing(table, row);
268
+ let row = yield findRow(ctx, db, ctx.params.tableId, ctx.params.rowId);
269
+ row = yield outputProcessing(ctx, table, row);
237
270
  return row;
238
271
  });
239
272
  exports.destroy = function (ctx) {
240
273
  return __awaiter(this, void 0, void 0, function* () {
241
- const db = getAppDB();
274
+ const appId = ctx.appId;
275
+ const db = new CouchDB(appId);
242
276
  const { _id, _rev } = ctx.request.body;
243
277
  let row = yield db.get(_id);
244
278
  if (row.tableId !== ctx.params.tableId) {
@@ -246,17 +280,16 @@ exports.destroy = function (ctx) {
246
280
  }
247
281
  const table = yield db.get(row.tableId);
248
282
  // update the row to include full relationships before deleting them
249
- row = yield outputProcessing(table, row, { squash: false });
283
+ row = yield outputProcessing(ctx, table, row, { squash: false });
250
284
  // now remove the relationships
251
285
  yield linkRows.updateLinks({
286
+ appId,
252
287
  eventType: linkRows.EventType.ROW_DELETE,
253
288
  row,
254
289
  tableId: row.tableId,
255
290
  });
256
291
  // remove any attachments that were on the row from object storage
257
- yield cleanupAttachments(table, { row });
258
- // remove any static formula
259
- yield updateRelatedFormula(table, row);
292
+ yield cleanupAttachments(appId, table, { row });
260
293
  let response;
261
294
  if (ctx.params.tableId === InternalTables.USER_METADATA) {
262
295
  ctx.params = {
@@ -272,15 +305,17 @@ exports.destroy = function (ctx) {
272
305
  });
273
306
  };
274
307
  exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
275
- const db = getAppDB();
308
+ const appId = ctx.appId;
309
+ const db = new CouchDB(appId);
276
310
  const tableId = ctx.params.tableId;
277
311
  const table = yield db.get(tableId);
278
312
  let { rows } = ctx.request.body;
279
313
  // before carrying out any updates, make sure the rows are ready to be returned
280
314
  // they need to be the full rows (including previous relationships) for automations
281
- rows = yield outputProcessing(table, rows, { squash: false });
315
+ rows = yield outputProcessing(ctx, table, rows, { squash: false });
282
316
  // remove the relationships first
283
317
  let updates = rows.map(row => linkRows.updateLinks({
318
+ appId,
284
319
  eventType: linkRows.EventType.ROW_DELETE,
285
320
  row,
286
321
  tableId: row.tableId,
@@ -297,8 +332,7 @@ exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
297
332
  yield db.bulkDocs(rows.map(row => (Object.assign(Object.assign({}, row), { _deleted: true }))));
298
333
  }
299
334
  // remove any attachments that were on the rows from object storage
300
- yield cleanupAttachments(table, { rows });
301
- yield updateRelatedFormula(table, rows);
335
+ yield cleanupAttachments(appId, table, { rows });
302
336
  yield Promise.all(updates);
303
337
  return { response: { ok: true }, rows };
304
338
  });
@@ -307,46 +341,50 @@ exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
307
341
  if (env.isCypress()) {
308
342
  return { rows: yield exports.fetch(ctx) };
309
343
  }
344
+ const appId = ctx.appId;
310
345
  const { tableId } = ctx.params;
311
- const db = getAppDB();
346
+ const db = new CouchDB(appId);
312
347
  const _a = ctx.request.body, { paginate, query } = _a, params = __rest(_a, ["paginate", "query"]);
313
348
  params.version = ctx.version;
314
349
  params.tableId = tableId;
315
350
  let response;
316
351
  if (paginate) {
317
- response = yield paginatedSearch(query, params);
352
+ response = yield paginatedSearch(appId, query, params);
318
353
  }
319
354
  else {
320
- response = yield fullSearch(query, params);
355
+ response = yield fullSearch(appId, query, params);
321
356
  }
322
357
  // Enrich search results with relationships
323
358
  if (response.rows && response.rows.length) {
324
359
  // enrich with global users if from users table
325
360
  if (tableId === InternalTables.USER_METADATA) {
326
- response.rows = yield getGlobalUsersFromMetadata(response.rows);
361
+ response.rows = yield getGlobalUsersFromMetadata(appId, response.rows);
327
362
  }
328
363
  const table = yield db.get(tableId);
329
- response.rows = yield outputProcessing(table, response.rows);
364
+ response.rows = yield outputProcessing(ctx, table, response.rows);
330
365
  }
331
366
  return response;
332
367
  });
333
368
  exports.validate = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
334
369
  return validate({
370
+ appId: ctx.appId,
335
371
  tableId: ctx.params.tableId,
336
372
  row: ctx.request.body,
337
373
  });
338
374
  });
339
375
  exports.fetchEnrichedRow = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
340
- const db = getAppDB();
376
+ const appId = ctx.appId;
377
+ const db = new CouchDB(appId);
341
378
  const tableId = ctx.params.tableId;
342
379
  const rowId = ctx.params.rowId;
343
380
  // need table to work out where links go in row
344
381
  let [table, row] = yield Promise.all([
345
382
  db.get(tableId),
346
- findRow(ctx, tableId, rowId),
383
+ findRow(ctx, db, tableId, rowId),
347
384
  ]);
348
385
  // get the link docs
349
386
  const linkVals = yield linkRows.getLinkDocuments({
387
+ appId,
350
388
  tableId,
351
389
  rowId,
352
390
  });
@@ -370,7 +408,7 @@ exports.fetchEnrichedRow = (ctx) => __awaiter(void 0, void 0, void 0, function*
370
408
  let linkedRows = [];
371
409
  for (let [tableId, rows] of Object.entries(groups)) {
372
410
  // need to include the IDs in these rows for any links they may have
373
- linkedRows = linkedRows.concat(yield outputProcessing(tables[tableId], rows));
411
+ linkedRows = linkedRows.concat(yield outputProcessing(ctx, tables[tableId], rows));
374
412
  }
375
413
  // insert the link rows in the correct place throughout the main row
376
414
  for (let fieldName of Object.keys(table.schema)) {
@@ -11,13 +11,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  const { SearchIndexes } = require("../../../db/utils");
12
12
  const fetch = require("node-fetch");
13
13
  const { getCouchUrl } = require("@budibase/backend-core/db");
14
- const { getAppId } = require("@budibase/backend-core/context");
15
14
  /**
16
15
  * Class to build lucene query URLs.
17
16
  * Optionally takes a base lucene query object.
18
17
  */
19
18
  class QueryBuilder {
20
- constructor(base) {
19
+ constructor(appId, base) {
20
+ this.appId = appId;
21
21
  this.query = Object.assign({ string: {}, fuzzy: {}, range: {}, equal: {}, notEqual: {}, empty: {}, notEmpty: {} }, base);
22
22
  this.limit = 50;
23
23
  this.sortOrder = "ascending";
@@ -34,27 +34,19 @@ class QueryBuilder {
34
34
  return this;
35
35
  }
36
36
  setLimit(limit) {
37
- if (limit != null) {
38
- this.limit = limit;
39
- }
37
+ this.limit = limit;
40
38
  return this;
41
39
  }
42
40
  setSort(sort) {
43
- if (sort != null) {
44
- this.sort = sort;
45
- }
41
+ this.sort = sort;
46
42
  return this;
47
43
  }
48
44
  setSortOrder(sortOrder) {
49
- if (sortOrder != null) {
50
- this.sortOrder = sortOrder;
51
- }
45
+ this.sortOrder = sortOrder;
52
46
  return this;
53
47
  }
54
48
  setSortType(sortType) {
55
- if (sortType != null) {
56
- this.sortType = sortType;
57
- }
49
+ this.sortType = sortType;
58
50
  return this;
59
51
  }
60
52
  setBookmark(bookmark) {
@@ -221,8 +213,7 @@ class QueryBuilder {
221
213
  }
222
214
  run() {
223
215
  return __awaiter(this, void 0, void 0, function* () {
224
- const appId = getAppId();
225
- const url = `${getCouchUrl()}/${appId}/_design/database/_search/${SearchIndexes.ROWS}`;
216
+ const url = `${getCouchUrl()}/${this.appId}/_design/database/_search/${SearchIndexes.ROWS}`;
226
217
  const body = this.buildSearchBody();
227
218
  return yield runQuery(url, body);
228
219
  });
@@ -255,6 +246,7 @@ const runQuery = (url, body) => __awaiter(void 0, void 0, void 0, function* () {
255
246
  * Gets round the fixed limit of 200 results from a query by fetching as many
256
247
  * pages as required and concatenating the results. This recursively operates
257
248
  * until enough results have been found.
249
+ * @param appId {string} The app ID to search
258
250
  * @param query {object} The JSON query structure
259
251
  * @param params {object} The search params including:
260
252
  * tableId {string} The table ID to search
@@ -267,7 +259,7 @@ const runQuery = (url, body) => __awaiter(void 0, void 0, void 0, function* () {
267
259
  * rows {array|null} Current results in the recursive search
268
260
  * @returns {Promise<*[]|*>}
269
261
  */
270
- const recursiveSearch = (query, params) => __awaiter(void 0, void 0, void 0, function* () {
262
+ const recursiveSearch = (appId, query, params) => __awaiter(void 0, void 0, void 0, function* () {
271
263
  const bookmark = params.bookmark;
272
264
  const rows = params.rows || [];
273
265
  if (rows.length >= params.limit) {
@@ -277,7 +269,7 @@ const recursiveSearch = (query, params) => __awaiter(void 0, void 0, void 0, fun
277
269
  if (rows.length > params.limit - 200) {
278
270
  pageSize = params.limit - rows.length;
279
271
  }
280
- const page = yield new QueryBuilder(query)
272
+ const page = yield new QueryBuilder(appId, query)
281
273
  .setVersion(params.version)
282
274
  .setTable(params.tableId)
283
275
  .setBookmark(bookmark)
@@ -293,12 +285,13 @@ const recursiveSearch = (query, params) => __awaiter(void 0, void 0, void 0, fun
293
285
  return [...rows, ...page.rows];
294
286
  }
295
287
  const newParams = Object.assign(Object.assign({}, params), { bookmark: page.bookmark, rows: [...rows, ...page.rows] });
296
- return yield recursiveSearch(query, newParams);
288
+ return yield recursiveSearch(appId, query, newParams);
297
289
  });
298
290
  /**
299
291
  * Performs a paginated search. A bookmark will be returned to allow the next
300
292
  * page to be fetched. There is a max limit off 200 results per page in a
301
293
  * paginated search.
294
+ * @param appId {string} The app ID to search
302
295
  * @param query {object} The JSON query structure
303
296
  * @param params {object} The search params including:
304
297
  * tableId {string} The table ID to search
@@ -310,13 +303,13 @@ const recursiveSearch = (query, params) => __awaiter(void 0, void 0, void 0, fun
310
303
  * bookmark {string} The bookmark to resume from
311
304
  * @returns {Promise<{hasNextPage: boolean, rows: *[]}>}
312
305
  */
313
- exports.paginatedSearch = (query, params) => __awaiter(void 0, void 0, void 0, function* () {
306
+ exports.paginatedSearch = (appId, query, params) => __awaiter(void 0, void 0, void 0, function* () {
314
307
  let limit = params.limit;
315
308
  if (limit == null || isNaN(limit) || limit < 0) {
316
309
  limit = 50;
317
310
  }
318
311
  limit = Math.min(limit, 200);
319
- const search = new QueryBuilder(query)
312
+ const search = new QueryBuilder(appId, query)
320
313
  .setVersion(params.version)
321
314
  .setTable(params.tableId)
322
315
  .setSort(params.sort)
@@ -339,6 +332,7 @@ exports.paginatedSearch = (query, params) => __awaiter(void 0, void 0, void 0, f
339
332
  * desired amount of results. There is a limit of 1000 results to avoid
340
333
  * heavy performance hits, and to avoid client components breaking from
341
334
  * handling too much data.
335
+ * @param appId {string} The app ID to search
342
336
  * @param query {object} The JSON query structure
343
337
  * @param params {object} The search params including:
344
338
  * tableId {string} The table ID to search
@@ -349,12 +343,12 @@ exports.paginatedSearch = (query, params) => __awaiter(void 0, void 0, void 0, f
349
343
  * limit {number} The desired number of results
350
344
  * @returns {Promise<{rows: *}>}
351
345
  */
352
- exports.fullSearch = (query, params) => __awaiter(void 0, void 0, void 0, function* () {
346
+ exports.fullSearch = (appId, query, params) => __awaiter(void 0, void 0, void 0, function* () {
353
347
  let limit = params.limit;
354
348
  if (limit == null || isNaN(limit) || limit < 0) {
355
349
  limit = 1000;
356
350
  }
357
351
  params.limit = Math.min(limit, 1000);
358
- const rows = yield recursiveSearch(query, params);
352
+ const rows = yield recursiveSearch(appId, query, params);
359
353
  return { rows };
360
354
  });
@@ -10,12 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  const validateJs = require("validate.js");
12
12
  const { cloneDeep } = require("lodash/fp");
13
+ const CouchDB = require("../../../db");
13
14
  const { InternalTables } = require("../../../db/utils");
14
15
  const userController = require("../user");
15
16
  const { FieldTypes } = require("../../../constants");
16
17
  const { processStringSync } = require("@budibase/string-templates");
17
18
  const { makeExternalQuery } = require("../../../integrations/base/utils");
18
- const { getAppDB } = require("@budibase/backend-core/context");
19
19
  validateJs.extend(validateJs.validators.datetime, {
20
20
  parse: function (value) {
21
21
  return new Date(value).getTime();
@@ -25,14 +25,13 @@ validateJs.extend(validateJs.validators.datetime, {
25
25
  return new Date(value).toISOString();
26
26
  },
27
27
  });
28
- exports.getDatasourceAndQuery = (json) => __awaiter(void 0, void 0, void 0, function* () {
28
+ exports.getDatasourceAndQuery = (appId, json) => __awaiter(void 0, void 0, void 0, function* () {
29
29
  const datasourceId = json.endpoint.datasourceId;
30
- const db = getAppDB();
30
+ const db = new CouchDB(appId);
31
31
  const datasource = yield db.get(datasourceId);
32
32
  return makeExternalQuery(datasource, json);
33
33
  });
34
- exports.findRow = (ctx, tableId, rowId) => __awaiter(void 0, void 0, void 0, function* () {
35
- const db = getAppDB();
34
+ exports.findRow = (ctx, db, tableId, rowId) => __awaiter(void 0, void 0, void 0, function* () {
36
35
  let row;
37
36
  // TODO remove special user case in future
38
37
  if (tableId === InternalTables.USER_METADATA) {
@@ -50,9 +49,9 @@ exports.findRow = (ctx, tableId, rowId) => __awaiter(void 0, void 0, void 0, fun
50
49
  }
51
50
  return row;
52
51
  });
53
- exports.validate = ({ tableId, row, table }) => __awaiter(void 0, void 0, void 0, function* () {
52
+ exports.validate = ({ appId, tableId, row, table }) => __awaiter(void 0, void 0, void 0, function* () {
54
53
  if (!table) {
55
- const db = getAppDB();
54
+ const db = new CouchDB(appId);
56
55
  table = yield db.get(tableId);
57
56
  }
58
57
  const errors = {};
@@ -65,17 +64,19 @@ exports.validate = ({ tableId, row, table }) => __awaiter(void 0, void 0, void 0
65
64
  }
66
65
  let res;
67
66
  // Validate.js doesn't seem to handle array
68
- if (type === FieldTypes.ARRAY && row[fieldName]) {
69
- if (row[fieldName].length) {
67
+ if (type === FieldTypes.ARRAY) {
68
+ const hasValues = Array.isArray(row[fieldName]) && row[fieldName].length > 0;
69
+ // Check values are valid if values are specified
70
+ if (hasValues) {
70
71
  row[fieldName].map(val => {
71
72
  if (!constraints.inclusion.includes(val)) {
72
- errors[fieldName] = "Field not in list";
73
+ errors[fieldName] = "Value not in list";
73
74
  }
74
75
  });
75
76
  }
76
- else if (constraints.presence && row[fieldName].length === 0) {
77
- // non required MultiSelect creates an empty array, which should not throw errors
78
- errors[fieldName] = [`${fieldName} is required`];
77
+ // Check for required constraint
78
+ if (constraints.presence === true && !hasValues) {
79
+ errors[fieldName] = "Required field";
79
80
  }
80
81
  }
81
82
  else if (type === FieldTypes.JSON && typeof row[fieldName] === "string") {
@@ -8,18 +8,20 @@ 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 { getScreenParams, generateScreenID } = require("../../db/utils");
12
13
  const { AccessController } = require("@budibase/backend-core/roles");
13
- const { getAppDB } = require("@budibase/backend-core/context");
14
14
  exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
15
- const db = getAppDB();
15
+ const appId = ctx.appId;
16
+ const db = new CouchDB(appId);
16
17
  const screens = (yield db.allDocs(getScreenParams(null, {
17
18
  include_docs: true,
18
19
  }))).rows.map(element => element.doc);
19
- ctx.body = yield new AccessController().checkScreensAccess(screens, ctx.user.role._id);
20
+ ctx.body = yield new AccessController(appId).checkScreensAccess(screens, ctx.user.role._id);
20
21
  });
21
22
  exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
22
- const db = getAppDB();
23
+ const appId = ctx.appId;
24
+ const db = new CouchDB(appId);
23
25
  let screen = ctx.request.body;
24
26
  if (!screen._id) {
25
27
  screen._id = generateScreenID();
@@ -29,7 +31,7 @@ exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
29
31
  ctx.body = Object.assign(Object.assign({}, screen), { _id: response.id, _rev: response.rev });
30
32
  });
31
33
  exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
32
- const db = getAppDB();
34
+ const db = new CouchDB(ctx.appId);
33
35
  yield db.remove(ctx.params.screenId, ctx.params.screenRev);
34
36
  ctx.body = {
35
37
  message: "Screen deleted successfully",
@@ -14,16 +14,14 @@ const { resolve, join } = require("../../../utilities/centralPath");
14
14
  const uuid = require("uuid");
15
15
  const { ObjectStoreBuckets } = require("../../../constants");
16
16
  const { processString } = require("@budibase/string-templates");
17
- const { getAllApps } = require("@budibase/backend-core/db");
17
+ const { getDeployedApps } = require("../../../utilities/workerRequests");
18
+ const CouchDB = require("../../../db");
18
19
  const { loadHandlebarsFile, NODE_MODULES_PATH, TOP_LEVEL_PATH, } = require("../../../utilities/fileSystem");
19
20
  const env = require("../../../environment");
20
21
  const { clientLibraryPath } = require("../../../utilities");
21
22
  const { upload } = require("../../../utilities/fileSystem");
22
23
  const { attachmentsRelativeURL } = require("../../../utilities");
23
24
  const { DocumentTypes } = require("../../../db/utils");
24
- const { getAppDB } = require("@budibase/backend-core/context");
25
- const AWS = require("aws-sdk");
26
- const AWS_REGION = env.AWS_REGION ? env.AWS_REGION : "eu-west-1";
27
25
  function prepareUpload({ s3Key, bucket, metadata, file }) {
28
26
  return __awaiter(this, void 0, void 0, function* () {
29
27
  const response = yield upload({
@@ -43,15 +41,13 @@ function prepareUpload({ s3Key, bucket, metadata, file }) {
43
41
  };
44
42
  });
45
43
  }
46
- function getAppIdFromUrl(ctx) {
44
+ function checkForSelfHostedURL(ctx) {
47
45
  return __awaiter(this, void 0, void 0, function* () {
48
- // the "appId" component of the URL can be the id or the custom url
46
+ // the "appId" component of the URL may actually be a specific self hosted URL
49
47
  let possibleAppUrl = `/${encodeURI(ctx.params.appId).toLowerCase()}`;
50
- // search prod apps for a url that matches, exclude dev where id is always used
51
- const apps = yield getAllApps({ dev: false });
52
- const app = apps.filter(a => a.url && a.url.toLowerCase() === possibleAppUrl)[0];
53
- if (app && app.appId) {
54
- return app.appId;
48
+ const apps = yield getDeployedApps();
49
+ if (apps[possibleAppUrl] && apps[possibleAppUrl].appId) {
50
+ return apps[possibleAppUrl].appId;
55
51
  }
56
52
  else {
57
53
  return ctx.params.appId;
@@ -84,9 +80,12 @@ exports.uploadFile = function (ctx) {
84
80
  };
85
81
  exports.serveApp = function (ctx) {
86
82
  return __awaiter(this, void 0, void 0, function* () {
87
- let appId = yield getAppIdFromUrl(ctx);
83
+ let appId = ctx.params.appId;
84
+ if (env.SELF_HOSTED) {
85
+ appId = yield checkForSelfHostedURL(ctx);
86
+ }
88
87
  const App = require("./templates/BudibaseApp.svelte").default;
89
- const db = getAppDB({ skip_setup: true });
88
+ const db = new CouchDB(appId, { skip_setup: true });
90
89
  const appInfo = yield db.get(DocumentTypes.APP_METADATA);
91
90
  const { head, html, css } = App.render({
92
91
  title: appInfo.name,
@@ -110,51 +109,3 @@ exports.serveClientLibrary = function (ctx) {
110
109
  });
111
110
  });
112
111
  };
113
- exports.getSignedUploadURL = function (ctx) {
114
- var _a, _b, _c;
115
- return __awaiter(this, void 0, void 0, function* () {
116
- const database = getAppDB();
117
- // Ensure datasource is valid
118
- let datasource;
119
- try {
120
- const { datasourceId } = ctx.params;
121
- datasource = yield database.get(datasourceId);
122
- if (!datasource) {
123
- ctx.throw(400, "The specified datasource could not be found");
124
- }
125
- }
126
- catch (error) {
127
- ctx.throw(400, "The specified datasource could not be found");
128
- }
129
- // Ensure we aren't using a custom endpoint
130
- if ((_a = datasource === null || datasource === void 0 ? void 0 : datasource.config) === null || _a === void 0 ? void 0 : _a.endpoint) {
131
- ctx.throw(400, "S3 datasources with custom endpoints are not supported");
132
- }
133
- // Determine type of datasource and generate signed URL
134
- let signedUrl;
135
- let publicUrl;
136
- if (datasource.source === "S3") {
137
- const { bucket, key } = ctx.request.body || {};
138
- if (!bucket || !key) {
139
- ctx.throw(400, "bucket and key values are required");
140
- return;
141
- }
142
- try {
143
- const s3 = new AWS.S3({
144
- region: AWS_REGION,
145
- accessKeyId: (_b = datasource === null || datasource === void 0 ? void 0 : datasource.config) === null || _b === void 0 ? void 0 : _b.accessKeyId,
146
- secretAccessKey: (_c = datasource === null || datasource === void 0 ? void 0 : datasource.config) === null || _c === void 0 ? void 0 : _c.secretAccessKey,
147
- apiVersion: "2006-03-01",
148
- signatureVersion: "v4",
149
- });
150
- const params = { Bucket: bucket, Key: key };
151
- signedUrl = s3.getSignedUrl("putObject", params);
152
- publicUrl = `https://${bucket}.s3.${AWS_REGION}.amazonaws.com/${key}`;
153
- }
154
- catch (error) {
155
- ctx.throw(400, error);
156
- }
157
- }
158
- ctx.body = { signedUrl, publicUrl };
159
- });
160
- };