@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
@@ -22,21 +22,19 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  const datasource_1 = require("../../../definitions/datasource");
24
24
  const utils_1 = require("../../../integrations/utils");
25
- const utils_2 = require("./utils");
26
- const constants_1 = require("../../../constants");
27
- const utils_3 = require("../../../integrations/utils");
28
- const string_templates_1 = require("@budibase/string-templates");
29
- // @ts-ignore
30
- const fp_1 = require("lodash/fp");
31
- const utils_4 = require("../../../utilities/rowProcessor/utils");
32
- // @ts-ignore
33
- const context_1 = require("@budibase/backend-core/context");
34
25
  var External;
35
26
  (function (External) {
27
+ const { getDatasourceAndQuery } = require("./utils");
28
+ const { DataSourceOperation, FieldTypes, RelationshipTypes, } = require("../../../constants");
29
+ const { breakExternalTableId, isSQL } = require("../../../integrations/utils");
30
+ const { processObjectSync } = require("@budibase/string-templates");
31
+ const { cloneDeep } = require("lodash/fp");
32
+ const CouchDB = require("../../../db");
33
+ const { processFormulas } = require("../../../utilities/rowProcessor/utils");
36
34
  function buildFilters(id, filters, table) {
37
35
  const primary = table.primary;
38
36
  // if passed in array need to copy for shifting etc
39
- let idCopy = fp_1.cloneDeep(id);
37
+ let idCopy = cloneDeep(id);
40
38
  if (filters) {
41
39
  // need to map over the filters and make sure the _id field isn't present
42
40
  for (let filter of Object.values(filters)) {
@@ -79,10 +77,10 @@ var External;
79
77
  */
80
78
  function cleanupConfig(config, table) {
81
79
  const primaryOptions = [
82
- constants_1.FieldTypes.STRING,
83
- constants_1.FieldTypes.LONGFORM,
84
- constants_1.FieldTypes.OPTIONS,
85
- constants_1.FieldTypes.NUMBER,
80
+ FieldTypes.STRING,
81
+ FieldTypes.LONGFORM,
82
+ FieldTypes.OPTIONS,
83
+ FieldTypes.NUMBER,
86
84
  ];
87
85
  // filter out fields which cannot be keys
88
86
  const fieldNames = Object.entries(table.schema)
@@ -135,7 +133,7 @@ var External;
135
133
  if (!tableId) {
136
134
  return {};
137
135
  }
138
- const { datasourceId, tableName } = utils_3.breakExternalTableId(tableId);
136
+ const { datasourceId, tableName } = breakExternalTableId(tableId);
139
137
  return {
140
138
  datasourceId,
141
139
  entityId: tableName,
@@ -155,11 +153,11 @@ var External;
155
153
  thisRow._id = generateIdForRow(row, table);
156
154
  thisRow.tableId = table._id;
157
155
  thisRow._rev = "rev";
158
- return utils_4.processFormulas(table, thisRow);
156
+ return thisRow;
159
157
  }
160
158
  function fixArrayTypes(row, table) {
161
159
  for (let [fieldName, schema] of Object.entries(table.schema)) {
162
- if (schema.type === constants_1.FieldTypes.ARRAY &&
160
+ if (schema.type === FieldTypes.ARRAY &&
163
161
  typeof row[fieldName] === "string") {
164
162
  try {
165
163
  row[fieldName] = JSON.parse(row[fieldName]);
@@ -176,8 +174,9 @@ var External;
176
174
  return (field.relationshipType && field.relationshipType.split("-")[0] === "one");
177
175
  }
178
176
  class ExternalRequest {
179
- constructor(operation, tableId, datasource) {
177
+ constructor(appId, operation, tableId, datasource) {
180
178
  this.tables = {};
179
+ this.appId = appId;
181
180
  this.operation = operation;
182
181
  this.tableId = tableId;
183
182
  this.datasource = datasource;
@@ -189,10 +188,8 @@ var External;
189
188
  if (!tableId) {
190
189
  throw "Table ID is unknown, cannot find table";
191
190
  }
192
- const { tableName } = utils_3.breakExternalTableId(tableId);
193
- if (tableName) {
194
- return this.tables[tableName];
195
- }
191
+ const { tableName } = breakExternalTableId(tableId);
192
+ return this.tables[tableName];
196
193
  }
197
194
  inputProcessing(row, table) {
198
195
  if (!row) {
@@ -207,7 +204,7 @@ var External;
207
204
  if (row[key] == null ||
208
205
  newRow[key] ||
209
206
  field.autocolumn ||
210
- field.type === constants_1.FieldTypes.FORMULA) {
207
+ field.type === FieldTypes.FORMULA) {
211
208
  continue;
212
209
  }
213
210
  // if its an empty string then it means return the column to null (if possible)
@@ -216,17 +213,17 @@ var External;
216
213
  continue;
217
214
  }
218
215
  // parse floats/numbers
219
- if (field.type === constants_1.FieldTypes.NUMBER && !isNaN(parseFloat(row[key]))) {
216
+ if (field.type === FieldTypes.NUMBER && !isNaN(parseFloat(row[key]))) {
220
217
  newRow[key] = parseFloat(row[key]);
221
218
  }
222
219
  // if its not a link then just copy it over
223
- if (field.type !== constants_1.FieldTypes.LINK) {
220
+ if (field.type !== FieldTypes.LINK) {
224
221
  newRow[key] = row[key];
225
222
  continue;
226
223
  }
227
- const { tableName: linkTableName } = utils_3.breakExternalTableId(field === null || field === void 0 ? void 0 : field.tableId);
224
+ const { tableName: linkTableName } = breakExternalTableId(field.tableId);
228
225
  // table has to exist for many to many
229
- if (!linkTableName || !this.tables[linkTableName]) {
226
+ if (!this.tables[linkTableName]) {
230
227
  continue;
231
228
  }
232
229
  const linkTable = this.tables[linkTableName];
@@ -278,24 +275,14 @@ var External;
278
275
  * This iterates through the returned rows and works out what elements of the rows
279
276
  * actually match up to another row (based on primary keys) - this is pretty specific
280
277
  * to SQL and the way that SQL relationships are returned based on joins.
281
- * This is complicated, but the idea is that when a SQL query returns all the relations
282
- * will be separate rows, with all of the data in each row. We have to decipher what comes
283
- * from where (which tables) and how to convert that into budibase columns.
284
278
  */
285
- updateRelationshipColumns(table, row, rows, relationships) {
279
+ updateRelationshipColumns(row, rows, relationships) {
286
280
  const columns = {};
287
281
  for (let relationship of relationships) {
288
282
  const linkedTable = this.tables[relationship.tableName];
289
283
  if (!linkedTable) {
290
284
  continue;
291
285
  }
292
- const fromColumn = `${table.name}.${relationship.from}`;
293
- const toColumn = `${linkedTable.name}.${relationship.to}`;
294
- // this is important when working with multiple relationships
295
- // between the same tables, don't want to overlap/multiply the relations
296
- if (!relationship.through && row[fromColumn] !== row[toColumn]) {
297
- continue;
298
- }
299
286
  let linked = basicProcessing(row, linkedTable);
300
287
  if (!linked._id) {
301
288
  continue;
@@ -333,7 +320,7 @@ var External;
333
320
  row._id = rowId;
334
321
  // this is a relationship of some sort
335
322
  if (finalRows[rowId]) {
336
- finalRows = this.updateRelationshipColumns(table, row, finalRows, relationships);
323
+ finalRows = this.updateRelationshipColumns(row, finalRows, relationships);
337
324
  continue;
338
325
  }
339
326
  const thisRow = fixArrayTypes(basicProcessing(row, table), table);
@@ -342,9 +329,9 @@ var External;
342
329
  }
343
330
  finalRows[thisRow._id] = thisRow;
344
331
  // do this at end once its been added to the final rows
345
- finalRows = this.updateRelationshipColumns(table, row, finalRows, relationships);
332
+ finalRows = this.updateRelationshipColumns(row, finalRows, relationships);
346
333
  }
347
- return utils_4.processFormulas(table, Object.values(finalRows));
334
+ return processFormulas(table, Object.values(finalRows));
348
335
  }
349
336
  /**
350
337
  * Gets the list of relationship JSON structures based on the columns in the table,
@@ -354,12 +341,12 @@ var External;
354
341
  buildRelationships(table) {
355
342
  const relationships = [];
356
343
  for (let [fieldName, field] of Object.entries(table.schema)) {
357
- if (field.type !== constants_1.FieldTypes.LINK) {
344
+ if (field.type !== FieldTypes.LINK) {
358
345
  continue;
359
346
  }
360
- const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
347
+ const { tableName: linkTableName } = breakExternalTableId(field.tableId);
361
348
  // no table to link to, this is not a valid relationships
362
- if (!linkTableName || !this.tables[linkTableName]) {
349
+ if (!this.tables[linkTableName]) {
363
350
  continue;
364
351
  }
365
352
  const linkTable = this.tables[linkTableName];
@@ -375,7 +362,7 @@ var External;
375
362
  column: fieldName,
376
363
  };
377
364
  if (field.through) {
378
- const { tableName: throughTableName } = utils_3.breakExternalTableId(field.through);
365
+ const { tableName: throughTableName } = breakExternalTableId(field.through);
379
366
  definition.through = throughTableName;
380
367
  // don't support composite keys for relationships
381
368
  definition.from = field.throughTo || table.primary[0];
@@ -394,24 +381,21 @@ var External;
394
381
  lookupRelations(tableId, row) {
395
382
  return __awaiter(this, void 0, void 0, function* () {
396
383
  const related = {};
397
- const { tableName } = utils_3.breakExternalTableId(tableId);
398
- if (!tableName) {
399
- return related;
400
- }
384
+ const { tableName } = breakExternalTableId(tableId);
401
385
  const table = this.tables[tableName];
402
386
  // @ts-ignore
403
387
  const primaryKey = table.primary[0];
404
388
  // make a new request to get the row with all its relationships
405
389
  // we need this to work out if any relationships need removed
406
390
  for (let field of Object.values(table.schema)) {
407
- if (field.type !== constants_1.FieldTypes.LINK ||
391
+ if (field.type !== FieldTypes.LINK ||
408
392
  !field.fieldName ||
409
393
  isOneSide(field)) {
410
394
  continue;
411
395
  }
412
- const isMany = field.relationshipType === constants_1.RelationshipTypes.MANY_TO_MANY;
396
+ const isMany = field.relationshipType === RelationshipTypes.MANY_TO_MANY;
413
397
  const tableId = isMany ? field.through : field.tableId;
414
- const { tableName: relatedTableName } = utils_3.breakExternalTableId(tableId);
398
+ const { tableName: relatedTableName } = breakExternalTableId(tableId);
415
399
  // @ts-ignore
416
400
  const linkPrimaryKey = this.tables[relatedTableName].primary[0];
417
401
  const manyKey = field.throughTo || primaryKey;
@@ -420,8 +404,8 @@ var External;
420
404
  if (!lookupField || !row[lookupField]) {
421
405
  continue;
422
406
  }
423
- const response = yield utils_2.getDatasourceAndQuery({
424
- endpoint: getEndpoint(tableId, constants_1.DataSourceOperation.READ),
407
+ const response = yield getDatasourceAndQuery(this.appId, {
408
+ endpoint: getEndpoint(tableId, DataSourceOperation.READ),
425
409
  filters: {
426
410
  equal: {
427
411
  [fieldName]: row[lookupField],
@@ -447,27 +431,26 @@ var External;
447
431
  * all and then re-create, as theres no chance of losing data (e.g. delete succeed, but write fail).
448
432
  */
449
433
  handleManyRelationships(mainTableId, row, relationships) {
434
+ var _a;
450
435
  return __awaiter(this, void 0, void 0, function* () {
436
+ const { appId } = this;
451
437
  // if we're creating (in a through table) need to wipe the existing ones first
452
438
  const promises = [];
453
439
  const related = yield this.lookupRelations(mainTableId, row);
454
440
  for (let relationship of relationships) {
455
441
  const { key, tableId, isUpdate, id } = relationship, rest = __rest(relationship, ["key", "tableId", "isUpdate", "id"]);
456
- const body = string_templates_1.processObjectSync(rest, row, {});
442
+ const body = processObjectSync(rest, row);
457
443
  const linkTable = this.getTable(tableId);
458
444
  // @ts-ignore
459
- const linkPrimary = linkTable === null || linkTable === void 0 ? void 0 : linkTable.primary[0];
460
- if (!linkTable || !linkPrimary) {
461
- return;
462
- }
463
- const rows = related[key].rows || [];
445
+ const linkPrimary = linkTable.primary[0];
446
+ const rows = ((_a = related[key]) === null || _a === void 0 ? void 0 : _a.rows) || [];
464
447
  const found = rows.find((row) => row[linkPrimary] === relationship.id ||
465
- row[linkPrimary] === (body === null || body === void 0 ? void 0 : body[linkPrimary]));
448
+ row[linkPrimary] === body[linkPrimary]);
466
449
  const operation = isUpdate
467
- ? constants_1.DataSourceOperation.UPDATE
468
- : constants_1.DataSourceOperation.CREATE;
450
+ ? DataSourceOperation.UPDATE
451
+ : DataSourceOperation.CREATE;
469
452
  if (!found) {
470
- promises.push(utils_2.getDatasourceAndQuery({
453
+ promises.push(getDatasourceAndQuery(appId, {
471
454
  endpoint: getEndpoint(tableId, operation),
472
455
  // if we're doing many relationships then we're writing, only one response
473
456
  body,
@@ -483,8 +466,7 @@ var External;
483
466
  for (let [colName, { isMany, rows, tableId }] of Object.entries(related)) {
484
467
  const table = this.getTable(tableId);
485
468
  // if its not the foreign key skip it, nothing to do
486
- if (!table ||
487
- (table.primary && table.primary.indexOf(colName) !== -1)) {
469
+ if (table.primary && table.primary.indexOf(colName) !== -1) {
488
470
  continue;
489
471
  }
490
472
  for (let row of rows) {
@@ -492,10 +474,10 @@ var External;
492
474
  // safety check, if there are no filters on deletion bad things happen
493
475
  if (Object.keys(filters).length !== 0) {
494
476
  const op = isMany
495
- ? constants_1.DataSourceOperation.DELETE
496
- : constants_1.DataSourceOperation.UPDATE;
477
+ ? DataSourceOperation.DELETE
478
+ : DataSourceOperation.UPDATE;
497
479
  const body = isMany ? null : { [colName]: null };
498
- promises.push(utils_2.getDatasourceAndQuery({
480
+ promises.push(getDatasourceAndQuery(this.appId, {
499
481
  endpoint: getEndpoint(tableId, op),
500
482
  body,
501
483
  filters,
@@ -516,36 +498,31 @@ var External;
516
498
  buildFields(table, includeRelations = datasource_1.IncludeRelationships.INCLUDE) {
517
499
  function extractRealFields(table, existing = []) {
518
500
  return Object.entries(table.schema)
519
- .filter(column => column[1].type !== constants_1.FieldTypes.LINK &&
520
- column[1].type !== constants_1.FieldTypes.FORMULA &&
501
+ .filter(column => column[1].type !== FieldTypes.LINK &&
502
+ column[1].type !== FieldTypes.FORMULA &&
521
503
  !existing.find((field) => field === column[0]))
522
504
  .map(column => `${table.name}.${column[0]}`);
523
505
  }
524
506
  let fields = extractRealFields(table);
525
507
  for (let field of Object.values(table.schema)) {
526
- if (field.type !== constants_1.FieldTypes.LINK || !includeRelations) {
508
+ if (field.type !== FieldTypes.LINK || !includeRelations) {
527
509
  continue;
528
510
  }
529
- const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
530
- if (linkTableName) {
531
- const linkTable = this.tables[linkTableName];
532
- if (linkTable) {
533
- const linkedFields = extractRealFields(linkTable, fields);
534
- fields = fields.concat(linkedFields);
535
- }
511
+ const { tableName: linkTableName } = breakExternalTableId(field.tableId);
512
+ const linkTable = this.tables[linkTableName];
513
+ if (linkTable) {
514
+ const linkedFields = extractRealFields(linkTable, fields);
515
+ fields = fields.concat(linkedFields);
536
516
  }
537
517
  }
538
518
  return fields;
539
519
  }
540
520
  run(config) {
541
521
  return __awaiter(this, void 0, void 0, function* () {
542
- const { operation, tableId } = this;
543
- let { datasourceId, tableName } = utils_3.breakExternalTableId(tableId);
544
- if (!tableName) {
545
- throw "Unable to run without a table name";
546
- }
522
+ const { appId, operation, tableId } = this;
523
+ let { datasourceId, tableName } = breakExternalTableId(tableId);
547
524
  if (!this.datasource) {
548
- const db = context_1.getAppDB();
525
+ const db = new CouchDB(appId);
549
526
  this.datasource = yield db.get(datasourceId);
550
527
  if (!this.datasource || !this.datasource.entities) {
551
528
  throw "No tables found, fetch tables before query.";
@@ -553,7 +530,7 @@ var External;
553
530
  this.tables = this.datasource.entities;
554
531
  }
555
532
  const table = this.tables[tableName];
556
- let isSql = utils_3.isSQL(this.datasource);
533
+ let isSql = isSQL(this.datasource);
557
534
  if (!table) {
558
535
  throw `Unable to process query, table "${tableName}" not defined.`;
559
536
  }
@@ -564,7 +541,7 @@ var External;
564
541
  // clean up row on ingress using schema
565
542
  const processed = this.inputProcessing(row, table);
566
543
  row = processed.row;
567
- if (operation === constants_1.DataSourceOperation.DELETE &&
544
+ if (operation === DataSourceOperation.DELETE &&
568
545
  (filters == null || Object.keys(filters).length === 0)) {
569
546
  throw "Deletion must be filtered";
570
547
  }
@@ -592,15 +569,15 @@ var External;
592
569
  },
593
570
  };
594
571
  // can't really use response right now
595
- const response = yield utils_2.getDatasourceAndQuery(json);
572
+ const response = yield getDatasourceAndQuery(appId, json);
596
573
  // handle many to many relationships now if we know the ID (could be auto increment)
597
- if (operation !== constants_1.DataSourceOperation.READ &&
574
+ if (operation !== DataSourceOperation.READ &&
598
575
  processed.manyRelationships) {
599
576
  yield this.handleManyRelationships(table._id || "", response[0], processed.manyRelationships);
600
577
  }
601
578
  const output = this.outputProcessing(response, table, relationships);
602
579
  // if reading it'll just be an array of rows, return whole thing
603
- return operation === constants_1.DataSourceOperation.READ && Array.isArray(response)
580
+ return operation === DataSourceOperation.READ && Array.isArray(response)
604
581
  ? output
605
582
  : { row: output[0], table };
606
583
  });
@@ -22,8 +22,8 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  const { DataSourceOperation, SortDirection, FieldTypes, NoEmptyFilterStrings, } = require("../../../constants");
23
23
  const { breakExternalTableId, breakRowIdField, } = require("../../../integrations/utils");
24
24
  const ExternalRequest = require("./ExternalRequest");
25
- const { getAppDB } = require("@budibase/backend-core/context");
26
- function handleRequest(operation, tableId, opts = {}) {
25
+ const CouchDB = require("../../../db");
26
+ function handleRequest(appId, operation, tableId, opts = {}) {
27
27
  return __awaiter(this, void 0, void 0, function* () {
28
28
  // make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
29
29
  if (opts && opts.filters) {
@@ -38,25 +38,27 @@ function handleRequest(operation, tableId, opts = {}) {
38
38
  }
39
39
  }
40
40
  }
41
- return new ExternalRequest(operation, tableId, opts.datasource).run(opts);
41
+ return new ExternalRequest(appId, operation, tableId, opts.datasource).run(opts);
42
42
  });
43
43
  }
44
44
  exports.handleRequest = handleRequest;
45
45
  exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
46
+ const appId = ctx.appId;
46
47
  const inputs = ctx.request.body;
47
48
  const tableId = ctx.params.tableId;
48
49
  const id = breakRowIdField(inputs._id);
49
50
  // don't save the ID to db
50
51
  delete inputs._id;
51
- return handleRequest(DataSourceOperation.UPDATE, tableId, {
52
+ return handleRequest(appId, DataSourceOperation.UPDATE, tableId, {
52
53
  id,
53
54
  row: inputs,
54
55
  });
55
56
  });
56
57
  exports.save = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
58
+ const appId = ctx.appId;
57
59
  const inputs = ctx.request.body;
58
60
  const tableId = ctx.params.tableId;
59
- return handleRequest(DataSourceOperation.CREATE, tableId, {
61
+ return handleRequest(appId, DataSourceOperation.CREATE, tableId, {
60
62
  row: inputs,
61
63
  });
62
64
  });
@@ -68,31 +70,35 @@ exports.fetchView = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
68
70
  return exports.fetch(ctx);
69
71
  });
70
72
  exports.fetch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
73
+ const appId = ctx.appId;
71
74
  const tableId = ctx.params.tableId;
72
- return handleRequest(DataSourceOperation.READ, tableId);
75
+ return handleRequest(appId, DataSourceOperation.READ, tableId);
73
76
  });
74
77
  exports.find = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
78
+ const appId = ctx.appId;
75
79
  const id = ctx.params.rowId;
76
80
  const tableId = ctx.params.tableId;
77
- const response = yield handleRequest(DataSourceOperation.READ, tableId, {
81
+ const response = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
78
82
  id,
79
83
  });
80
84
  return response ? response[0] : response;
81
85
  });
82
86
  exports.destroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
87
+ const appId = ctx.appId;
83
88
  const tableId = ctx.params.tableId;
84
89
  const id = ctx.request.body._id;
85
- const { row } = yield handleRequest(DataSourceOperation.DELETE, tableId, {
90
+ const { row } = yield handleRequest(appId, DataSourceOperation.DELETE, tableId, {
86
91
  id,
87
92
  });
88
93
  return { response: { ok: true }, row };
89
94
  });
90
95
  exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
96
+ const appId = ctx.appId;
91
97
  const { rows } = ctx.request.body;
92
98
  const tableId = ctx.params.tableId;
93
99
  let promises = [];
94
100
  for (let row of rows) {
95
- promises.push(handleRequest(DataSourceOperation.DELETE, tableId, {
101
+ promises.push(handleRequest(appId, DataSourceOperation.DELETE, tableId, {
96
102
  id: breakRowIdField(row._id),
97
103
  }));
98
104
  }
@@ -100,6 +106,7 @@ exports.bulkDestroy = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
100
106
  return { response: { ok: true }, rows: responses.map(resp => resp.row) };
101
107
  });
102
108
  exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
109
+ const appId = ctx.appId;
103
110
  const tableId = ctx.params.tableId;
104
111
  const _a = ctx.request.body, { paginate, query } = _a, params = __rest(_a, ["paginate", "query"]);
105
112
  let { bookmark, limit } = params;
@@ -128,14 +135,14 @@ exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
128
135
  [params.sort]: direction,
129
136
  };
130
137
  }
131
- const rows = yield handleRequest(DataSourceOperation.READ, tableId, {
138
+ const rows = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
132
139
  filters: query,
133
140
  sort,
134
141
  paginate: paginateObj,
135
142
  });
136
143
  let hasNextPage = false;
137
144
  if (paginate && rows.length === limit) {
138
- const nextRows = yield handleRequest(DataSourceOperation.READ, tableId, {
145
+ const nextRows = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
139
146
  filters: query,
140
147
  sort,
141
148
  paginate: {
@@ -153,16 +160,17 @@ exports.validate = () => __awaiter(void 0, void 0, void 0, function* () {
153
160
  return { valid: true };
154
161
  });
155
162
  exports.fetchEnrichedRow = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
163
+ const appId = ctx.appId;
156
164
  const id = ctx.params.rowId;
157
165
  const tableId = ctx.params.tableId;
158
166
  const { datasourceId, tableName } = breakExternalTableId(tableId);
159
- const db = getAppDB();
167
+ const db = new CouchDB(appId);
160
168
  const datasource = yield db.get(datasourceId);
161
169
  if (!datasource || !datasource.entities) {
162
170
  ctx.throw(400, "Datasource has not been configured for plus API.");
163
171
  }
164
172
  const tables = datasource.entities;
165
- const response = yield handleRequest(DataSourceOperation.READ, tableId, {
173
+ const response = yield handleRequest(appId, DataSourceOperation.READ, tableId, {
166
174
  id,
167
175
  datasource,
168
176
  });
@@ -181,7 +189,7 @@ exports.fetchEnrichedRow = (ctx) => __awaiter(void 0, void 0, void 0, function*
181
189
  const linkedTable = tables[breakExternalTableId(linkedTableId).tableName];
182
190
  // don't support composite keys right now
183
191
  const linkedIds = links.map(link => breakRowIdField(link._id)[0]);
184
- row[fieldName] = yield handleRequest(DataSourceOperation.READ, linkedTableId, {
192
+ row[fieldName] = yield handleRequest(appId, DataSourceOperation.READ, linkedTableId, {
185
193
  tables,
186
194
  filters: {
187
195
  oneOf: {