@budibase/server 1.0.123 → 1.0.125

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 (325) hide show
  1. package/builder/assets/index.3d890df7.js +1299 -0
  2. package/builder/assets/index.89795487.css +6 -0
  3. package/builder/assets/{vendor.8e34a169.js → vendor.5240f480.js} +1 -1
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +695 -1678
  6. package/coverage/coverage-final.json +28 -43
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +8 -3
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +9 -4
  9. package/coverage/lcov-report/api/controllers/auth.js.html +8 -3
  10. package/coverage/lcov-report/api/controllers/automation.js.html +8 -3
  11. package/coverage/lcov-report/api/controllers/backup.js.html +8 -3
  12. package/coverage/lcov-report/api/controllers/cloud.js.html +8 -3
  13. package/coverage/lcov-report/api/controllers/component.js.html +8 -3
  14. package/coverage/lcov-report/api/controllers/datasource.js.html +11 -6
  15. package/coverage/lcov-report/api/controllers/dev.js.html +8 -3
  16. package/coverage/lcov-report/api/controllers/index.html +16 -26
  17. package/coverage/lcov-report/api/controllers/integration.js.html +8 -3
  18. package/coverage/lcov-report/api/controllers/layout.js.html +8 -3
  19. package/coverage/lcov-report/api/controllers/metadata.js.html +8 -3
  20. package/coverage/lcov-report/api/controllers/migrations.js.html +8 -3
  21. package/coverage/lcov-report/api/controllers/permission.js.html +8 -3
  22. package/coverage/lcov-report/api/controllers/query/index.html +16 -26
  23. package/coverage/lcov-report/api/controllers/query/validation.js.html +8 -3
  24. package/coverage/lcov-report/api/controllers/role.js.html +10 -5
  25. package/coverage/lcov-report/api/controllers/routing.js.html +9 -4
  26. package/coverage/lcov-report/api/controllers/row/external.js.html +8 -3
  27. package/coverage/lcov-report/api/controllers/row/index.html +25 -35
  28. package/coverage/lcov-report/api/controllers/row/internal.js.html +32 -24
  29. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +21 -16
  30. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -19
  31. package/coverage/lcov-report/api/controllers/row/utils.js.html +33 -19
  32. package/coverage/lcov-report/api/controllers/screen.js.html +9 -4
  33. package/coverage/lcov-report/api/controllers/script.js.html +8 -3
  34. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +55 -50
  35. package/coverage/lcov-report/api/controllers/table/external.js.html +8 -3
  36. package/coverage/lcov-report/api/controllers/table/index.html +19 -44
  37. package/coverage/lcov-report/api/controllers/table/index.js.html +20 -15
  38. package/coverage/lcov-report/api/controllers/templates.js.html +8 -3
  39. package/coverage/lcov-report/api/controllers/user.js.html +8 -3
  40. package/coverage/lcov-report/api/controllers/view/exporters.js.html +8 -3
  41. package/coverage/lcov-report/api/controllers/view/index.html +8 -3
  42. package/coverage/lcov-report/api/controllers/view/index.js.html +10 -5
  43. package/coverage/lcov-report/api/controllers/view/utils.js.html +8 -3
  44. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +8 -3
  45. package/coverage/lcov-report/api/controllers/webhook.js.html +10 -5
  46. package/coverage/lcov-report/api/index.html +18 -13
  47. package/coverage/lcov-report/api/index.js.html +28 -8
  48. package/coverage/lcov-report/api/routes/analytics.js.html +8 -3
  49. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -3
  50. package/coverage/lcov-report/api/routes/auth.js.html +8 -3
  51. package/coverage/lcov-report/api/routes/automation.js.html +8 -3
  52. package/coverage/lcov-report/api/routes/backup.js.html +8 -3
  53. package/coverage/lcov-report/api/routes/cloud.js.html +8 -3
  54. package/coverage/lcov-report/api/routes/component.js.html +8 -3
  55. package/coverage/lcov-report/api/routes/datasource.js.html +8 -3
  56. package/coverage/lcov-report/api/routes/deploy.js.html +8 -3
  57. package/coverage/lcov-report/api/routes/dev.js.html +9 -4
  58. package/coverage/lcov-report/api/routes/index.html +13 -68
  59. package/coverage/lcov-report/api/routes/integration.js.html +8 -3
  60. package/coverage/lcov-report/api/routes/layout.js.html +8 -3
  61. package/coverage/lcov-report/api/routes/metadata.js.html +8 -3
  62. package/coverage/lcov-report/api/routes/migrations.js.html +8 -3
  63. package/coverage/lcov-report/api/routes/permission.js.html +8 -3
  64. package/coverage/lcov-report/api/routes/query.js.html +8 -3
  65. package/coverage/lcov-report/api/routes/role.js.html +8 -3
  66. package/coverage/lcov-report/api/routes/routing.js.html +8 -3
  67. package/coverage/lcov-report/api/routes/screen.js.html +8 -3
  68. package/coverage/lcov-report/api/routes/script.js.html +8 -3
  69. package/coverage/lcov-report/api/routes/table.js.html +8 -3
  70. package/coverage/lcov-report/api/routes/templates.js.html +8 -3
  71. package/coverage/lcov-report/api/routes/user.js.html +8 -3
  72. package/coverage/lcov-report/api/routes/utils/index.html +8 -3
  73. package/coverage/lcov-report/api/routes/utils/validators.js.html +8 -3
  74. package/coverage/lcov-report/api/routes/view.js.html +8 -3
  75. package/coverage/lcov-report/api/routes/webhook.js.html +8 -3
  76. package/coverage/lcov-report/automations/actions.js.html +21 -7
  77. package/coverage/lcov-report/automations/automationUtils.js.html +64 -23
  78. package/coverage/lcov-report/automations/bullboard.js.html +8 -3
  79. package/coverage/lcov-report/automations/index.html +27 -37
  80. package/coverage/lcov-report/automations/index.js.html +8 -3
  81. package/coverage/lcov-report/automations/steps/bash.js.html +8 -3
  82. package/coverage/lcov-report/automations/steps/delay.js.html +8 -3
  83. package/coverage/lcov-report/automations/steps/discord.js.html +8 -3
  84. package/coverage/lcov-report/automations/steps/executeQuery.js.html +8 -3
  85. package/coverage/lcov-report/automations/steps/executeScript.js.html +8 -3
  86. package/coverage/lcov-report/automations/steps/filter.js.html +8 -3
  87. package/coverage/lcov-report/automations/steps/index.html +31 -41
  88. package/coverage/lcov-report/automations/steps/integromat.js.html +8 -3
  89. package/coverage/lcov-report/{api/routes/static.js.html → automations/steps/loop.js.html} +70 -80
  90. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +9 -4
  91. package/coverage/lcov-report/automations/steps/queryRows.js.html +9 -4
  92. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +8 -3
  93. package/coverage/lcov-report/automations/steps/serverLog.js.html +8 -3
  94. package/coverage/lcov-report/automations/steps/slack.js.html +8 -3
  95. package/coverage/lcov-report/automations/steps/updateRow.js.html +8 -3
  96. package/coverage/lcov-report/automations/steps/utils.js.html +14 -9
  97. package/coverage/lcov-report/automations/steps/zapier.js.html +8 -3
  98. package/coverage/lcov-report/automations/triggerInfo/app.js.html +8 -3
  99. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +8 -3
  100. package/coverage/lcov-report/automations/triggerInfo/index.html +8 -3
  101. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -3
  102. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +8 -3
  103. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +8 -3
  104. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +8 -3
  105. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +8 -3
  106. package/coverage/lcov-report/automations/triggers.js.html +16 -11
  107. package/coverage/lcov-report/block-navigation.js +8 -0
  108. package/coverage/lcov-report/constants/index.html +12 -7
  109. package/coverage/lcov-report/constants/index.js.html +55 -32
  110. package/coverage/lcov-report/constants/layouts.js.html +8 -3
  111. package/coverage/lcov-report/constants/screens.js.html +8 -3
  112. package/coverage/lcov-report/db/inMemoryView.js.html +8 -3
  113. package/coverage/lcov-report/db/index.html +8 -3
  114. package/coverage/lcov-report/db/index.js.html +9 -4
  115. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +20 -15
  116. package/coverage/lcov-report/db/linkedRows/index.html +8 -3
  117. package/coverage/lcov-report/db/linkedRows/index.js.html +22 -17
  118. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +12 -7
  119. package/coverage/lcov-report/db/newid.js.html +11 -6
  120. package/coverage/lcov-report/db/utils.js.html +84 -79
  121. package/coverage/lcov-report/events/AutomationEmitter.js.html +14 -9
  122. package/coverage/lcov-report/events/index.html +8 -3
  123. package/coverage/lcov-report/events/index.js.html +9 -4
  124. package/coverage/lcov-report/events/utils.js.html +18 -13
  125. package/coverage/lcov-report/index.html +125 -120
  126. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +8 -3
  127. package/coverage/lcov-report/integrations/tests/index.html +8 -3
  128. package/coverage/lcov-report/middleware/appInfo.js.html +8 -3
  129. package/coverage/lcov-report/middleware/builder.js.html +8 -3
  130. package/coverage/lcov-report/middleware/currentapp.js.html +65 -15
  131. package/coverage/lcov-report/middleware/index.html +25 -50
  132. package/coverage/lcov-report/middleware/joi-validator.js.html +9 -4
  133. package/coverage/lcov-report/middleware/publicApi.js.html +8 -3
  134. package/coverage/lcov-report/middleware/resourceId.js.html +8 -3
  135. package/coverage/lcov-report/middleware/selfhost.js.html +9 -4
  136. package/coverage/lcov-report/middleware/utils.js.html +8 -3
  137. package/coverage/lcov-report/sorter.js +26 -0
  138. package/coverage/lcov-report/threads/automation.js.html +581 -90
  139. package/coverage/lcov-report/threads/index.html +30 -40
  140. package/coverage/lcov-report/threads/query.js.html +9 -4
  141. package/coverage/lcov-report/threads/utils.js.html +17 -9
  142. package/coverage/lcov-report/utilities/bcrypt.js.html +8 -3
  143. package/coverage/lcov-report/utilities/budibaseDir.js.html +8 -3
  144. package/coverage/lcov-report/utilities/centralPath.js.html +8 -3
  145. package/coverage/lcov-report/utilities/csvParser.js.html +10 -5
  146. package/coverage/lcov-report/utilities/global.js.html +9 -4
  147. package/coverage/lcov-report/utilities/index.html +8 -3
  148. package/coverage/lcov-report/utilities/index.js.html +11 -6
  149. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +32 -9
  150. package/coverage/lcov-report/utilities/queue/index.html +12 -7
  151. package/coverage/lcov-report/utilities/routing/index.html +8 -3
  152. package/coverage/lcov-report/utilities/routing/index.js.html +8 -3
  153. package/coverage/lcov-report/utilities/rowProcessor/index.html +8 -3
  154. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +48 -43
  155. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +18 -13
  156. package/coverage/lcov-report/utilities/scriptRunner.js.html +8 -3
  157. package/coverage/lcov-report/utilities/security.js.html +9 -4
  158. package/coverage/lcov-report/utilities/statusCodes.js.html +8 -3
  159. package/coverage/lcov-report/utilities/usageQuota/index.html +24 -34
  160. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +44 -39
  161. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +8 -3
  162. package/coverage/lcov-report/utilities/users.js.html +8 -3
  163. package/coverage/lcov-report/utilities/workerRequests.js.html +9 -4
  164. package/coverage/lcov.info +1144 -2875
  165. package/dist/api/controllers/application.js +145 -73
  166. package/dist/api/controllers/deploy/index.js +68 -36
  167. package/dist/api/controllers/public/applications.js +29 -9
  168. package/dist/api/controllers/public/queries.js +27 -7
  169. package/dist/api/controllers/public/rows.js +32 -12
  170. package/dist/api/controllers/public/tables.js +2 -2
  171. package/dist/api/controllers/public/users.js +8 -8
  172. package/dist/api/controllers/public/utils.js +1 -1
  173. package/dist/api/controllers/query/import/index.js +3 -3
  174. package/dist/api/controllers/query/index.js +57 -44
  175. package/dist/api/controllers/row/ExternalRequest.js +27 -27
  176. package/dist/api/controllers/row/index.js +83 -60
  177. package/dist/api/controllers/row/internal.js +2 -1
  178. package/dist/api/controllers/row/utils.js +2 -1
  179. package/dist/api/controllers/static/templates/BudibaseApp.svelte +3 -0
  180. package/dist/api/controllers/table/bulkFormula.js +2 -1
  181. package/dist/api/controllers/table/internal.js +41 -35
  182. package/dist/api/controllers/table/utils.js +271 -229
  183. package/dist/api/index.js +5 -0
  184. package/dist/api/routes/application.js +39 -13
  185. package/dist/api/routes/index.js +61 -56
  186. package/dist/api/routes/public/index.js +6 -9
  187. package/dist/api/routes/public/queries.js +1 -1
  188. package/dist/api/routes/public/rows.js +1 -1
  189. package/dist/api/routes/public/tables.js +3 -3
  190. package/dist/api/routes/public/users.js +1 -1
  191. package/dist/api/routes/row.js +43 -17
  192. package/dist/api/routes/static.js +40 -13
  193. package/dist/api/routes/tests/utilities/TestFunctions.js +75 -33
  194. package/dist/app.js +8 -4
  195. package/dist/automations/actions.js +3 -0
  196. package/dist/automations/automationUtils.js +10 -0
  197. package/dist/automations/steps/createRow.js +12 -12
  198. package/dist/automations/steps/deleteRow.js +13 -16
  199. package/dist/automations/steps/loop.js +51 -0
  200. package/dist/automations/tests/utilities/index.js +13 -11
  201. package/dist/automations/utils.js +187 -133
  202. package/dist/constants/index.js +5 -0
  203. package/dist/definitions/datasource.js +1 -0
  204. package/dist/environment.js +2 -3
  205. package/dist/index.js +4 -0
  206. package/dist/integrations/base/sql.js +2 -2
  207. package/dist/integrations/base/sqlTable.js +2 -2
  208. package/dist/integrations/googlesheets.js +1 -1
  209. package/dist/integrations/index.js +4 -0
  210. package/dist/integrations/microsoftSqlServer.js +8 -8
  211. package/dist/integrations/mysql.js +9 -9
  212. package/dist/integrations/oracle.js +7 -7
  213. package/dist/integrations/postgres.js +7 -7
  214. package/dist/integrations/queries/sql.js +2 -2
  215. package/dist/integrations/redis.js +158 -0
  216. package/dist/integrations/rest.js +1 -1
  217. package/dist/middleware/authorized.js +51 -51
  218. package/dist/middleware/currentapp.js +15 -1
  219. package/dist/migrations/functions/appUrls.js +1 -1
  220. package/dist/migrations/functions/developerQuota.js +49 -0
  221. package/dist/migrations/functions/publishedAppsQuota.js +47 -0
  222. package/dist/migrations/functions/quotas1.js +6 -2
  223. package/dist/migrations/functions/usageQuotas/index.js +0 -4
  224. package/dist/migrations/functions/usageQuotas/syncApps.js +4 -7
  225. package/dist/migrations/functions/usageQuotas/syncDevelopers.js +24 -0
  226. package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +26 -0
  227. package/dist/migrations/functions/usageQuotas/syncRows.js +5 -8
  228. package/dist/migrations/index.js +17 -1
  229. package/dist/package.json +14 -8
  230. package/dist/threads/automation.js +149 -27
  231. package/dist/threads/index.js +36 -10
  232. package/dist/threads/utils.js +1 -0
  233. package/dist/tsconfig.build.tsbuildinfo +1 -0
  234. package/dist/utilities/queue/inMemoryQueue.js +6 -1
  235. package/nodemon.json +1 -1
  236. package/package.json +15 -9
  237. package/scripts/dev/manage.js +2 -0
  238. package/src/api/controllers/{application.js → application.ts} +118 -51
  239. package/src/api/controllers/deploy/{index.js → index.ts} +53 -29
  240. package/src/api/controllers/public/applications.ts +2 -2
  241. package/src/api/controllers/public/queries.ts +1 -1
  242. package/src/api/controllers/public/rows.ts +1 -1
  243. package/src/api/controllers/query/{index.js → index.ts} +51 -48
  244. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  245. package/src/api/controllers/row/{index.js → index.ts} +24 -17
  246. package/src/api/controllers/row/internal.js +2 -1
  247. package/src/api/controllers/row/utils.js +4 -1
  248. package/src/api/controllers/static/templates/BudibaseApp.svelte +3 -0
  249. package/src/api/controllers/table/bulkFormula.js +1 -1
  250. package/src/api/controllers/table/{internal.js → internal.ts} +30 -26
  251. package/src/api/controllers/table/{utils.js → utils.ts} +86 -69
  252. package/src/api/index.js +5 -0
  253. package/src/api/routes/{application.js → application.ts} +8 -14
  254. package/src/api/routes/index.ts +60 -0
  255. package/src/api/routes/public/index.ts +1 -4
  256. package/src/api/routes/{row.js → row.ts} +7 -15
  257. package/src/api/routes/{static.js → static.ts} +11 -11
  258. package/src/api/routes/tests/misc.spec.js +39 -37
  259. package/src/api/routes/tests/utilities/{TestFunctions.js → TestFunctions.ts} +57 -33
  260. package/src/app.ts +1 -2
  261. package/src/automations/actions.js +3 -0
  262. package/src/automations/automationUtils.js +12 -0
  263. package/src/automations/steps/{createRow.js → createRow.ts} +9 -15
  264. package/src/automations/steps/{deleteRow.js → deleteRow.ts} +10 -16
  265. package/src/automations/steps/loop.js +50 -0
  266. package/src/automations/tests/automation.spec.js +0 -1
  267. package/src/automations/tests/{createRow.spec.js → createRow.spec.ts} +4 -15
  268. package/src/automations/tests/{deleteRow.spec.js → deleteRow.spec.ts} +3 -5
  269. package/src/automations/tests/utilities/index.js +12 -10
  270. package/src/automations/{utils.js → utils.ts} +39 -28
  271. package/src/constants/index.js +6 -0
  272. package/src/definitions/common.ts +1 -0
  273. package/src/definitions/datasource.ts +1 -0
  274. package/src/environment.js +2 -3
  275. package/src/index.ts +3 -0
  276. package/src/integrations/index.ts +4 -0
  277. package/src/integrations/redis.ts +152 -0
  278. package/src/integrations/tests/redis.spec.js +60 -0
  279. package/src/middleware/{authorized.js → authorized.ts} +20 -14
  280. package/src/middleware/currentapp.js +16 -1
  281. package/src/middleware/tests/currentapp.spec.js +8 -4
  282. package/src/migrations/functions/developerQuota.ts +15 -0
  283. package/src/migrations/functions/publishedAppsQuota.ts +13 -0
  284. package/src/migrations/functions/tests/quotas1.spec.js +0 -2
  285. package/src/migrations/functions/usageQuotas/index.ts +0 -5
  286. package/src/migrations/functions/usageQuotas/syncApps.ts +3 -6
  287. package/src/migrations/functions/usageQuotas/syncDevelopers.ts +19 -0
  288. package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +21 -0
  289. package/src/migrations/functions/usageQuotas/syncRows.ts +3 -6
  290. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +34 -0
  291. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +40 -0
  292. package/src/migrations/index.ts +13 -1
  293. package/src/threads/automation.js +196 -34
  294. package/src/threads/{index.js → index.ts} +18 -14
  295. package/src/threads/utils.js +1 -0
  296. package/src/utilities/queue/inMemoryQueue.js +7 -1
  297. package/tsconfig.build.json +10 -0
  298. package/tsconfig.json +2 -2
  299. package/builder/assets/index.68a7f4e3.css +0 -6
  300. package/builder/assets/index.8d4a5b33.js +0 -1291
  301. package/coverage/lcov-report/api/controllers/application.js.html +0 -1436
  302. package/coverage/lcov-report/api/controllers/query/index.js.html +0 -713
  303. package/coverage/lcov-report/api/controllers/row/index.js.html +0 -524
  304. package/coverage/lcov-report/api/controllers/table/internal.js.html +0 -620
  305. package/coverage/lcov-report/api/controllers/table/utils.js.html +0 -1331
  306. package/coverage/lcov-report/api/routes/application.js.html +0 -179
  307. package/coverage/lcov-report/api/routes/index.js.html +0 -266
  308. package/coverage/lcov-report/api/routes/row.js.html +0 -908
  309. package/coverage/lcov-report/automations/steps/createRow.js.html +0 -380
  310. package/coverage/lcov-report/automations/steps/deleteRow.js.html +0 -347
  311. package/coverage/lcov-report/automations/utils.js.html +0 -665
  312. package/coverage/lcov-report/middleware/authorized.js.html +0 -458
  313. package/coverage/lcov-report/middleware/usageQuota.js.html +0 -572
  314. package/coverage/lcov-report/threads/index.js.html +0 -296
  315. package/coverage/lcov-report/utilities/usageQuota/index.js.html +0 -359
  316. package/dist/middleware/usageQuota.js +0 -154
  317. package/dist/tsconfig.tsbuildinfo +0 -1
  318. package/dist/utilities/usageQuota/index.js +0 -86
  319. package/src/api/routes/index.js +0 -62
  320. package/src/middleware/tests/usageQuota.spec.js +0 -120
  321. package/src/middleware/usageQuota.js +0 -164
  322. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +0 -41
  323. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +0 -45
  324. package/src/utilities/tests/usageQuota/usageQuota.spec.js +0 -72
  325. package/src/utilities/usageQuota/index.js +0 -93
