@budibase/server 1.0.200-alpha.3 → 1.0.200

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 (285) hide show
  1. package/Dockerfile +0 -2
  2. package/builder/assets/index.f83b3433.js +1315 -0
  3. package/builder/index.html +1 -1
  4. package/coverage/clover.xml +1998 -2086
  5. package/coverage/coverage-final.json +122 -121
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +202 -0
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
  8. package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
  9. package/coverage/lcov-report/api/controllers/automation.js.html +72 -174
  10. package/coverage/lcov-report/api/controllers/backup.js.html +6 -30
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
  12. package/coverage/lcov-report/api/controllers/component.js.html +5 -5
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +41 -53
  14. package/coverage/lcov-report/api/controllers/dev.js.html +70 -94
  15. package/coverage/lcov-report/api/controllers/index.html +72 -57
  16. package/coverage/lcov-report/api/controllers/integration.js.html +8 -8
  17. package/coverage/lcov-report/api/controllers/layout.js.html +19 -28
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
  19. package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
  20. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  21. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
  23. package/coverage/lcov-report/api/controllers/role.js.html +48 -78
  24. package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +19 -19
  26. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +54 -54
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +9 -9
  29. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +24 -24
  31. package/coverage/lcov-report/api/controllers/screen.js.html +20 -56
  32. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  33. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
  34. package/coverage/lcov-report/api/controllers/table/external.js.html +17 -23
  35. package/coverage/lcov-report/api/controllers/table/index.html +26 -26
  36. package/coverage/lcov-report/api/controllers/table/index.js.html +49 -85
  37. package/coverage/lcov-report/api/controllers/templates.js.html +6 -6
  38. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +11 -11
  40. package/coverage/lcov-report/api/controllers/view/index.html +21 -21
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +65 -275
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +23 -23
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +40 -40
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +17 -17
  45. package/coverage/lcov-report/api/index.html +15 -15
  46. package/coverage/lcov-report/api/index.js.html +45 -39
  47. package/coverage/lcov-report/api/routes/analytics.js.html +13 -7
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
  49. package/coverage/lcov-report/api/routes/auth.js.html +6 -6
  50. package/coverage/lcov-report/api/routes/automation.js.html +11 -11
  51. package/coverage/lcov-report/api/routes/backup.js.html +8 -8
  52. package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
  53. package/coverage/lcov-report/api/routes/component.js.html +8 -8
  54. package/coverage/lcov-report/api/routes/datasource.js.html +9 -9
  55. package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
  56. package/coverage/lcov-report/api/routes/dev.js.html +13 -13
  57. package/coverage/lcov-report/api/routes/index.html +1 -1
  58. package/coverage/lcov-report/api/routes/integration.js.html +8 -8
  59. package/coverage/lcov-report/api/routes/layout.js.html +8 -8
  60. package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
  61. package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
  62. package/coverage/lcov-report/api/routes/permission.js.html +9 -9
  63. package/coverage/lcov-report/api/routes/query.js.html +10 -10
  64. package/coverage/lcov-report/api/routes/role.js.html +9 -9
  65. package/coverage/lcov-report/api/routes/routing.js.html +8 -8
  66. package/coverage/lcov-report/api/routes/screen.js.html +9 -9
  67. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/table.js.html +10 -10
  69. package/coverage/lcov-report/api/routes/templates.js.html +8 -8
  70. package/coverage/lcov-report/api/routes/user.js.html +8 -8
  71. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  72. package/coverage/lcov-report/api/routes/utils/validators.js.html +36 -36
  73. package/coverage/lcov-report/api/routes/view.js.html +10 -10
  74. package/coverage/lcov-report/api/routes/webhook.js.html +9 -9
  75. package/coverage/lcov-report/automations/actions.js.html +25 -25
  76. package/coverage/lcov-report/automations/automationUtils.js.html +8 -8
  77. package/coverage/lcov-report/automations/bullboard.js.html +35 -35
  78. package/coverage/lcov-report/automations/index.html +29 -29
  79. package/coverage/lcov-report/automations/index.js.html +17 -29
  80. package/coverage/lcov-report/automations/steps/bash.js.html +7 -7
  81. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  82. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  83. package/coverage/lcov-report/automations/steps/executeQuery.js.html +7 -7
  84. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  85. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  86. package/coverage/lcov-report/automations/steps/index.html +1 -1
  87. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  88. package/coverage/lcov-report/automations/steps/loop.js.html +2 -2
  89. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  90. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  91. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  92. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  93. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  94. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  96. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  97. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  98. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  99. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  101. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  102. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  103. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  104. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  105. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  106. package/coverage/lcov-report/constants/index.html +1 -1
  107. package/coverage/lcov-report/constants/index.js.html +30 -30
  108. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  109. package/coverage/lcov-report/constants/screens.js.html +4 -4
  110. package/coverage/lcov-report/db/inMemoryView.js.html +5 -5
  111. package/coverage/lcov-report/db/index.html +1 -1
  112. package/coverage/lcov-report/db/index.js.html +9 -9
  113. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +17 -17
  114. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
  116. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +19 -19
  117. package/coverage/lcov-report/db/newid.js.html +4 -4
  118. package/coverage/lcov-report/db/utils.js.html +81 -81
  119. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  120. package/coverage/lcov-report/events/index.html +1 -1
  121. package/coverage/lcov-report/events/index.js.html +7 -7
  122. package/coverage/lcov-report/events/utils.js.html +10 -10
  123. package/coverage/lcov-report/index.html +74 -74
  124. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  125. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  126. package/coverage/lcov-report/middleware/appInfo.js.html +5 -5
  127. package/coverage/lcov-report/middleware/builder.js.html +20 -20
  128. package/coverage/lcov-report/middleware/currentapp.js.html +49 -49
  129. package/coverage/lcov-report/middleware/index.html +1 -1
  130. package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
  131. package/coverage/lcov-report/middleware/publicApi.js.html +5 -5
  132. package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
  133. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  134. package/coverage/lcov-report/middleware/utils.js.html +4 -4
  135. package/coverage/lcov-report/threads/automation.js.html +1 -1
  136. package/coverage/lcov-report/threads/index.html +1 -1
  137. package/coverage/lcov-report/threads/query.js.html +1 -1
  138. package/coverage/lcov-report/threads/utils.js.html +13 -13
  139. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  140. package/coverage/lcov-report/utilities/centralPath.js.html +14 -14
  141. package/coverage/lcov-report/utilities/csvParser.js.html +34 -34
  142. package/coverage/lcov-report/utilities/global.js.html +28 -28
  143. package/coverage/lcov-report/utilities/index.html +25 -25
  144. package/coverage/lcov-report/utilities/index.js.html +41 -41
  145. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +18 -18
  146. package/coverage/lcov-report/utilities/queue/index.html +15 -15
  147. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  148. package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
  149. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  150. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +59 -59
  151. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +15 -15
  152. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  153. package/coverage/lcov-report/utilities/security.js.html +8 -8
  154. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  156. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +30 -30
  157. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  158. package/coverage/lcov-report/utilities/users.js.html +7 -7
  159. package/coverage/lcov-report/utilities/workerRequests.js.html +29 -29
  160. package/coverage/lcov.info +2762 -2903
  161. package/dist/api/controllers/analytics.js +30 -7
  162. package/dist/api/controllers/application.js +16 -56
  163. package/dist/api/controllers/automation.js +2 -31
  164. package/dist/api/controllers/backup.js +0 -7
  165. package/dist/api/controllers/datasource.js +2 -8
  166. package/dist/api/controllers/deploy/index.js +2 -6
  167. package/dist/api/controllers/dev.js +2 -9
  168. package/dist/api/controllers/layout.js +0 -3
  169. package/dist/api/controllers/query/import/index.js +2 -12
  170. package/dist/api/controllers/query/import/sources/curl.js +0 -3
  171. package/dist/api/controllers/query/import/sources/openapi2.js +0 -3
  172. package/dist/api/controllers/query/import/sources/openapi3.js +0 -3
  173. package/dist/api/controllers/query/index.js +2 -16
  174. package/dist/api/controllers/role.js +0 -11
  175. package/dist/api/controllers/screen.js +1 -10
  176. package/dist/api/controllers/static/index.js +15 -29
  177. package/dist/api/controllers/table/external.js +0 -2
  178. package/dist/api/controllers/table/index.js +0 -12
  179. package/dist/api/controllers/table/utils.js +3 -3
  180. package/dist/api/controllers/view/index.js +6 -62
  181. package/dist/api/index.js +4 -2
  182. package/dist/api/routes/analytics.js +3 -1
  183. package/dist/app.js +8 -16
  184. package/dist/automations/index.js +0 -4
  185. package/dist/automations/steps/executeQuery.js +1 -1
  186. package/dist/environment.js +2 -4
  187. package/dist/integrations/firebase.js +0 -1
  188. package/dist/migrations/index.js +31 -95
  189. package/dist/package.json +69 -79
  190. package/dist/tests/utilities/TestConfiguration.js +93 -121
  191. package/dist/tests/utilities/structures.js +0 -45
  192. package/dist/tsconfig.build.tsbuildinfo +1 -1
  193. package/nodemon.json +1 -1
  194. package/package.json +70 -80
  195. package/scripts/dev/manage.js +0 -2
  196. package/scripts/jestSetup.js +0 -7
  197. package/scripts/likeCypress.ts +1 -1
  198. package/src/api/controllers/analytics.js +39 -0
  199. package/src/api/controllers/application.ts +18 -60
  200. package/src/api/controllers/automation.js +2 -36
  201. package/src/api/controllers/backup.js +0 -8
  202. package/src/api/controllers/datasource.js +4 -8
  203. package/src/api/controllers/deploy/index.ts +2 -6
  204. package/src/api/controllers/dev.js +2 -10
  205. package/src/api/controllers/layout.js +0 -3
  206. package/src/api/controllers/query/import/index.ts +3 -16
  207. package/src/api/controllers/query/import/sources/base/index.ts +1 -2
  208. package/src/api/controllers/query/import/sources/curl.ts +0 -4
  209. package/src/api/controllers/query/import/sources/openapi2.ts +0 -4
  210. package/src/api/controllers/query/import/sources/openapi3.ts +0 -4
  211. package/src/api/controllers/query/import/tests/index.spec.js +7 -20
  212. package/src/api/controllers/query/index.ts +3 -16
  213. package/src/api/controllers/role.js +0 -10
  214. package/src/api/controllers/screen.js +1 -13
  215. package/src/api/controllers/static/index.js +15 -28
  216. package/src/api/controllers/table/external.js +0 -2
  217. package/src/api/controllers/table/index.js +0 -12
  218. package/src/api/controllers/table/utils.ts +4 -4
  219. package/src/api/controllers/view/index.js +6 -76
  220. package/src/api/index.js +4 -2
  221. package/src/api/routes/analytics.js +3 -1
  222. package/src/api/routes/public/utils/Endpoint.ts +1 -1
  223. package/src/api/routes/tests/__snapshots__/datasource.spec.js.snap +1 -5
  224. package/src/api/routes/tests/application.spec.js +4 -64
  225. package/src/api/routes/tests/automation.spec.js +60 -168
  226. package/src/api/routes/tests/backup.spec.js +0 -2
  227. package/src/api/routes/tests/datasource.spec.js +0 -5
  228. package/src/api/routes/tests/layout.spec.js +0 -4
  229. package/src/api/routes/tests/query.spec.js +13 -56
  230. package/src/api/routes/tests/role.spec.js +7 -40
  231. package/src/api/routes/tests/row.spec.js +3 -2
  232. package/src/api/routes/tests/screen.spec.js +4 -30
  233. package/src/api/routes/tests/static.spec.js +54 -120
  234. package/src/api/routes/tests/table.spec.js +38 -102
  235. package/src/api/routes/tests/view.spec.js +43 -222
  236. package/src/app.ts +9 -18
  237. package/src/automations/index.js +0 -4
  238. package/src/automations/steps/executeQuery.js +1 -1
  239. package/src/automations/tests/delay.spec.js +0 -4
  240. package/src/environment.js +2 -5
  241. package/src/integrations/firebase.ts +0 -1
  242. package/src/migrations/index.ts +51 -120
  243. package/src/module.d.ts +1 -0
  244. package/src/tests/utilities/TestConfiguration.js +90 -138
  245. package/src/tests/utilities/structures.js +0 -71
  246. package/tsconfig.build.json +5 -20
  247. package/tsconfig.json +17 -22
  248. package/builder/assets/index.05491b9d.js +0 -1315
  249. package/dist/migrations/functions/backfill/app/automations.js +0 -31
  250. package/dist/migrations/functions/backfill/app/datasources.js +0 -28
  251. package/dist/migrations/functions/backfill/app/layouts.js +0 -33
  252. package/dist/migrations/functions/backfill/app/queries.js +0 -32
  253. package/dist/migrations/functions/backfill/app/roles.js +0 -28
  254. package/dist/migrations/functions/backfill/app/screens.js +0 -28
  255. package/dist/migrations/functions/backfill/app/tables.js +0 -40
  256. package/dist/migrations/functions/backfill/app.js +0 -175
  257. package/dist/migrations/functions/backfill/global/configs.js +0 -61
  258. package/dist/migrations/functions/backfill/global/quotas.js +0 -60
  259. package/dist/migrations/functions/backfill/global/users.js +0 -50
  260. package/dist/migrations/functions/backfill/global.js +0 -189
  261. package/dist/migrations/functions/backfill/index.js +0 -32
  262. package/dist/migrations/functions/backfill/installation.js +0 -80
  263. package/dist/migrations/tests/helpers.js +0 -72
  264. package/dist/migrations/tests/structures.js +0 -37
  265. package/src/api/controllers/analytics.ts +0 -8
  266. package/src/api/routes/tests/data/export.txt +0 -1
  267. package/src/api/routes/tests/deployment.spec.js +0 -25
  268. package/src/api/routes/tests/dev.spec.js +0 -40
  269. package/src/migrations/functions/backfill/app/automations.ts +0 -26
  270. package/src/migrations/functions/backfill/app/datasources.ts +0 -22
  271. package/src/migrations/functions/backfill/app/layouts.ts +0 -29
  272. package/src/migrations/functions/backfill/app/queries.ts +0 -33
  273. package/src/migrations/functions/backfill/app/roles.ts +0 -22
  274. package/src/migrations/functions/backfill/app/screens.ts +0 -22
  275. package/src/migrations/functions/backfill/app/tables.ts +0 -36
  276. package/src/migrations/functions/backfill/app.ts +0 -148
  277. package/src/migrations/functions/backfill/global/configs.ts +0 -66
  278. package/src/migrations/functions/backfill/global/quotas.ts +0 -60
  279. package/src/migrations/functions/backfill/global/users.ts +0 -49
  280. package/src/migrations/functions/backfill/global.ts +0 -194
  281. package/src/migrations/functions/backfill/index.ts +0 -7
  282. package/src/migrations/functions/backfill/installation.ts +0 -50
  283. package/src/migrations/tests/helpers.ts +0 -40
  284. package/src/migrations/tests/index.spec.ts +0 -132
  285. package/src/migrations/tests/structures.ts +0 -66
