@budibase/server 1.0.49 → 1.0.50-alpha.0

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 (381) hide show
  1. package/__mocks__/arangojs.ts +1 -1
  2. package/__mocks__/aws-sdk.ts +4 -4
  3. package/__mocks__/mongodb.ts +4 -5
  4. package/__mocks__/mssql.ts +3 -3
  5. package/__mocks__/node-fetch.ts +2 -1
  6. package/__mocks__/pg.ts +3 -5
  7. package/builder/assets/index.c0cc369d.css +6 -0
  8. package/builder/assets/{index.2c37968e.js → index.ff2bad21.js} +252 -249
  9. package/builder/assets/{vendor.f9faf6ab.js → vendor.5ad9695a.js} +202 -106
  10. package/builder/index.html +3 -3
  11. package/coverage/clover.xml +3105 -2814
  12. package/coverage/coverage-final.json +106 -101
  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 +257 -152
  16. package/coverage/lcov-report/api/controllers/auth.js.html +22 -13
  17. package/coverage/lcov-report/api/controllers/automation.js.html +39 -69
  18. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/cloud.js.html +8 -11
  20. package/coverage/lcov-report/api/controllers/component.js.html +13 -16
  21. package/coverage/lcov-report/api/controllers/datasource.js.html +81 -51
  22. package/coverage/lcov-report/api/controllers/dev.js.html +6 -6
  23. package/coverage/lcov-report/api/controllers/index.html +78 -78
  24. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/layout.js.html +9 -9
  26. package/coverage/lcov-report/api/controllers/metadata.js.html +6 -21
  27. package/coverage/lcov-report/api/controllers/migrations.js.html +119 -0
  28. package/coverage/lcov-report/api/controllers/permission.js.html +19 -19
  29. package/coverage/lcov-report/api/controllers/query/index.html +10 -10
  30. package/coverage/lcov-report/api/controllers/query/index.js.html +38 -35
  31. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  32. package/coverage/lcov-report/api/controllers/role.js.html +16 -16
  33. package/coverage/lcov-report/api/controllers/routing.js.html +7 -10
  34. package/coverage/lcov-report/api/controllers/row/external.js.html +48 -141
  35. package/coverage/lcov-report/api/controllers/row/index.html +55 -40
  36. package/coverage/lcov-report/api/controllers/row/index.js.html +26 -26
  37. package/coverage/lcov-report/api/controllers/row/internal.js.html +118 -226
  38. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +52 -34
  39. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +548 -0
  40. package/coverage/lcov-report/api/controllers/row/utils.js.html +47 -62
  41. package/coverage/lcov-report/api/controllers/screen.js.html +15 -21
  42. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  43. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +599 -0
  44. package/coverage/lcov-report/api/controllers/table/external.js.html +25 -34
  45. package/coverage/lcov-report/api/controllers/table/index.html +58 -43
  46. package/coverage/lcov-report/api/controllers/table/index.js.html +58 -82
  47. package/coverage/lcov-report/api/controllers/table/internal.js.html +81 -66
  48. package/coverage/lcov-report/api/controllers/table/utils.js.html +218 -110
  49. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  50. package/coverage/lcov-report/api/controllers/user.js.html +79 -76
  51. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  52. package/coverage/lcov-report/api/controllers/view/index.html +16 -16
  53. package/coverage/lcov-report/api/controllers/view/index.js.html +27 -33
  54. package/coverage/lcov-report/api/controllers/view/utils.js.html +35 -20
  55. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  56. package/coverage/lcov-report/api/controllers/webhook.js.html +34 -28
  57. package/coverage/lcov-report/api/index.html +1 -1
  58. package/coverage/lcov-report/api/index.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/index.html +18 -18
  71. package/coverage/lcov-report/api/routes/index.js.html +3 -3
  72. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/{hosting.js.html → migrations.js.html} +17 -14
  76. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  82. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  83. package/coverage/lcov-report/api/routes/static.js.html +17 -2
  84. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  85. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  86. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  87. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  88. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  89. package/coverage/lcov-report/automations/actions.js.html +24 -24
  90. package/coverage/lcov-report/automations/automationUtils.js.html +7 -10
  91. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  92. package/coverage/lcov-report/automations/index.html +18 -18
  93. package/coverage/lcov-report/automations/index.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/createRow.js.html +13 -22
  96. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  97. package/coverage/lcov-report/automations/steps/deleteRow.js.html +11 -20
  98. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  99. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  100. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  101. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  102. package/coverage/lcov-report/automations/steps/index.html +13 -13
  103. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  104. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  105. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  106. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  107. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  108. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  109. package/coverage/lcov-report/automations/steps/updateRow.js.html +7 -7
  110. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  111. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  112. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  115. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  116. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  117. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  118. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  119. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  120. package/coverage/lcov-report/automations/triggers.js.html +61 -55
  121. package/coverage/lcov-report/automations/utils.js.html +54 -42
  122. package/coverage/lcov-report/constants/index.html +5 -5
  123. package/coverage/lcov-report/constants/index.js.html +53 -26
  124. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  125. package/coverage/lcov-report/constants/screens.js.html +4 -4
  126. package/coverage/lcov-report/db/client.js.html +18 -18
  127. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  128. package/coverage/lcov-report/db/index.html +15 -15
  129. package/coverage/lcov-report/db/index.js.html +3 -3
  130. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +25 -37
  131. package/coverage/lcov-report/db/linkedRows/index.html +27 -27
  132. package/coverage/lcov-report/db/linkedRows/index.js.html +51 -96
  133. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +42 -42
  134. package/coverage/lcov-report/db/newid.js.html +4 -4
  135. package/coverage/lcov-report/db/utils.js.html +87 -87
  136. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  137. package/coverage/lcov-report/events/index.html +1 -1
  138. package/coverage/lcov-report/events/index.js.html +5 -5
  139. package/coverage/lcov-report/events/utils.js.html +3 -3
  140. package/coverage/lcov-report/index.html +135 -120
  141. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  142. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  143. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  144. package/coverage/lcov-report/middleware/authorized.js.html +173 -65
  145. package/coverage/lcov-report/middleware/builder.js.html +10 -10
  146. package/coverage/lcov-report/middleware/currentapp.js.html +95 -83
  147. package/coverage/lcov-report/middleware/index.html +38 -38
  148. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  149. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  150. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  151. package/coverage/lcov-report/middleware/usageQuota.js.html +281 -53
  152. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  153. package/coverage/lcov-report/threads/automation.js.html +30 -24
  154. package/coverage/lcov-report/threads/index.html +26 -26
  155. package/coverage/lcov-report/threads/index.js.html +10 -10
  156. package/coverage/lcov-report/threads/query.js.html +39 -24
  157. package/coverage/lcov-report/threads/utils.js.html +14 -14
  158. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  159. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  160. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  161. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  162. package/coverage/lcov-report/utilities/global.js.html +58 -49
  163. package/coverage/lcov-report/utilities/index.html +37 -37
  164. package/coverage/lcov-report/utilities/index.js.html +43 -73
  165. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  166. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  167. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  168. package/coverage/lcov-report/utilities/routing/index.js.html +7 -7
  169. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  170. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +97 -103
  171. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
  172. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  173. package/coverage/lcov-report/utilities/security.js.html +8 -8
  174. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  175. package/coverage/lcov-report/utilities/usageQuota/index.html +141 -0
  176. package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
  177. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +305 -0
  178. package/coverage/lcov-report/{api/controllers/hosting.js.html → utilities/usageQuota/usageQuoteReset.js.html} +36 -48
  179. package/coverage/lcov-report/utilities/users.js.html +9 -9
  180. package/coverage/lcov-report/utilities/workerRequests.js.html +43 -112
  181. package/coverage/lcov.info +5010 -4425
  182. package/dist/api/controllers/application.js +90 -60
  183. package/dist/api/controllers/auth.js +8 -5
  184. package/dist/api/controllers/automation.js +14 -19
  185. package/dist/api/controllers/cloud.js +2 -3
  186. package/dist/api/controllers/component.js +3 -4
  187. package/dist/api/controllers/datasource.js +20 -10
  188. package/dist/api/controllers/deploy/Deployment.js +3 -6
  189. package/dist/api/controllers/deploy/index.js +12 -13
  190. package/dist/api/controllers/dev.js +5 -5
  191. package/dist/api/controllers/layout.js +3 -3
  192. package/dist/api/controllers/metadata.js +4 -4
  193. package/dist/api/controllers/migrations.js +21 -0
  194. package/dist/api/controllers/permission.js +4 -4
  195. package/dist/api/controllers/query/import/index.js +4 -6
  196. package/dist/api/controllers/query/index.js +11 -10
  197. package/dist/api/controllers/role.js +5 -5
  198. package/dist/api/controllers/routing.js +5 -6
  199. package/dist/api/controllers/row/ExternalRequest.js +90 -67
  200. package/dist/api/controllers/row/external.js +14 -22
  201. package/dist/api/controllers/row/internal.js +55 -93
  202. package/dist/api/controllers/row/internalSearch.js +23 -17
  203. package/dist/api/controllers/row/staticFormula.js +147 -0
  204. package/dist/api/controllers/row/utils.js +13 -14
  205. package/dist/api/controllers/screen.js +5 -7
  206. package/dist/api/controllers/static/index.js +62 -16
  207. package/dist/api/controllers/table/bulkFormula.js +159 -0
  208. package/dist/api/controllers/table/external.js +7 -10
  209. package/dist/api/controllers/table/index.js +16 -13
  210. package/dist/api/controllers/table/internal.js +22 -16
  211. package/dist/api/controllers/table/utils.js +62 -35
  212. package/dist/api/controllers/user.js +43 -43
  213. package/dist/api/controllers/view/index.js +8 -10
  214. package/dist/api/controllers/view/utils.js +9 -4
  215. package/dist/api/controllers/webhook.js +10 -8
  216. package/dist/api/routes/index.js +2 -2
  217. package/dist/api/routes/migrations.js +9 -0
  218. package/dist/api/routes/static.js +2 -1
  219. package/dist/api/routes/tests/utilities/TestFunctions.js +37 -17
  220. package/dist/app.js +35 -5
  221. package/dist/automations/automationUtils.js +2 -3
  222. package/dist/automations/steps/createRow.js +3 -5
  223. package/dist/automations/steps/deleteRow.js +1 -4
  224. package/dist/automations/steps/updateRow.js +1 -1
  225. package/dist/automations/triggers.js +27 -25
  226. package/dist/automations/utils.js +10 -5
  227. package/dist/constants/index.js +7 -0
  228. package/dist/db/linkedRows/LinkController.js +3 -7
  229. package/dist/db/linkedRows/index.js +16 -27
  230. package/dist/db/linkedRows/linkUtils.js +6 -6
  231. package/dist/db/views/staticViews.js +9 -10
  232. package/dist/definitions/datasource.js +1 -0
  233. package/dist/environment.js +4 -1
  234. package/dist/integrations/base/sql.js +62 -21
  235. package/dist/integrations/googlesheets.js +340 -0
  236. package/dist/integrations/index.js +3 -0
  237. package/dist/integrations/utils.js +60 -9
  238. package/dist/middleware/authorized.js +57 -30
  239. package/dist/middleware/builder.js +2 -2
  240. package/dist/middleware/currentapp.js +41 -37
  241. package/dist/middleware/usageQuota.js +82 -15
  242. package/dist/migrations/functions/appUrls.js +46 -0
  243. package/dist/migrations/functions/quotas1.js +50 -0
  244. package/dist/migrations/functions/usageQuotas/index.js +20 -0
  245. package/dist/migrations/functions/usageQuotas/syncApps.js +29 -0
  246. package/dist/migrations/functions/usageQuotas/syncRows.js +33 -0
  247. package/dist/migrations/functions/userEmailViewCasing.js +24 -0
  248. package/dist/migrations/index.js +62 -0
  249. package/dist/package.json +8 -5
  250. package/dist/tests/utilities/TestConfiguration.js +80 -50
  251. package/dist/threads/automation.js +13 -11
  252. package/dist/threads/query.js +15 -11
  253. package/dist/tsconfig.tsbuildinfo +1 -1
  254. package/dist/utilities/fileSystem/index.js +4 -3
  255. package/dist/utilities/global.js +15 -12
  256. package/dist/utilities/index.js +7 -17
  257. package/dist/utilities/routing/index.js +5 -5
  258. package/dist/utilities/rowProcessor/index.js +23 -17
  259. package/dist/utilities/rowProcessor/utils.js +14 -4
  260. package/dist/utilities/{usageQuota.js → usageQuota/index.js} +45 -31
  261. package/dist/utilities/usageQuota/rows.js +78 -0
  262. package/dist/utilities/usageQuota/usageQuoteReset.js +16 -0
  263. package/dist/utilities/users.js +3 -3
  264. package/dist/utilities/workerRequests.js +4 -24
  265. package/nodemon.json +1 -1
  266. package/package.json +9 -6
  267. package/scripts/integrations/mssql/data/Dockerfile +1 -1
  268. package/scripts/integrations/mssql/data/setup.sql +17 -4
  269. package/scripts/integrations/postgres/init.sql +11 -6
  270. package/scripts/likeCypress.ts +1 -1
  271. package/src/api/controllers/application.js +85 -50
  272. package/src/api/controllers/auth.js +8 -5
  273. package/src/api/controllers/automation.js +13 -23
  274. package/src/api/controllers/cloud.js +2 -3
  275. package/src/api/controllers/component.js +3 -4
  276. package/src/api/controllers/datasource.js +21 -11
  277. package/src/api/controllers/deploy/Deployment.js +3 -7
  278. package/src/api/controllers/deploy/index.js +20 -13
  279. package/src/api/controllers/dev.js +5 -5
  280. package/src/api/controllers/layout.js +3 -3
  281. package/src/api/controllers/metadata.js +4 -9
  282. package/src/api/controllers/migrations.js +13 -0
  283. package/src/api/controllers/permission.js +4 -4
  284. package/src/api/controllers/query/import/index.ts +4 -6
  285. package/src/api/controllers/query/import/tests/index.spec.js +2 -1
  286. package/src/api/controllers/query/index.js +11 -10
  287. package/src/api/controllers/role.js +5 -5
  288. package/src/api/controllers/routing.js +5 -6
  289. package/src/api/controllers/row/ExternalRequest.ts +67 -43
  290. package/src/api/controllers/row/external.js +27 -58
  291. package/src/api/controllers/row/internal.js +54 -90
  292. package/src/api/controllers/row/internalSearch.js +23 -17
  293. package/src/api/controllers/row/staticFormula.js +156 -0
  294. package/src/api/controllers/row/utils.js +13 -18
  295. package/src/api/controllers/screen.js +5 -7
  296. package/src/api/controllers/static/index.js +66 -15
  297. package/src/api/controllers/table/bulkFormula.js +173 -0
  298. package/src/api/controllers/table/external.js +7 -10
  299. package/src/api/controllers/table/index.js +20 -28
  300. package/src/api/controllers/table/internal.js +24 -19
  301. package/src/api/controllers/table/utils.js +78 -42
  302. package/src/api/controllers/user.js +46 -45
  303. package/src/api/controllers/view/index.js +8 -10
  304. package/src/api/controllers/view/utils.js +9 -4
  305. package/src/api/controllers/webhook.js +10 -8
  306. package/src/api/routes/index.js +2 -2
  307. package/src/api/routes/migrations.js +14 -0
  308. package/src/api/routes/static.js +5 -0
  309. package/src/api/routes/tests/application.spec.js +2 -2
  310. package/src/api/routes/tests/auth.spec.js +1 -2
  311. package/src/api/routes/tests/automation.spec.js +1 -0
  312. package/src/api/routes/tests/misc.spec.js +0 -1
  313. package/src/api/routes/tests/routing.spec.js +21 -12
  314. package/src/api/routes/tests/row.spec.js +7 -4
  315. package/src/api/routes/tests/static.spec.js +98 -0
  316. package/src/api/routes/tests/utilities/TestFunctions.js +39 -17
  317. package/src/app.ts +18 -5
  318. package/src/automations/automationUtils.js +2 -3
  319. package/src/automations/steps/createRow.js +2 -5
  320. package/src/automations/steps/deleteRow.js +1 -4
  321. package/src/automations/steps/updateRow.js +1 -1
  322. package/src/automations/triggers.js +33 -31
  323. package/src/automations/utils.js +9 -5
  324. package/src/constants/index.js +9 -0
  325. package/src/db/linkedRows/LinkController.js +3 -7
  326. package/src/db/linkedRows/index.js +16 -31
  327. package/src/db/linkedRows/linkUtils.js +6 -6
  328. package/src/db/tests/linkController.spec.js +0 -1
  329. package/src/db/tests/linkTests.spec.js +5 -6
  330. package/src/db/views/staticViews.js +8 -10
  331. package/src/definitions/common.ts +3 -0
  332. package/src/definitions/datasource.ts +3 -0
  333. package/src/environment.js +4 -1
  334. package/src/integrations/base/sql.ts +75 -29
  335. package/src/integrations/googlesheets.ts +353 -0
  336. package/src/integrations/index.ts +3 -0
  337. package/src/integrations/tests/sql.spec.js +16 -0
  338. package/src/integrations/utils.ts +75 -12
  339. package/src/middleware/authorized.js +66 -30
  340. package/src/middleware/builder.js +2 -2
  341. package/src/middleware/currentapp.js +50 -46
  342. package/src/middleware/tests/authorized.spec.js +13 -6
  343. package/src/middleware/tests/currentapp.spec.js +6 -0
  344. package/src/middleware/tests/usageQuota.spec.js +18 -24
  345. package/src/middleware/usageQuota.js +93 -17
  346. package/src/migrations/functions/appUrls.ts +34 -0
  347. package/src/migrations/functions/quotas1.ts +20 -0
  348. package/src/migrations/functions/tests/appUrls.spec.js +29 -0
  349. package/src/migrations/functions/tests/quotas1.spec.js +27 -0
  350. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
  351. package/src/migrations/functions/usageQuotas/index.ts +8 -0
  352. package/src/migrations/functions/usageQuotas/syncApps.ts +18 -0
  353. package/src/migrations/functions/usageQuotas/syncRows.ts +22 -0
  354. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +37 -0
  355. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +43 -0
  356. package/src/migrations/functions/userEmailViewCasing.ts +13 -0
  357. package/src/migrations/index.ts +56 -0
  358. package/src/module.d.ts +3 -0
  359. package/src/tests/utilities/TestConfiguration.js +82 -55
  360. package/src/threads/automation.js +17 -15
  361. package/src/threads/query.js +17 -12
  362. package/src/utilities/fileSystem/index.js +4 -3
  363. package/src/utilities/global.js +15 -12
  364. package/src/utilities/index.js +7 -17
  365. package/src/utilities/routing/index.js +5 -5
  366. package/src/utilities/rowProcessor/index.js +25 -27
  367. package/src/utilities/rowProcessor/utils.js +23 -7
  368. package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
  369. package/src/utilities/usageQuota/index.js +93 -0
  370. package/src/utilities/usageQuota/rows.js +75 -0
  371. package/src/utilities/usageQuota/usageQuoteReset.js +18 -0
  372. package/src/utilities/users.js +3 -3
  373. package/src/utilities/workerRequests.js +4 -27
  374. package/tsconfig.json +2 -1
  375. package/builder/assets/index.39e01193.css +0 -1
  376. package/dist/api/controllers/hosting.js +0 -30
  377. package/dist/api/routes/hosting.js +0 -11
  378. package/src/api/controllers/hosting.js +0 -22
  379. package/src/api/routes/hosting.js +0 -13
  380. package/src/api/routes/tests/hosting.spec.js +0 -36
  381. package/src/utilities/usageQuota.js +0 -73