@@ -1,22 +1,19 @@
1
- const {
2
- generateQueryID,
3
- getQueryParams,
4
- isProdAppID,
5
- } = require("../../../db/utils")
6
- const { BaseQueryVerbs } = require("../../../constants")
7
- const { Thread, ThreadType } = require("../../../threads")
8
- const { save: saveDatasource } = require("../datasource")
9
- const { RestImporter } = require("./import")
10
- const { invalidateDynamicVariables } = require("../../../threads/utils")
11
- const environment = require("../../../environment")
12
- const { getAppDB } = require("@budibase/backend-core/context")
1
+ import { generateQueryID, getQueryParams, isProdAppID } from "../../../db/utils"
2
+ import { BaseQueryVerbs } from "../../../constants"
3
+ import { Thread, ThreadType } from "../../../threads"
4
+ import { save as saveDatasource } from "../datasource"
5
+ import { RestImporter } from "./import"
6
+ import { invalidateDynamicVariables } from "../../../threads/utils"
7
+ import { QUERY_THREAD_TIMEOUT } from "../../../environment"
8
+ import { getAppDB } from "@budibase/backend-core/context"
9
+ import { quotas } from "@budibase/pro"
13
10
 
14
11
  const Runner = new Thread(ThreadType.QUERY, {
15
- timeoutMs: environment.QUERY_THREAD_TIMEOUT || 10000,
12
+ timeoutMs: QUERY_THREAD_TIMEOUT || 10000,
16
13
  })