@@ -1,5 +1,4 @@
1
1
  const setup = require("./utilities")
2
- const { events } = require("@budibase/backend-core")
3
2
 
4
3
  function priceTable() {
5
4
  return {
@@ -30,70 +29,27 @@ describe("/views", () => {
30
29
 
31
30
  beforeEach(async () => {
32
31
  await config.init()
33
- table = await config.createTable(priceTable())
34
32
  })
35
33
 
36
- const saveView = async (view) => {
37
- const viewToSave = {
38
- name: "TestView",
39
- field: "Price",
40
- calculation: "stats",
41
- tableId: table._id,
42
- ...view
43
- }
44
- return request
45
- .post(`/api/views`)
46
- .send(viewToSave)
47
- .set(config.defaultHeaders())
48
- .expect("Content-Type", /json/)
49
- .expect(200)
50
- }
51
-
52
34
  describe("create", () => {
53
-
54
- it("returns a success message when the view is successfully created", async () => {
55
- const res = await saveView()
56
- expect(res.body.tableId).toBe(table._id)
57
- expect(events.view.created).toBeCalledTimes(1)
58
- })
59
-
60
- it("creates a view with a calculation", async () => {
61
- jest.clearAllMocks()
62
-
63
- const res = await saveView({ calculation: "count" })
64
-
65
- expect(res.body.tableId).toBe(table._id)
66
- expect(events.view.created).toBeCalledTimes(1)
67
- expect(events.view.updated).not.toBeCalled()
68
- expect(events.view.calculationCreated).toBeCalledTimes(1)
69
- expect(events.view.calculationUpdated).not.toBeCalled()
70
- expect(events.view.calculationDeleted).not.toBeCalled()
71
- expect(events.view.filterCreated).not.toBeCalled()
72
- expect(events.view.filterUpdated).not.toBeCalled()
73
- expect(events.view.filterDeleted).not.toBeCalled()
35
+ beforeEach(async () => {
36
+ table = await config.createTable(priceTable())
74
37
  })
75
38
 
76
- it("creates a view with a filter", async () => {
77
- jest.clearAllMocks()
78
-
79
- const res = await saveView({
80
- calculation: null,
81
- filters: [{
82
- value: "1",
83
- condition: "EQUALS",
84
- key: "price"
85
- }],
86
- })
39
+ it("returns a success message when the view is successfully created", async () => {
40
+ const res = await request
41
+ .post(`/api/views`)
42
+ .send({
43
+ name: "TestView",
44
+ field: "Price",
45
+ calculation: "stats",
46
+ tableId: table._id,
47
+ })
48
+ .set(config.defaultHeaders())
49
+ .expect("Content-Type", /json/)
50
+ .expect(200)
87
51
 
88
52
  expect(res.body.tableId).toBe(table._id)
89
- expect(events.view.created).toBeCalledTimes(1)
90
- expect(events.view.updated).not.toBeCalled()
91
- expect(events.view.calculationCreated).not.toBeCalled()
92
- expect(events.view.calculationUpdated).not.toBeCalled()
93
- expect(events.view.calculationDeleted).not.toBeCalled()
94
- expect(events.view.filterCreated).toBeCalledTimes(1)
95
- expect(events.view.filterUpdated).not.toBeCalled()
96
- expect(events.view.filterDeleted).not.toBeCalled()
97
53
  })
98
54
 
99
55
  it("updates the table row with the new view metadata", async () => {
@@ -145,100 +101,6 @@ describe("/views", () => {
145
101
  })
146
102
  })
147
103
 
148
- describe("update", () => {
149
- it("updates a view with no calculation or filter changed", async () => {
150
- await saveView()
151
- jest.clearAllMocks()
152
-
153
- await saveView()
154
-
155
- expect(events.view.created).not.toBeCalled()
156
- expect(events.view.updated).toBeCalledTimes(1)
157
- expect(events.view.calculationCreated).not.toBeCalled()
158
- expect(events.view.calculationUpdated).not.toBeCalled()
159
- expect(events.view.calculationDeleted).not.toBeCalled()
160
- expect(events.view.filterCreated).not.toBeCalled()
161
- expect(events.view.filterUpdated).not.toBeCalled()
162
- expect(events.view.filterDeleted).not.toBeCalled()
163
- })
164
-
165
- it("updates a view calculation", async () => {
166
- await saveView({ calculation: "sum" })
167
- jest.clearAllMocks()
168
-
169
- await saveView({ calculation: "count" })
170
-
171
- expect(events.view.created).not.toBeCalled()
172
- expect(events.view.updated).toBeCalledTimes(1)
173
- expect(events.view.calculationCreated).not.toBeCalled()
174
- expect(events.view.calculationUpdated).toBeCalledTimes(1)
175
- expect(events.view.calculationDeleted).not.toBeCalled()
176
- expect(events.view.filterCreated).not.toBeCalled()
177
- expect(events.view.filterUpdated).not.toBeCalled()
178
- expect(events.view.filterDeleted).not.toBeCalled()
179
- })
180
-
181
- it("deletes a view calculation", async () => {
182
- await saveView({ calculation: "sum" })
183
- jest.clearAllMocks()
184
-
185
- await saveView({ calculation: null })
186
-
187
- expect(events.view.created).not.toBeCalled()
188
- expect(events.view.updated).toBeCalledTimes(1)
189
- expect(events.view.calculationCreated).not.toBeCalled()
190
- expect(events.view.calculationUpdated).not.toBeCalled()
191
- expect(events.view.calculationDeleted).toBeCalledTimes(1)
192
- expect(events.view.filterCreated).not.toBeCalled()
193
- expect(events.view.filterUpdated).not.toBeCalled()
194
- expect(events.view.filterDeleted).not.toBeCalled()
195
- })
196
-
197
- it("updates a view filter", async () => {
198
- await saveView({ filters: [{
199
- value: "1",
200
- condition: "EQUALS",
201
- key: "price"
202
- }] })
203
- jest.clearAllMocks()
204
-
205
- await saveView({ filters: [{
206
- value: "2",
207
- condition: "EQUALS",
208
- key: "price"
209
- }] })
210
-
211
- expect(events.view.created).not.toBeCalled()
212
- expect(events.view.updated).toBeCalledTimes(1)
213
- expect(events.view.calculationCreated).not.toBeCalled()
214
- expect(events.view.calculationUpdated).not.toBeCalled()
215
- expect(events.view.calculationDeleted).not.toBeCalled()
216
- expect(events.view.filterCreated).not.toBeCalled()
217
- expect(events.view.filterUpdated).toBeCalledTimes(1)
218
- expect(events.view.filterDeleted).not.toBeCalled()
219
- })
220
-
221
- it("deletes a view filter", async () => {
222
- await saveView({ filters: [{
223
- value: "1",
224
- condition: "EQUALS",
225
- key: "price"
226
- }] })
227
- jest.clearAllMocks()
228
-
229
- await saveView({ filters: [] })
230
-
231
- expect(events.view.created).not.toBeCalled()
232
- expect(events.view.updated).toBeCalledTimes(1)
233
- expect(events.view.calculationCreated).not.toBeCalled()
234
- expect(events.view.calculationUpdated).not.toBeCalled()
235
- expect(events.view.calculationDeleted).not.toBeCalled()
236
- expect(events.view.filterCreated).not.toBeCalled()
237
- expect(events.view.filterUpdated).not.toBeCalled()
238
- expect(events.view.filterDeleted).toBeCalledTimes(1)
239
- })
240
- })
241
-
242
104
  describe("fetch", () => {
243
105
  beforeEach(async () => {
244
106
  table = await config.createTable(priceTable())
@@ -262,6 +124,10 @@ describe("/views", () => {
262
124
  })
263
125
 
264
126
  describe("query", () => {
127
+ beforeEach(async () => {
128
+ table = await config.createTable(priceTable())
129
+ })
130
+
265
131
  it("returns data for the created view", async () => {
266
132
  await config.createView({
267
133
  name: "TestView",
@@ -335,82 +201,37 @@ describe("/views", () => {
335
201
  .expect(200)
336
202
  expect(res.body.map).toBeDefined()
337
203
  expect(res.body.meta.tableId).toEqual(table._id)
338
- expect(events.view.deleted).toBeCalledTimes(1)
339
204
  })
340
205
  })
341
206
 
342
207
  describe("exportView", () => {
343
-
344
- beforeEach(() => {
345
- jest.clearAllMocks()
346
- })
347
-
348
- const setupExport = async () => {
349
- const table = await config.createTable()
350
- await config.createRow({ name: "test-name", description: "test-desc" })
351
- return table
352
- }
353
-
354
- const exportView = async (viewName, format) => {
355
- return request
356
- .get(`/api/views/export?view=${viewName}&format=${format}`)
208
+ it("should be able to export a view", async () => {
209
+ await config.createTable(priceTable())
210
+ await config.createRow()
211
+ const view = await config.createView()
212
+ let res = await request
213
+ .get(`/api/views/export?view=${view.name}&format=json`)
357
214
  .set(config.defaultHeaders())
358
215
  .expect(200)
359
- }
360
-
361
- const assertJsonExport = (res) => {
362
- const rows = JSON.parse(res.text)
363
- expect(rows.length).toBe(1)
364
- expect(rows[0].name).toBe("test-name")
365
- expect(rows[0].description).toBe("test-desc")
366
- }
367
-
368
- const assertCSVExport = (res) => {
369
- expect(res.text).toBe("\"name\",\"description\"\n\"test-name\",\"test-desc\"")
370
- }
371
-
372
- it("should be able to export a table as JSON", async () => {
373
- const table = await setupExport()
374
-
375
- const res = await exportView(table._id, "json")
376
-
377
- assertJsonExport(res)
378
- expect(events.table.exported).toBeCalledTimes(1)
379
- expect(events.table.exported).toBeCalledWith(table, "json")
380
- })
381
-
382
- it("should be able to export a table as CSV", async () => {
383
- const table = await setupExport()
384
-
385
- const res = await exportView(table._id, "csv")
386
-
387
- assertCSVExport(res)
388
- expect(events.table.exported).toBeCalledTimes(1)
389
- expect(events.table.exported).toBeCalledWith(table, "csv")
390
- })
391
-
392
- it("should be able to export a view as JSON", async () => {
393
- let table = await setupExport()
394
- const view = await config.createView()
395
- table = await config.getTable(table._id)
396
-
397
- let res = await exportView(view.name, "json")
398
-
399
- assertJsonExport(res)
400
- expect(events.view.exported).toBeCalledTimes(1)
401
- expect(events.view.exported).toBeCalledWith(table, "json")
402
- })
403
-
404
- it("should be able to export a view as CSV", async () => {
405
- let table = await setupExport()
406
- const view = await config.createView()
407
- table = await config.getTable(table._id)
408
-
409
- let res = await exportView(view.name, "csv")
410
-
411
- assertCSVExport(res)
412
- expect(events.view.exported).toBeCalledTimes(1)
413
- expect(events.view.exported).toBeCalledWith(table, "csv")
216
+ let error
217
+ try {
218
+ const obj = JSON.parse(res.text)
219
+ expect(obj.length).toBe(1)
220
+ } catch (err) {
221
+ error = err
222
+ }
223
+ expect(error).toBeUndefined()
224
+ res = await request
225
+ .get(`/api/views/export?view=${view.name}&format=csv`)
226
+ .set(config.defaultHeaders())
227
+ .expect(200)
228
+ // this shouldn't be JSON
229
+ try {
230
+ JSON.parse(res.text)
231
+ } catch (err) {
232
+ error = err
233
+ }
234
+ expect(error).toBeDefined()
414
235
  })
415
236
  })
416
237
  })
package/src/app.ts CHANGED
@@ -18,7 +18,6 @@ const { logAlert } = require("@budibase/backend-core/logging")
18
18
  const { Thread } = require("./threads")
19
19
  import redis from "./utilities/redis"
20
20
  import * as migrations from "./migrations"
21
- import { events, installation } from "@budibase/backend-core"
22
21
 
23
22
  const app = new Koa()
24
23
 
@@ -84,7 +83,6 @@ server.on("close", async () => {
84
83
  }
85
84
  await automations.shutdown()
86
85
  await redis.shutdown()
87
- await events.shutdown()
88
86
  await Thread.shutdown()
89
87
  api.shutdown()
90
88
  if (!env.isTest()) {
@@ -98,22 +96,6 @@ module.exports = server.listen(env.PORT || 0, async () => {
98
96
  eventEmitter.emitPort(env.PORT)
99
97
  fileSystem.init()
100
98
  await redis.init()
101
-
102
- // run migrations on startup if not done via http
103
- // not recommended in a clustered environment
104
- if (!env.HTTP_MIGRATIONS && !env.isTest()) {
105
- try {
106
- await migrations.migrate()
107
- } catch (e) {
108
- logAlert("Error performing migrations. Exiting.", e)
109
- shutdown()
110
- }
111
- }
112
-
113
- // check for version updates
114
- await installation.checkInstallVersion()
115
-
116
- // done last - this will never complete
117
99
  await automations.init()
118
100
  })
119
101
 
@@ -136,3 +118,12 @@ process.on("uncaughtException", err => {
136
118
  process.on("SIGTERM", () => {
137
119
  shutdown()
138
120
  })
121
+
122
+ // run migrations on startup if not done via http
123
+ // not recommended in a clustered environment
124
+ if (!env.HTTP_MIGRATIONS) {
125
+ migrations.migrate().catch(err => {
126
+ logAlert("Error performing migrations. Exiting.", err)
127
+ shutdown()
128
+ })
129
+ }
@@ -1,7 +1,5 @@
1
1
  const { processEvent } = require("./utils")
2
2
  const { queue, shutdown } = require("./bullboard")
3
- const { TRIGGER_DEFINITIONS } = require("./triggers")
4
- const { ACTION_DEFINITIONS } = require("./actions")
5
3
 
6
4
  /**
7
5
  * This module is built purely to kick off the worker farm and manage the inputs/outputs
@@ -22,5 +20,3 @@ exports.shutdown = () => {
22
20
  }
23
21
 
24
22
  exports.queue = queue
25
- exports.TRIGGER_DEFINITIONS = TRIGGER_DEFINITIONS
26
- exports.ACTION_DEFINITIONS = ACTION_DEFINITIONS
@@ -72,7 +72,7 @@ exports.run = async function ({ inputs, appId, emitter }) {
72
72
  })
73
73
 
74
74
  try {
75
- await queryController.executeV1(ctx)
75
+ await queryController.executeV2(ctx)
76
76
  const { data, ...rest } = ctx.body
77
77
  return {
78
78
  response: data,
@@ -1,9 +1,5 @@
1
1
  const setup = require("./utilities")
2
2
 
3
- // need real Date for this test
4
- const tk = require('timekeeper');
5
- tk.reset()
6
-
7
3
  describe("test the delay logic", () => {
8
4
  it("should be able to run the delay", async () => {
9
5
  const time = 100
@@ -1,12 +1,9 @@
1
1
  const { join } = require("path")
2
2
 
3
3
  function isTest() {
4
- return isCypress() || isJest()
5
- }
6
-
7
- function isJest() {
8
4
  return (
9
5
  process.env.NODE_ENV === "jest" ||
6
+ process.env.NODE_ENV === "cypress" ||
10
7
  (process.env.JEST_WORKER_ID != null &&
11
8
  process.env.JEST_WORKER_ID !== "null")
12
9
  )
@@ -70,6 +67,7 @@ module.exports = {
70
67
  AUTOMATION_MAX_ITERATIONS: process.env.AUTOMATION_MAX_ITERATIONS,
71
68
  SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
72
69
  DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
70
+ POSTHOG_TOKEN: process.env.POSTHOG_TOKEN,
73
71
  QUERY_THREAD_TIMEOUT: parseIntSafe(process.env.QUERY_THREAD_TIMEOUT),
74
72
  SQL_MAX_ROWS: process.env.SQL_MAX_ROWS,
75
73
  // flags
@@ -86,7 +84,6 @@ module.exports = {
86
84
  module.exports[key] = value
87
85
  },
88
86
  isTest,
89
- isJest,
90
87
  isCypress,
91
88
  isDev,
92
89
  isProd: () => {
@@ -66,7 +66,6 @@ module Firebase {
66
66
  "==",
67
67
  "<",
68
68
  "<=",
69
- "==",
70
69
  "!=",
71
70
  ">=",
72
71
  ">",
@@ -1,6 +1,7 @@
1
- import { migrations, redis } from "@budibase/backend-core"
2
- import { Migration, MigrationOptions, MigrationName } from "@budibase/types"
3
- import env from "../environment"
1
+ const {
2
+ MIGRATION_TYPES,
3
+ runMigrations,
4
+ } = require("@budibase/backend-core/migrations")
4
5
 
5
6
  // migration functions
6
7
  import * as userEmailViewCasing from "./functions/userEmailViewCasing"
@@ -8,129 +9,59 @@ import * as quota1 from "./functions/quotas1"
8
9
  import * as appUrls from "./functions/appUrls"
9
10
  import * as developerQuota from "./functions/developerQuota"
10
11
  import * as publishedAppsQuota from "./functions/publishedAppsQuota"
11
- import * as backfill from "./functions/backfill"
12
+
13
+ export interface Migration {
14
+ type: string
15
+ name: string
16
+ opts?: object
17
+ fn: Function
18
+ }
12
19
 
13
20
  /**
14
- * Populate the migration function and additional configuration from
15
- * the static migration definitions.
21
+ * e.g.
22
+ * {
23
+ * tenantIds: ['bb'],
24
+ * force: {
25
+ * global: ['quota_1']
26
+ * }
27
+ * }
16
28
  */
17
- export const buildMigrations = () => {
18
- const definitions = migrations.DEFINITIONS
19
- const serverMigrations: Migration[] = []
20
-
21
- for (const definition of definitions) {
22
- switch (definition.name) {
23
- case MigrationName.USER_EMAIL_VIEW_CASING: {
24
- serverMigrations.push({
25
- ...definition,
26
- fn: userEmailViewCasing.run,
27
- })
28
- break
29
- }
30
- case MigrationName.QUOTAS_1: {
31
- serverMigrations.push({
32
- ...definition,
33
- fn: quota1.run,
34
- })
35
- break
36
- }
37
- case MigrationName.APP_URLS: {
38
- serverMigrations.push({
39
- ...definition,
40
- appOpts: { all: true },
41
- fn: appUrls.run,
42
- })
43
- break
44
- }
45
- case MigrationName.DEVELOPER_QUOTA: {
46
- serverMigrations.push({
47
- ...definition,
48
- fn: developerQuota.run,
49
- })
50
- break
51
- }
52
- case MigrationName.PUBLISHED_APP_QUOTA: {
53
- serverMigrations.push({
54
- ...definition,
55
- fn: publishedAppsQuota.run,
56
- })
57
- break
58
- }
59
- case MigrationName.EVENT_APP_BACKFILL: {
60
- serverMigrations.push({
61
- ...definition,
62
- appOpts: { all: true },
63
- fn: backfill.app.run,
64
- silent: !!env.SELF_HOSTED, // reduce noisy logging
65
- preventRetry: !!env.SELF_HOSTED, // only ever run once
66
- })
67
- break
68
- }
69
- case MigrationName.EVENT_GLOBAL_BACKFILL: {
70
- serverMigrations.push({
71
- ...definition,
72
- fn: backfill.global.run,
73
- silent: !!env.SELF_HOSTED, // reduce noisy logging
74
- preventRetry: !!env.SELF_HOSTED, // only ever run once
75
- })
76
- break
77
- }
78
- case MigrationName.EVENT_INSTALLATION_BACKFILL: {
79
- serverMigrations.push({
80
- ...definition,
81
- fn: backfill.installation.run,
82
- silent: !!env.SELF_HOSTED, // reduce noisy logging
83
- preventRetry: !!env.SELF_HOSTED, // only ever run once
84
- })
85
- break
86
- }
87
- }
29
+ export interface MigrationOptions {
30
+ tenantIds?: string[]
31
+ force?: {
32
+ [type: string]: string[]
88
33
  }
89
-
90
- return serverMigrations
91
34
  }
92
35
 
93
- export const MIGRATIONS = buildMigrations()
36
+ export const MIGRATIONS: Migration[] = [
37
+ {
38
+ type: MIGRATION_TYPES.GLOBAL,
39
+ name: "user_email_view_casing",
40
+ fn: userEmailViewCasing.run,
41
+ },
42
+ {
43
+ type: MIGRATION_TYPES.GLOBAL,
44
+ name: "quotas_1",
45
+ fn: quota1.run,
46
+ },
47
+ {
48
+ type: MIGRATION_TYPES.APP,
49
+ name: "app_urls",
50
+ opts: { all: true },
51
+ fn: appUrls.run,
52
+ },
53
+ {
54
+ type: MIGRATION_TYPES.GLOBAL,
55
+ name: "developer_quota",
56
+ fn: developerQuota.run,
57
+ },
58
+ {
59
+ type: MIGRATION_TYPES.GLOBAL,
60
+ name: "published_apps_quota",
61
+ fn: publishedAppsQuota.run,
62
+ },
63
+ ]
94
64
 
95
65
  export const migrate = async (options?: MigrationOptions) => {
96
- if (env.SELF_HOSTED) {
97
- // self host runs migrations on startup
98
- // make sure only a single instance runs them
99
- await migrateWithLock(options)
100
- } else {
101
- await migrations.runMigrations(MIGRATIONS, options)
102
- }
103
- }
104
-
105
- const migrateWithLock = async (options?: MigrationOptions) => {
106
- // get a new lock client
107
-
108
- const redlock = await redis.clients.getMigrationsRedlock()
109
- // lock for 15 minutes
110
- const ttl = 1000 * 60 * 15
111
-
112
- let migrationLock
113
-
114
- // acquire lock
115
- try {
116
- migrationLock = await redlock.lock("migrations", ttl)
117
- } catch (e: any) {
118
- if (e.name === "LockError") {
119
- return
120
- } else {
121
- throw e
122
- }
123
- }
124
-
125
- // run migrations
126
- try {
127
- await migrations.runMigrations(MIGRATIONS, options)
128
- } finally {
129
- // release lock
130
- try {
131
- await migrationLock.unlock()
132
- } catch (e) {
133
- console.error("unable to release migration lock")
134
- }
135
- }
66
+ await runMigrations(MIGRATIONS, options)
136
67
  }
package/src/module.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ declare module "@budibase/backend-core"
1
2
  declare module "@budibase/backend-core/tenancy"
2
3
  declare module "@budibase/backend-core/db"
3
4
  declare module "@budibase/backend-core/context"