@@ -9,12 +9,12 @@ const {
9
9
  getLinkedTable,
10
10
  } = require("./linkUtils")
11
11
  const { flatten } = require("lodash")
12
- const CouchDB = require("../../db")
13
12
  const { FieldTypes } = require("../../constants")
14
13
  const { getMultiIDParams, USER_METDATA_PREFIX } = require("../../db/utils")
15
14
  const { partition } = require("lodash")
16
15
  const { getGlobalUsersFromMetadata } = require("../../utilities/global")
17
16
  const { processFormulas } = require("../../utilities/rowProcessor/utils")
17
+ const { getAppDB } = require("@budibase/backend-core/context")
18
18
 
19
19
  /**
20
20
  * This functionality makes sure that when rows with links are created, updated or deleted they are processed
@@ -48,14 +48,13 @@ function clearRelationshipFields(table, rows) {
48
48
  return rows
49
49
  }
50
50
 
51
- async function getLinksForRows(appId, rows) {
51
+ async function getLinksForRows(rows) {
52
52
  const tableIds = [...new Set(rows.map(el => el.tableId))]
53
53
  // start by getting all the link values for performance reasons
54
54
  const responses = flatten(
55
55
  await Promise.all(
56
56
  tableIds.map(tableId =>
57
57
  getLinkDocuments({
58
- appId,
59
58
  tableId: tableId,
60
59
  includeDocs: IncludeDocs.EXCLUDE,
61
60
  })
@@ -72,9 +71,9 @@ async function getLinksForRows(appId, rows) {
72
71
  )
73
72
  }
74
73
 
75
- async function getFullLinkedDocs(ctx, appId, links) {
74
+ async function getFullLinkedDocs(links) {
76
75
  // create DBs
77
- const db = new CouchDB(appId)
76
+ const db = getAppDB()
78
77
  const linkedRowIds = links.map(link => link.id)
79
78
  const uniqueRowIds = [...new Set(linkedRowIds)]
80
79
  let dbRows = (await db.allDocs(getMultiIDParams(uniqueRowIds))).rows.map(
@@ -88,7 +87,7 @@ async function getFullLinkedDocs(ctx, appId, links) {
88
87
  let [users, other] = partition(linked, linkRow =>
89
88
  linkRow._id.startsWith(USER_METDATA_PREFIX)
90
89
  )
91
- users = await getGlobalUsersFromMetadata(appId, users)
90
+ users = await getGlobalUsersFromMetadata(users)
92
91
  return [...other, ...users]
93
92
  }
94
93
 
@@ -96,20 +95,16 @@ async function getFullLinkedDocs(ctx, appId, links) {
96
95
  * Update link documents for a row or table - this is to be called by the API controller when a change is occurring.
97
96
  * @param {string} args.eventType states what type of change which is occurring, means this can be expanded upon in the
98
97
  * future quite easily (all updates go through one function).
99
- * @param {string} args.appId The ID of the instance in which the change is occurring.
100
98
  * @param {string} args.tableId The ID of the of the table which is being changed.
101
- * @param {object|null} args.row The row which is changing, e.g. created, updated or deleted.
102
- * @param {object|null} args.table If the table has already been retrieved this can be used to reduce database gets.
103
- * @param {object|null} args.oldTable If the table is being updated then the old table can be provided for differencing.
99
+ * @param {object|undefined} args.row The row which is changing, e.g. created, updated or deleted.
100
+ * @param {object|undefined} args.table If the table has already been retrieved this can be used to reduce database gets.
101
+ * @param {object|undefined} args.oldTable If the table is being updated then the old table can be provided for differencing.
104
102
  * @returns {Promise<object>} When the update is complete this will respond successfully. Returns the row for
105
103
  * row operations and the table for table operations.
106
104
  */