17
14
 
18
15
  // simple function to append "readable" to all read queries
19
- function enrichQueries(input) {
16
+ function enrichQueries(input: any) {
20
17
  const wasArray = Array.isArray(input)
21
18
  const queries = wasArray ? input : [input]
22
19
  for (let query of queries) {
@@ -27,7 +24,7 @@ function enrichQueries(input) {
27
24
  return wasArray ? queries : queries[0]
28
25
  }
29
26
 
30
- exports.fetch = async function (ctx) {
27
+ export async function fetch(ctx: any) {
31
28
  const db = getAppDB()
32
29
 
33
30
  const body = await db.allDocs(
@@ -36,10 +33,10 @@ exports.fetch = async function (ctx) {
36
33
  })
37
34
  )
38
35
 
39
- ctx.body = enrichQueries(body.rows.map(row => row.doc))
36
+ ctx.body = enrichQueries(body.rows.map((row: any) => row.doc))
40
37
  }
41
38
 
42
- exports.import = async ctx => {
39
+ const _import = async (ctx: any) => {
43
40
  const body = ctx.request.body
44
41
  const data = body.data
45
42
 
@@ -49,7 +46,7 @@ exports.import = async ctx => {
49
46
  let datasourceId
50
47
  if (!body.datasourceId) {
51
48
  // construct new datasource
52
- const info = await importer.getInfo()
49
+ const info: any = await importer.getInfo()
53
50
  let datasource = {
54
51
  type: "datasource",
55
52
  source: "REST",
@@ -77,8 +74,9 @@ exports.import = async ctx => {
77
74
  }
78
75
  ctx.status = 200
79
76
  }
77
+ export { _import as import }
80
78
 
81
- exports.save = async function (ctx) {
79
+ export async function save(ctx: any) {
82
80
  const db = getAppDB()
83
81
  const query = ctx.request.body
84
82
 
@@ -93,7 +91,7 @@ exports.save = async function (ctx) {
93
91
  ctx.message = `Query ${query.name} saved successfully.`
94
92
  }
95
93
 
96
- exports.find = async function (ctx) {
94
+ export async function find(ctx: any) {
97
95
  const db = getAppDB()
98
96
  const query = enrichQueries(await db.get(ctx.params.queryId))
99
97
  // remove properties that could be dangerous in real app
@@ -104,7 +102,7 @@ exports.find = async function (ctx) {
104
102
  ctx.body = query
105
103
  }
106
104
 
107
- exports.preview = async function (ctx) {
105
+ export async function preview(ctx: any) {
108
106
  const db = getAppDB()
109
107
 
110
108
  const datasource = await db.get(ctx.request.body.datasourceId)
@@ -114,16 +112,18 @@ exports.preview = async function (ctx) {
114
112
  ctx.request.body
115
113
 
116
114
  try {
117
- const { rows, keys, info, extra } = await Runner.run({
118
- appId: ctx.appId,
119
- datasource,
120
- queryVerb,
121
- fields,
122
- parameters,
123
- transformer,
124
- queryId,
125
- })
126
-
115
+ const runFn = () =>
116
+ Runner.run({
117
+ appId: ctx.appId,
118
+ datasource,
119
+ queryVerb,
120
+ fields,
121
+ parameters,
122
+ transformer,
123
+ queryId,
124
+ })
125
+
126
+ const { rows, keys, info, extra } = await quotas.addQuery(runFn)
127
127
  ctx.body = {
128
128
  rows,
129
129
  schemaFields: [...new Set(keys)],
@@ -135,7 +135,7 @@ exports.preview = async function (ctx) {
135
135
  }
136
136
  }
137
137
 
138
- async function execute(ctx, opts = { rowsOnly: false }) {
138
+ async function execute(ctx: any, opts = { rowsOnly: false }) {
139
139
  const db = getAppDB()
140
140
 
141
141
  const query = await db.get(ctx.params.queryId)
@@ -153,16 +153,19 @@ async function execute(ctx, opts = { rowsOnly: false }) {
153
153
 
154
154
  // call the relevant CRUD method on the integration class
155
155
  try {
156
- const { rows, pagination, extra } = await Runner.run({
157
- appId: ctx.appId,
158
- datasource,
159
- queryVerb: query.queryVerb,
160
- fields: query.fields,
161
- pagination: ctx.request.body.pagination,
162
- parameters: enrichedParameters,
163
- transformer: query.transformer,
164
- queryId: ctx.params.queryId,
165
- })
156
+ const runFn = () =>
157
+ Runner.run({
158
+ appId: ctx.appId,
159
+ datasource,
160
+ queryVerb: query.queryVerb,
161
+ fields: query.fields,
162
+ pagination: ctx.request.body.pagination,
163
+ parameters: enrichedParameters,
164
+ transformer: query.transformer,
165
+ queryId: ctx.params.queryId,
166
+ })
167
+
168
+ const { rows, pagination, extra } = await quotas.addQuery(runFn)
166
169
  if (opts && opts.rowsOnly) {
167
170
  ctx.body = rows
168
171
  } else {
@@ -173,15 +176,15 @@ async function execute(ctx, opts = { rowsOnly: false }) {
173
176
  }
174
177
  }
175
178
 
176
- exports.executeV1 = async function (ctx) {
179
+ export async function executeV1(ctx: any) {
177
180
  return execute(ctx, { rowsOnly: true })
178
181
  }
179
182
 
180
- exports.executeV2 = async function (ctx) {
183
+ export async function executeV2(ctx: any) {
181
184
  return execute(ctx, { rowsOnly: false })
182
185
  }
183
186
 
184
- const removeDynamicVariables = async queryId => {
187
+ const removeDynamicVariables = async (queryId: any) => {
185
188
  const db = getAppDB()
186
189
  const query = await db.get(queryId)
187
190
  const datasource = await db.get(query.datasourceId)
@@ -190,19 +193,19 @@ const removeDynamicVariables = async queryId => {
190
193
  if (dynamicVariables) {
191
194
  // delete dynamic variables from the datasource
192
195
  datasource.config.dynamicVariables = dynamicVariables.filter(
193
- dv => dv.queryId !== queryId
196
+ (dv: any) => dv.queryId !== queryId
194
197
  )
195
198
  await db.put(datasource)
196
199
 
197
200
  // invalidate the deleted variables
198
201
  const variablesToDelete = dynamicVariables.filter(
199
- dv => dv.queryId === queryId
202
+ (dv: any) => dv.queryId === queryId
200
203
  )
201
204
  await invalidateDynamicVariables(variablesToDelete)
202
205
  }
203
206
  }
204
207
 
205
- exports.destroy = async function (ctx) {
208
+ export async function destroy(ctx: any) {
206
209
  const db = getAppDB()
207
210
  await removeDynamicVariables(ctx.params.queryId)
208
211
  await db.remove(ctx.params.queryId, ctx.params.revId)
@@ -52,7 +52,7 @@ interface RunConfig {
52
52
 
53
53
  module External {
54
54
  function buildFilters(
55
- id: string | undefined,
55
+ id: string | undefined | string[],
56
56
  filters: SearchFilters,
57
57
  table: Table
58
58
  ) {
@@ -1,15 +1,16 @@
1
- const internal = require("./internal")
2
- const external = require("./external")
3
- const { isExternalTable } = require("../../../integrations/utils")
1
+ import { quotas } from "@budibase/pro"
2
+ import internal from "./internal"
3
+ import external from "./external"
4
+ import { isExternalTable } from "../../../integrations/utils"
4
5
 
5
- function pickApi(tableId) {
6
+ function pickApi(tableId: any) {
6
7
  if (isExternalTable(tableId)) {
7
8
  return external
8
9
  }
9
10
  return internal
10
11
  }
11
12
 
12
- function getTableId(ctx) {
13
+ function getTableId(ctx: any) {
13
14
  if (ctx.request.body && ctx.request.body.tableId) {
14
15
  return ctx.request.body.tableId
15
16
  }
@@ -21,13 +22,13 @@ function getTableId(ctx) {
21
22
  }
22
23
  }
23
24
 
24
- exports.patch = async ctx => {
25
+ export async function patch(ctx: any): Promise<any> {
25
26
  const appId = ctx.appId
26
27
  const tableId = getTableId(ctx)
27
28
  const body = ctx.request.body
28
29
  // if it doesn't have an _id then its save
29
30
  if (body && !body._id) {
30
- return exports.save(ctx)
31
+ return save(ctx)
31
32
  }
32
33
  try {
33
34
  const { row, table } = await pickApi(tableId).patch(ctx)
@@ -41,13 +42,13 @@ exports.patch = async ctx => {
41
42
  }
42
43
  }
43
44
 
44
- exports.save = async function (ctx) {
45
+ const saveRow = async (ctx: any) => {
45
46
  const appId = ctx.appId
46
47
  const tableId = getTableId(ctx)
47
48
  const body = ctx.request.body
48
49
  // if it has an ID already then its a patch
49
50
  if (body && body._id) {
50
- return exports.patch(ctx)
51
+ return patch(ctx)
51
52
  }
52
53
  try {
53
54
  const { row, table } = await pickApi(tableId).save(ctx)
@@ -60,7 +61,11 @@ exports.save = async function (ctx) {
60
61
  }
61
62
  }
62
63
 
63
- exports.fetchView = async function (ctx) {
64
+ export async function save(ctx: any) {
65
+ await quotas.addRow(() => saveRow(ctx))
66
+ }
67
+
68
+ export async function fetchView(ctx: any) {
64
69
  const tableId = getTableId(ctx)
65
70
  try {
66
71
  ctx.body = await pickApi(tableId).fetchView(ctx)
@@ -69,7 +74,7 @@ exports.fetchView = async function (ctx) {
69
74
  }
70
75
  }
71
76
 
72
- exports.fetch = async function (ctx) {
77
+ export async function fetch(ctx: any) {
73
78
  const tableId = getTableId(ctx)
74
79
  try {
75
80
  ctx.body = await pickApi(tableId).fetch(ctx)
@@ -78,7 +83,7 @@ exports.fetch = async function (ctx) {
78
83
  }
79
84
  }
80
85
 
81
- exports.find = async function (ctx) {
86
+ export async function find(ctx: any) {
82
87
  const tableId = getTableId(ctx)
83
88
  try {
84
89
  ctx.body = await pickApi(tableId).find(ctx)
@@ -87,19 +92,21 @@ exports.find = async function (ctx) {
87
92
  }
88
93
  }
89
94
 
90
- exports.destroy = async function (ctx) {
95
+ export async function destroy(ctx: any) {
91
96
  const appId = ctx.appId
92
97
  const inputs = ctx.request.body
93
98
  const tableId = getTableId(ctx)
94
99
  let response, row
95
100
  if (inputs.rows) {
96
101
  let { rows } = await pickApi(tableId).bulkDestroy(ctx)
102
+ await quotas.removeRows(rows.length)
97
103
  response = rows
98
104
  for (let row of rows) {
99
105
  ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
100
106
  }
101
107
  } else {
102
108
  let resp = await pickApi(tableId).destroy(ctx)
109
+ await quotas.removeRow()
103
110
  response = resp.response
104
111
  row = resp.row
105
112
  ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
@@ -110,7 +117,7 @@ exports.destroy = async function (ctx) {
110
117
  ctx.body = response
111
118
  }
112
119
 
113
- exports.search = async ctx => {
120
+ export async function search(ctx: any) {
114
121
  const tableId = getTableId(ctx)
115
122
  try {
116
123
  ctx.status = 200
@@ -120,7 +127,7 @@ exports.search = async ctx => {
120
127
  }
121
128
  }
122
129
 
123
- exports.validate = async function (ctx) {
130
+ export async function validate(ctx: any) {
124
131
  const tableId = getTableId(ctx)
125
132
  try {
126
133
  ctx.body = await pickApi(tableId).validate(ctx)
@@ -129,7 +136,7 @@ exports.validate = async function (ctx) {
129
136
  }
130
137
  }
131
138
 
132
- exports.fetchEnrichedRow = async function (ctx) {
139
+ export async function fetchEnrichedRow(ctx: any) {
133
140
  const tableId = getTableId(ctx)
134
141
  try {
135
142
  ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx)
@@ -138,7 +145,7 @@ exports.fetchEnrichedRow = async function (ctx) {
138
145
  }
139
146
  }
140
147
 
141
- exports.export = async function (ctx) {
148
+ export const exportRows = async (ctx: any) => {
142
149
  const tableId = getTableId(ctx)
143
150
  try {
144
151
  ctx.body = await pickApi(tableId).exportRows(ctx)
@@ -260,8 +260,9 @@ exports.find = async ctx => {
260
260
 
261
261
  exports.destroy = async function (ctx) {
262
262
  const db = getAppDB()
263
- const { _id, _rev } = ctx.request.body
263
+ const { _id } = ctx.request.body
264
264
  let row = await db.get(_id)
265
+ let _rev = ctx.request.body._rev || row._rev
265
266
 
266
267
  if (row.tableId !== ctx.params.tableId) {
267
268
  throw "Supplied tableId doesn't match the row's tableId"
@@ -65,7 +65,10 @@ exports.validate = async ({ tableId, row, table }) => {
65
65
  if (type === FieldTypes.ARRAY && row[fieldName]) {
66
66
  if (row[fieldName].length) {
67
67
  row[fieldName].map(val => {
68
- if (!constraints.inclusion.includes(val)) {
68
+ if (
69
+ !constraints.inclusion.includes(val) &&
70
+ constraints.inclusion.length !== 0
71
+ ) {
69
72
  errors[fieldName] = "Field not in list"
70
73
  }
71
74
  })
@@ -78,6 +78,9 @@
78
78
  app.
79
79
  </h2>
80
80
  </div>
81
+ <script type="application/javascript">
82
+ window.INIT_TIME = Date.now()
83
+ </script>
81
84
  <script type="application/javascript" src={clientLibPath}>
82
85
  </script>
83
86
  <script type="application/javascript">
@@ -25,7 +25,7 @@ function getFormulaThatUseColumn(table, columnNames) {
25
25
  if (!isStaticFormula(column)) {
26
26
  continue
27
27
  }
28
- if (!doesContainStrings(column.formula, columnNames)) {
28
+ if (!doesContainStrings(column?.formula ?? "", columnNames)) {
29
29
  continue
30
30
  }
31
31
  formula.push(column.name)
@@ -1,22 +1,23 @@
1
- const linkRows = require("../../../db/linkedRows")
2
- const { getRowParams, generateTableID } = require("../../../db/utils")
3
- const { FieldTypes } = require("../../../constants")
4
- const {
1
+ import { updateLinks, EventType } from "../../../db/linkedRows"
2
+ import { getRowParams, generateTableID } from "../../../db/utils"
3
+ import { FieldTypes } from "../../../constants"
4
+ import {
5
5
  TableSaveFunctions,
6
6
  hasTypeChanged,
7
7
  getTable,
8
8
  handleDataImport,
9
- } = require("./utils")
10
- const usageQuota = require("../../../utilities/usageQuota")
9
+ } from "./utils"
11
10
  const { getAppDB } = require("@budibase/backend-core/context")
12
- const env = require("../../../environment")
13
- const {
11
+ import { isTest } from "../../../environment"
12
+ import {
14
13
  cleanupAttachments,
15
14
  fixAutoColumnSubType,
16
- } = require("../../../utilities/rowProcessor")
17
- const { runStaticFormulaChecks } = require("./bulkFormula")
15
+ } from "../../../utilities/rowProcessor"
16
+ import { runStaticFormulaChecks } from "./bulkFormula"
17
+ import { Table } from "../../../definitions/common"
18
+ import { quotas } from "@budibase/pro"
18
19
 
19
- function checkAutoColumns(table, oldTable) {
20
+ function checkAutoColumns(table: Table, oldTable: Table) {
20
21
  if (!table.schema) {
21
22
  return table
22
23
  }
@@ -34,7 +35,7 @@ function checkAutoColumns(table, oldTable) {
34
35
  return table
35
36
  }
36
37
 
37
- exports.save = async function (ctx) {
38
+ export async function save(ctx: any) {
38
39
  const db = getAppDB()
39
40
  const { dataImport, ...rest } = ctx.request.body
40
41
  let tableToSave = {
@@ -104,10 +105,8 @@ exports.save = async function (ctx) {
104
105
 
105
106
  // update linked rows
106
107
  try {
107
- const linkResp = await linkRows.updateLinks({
108
- eventType: oldTable
109
- ? linkRows.EventType.TABLE_UPDATED
110
- : linkRows.EventType.TABLE_SAVE,
108
+ const linkResp: any = await updateLinks({
109
+ eventType: oldTable ? EventType.TABLE_UPDATED : EventType.TABLE_SAVE,
111
110
  table: tableToSave,
112
111
  oldTable: oldTable,
113
112
  })
@@ -129,11 +128,11 @@ exports.save = async function (ctx) {
129
128
 
130
129
  tableToSave = await tableSaveFunctions.after(tableToSave)
131
130
  // has to run after, make sure it has _id
132
- await runStaticFormulaChecks(tableToSave, { oldTable })
131
+ await runStaticFormulaChecks(tableToSave, { oldTable, deletion: null })
133
132
  return tableToSave
134
133
  }
135
134
 
136
- exports.destroy = async function (ctx) {
135
+ export async function destroy(ctx: any) {
137
136
  const db = getAppDB()
138
137
  const tableToDelete = await db.get(ctx.params.tableId)
139
138
 
@@ -143,12 +142,14 @@ exports.destroy = async function (ctx) {
143
142
  include_docs: true,
144
143
  })
145
144
  )
146
- await db.bulkDocs(rows.rows.map(row => ({ ...row.doc, _deleted: true })))
147
- await usageQuota.update(usageQuota.Properties.ROW, -rows.rows.length)
145
+ await db.bulkDocs(
146
+ rows.rows.map((row: any) => ({ ...row.doc, _deleted: true }))
147
+ )
148
+ await quotas.removeRows(rows.rows.length)
148
149
 
149
150
  // update linked rows
150
- await linkRows.updateLinks({
151
- eventType: linkRows.EventType.TABLE_DELETE,
151
+ await updateLinks({
152
+ eventType: EventType.TABLE_DELETE,
152
153
  table: tableToDelete,
153
154
  })
154
155
 
@@ -156,10 +157,10 @@ exports.destroy = async function (ctx) {
156
157
  await db.remove(tableToDelete)
157
158
 
158
159
  // remove table search index
159
- if (!env.isTest()) {
160
+ if (!isTest()) {
160
161
  const currentIndexes = await db.getIndexes()
161
162
  const existingIndex = currentIndexes.indexes.find(
162
- existing => existing.name === `search:${ctx.params.tableId}`
163
+ (existing: any) => existing.name === `search:${ctx.params.tableId}`
163
164
  )
164
165
  if (existingIndex) {
165
166
  await db.deleteIndex(existingIndex)
@@ -167,12 +168,15 @@ exports.destroy = async function (ctx) {
167
168
  }
168
169
 
169
170
  // has to run after, make sure it has _id
170
- await runStaticFormulaChecks(tableToDelete, { deletion: true })
171
+ await runStaticFormulaChecks(tableToDelete, {
172
+ oldTable: null,
173
+ deletion: true,
174
+ })
171
175
  await cleanupAttachments(tableToDelete, { rows })
172
176
  return tableToDelete
173
177
  }
174
178
 
175
- exports.bulkImport = async function (ctx) {
179
+ export async function bulkImport(ctx: any) {
176
180
  const table = await getTable(ctx.params.tableId)
177
181
  const { dataImport } = ctx.request.body
178
182
  await handleDataImport(ctx.user, table, dataImport)