107
105
  exports.updateLinks = async function (args) {
108
- const { eventType, appId, row, tableId, table, oldTable } = args
106
+ const { eventType, row, tableId, table, oldTable } = args
109
107
  const baseReturnObj = row == null ? table : row
110
- if (appId == null) {
111
- throw "Cannot operate without an instance ID."
112
- }
113
108
  // make sure table ID is set
114
109
  if (tableId == null && table != null) {
115
110
  args.tableId = table._id
@@ -146,27 +141,23 @@ exports.updateLinks = async function (args) {
146
141
  /**
147
142
  * Given a table and a list of rows this will retrieve all of the attached docs and enrich them into the row.
148
143
  * This is required for formula fields, this may only be utilised internally (for now).
149
- * @param {object} ctx The request which is looking for rows.
150
144
  * @param {object} table The table from which the rows originated.
151
145
  * @param {array<object>} rows The rows which are to be enriched.
152
146
  * @return {Promise<*>} returns the rows with all of the enriched relationships on it.
153
147
  */
154
- exports.attachFullLinkedDocs = async (ctx, table, rows) => {
155
- const appId = ctx.appId
148
+ exports.attachFullLinkedDocs = async (table, rows) => {
156
149
  const linkedTableIds = getLinkedTableIDs(table)
157
150
  if (linkedTableIds.length === 0) {
158
151
  return rows
159
152
  }
160
- // create DBs
161
- const db = new CouchDB(appId)
162
153
  // get all the links
163
- const links = (await getLinksForRows(appId, rows)).filter(link =>
154
+ const links = (await getLinksForRows(rows)).filter(link =>
164
155
  rows.some(row => row._id === link.thisId)
165
156
  )
166
157
  // clear any existing links that could be dupe'd
167
158
  rows = clearRelationshipFields(table, rows)
168
159
  // now get the docs and combine into the rows
169
- let linked = await getFullLinkedDocs(ctx, appId, links)
160
+ let linked = await getFullLinkedDocs(links)
170
161
  const linkedTables = []
171
162
  for (let row of rows) {
172
163
  for (let link of links.filter(link => link.thisId === row._id)) {
@@ -177,11 +168,7 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => {
177
168
  if (linkedRow) {
178
169
  const linkedTableId =
179
170
  linkedRow.tableId || getRelatedTableForField(table, link.fieldName)
180
- const linkedTable = await getLinkedTable(
181
- db,
182
- linkedTableId,
183
- linkedTables
184
- )
171
+ const linkedTable = await getLinkedTable(linkedTableId, linkedTables)
185
172
  if (linkedTable) {
186
173
  row[link.fieldName].push(processFormulas(linkedTable, linkedRow))
187
174
  }
@@ -193,18 +180,16 @@ exports.attachFullLinkedDocs = async (ctx, table, rows) => {
193
180
 
194
181
  /**
195
182
  * This function will take the given enriched rows and squash the links to only contain the primary display field.
196
- * @param {string} appId The app in which the tables/rows/links exist.
197
183
  * @param {object} table The table from which the rows originated.
198
184
  * @param {array<object>} enriched The pre-enriched rows (full docs) which are to be squashed.
199
185
  * @returns {Promise<Array>} The rows after having their links squashed to only contain the ID and primary display.
200
186
  */
201
- exports.squashLinksToPrimaryDisplay = async (appId, table, enriched) => {
202
- const db = new CouchDB(appId)
187
+ exports.squashLinksToPrimaryDisplay = async (table, enriched) => {
203
188
  // will populate this as we find them
204
189
  const linkedTables = [table]
205
190
  for (let row of enriched) {
206
191
  // this only fetches the table if its not already in array
207
- const rowTable = await getLinkedTable(db, row.tableId, linkedTables)
192
+ const rowTable = await getLinkedTable(row.tableId, linkedTables)
208
193
  for (let [column, schema] of Object.entries(rowTable.schema)) {
209
194
  if (schema.type !== FieldTypes.LINK || !Array.isArray(row[column])) {
210
195
  continue
@@ -212,7 +197,7 @@ exports.squashLinksToPrimaryDisplay = async (appId, table, enriched) => {
212
197
  const newLinks = []
213
198
  for (let link of row[column]) {
214
199
  const linkTblId = link.tableId || getRelatedTableForField(table, column)
215
- const linkedTable = await getLinkedTable(db, linkTblId, linkedTables)
200
+ const linkedTable = await getLinkedTable(linkTblId, linkedTables)
216
201
  const obj = { _id: link._id }
217
202
  if (link[linkedTable.primaryDisplay]) {
218
203
  obj.primaryDisplay = link[linkedTable.primaryDisplay]
@@ -1,8 +1,8 @@
1
- const CouchDB = require("../index")
2
1
  const Sentry = require("@sentry/node")
3
2
  const { ViewNames, getQueryIndex } = require("../utils")
4
3
  const { FieldTypes } = require("../../constants")
5
4
  const { createLinkView } = require("../views/staticViews")
5
+ const { getAppDB } = require("@budibase/backend-core/context")
6
6
 
7
7
  /**
8
8
  * Only needed so that boolean parameters are being used for includeDocs
@@ -17,7 +17,6 @@ exports.createLinkView = createLinkView
17
17
 
18
18
  /**
19
19
  * Gets the linking documents, not the linked documents themselves.
20
- * @param {string} args.appId The instance in which we are searching for linked rows.
21
20
  * @param {string} args.tableId The table which we are searching for linked rows against.
22
21
  * @param {string|null} args.fieldName The name of column/field which is being altered, only looking for
23
22
  * linking documents that are related to it. If this is not specified then the table level will be assumed.
@@ -30,8 +29,8 @@ exports.createLinkView = createLinkView
30
29
  * (if any).
31
30
  */
32
31
  exports.getLinkDocuments = async function (args) {
33
- const { appId, tableId, rowId, includeDocs } = args
34
- const db = new CouchDB(appId)
32
+ const { tableId, rowId, includeDocs } = args
33
+ const db = getAppDB()
35
34
  let params
36
35
  if (rowId != null) {
37
36
  params = { key: [tableId, rowId] }
@@ -68,7 +67,7 @@ exports.getLinkDocuments = async function (args) {
68
67
  } catch (err) {
69
68
  // check if the view doesn't exist, it should for all new instances
70
69
  if (err != null && err.name === "not_found") {
71
- await exports.createLinkView(appId)
70
+ await exports.createLinkView()
72
71
  return exports.getLinkDocuments(arguments[0])
73
72
  } else {
74
73
  /* istanbul ignore next */
@@ -89,7 +88,8 @@ exports.getLinkedTableIDs = table => {
89
88
  .map(column => column.tableId)
90
89
  }
91
90
 
92
- exports.getLinkedTable = async (db, id, tables) => {
91
+ exports.getLinkedTable = async (id, tables) => {
92
+ const db = getAppDB()
93
93
  let linkedTable = tables.find(table => table._id === id)
94
94
  if (linkedTable) {
95
95
  return linkedTable
@@ -20,7 +20,6 @@ describe("test the link controller", () => {
20
20
 
21
21
  function createLinkController(table, row = null, oldTable = null) {
22
22
  const linkConfig = {
23
- appId: config.getAppId(),
24
23
  tableId: table._id,
25
24
  table,
26
25
  }
@@ -1,8 +1,8 @@
1
1
  const TestConfig = require("../../tests/utilities/TestConfiguration")
2
- const { basicTable, basicLinkedRow } = require("../../tests/utilities/structures")
2
+ const { basicTable } = require("../../tests/utilities/structures")
3
3
  const linkUtils = require("../linkedRows/linkUtils")
4
- const links = require("../linkedRows")
5
4
  const CouchDB = require("../index")
5
+ const { getAppDB } = require("@budibase/backend-core/context")
6
6
 
7
7
  describe("test link functionality", () => {
8
8
  const config = new TestConfig(false)
@@ -11,18 +11,18 @@ describe("test link functionality", () => {
11
11
  let db, table
12
12
  beforeEach(async () => {
13
13
  await config.init()
14
- db = new CouchDB(config.getAppId())
14
+ db = getAppDB()
15
15
  table = await config.createTable()
16
16
  })
17
17
 
18
18
  it("should be able to retrieve a linked table from a list", async () => {
19
- const retrieved = await linkUtils.getLinkedTable(db, table._id, [table])
19
+ const retrieved = await linkUtils.getLinkedTable(table._id, [table])
20
20
  expect(retrieved._id).toBe(table._id)
21
21
  })
22
22
 
23
23
  it("should be able to retrieve a table from DB and update list", async () => {
24
24
  const tables = []
25
- const retrieved = await linkUtils.getLinkedTable(db, table._id, tables)
25
+ const retrieved = await linkUtils.getLinkedTable(table._id, tables)
26
26
  expect(retrieved._id).toBe(table._id)
27
27
  expect(tables[0]).toBeDefined()
28
28
  })
@@ -51,7 +51,6 @@ describe("test link functionality", () => {
51
51
  const db = new CouchDB("test")
52
52
  await db.put({ _id: "_design/database", views: {} })
53
53
  const output = await linkUtils.getLinkDocuments({
54
- appId: "test",
55
54
  tableId: "test",
56
55
  rowId: "test",
57
56
  includeDocs: false,
@@ -1,4 +1,4 @@
1
- const CouchDB = require("../index")
1
+ const { getAppDB } = require("@budibase/backend-core/context")
2
2
  const {
3
3
  DocumentTypes,
4
4
  SEPARATOR,
@@ -21,12 +21,11 @@ const SCREEN_PREFIX = DocumentTypes.SCREEN + SEPARATOR
21
21
  /**
22
22
  * Creates the link view for the instance, this will overwrite the existing one, but this should only
23
23
  * be called if it is found that the view does not exist.
24
- * @param {string} appId The instance to which the view should be added.
25
24
  * @returns {Promise<void>} The view now exists, please note that the next view of this query will actually build it,
26
25
  * so it may be slow.
27
26
  */
28
- exports.createLinkView = async appId => {
29
- const db = new CouchDB(appId)
27
+ exports.createLinkView = async () => {
28
+ const db = getAppDB()
30
29
  const designDoc = await db.get("_design/database")
31
30
  const view = {
32
31
  map: function (doc) {
@@ -57,8 +56,8 @@ exports.createLinkView = async appId => {
57
56
  await db.put(designDoc)
58
57
  }
59
58
 
60
- exports.createRoutingView = async appId => {
61
- const db = new CouchDB(appId)
59
+ exports.createRoutingView = async () => {
60
+ const db = getAppDB()
62
61
  const designDoc = await db.get("_design/database")
63
62
  const view = {
64
63
  // if using variables in a map function need to inject them before use
@@ -78,8 +77,8 @@ exports.createRoutingView = async appId => {
78
77
  await db.put(designDoc)
79
78
  }
80
79
 
81
- async function searchIndex(appId, indexName, fnString) {
82
- const db = new CouchDB(appId)
80
+ async function searchIndex(indexName, fnString) {
81
+ const db = getAppDB()
83
82
  const designDoc = await db.get("_design/database")
84
83
  designDoc.indexes = {
85
84
  [indexName]: {
@@ -90,9 +89,8 @@ async function searchIndex(appId, indexName, fnString) {
90
89
  await db.put(designDoc)
91
90
  }
92
91
 
93
- exports.createAllSearchIndex = async appId => {
92
+ exports.createAllSearchIndex = async () => {
94
93
  await searchIndex(
95
- appId,
96
94
  SearchIndexes.ROWS,
97
95
  function (doc) {
98
96
  function idx(input, prev) {
@@ -17,6 +17,8 @@ export interface FieldSchema {
17
17
  autocolumn?: boolean
18
18
  throughFrom?: string
19
19
  throughTo?: string
20
+ formula?: string
21
+ formulaType?: string
20
22
  main?: boolean
21
23
  meta?: {
22
24
  toTable: string
@@ -46,6 +48,7 @@ export interface Table extends Base {
46
48
  schema: TableSchema
47
49
  primaryDisplay?: string
48
50
  sourceId?: string
51
+ relatedFormula?: string[]
49
52
  constrained?: string[]
50
53
  }
51
54
 
@@ -47,6 +47,7 @@ export enum SourceNames {
47
47
  ARANGODB = "ARANGODB",
48
48
  REST = "REST",
49
49
  ORACLE = "ORACLE",
50
+ GOOGLE_SHEETS = "GOOGLE_SHEETS",
50
51
  }
51
52
 
52
53
  export enum IncludeRelationships {
@@ -86,6 +87,8 @@ export interface ExtraQueryConfig {
86
87
  export interface Integration {
87
88
  docs: string
88
89
  plus?: boolean
90
+ auth?: { type: string }
91
+ relationships?: boolean
89
92
  description: string
90
93
  friendlyName: string
91
94
  datasource: {}
@@ -2,7 +2,8 @@ function isTest() {
2
2
  return (
3
3
  process.env.NODE_ENV === "jest" ||
4
4
  process.env.NODE_ENV === "cypress" ||
5
- process.env.JEST_WORKER_ID != null
5
+ (process.env.JEST_WORKER_ID != null &&
6
+ process.env.JEST_WORKER_ID !== "null")
6
7
  )
7
8
  }
8
9
 
@@ -38,10 +39,12 @@ module.exports = {
38
39
  MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
39
40
  MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
40
41
  USE_QUOTAS: process.env.USE_QUOTAS,
42
+ EXCLUDE_QUOTAS_TENANTS: process.env.EXCLUDE_QUOTAS_TENANTS,
41
43
  REDIS_URL: process.env.REDIS_URL,
42
44
  REDIS_PASSWORD: process.env.REDIS_PASSWORD,
43
45
  INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
44
46
  MULTI_TENANCY: process.env.MULTI_TENANCY,
47
+ HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
45
48
  // environment
46
49
  NODE_ENV: process.env.NODE_ENV,
47
50
  JEST_WORKER_ID: process.env.JEST_WORKER_ID,
@@ -72,16 +72,22 @@ class InternalBuilder {
72
72
 
73
73
  // right now we only do filters on the specific table being queried
74
74
  addFilters(
75
- tableName: string,
76
75
  query: KnexQuery,
77
- filters: SearchFilters | undefined
76
+ filters: SearchFilters | undefined,
77
+ opts: { relationship?: boolean; tableName?: string }
78
78
  ): KnexQuery {
79
79
  function iterate(
80
80
  structure: { [key: string]: any },
81
81
  fn: (key: string, value: any) => void
82
82
  ) {
83
83
  for (let [key, value] of Object.entries(structure)) {
84
- fn(`${tableName}.${key}`, value)
84
+ const isRelationshipField = key.includes(".")
85
+ if (!opts.relationship && !isRelationshipField) {
86
+ fn(`${opts.tableName}.${key}`, value)
87
+ }
88
+ if (opts.relationship && isRelationshipField) {
89
+ fn(key, value)
90
+ }
85
91
  }
86
92
  }
87
93
  if (!filters) {
@@ -160,15 +166,13 @@ class InternalBuilder {
160
166
 
161
167
  addSorting(query: KnexQuery, json: QueryJson): KnexQuery {
162
168
  let { sort, paginate } = json
163
- if (!sort) {
164
- return query
165
- }
166
169
  const table = json.meta?.table
167
- for (let [key, value] of Object.entries(sort)) {
168
- const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
169
- query = query.orderBy(`${table?.name}.${key}`, direction)
170
- }
171
- if (this.client === SqlClients.MS_SQL && !sort && paginate?.limit) {
170
+ if (sort) {
171
+ for (let [key, value] of Object.entries(sort)) {
172
+ const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
173
+ query = query.orderBy(`${table?.name}.${key}`, direction)
174
+ }
175
+ } else if (this.client === SqlClients.MS_SQL && paginate?.limit) {
172
176
  // @ts-ignore
173
177
  query = query.orderBy(`${table?.name}.${table?.primary[0]}`)
174
178
  }
@@ -185,29 +189,70 @@ class InternalBuilder {
185
189
  if (!relationships) {
186
190
  return query
187
191
  }
192
+ const tableSets: Record<string, [any]> = {}
193
+ // aggregate into table sets (all the same to tables)
188
194
  for (let relationship of relationships) {
189
- const from = relationship.from,
190
- to = relationship.to,
191
- toTable = relationship.tableName
192
- if (!relationship.through) {
195
+ const keyObj: { toTable: string; throughTable: string | undefined } = {
196
+ toTable: relationship.tableName,
197
+ throughTable: undefined,
198
+ }
199
+ if (relationship.through) {
200
+ keyObj.throughTable = relationship.through
201
+ }
202
+ const key = JSON.stringify(keyObj)
203
+ if (tableSets[key]) {
204
+ tableSets[key].push(relationship)
205
+ } else {
206
+ tableSets[key] = [relationship]
207
+ }
208
+ }
209
+ for (let [key, relationships] of Object.entries(tableSets)) {
210
+ const { toTable, throughTable } = JSON.parse(key)
211
+ if (!throughTable) {
193
212
  // @ts-ignore
194
- query = query.leftJoin(
213
+ query = query.join(
195
214
  toTable,
196
- `${fromTable}.${from}`,
197
- `${toTable}.${to}`
215
+ function () {
216
+ for (let relationship of relationships) {
217
+ const from = relationship.from,
218
+ to = relationship.to
219
+ // @ts-ignore
220
+ this.orOn(`${fromTable}.${from}`, "=", `${toTable}.${to}`)
221
+ }
222
+ },
223
+ "left"
198
224
  )
199
225
  } else {
200
- const throughTable = relationship.through
201
- const fromPrimary = relationship.fromPrimary
202
- const toPrimary = relationship.toPrimary
203
226
  query = query
204
227
  // @ts-ignore
205
- .leftJoin(
228
+ .join(
206
229
  throughTable,
207
- `${fromTable}.${fromPrimary}`,
208
- `${throughTable}.${from}`
230
+ function () {
231
+ for (let relationship of relationships) {
232
+ const fromPrimary = relationship.fromPrimary
233
+ const from = relationship.from
234
+ // @ts-ignore
235
+ this.orOn(
236
+ `${fromTable}.${fromPrimary}`,
237
+ "=",
238
+ `${throughTable}.${from}`
239
+ )
240
+ }
241
+ },
242
+ "left"
243
+ )
244
+ .join(
245
+ toTable,
246
+ function () {
247
+ for (let relationship of relationships) {
248
+ const toPrimary = relationship.toPrimary
249
+ const to = relationship.to
250
+ // @ts-ignore
251
+ this.orOn(`${toTable}.${toPrimary}`, `${throughTable}.${to}`)
252
+ }
253
+ },
254
+ "left"
209
255
  )
210
- .leftJoin(toTable, `${toTable}.${toPrimary}`, `${throughTable}.${to}`)
211
256
  }
212
257
  }
213
258
  return query.limit(BASE_LIMIT)
@@ -272,7 +317,7 @@ class InternalBuilder {
272
317
  if (foundOffset) {
273
318
  query = query.offset(foundOffset)
274
319
  }
275
- query = this.addFilters(tableName, query, filters)
320
+ query = this.addFilters(query, filters, { tableName })
276
321
  // add sorting to pre-query
277
322
  query = this.addSorting(query, json)
278
323
  // @ts-ignore
@@ -285,20 +330,21 @@ class InternalBuilder {
285
330
  preQuery = this.addSorting(preQuery, json)
286
331
  }
287
332
  // handle joins
288
- return this.addRelationships(
333
+ query = this.addRelationships(
289
334
  knex,
290
335
  preQuery,
291
336
  selectStatement,
292
337
  tableName,
293
338
  relationships
294
339
  )
340
+ return this.addFilters(query, filters, { relationship: true })
295
341
  }
296
342
 
297
343
  update(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
298
344
  const { endpoint, body, filters } = json
299
345
  let query: KnexQuery = knex(endpoint.entityId)
300
346
  const parsedBody = parseBody(body)
301
- query = this.addFilters(endpoint.entityId, query, filters)
347
+ query = this.addFilters(query, filters, { tableName: endpoint.entityId })
302
348
  // mysql can't use returning
303
349
  if (opts.disableReturning) {
304
350
  return query.update(parsedBody)
@@ -310,7 +356,7 @@ class InternalBuilder {
310
356
  delete(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
311
357
  const { endpoint, filters } = json
312
358
  let query: KnexQuery = knex(endpoint.entityId)
313
- query = this.addFilters(endpoint.entityId, query, filters)
359
+ query = this.addFilters(query, filters, { tableName: endpoint.entityId })
314
360
  // mysql can't use returning
315
361
  if (opts.disableReturning) {
316
362
  return query.delete()