@budibase/server 1.0.49-alpha.0 → 1.0.49-alpha.4

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 (239) hide show
  1. package/builder/assets/{index.dd9e386f.css → index.83c0944f.css} +1 -1
  2. package/builder/assets/{index.8184eed9.js → index.f763d886.js} +206 -205
  3. package/builder/assets/{vendor.3bd2f661.js → vendor.d526bfe8.js} +1 -1
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +1743 -1610
  6. package/coverage/coverage-final.json +90 -89
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/application.js.html +106 -106
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
  12. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +27 -12
  18. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/{migrations/usageQuotas/syncApps.js.html → api/controllers/migrations.js.html} +30 -45
  22. package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/index.js.html +19 -19
  25. package/coverage/lcov-report/api/controllers/query/validation.js.html +6 -6
  26. package/coverage/lcov-report/api/controllers/role.js.html +9 -9
  27. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
  29. package/coverage/lcov-report/api/controllers/row/index.html +40 -25
  30. package/coverage/lcov-report/api/controllers/row/index.js.html +13 -13
  31. package/coverage/lcov-report/api/controllers/row/internal.js.html +83 -146
  32. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +41 -17
  33. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +551 -0
  34. package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
  35. package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
  36. package/coverage/lcov-report/api/controllers/script.js.html +4 -4
  37. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +629 -0
  38. package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
  39. package/coverage/lcov-report/api/controllers/table/index.html +45 -30
  40. package/coverage/lcov-report/api/controllers/table/index.js.html +23 -65
  41. package/coverage/lcov-report/api/controllers/table/internal.js.html +33 -15
  42. package/coverage/lcov-report/api/controllers/table/utils.js.html +161 -41
  43. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/user.js.html +20 -20
  45. package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
  46. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  47. package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
  48. package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
  49. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
  50. package/coverage/lcov-report/api/controllers/webhook.js.html +15 -15
  51. package/coverage/lcov-report/api/index.html +1 -1
  52. package/coverage/lcov-report/api/index.js.html +3 -3
  53. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/index.html +22 -7
  65. package/coverage/lcov-report/api/routes/index.js.html +10 -4
  66. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  69. package/coverage/lcov-report/{migrations/usageQuotas/index.js.html → api/routes/migrations.js.html} +25 -55
  70. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  78. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  79. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  80. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  81. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  82. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  83. package/coverage/lcov-report/automations/actions.js.html +24 -24
  84. package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
  85. package/coverage/lcov-report/automations/bullboard.js.html +16 -16
  86. package/coverage/lcov-report/automations/index.html +1 -1
  87. package/coverage/lcov-report/automations/index.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
  89. package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
  90. package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
  91. package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
  92. package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
  93. package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
  94. package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
  95. package/coverage/lcov-report/automations/steps/filter.js.html +7 -7
  96. package/coverage/lcov-report/automations/steps/index.html +1 -1
  97. package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
  98. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
  99. package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -10
  100. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
  101. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
  102. package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
  103. package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
  104. package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
  105. package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
  106. package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
  107. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
  108. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
  110. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
  111. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
  112. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
  113. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
  114. package/coverage/lcov-report/automations/triggers.js.html +18 -18
  115. package/coverage/lcov-report/automations/utils.js.html +32 -32
  116. package/coverage/lcov-report/constants/index.html +5 -5
  117. package/coverage/lcov-report/constants/index.js.html +42 -27
  118. package/coverage/lcov-report/constants/layouts.js.html +5 -5
  119. package/coverage/lcov-report/constants/screens.js.html +4 -4
  120. package/coverage/lcov-report/db/client.js.html +18 -18
  121. package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
  122. package/coverage/lcov-report/db/index.html +1 -1
  123. package/coverage/lcov-report/db/index.js.html +3 -3
  124. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +7 -7
  125. package/coverage/lcov-report/db/linkedRows/index.html +10 -10
  126. package/coverage/lcov-report/db/linkedRows/index.js.html +26 -29
  127. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +13 -13
  128. package/coverage/lcov-report/db/newid.js.html +4 -4
  129. package/coverage/lcov-report/db/utils.js.html +71 -71
  130. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  131. package/coverage/lcov-report/events/index.html +1 -1
  132. package/coverage/lcov-report/events/index.js.html +5 -5
  133. package/coverage/lcov-report/events/utils.js.html +3 -3
  134. package/coverage/lcov-report/index.html +61 -76
  135. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  136. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  137. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  138. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  139. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  140. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  141. package/coverage/lcov-report/middleware/index.html +11 -11
  142. package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
  143. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  144. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  145. package/coverage/lcov-report/middleware/usageQuota.js.html +6 -12
  146. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  147. package/coverage/lcov-report/threads/automation.js.html +1 -1
  148. package/coverage/lcov-report/threads/index.html +1 -1
  149. package/coverage/lcov-report/threads/index.js.html +10 -10
  150. package/coverage/lcov-report/threads/query.js.html +1 -1
  151. package/coverage/lcov-report/threads/utils.js.html +14 -14
  152. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  153. package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
  154. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  155. package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
  156. package/coverage/lcov-report/utilities/global.js.html +14 -14
  157. package/coverage/lcov-report/utilities/index.html +1 -1
  158. package/coverage/lcov-report/utilities/index.js.html +24 -24
  159. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +8 -8
  160. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  161. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  162. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  163. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -27
  164. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +80 -44
  165. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +75 -27
  166. package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
  167. package/coverage/lcov-report/utilities/security.js.html +8 -8
  168. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  169. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  170. package/coverage/lcov-report/utilities/usageQuota/index.js.html +10 -10
  171. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  172. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  173. package/coverage/lcov-report/utilities/users.js.html +5 -5
  174. package/coverage/lcov-report/utilities/workerRequests.js.html +12 -12
  175. package/coverage/lcov.info +2545 -2257
  176. package/dist/api/controllers/application.js +18 -20
  177. package/dist/api/controllers/migrations.js +21 -0
  178. package/dist/api/controllers/row/internal.js +30 -53
  179. package/dist/api/controllers/row/internalSearch.js +12 -4
  180. package/dist/api/controllers/row/staticFormula.js +147 -0
  181. package/dist/api/controllers/table/bulkFormula.js +160 -0
  182. package/dist/api/controllers/table/index.js +3 -6
  183. package/dist/api/controllers/table/internal.js +7 -0
  184. package/dist/api/controllers/table/utils.js +32 -10
  185. package/dist/api/routes/index.js +2 -0
  186. package/dist/api/routes/migrations.js +9 -0
  187. package/dist/app.js +35 -5
  188. package/dist/constants/index.js +4 -0
  189. package/dist/db/linkedRows/index.js +4 -5
  190. package/dist/environment.js +1 -0
  191. package/dist/middleware/usageQuota.js +0 -2
  192. package/dist/migrations/functions/appUrls.js +46 -0
  193. package/dist/migrations/functions/quotas1.js +50 -0
  194. package/dist/migrations/{usageQuotas → functions/usageQuotas}/index.js +6 -10
  195. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncApps.js +11 -5
  196. package/dist/migrations/{usageQuotas → functions/usageQuotas}/syncRows.js +14 -8
  197. package/dist/migrations/functions/userEmailViewCasing.js +24 -0
  198. package/dist/migrations/index.js +62 -0
  199. package/dist/package.json +4 -4
  200. package/dist/tests/utilities/TestConfiguration.js +3 -0
  201. package/dist/tsconfig.tsbuildinfo +1 -1
  202. package/dist/utilities/rowProcessor/index.js +18 -11
  203. package/dist/utilities/rowProcessor/utils.js +14 -4
  204. package/package.json +5 -5
  205. package/src/api/controllers/application.js +3 -3
  206. package/src/api/controllers/migrations.js +13 -0
  207. package/src/api/controllers/row/internal.js +29 -50
  208. package/src/api/controllers/row/internalSearch.js +12 -4
  209. package/src/api/controllers/row/staticFormula.js +157 -0
  210. package/src/api/controllers/table/bulkFormula.js +183 -0
  211. package/src/api/controllers/table/index.js +3 -17
  212. package/src/api/controllers/table/internal.js +7 -1
  213. package/src/api/controllers/table/utils.js +48 -8
  214. package/src/api/routes/index.js +2 -0
  215. package/src/api/routes/migrations.js +14 -0
  216. package/src/app.ts +18 -5
  217. package/src/constants/index.js +5 -0
  218. package/src/db/linkedRows/index.js +4 -5
  219. package/src/definitions/common.ts +3 -0
  220. package/src/environment.js +1 -0
  221. package/src/middleware/usageQuota.js +0 -2
  222. package/src/migrations/functions/appUrls.ts +34 -0
  223. package/src/migrations/functions/quotas1.ts +20 -0
  224. package/src/migrations/functions/tests/appUrls.spec.js +29 -0
  225. package/src/migrations/{tests/usageQuotas/index.spec.js → functions/tests/quotas1.spec.js} +5 -5
  226. package/src/migrations/functions/tests/userEmailViewCasing.spec.js +25 -0
  227. package/src/migrations/functions/usageQuotas/index.ts +8 -0
  228. package/src/migrations/{usageQuotas/syncApps.js → functions/usageQuotas/syncApps.ts} +3 -3
  229. package/src/migrations/{usageQuotas/syncRows.js → functions/usageQuotas/syncRows.ts} +5 -5
  230. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncApps.spec.js +4 -4
  231. package/src/migrations/{tests/usageQuotas → functions/usageQuotas/tests}/syncRows.spec.js +4 -4
  232. package/src/migrations/functions/userEmailViewCasing.ts +13 -0
  233. package/src/migrations/index.ts +56 -0
  234. package/src/tests/utilities/TestConfiguration.js +4 -0
  235. package/src/utilities/rowProcessor/index.js +24 -12
  236. package/src/utilities/rowProcessor/utils.js +23 -7
  237. package/coverage/lcov-report/migrations/usageQuotas/index.html +0 -141
  238. package/coverage/lcov-report/migrations/usageQuotas/syncRows.js.html +0 -143
  239. package/src/migrations/usageQuotas/index.js +0 -24
@@ -1,14 +1,14 @@
1
1
  const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy")
2
2
  const { getAllApps } = require("@budibase/backend-core/db")
3
- const CouchDB = require("../../db")
4
- const { getUsageQuotaDoc } = require("../../utilities/usageQuota")
5
- const { getUniqueRows } = require("../../utilities/usageQuota/rows")
3
+ import CouchDB from "../../../db"
4
+ import { getUsageQuotaDoc } from "../../../utilities/usageQuota"
5
+ import { getUniqueRows } from "../../../utilities/usageQuota/rows"
6
6
 
7
- exports.run = async () => {
7
+ export const run = async () => {
8
8
  const db = getGlobalDB()
9
9
  // get all rows in all apps
10
10
  const allApps = await getAllApps(CouchDB, { all: true })
11
- const appIds = allApps ? allApps.map(app => app.appId) : []
11
+ const appIds = allApps ? allApps.map((app: { appId: any }) => app.appId) : []
12
12
  const rows = await getUniqueRows(appIds)
13
13
  const rowCount = rows ? rows.length : 0
14
14
 
@@ -1,8 +1,8 @@
1
1
  const { getGlobalDB } = require("@budibase/backend-core/tenancy")
2
- const TestConfig = require("../../../tests/utilities/TestConfiguration")
3
- const { getUsageQuotaDoc, update, Properties } = require("../../../utilities/usageQuota")
4
- const syncApps = require("../../usageQuotas/syncApps")
5
- const env = require("../../../environment")
2
+ const TestConfig = require("../../../../tests/utilities/TestConfiguration")
3
+ const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
4
+ const syncApps = require("../syncApps")
5
+ const env = require("../../../../environment")
6
6
 
7
7
  describe("syncApps", () => {
8
8
  let config = new TestConfig(false)
@@ -1,8 +1,8 @@
1
1
  const { getGlobalDB } = require("@budibase/backend-core/tenancy")
2
- const TestConfig = require("../../../tests/utilities/TestConfiguration")
3
- const { getUsageQuotaDoc, update, Properties } = require("../../../utilities/usageQuota")
4
- const syncRows = require("../../usageQuotas/syncRows")
5
- const env = require("../../../environment")
2
+ const TestConfig = require("../../../../tests/utilities/TestConfiguration")
3
+ const { getUsageQuotaDoc, update, Properties } = require("../../../../utilities/usageQuota")
4
+ const syncRows = require("../syncRows")
5
+ const env = require("../../../../environment")
6
6
 
7
7
  describe("syncRows", () => {
8
8
  let config = new TestConfig(false)
@@ -0,0 +1,13 @@
1
+ const { createUserEmailView } = require("@budibase/backend-core/db")
2
+
3
+ /**
4
+ * Date:
5
+ * October 2021
6
+ *
7
+ * Description:
8
+ * Recreate the user email view to include latest changes i.e. lower casing the email address
9
+ */
10
+
11
+ export const run = async (db: any) => {
12
+ await createUserEmailView(db)
13
+ }
@@ -0,0 +1,56 @@
1
+ import CouchDB from "../db"
2
+ const {
3
+ MIGRATION_TYPES,
4
+ runMigrations,
5
+ } = require("@budibase/backend-core/migrations")
6
+
7
+ // migration functions
8
+ import * as userEmailViewCasing from "./functions/userEmailViewCasing"
9
+ import * as quota1 from "./functions/quotas1"
10
+ import * as appUrls from "./functions/appUrls"
11
+
12
+ export interface Migration {
13
+ type: string
14
+ name: string
15
+ opts?: object
16
+ fn: Function
17
+ }
18
+
19
+ /**
20
+ * e.g.
21
+ * {
22
+ * tenantIds: ['bb'],
23
+ * force: {
24
+ * global: ['quota_1']
25
+ * }
26
+ * }
27
+ */
28
+ export interface MigrationOptions {
29
+ tenantIds?: string[]
30
+ forced?: {
31
+ [type: string]: string[]
32
+ }
33
+ }
34
+
35
+ export const MIGRATIONS: Migration[] = [
36
+ {
37
+ type: MIGRATION_TYPES.GLOBAL,
38
+ name: "user_email_view_casing",
39
+ fn: userEmailViewCasing.run,
40
+ },
41
+ {
42
+ type: MIGRATION_TYPES.GLOBAL,
43
+ name: "quotas_1",
44
+ fn: quota1.run,
45
+ },
46
+ {
47
+ type: MIGRATION_TYPES.APP,
48
+ name: "app_urls",
49
+ opts: { all: true },
50
+ fn: appUrls.run,
51
+ },
52
+ ]
53
+
54
+ export const migrate = async (options?: MigrationOptions) => {
55
+ await runMigrations(CouchDB, MIGRATIONS, options)
56
+ }
@@ -50,6 +50,10 @@ class TestConfiguration {
50
50
  return this.appId
51
51
  }
52
52
 
53
+ getCouch() {
54
+ return CouchDB
55
+ }
56
+
53
57
  async _req(config, params, controlFunc) {
54
58
  const request = {}
55
59
  // fake cookies, we don't need them
@@ -180,6 +180,8 @@ function processAutoColumn(
180
180
  }
181
181
  exports.processAutoColumn = processAutoColumn
182
182
 
183
+ exports.processFormulas = processFormulas
184
+
183
185
  /**
184
186
  * This will coerce a value to the correct types based on the type transform map
185
187
  * @param {object} row The value to coerce
@@ -229,11 +231,12 @@ exports.inputProcessing = (
229
231
  }
230
232
  continue
231
233
  }
232
- // specific case to delete formula values if they get saved
233
- // type coercion cannot completely remove the field, so have to do it here
234
+ // remove any formula values, they are to be generated
234
235
  if (field.type === FieldTypes.FORMULA) {
235
236
  delete clonedRow[key]
236
- } else {
237
+ }
238
+ // otherwise coerce what is there to correct types
239
+ else {
237
240
  clonedRow[key] = exports.coerce(value, field.type)
238
241
  }
239
242
  }
@@ -250,7 +253,7 @@ exports.inputProcessing = (
250
253
  /**
251
254
  * This function enriches the input rows with anything they are supposed to contain, for example
252
255
  * link records or attachment links.
253
- * @param {object} ctx the request which is looking for enriched rows.
256
+ * @param {string} appId the app in which the request is looking for enriched rows.
254
257
  * @param {object} table the table from which these rows came from originally, this is used to determine
255
258
  * the schema of the rows and then enrich.
256
259
  * @param {object[]|object} rows the rows which are to be enriched.
@@ -258,22 +261,21 @@ exports.inputProcessing = (
258
261
  * @returns {object[]|object} the enriched rows will be returned.
259
262
  */
260
263
  exports.outputProcessing = async (
261
- ctx,
264
+ { appId },
262
265
  table,
263
266
  rows,
264
267
  opts = { squash: true }
265
268
  ) => {
266
- const appId = ctx.appId
267
269
  let wasArray = true
268
270
  if (!(rows instanceof Array)) {
269
271
  rows = [rows]
270
272
  wasArray = false
271
273
  }
272
274
  // attach any linked row information
273
- let enriched = await linkRows.attachFullLinkedDocs(ctx, table, rows)
275
+ let enriched = await linkRows.attachFullLinkedDocs(appId, table, rows)
274
276
 
275
277
  // process formulas
276
- enriched = processFormulas(table, enriched)
278
+ enriched = processFormulas(table, enriched, { dynamic: true })
277
279
 
278
280
  // update the attachments URL depending on hosting
279
281
  for (let [property, column] of Object.entries(table.schema)) {
@@ -305,9 +307,15 @@ exports.outputProcessing = async (
305
307
  * @param {any} row optional - the row being removed.
306
308
  * @param {any} rows optional - if multiple rows being deleted can do this in bulk.
307
309
  * @param {any} oldRow optional - if updating a row this will determine the difference.
310
+ * @param {any} oldTable optional - if updating a table, can supply the old table to look for
311
+ * deleted attachment columns.
308
312
  * @return {Promise<void>} When all attachments have been removed this will return.
309
313
  */
310
- exports.cleanupAttachments = async (appId, table, { row, rows, oldRow }) => {
314
+ exports.cleanupAttachments = async (
315
+ appId,
316
+ table,
317
+ { row, rows, oldRow, oldTable }
318
+ ) => {
311
319
  if (!isProdAppID(appId)) {
312
320
  const prodAppId = getDeployedAppID(appId)
313
321
  // if prod exists, then don't allow deleting
@@ -322,12 +330,16 @@ exports.cleanupAttachments = async (appId, table, { row, rows, oldRow }) => {
322
330
  files = files.concat(row[key].map(attachment => attachment.key))
323
331
  }
324
332
  }
325
- for (let [key, schema] of Object.entries(table.schema)) {
333
+ const schemaToUse = oldTable ? oldTable.schema : table.schema
334
+ for (let [key, schema] of Object.entries(schemaToUse)) {
326
335
  if (schema.type !== FieldTypes.ATTACHMENT) {
327
336
  continue
328
337
  }
329
- // if updating, need to manage the differences
330
- if (oldRow && row) {
338
+ // old table had this column, new table doesn't - delete it
339
+ if (oldTable && !table.schema[key]) {
340
+ rows.forEach(row => addFiles(row, key))
341
+ } else if (oldRow && row) {
342
+ // if updating, need to manage the differences
331
343
  files = files.concat(getRemovedAttachmentKeys(oldRow, row, key))
332
344
  } else if (row) {
333
345
  addFiles(row, key)
@@ -1,23 +1,39 @@
1
- const { FieldTypes } = require("../../constants")
1
+ const { FieldTypes, FormulaTypes } = require("../../constants")
2
2
  const { processStringSync } = require("@budibase/string-templates")
3
3
 
4
4
  /**
5
5
  * Looks through the rows provided and finds formulas - which it then processes.
6
6
  */
7
- exports.processFormulas = (table, rows) => {
7
+ exports.processFormulas = (
8
+ table,
9
+ rows,
10
+ { dynamic, contextRows } = { dynamic: true }
11
+ ) => {
8
12
  const single = !Array.isArray(rows)
9
13
  if (single) {
10
14
  rows = [rows]
15
+ contextRows = contextRows ? [contextRows] : contextRows
11
16
  }
12
17
  for (let [column, schema] of Object.entries(table.schema)) {
13
- if (schema.type !== FieldTypes.FORMULA) {
18
+ const isStatic = schema.formulaType === FormulaTypes.STATIC
19
+ if (
20
+ schema.type !== FieldTypes.FORMULA ||
21
+ (dynamic && isStatic) ||
22
+ (!dynamic && !isStatic)
23
+ ) {
14
24
  continue
15
25
  }
16
26
  // iterate through rows and process formula
17
- rows = rows.map(row => ({
18
- ...row,
19
- [column]: processStringSync(schema.formula, row),
20
- }))
27
+ for (let i = 0; i < rows.length; i++) {
28
+ if (schema.formula) {
29
+ let row = rows[i]
30
+ let context = contextRows ? contextRows[i] : row
31
+ rows[i] = {
32
+ ...row,
33
+ [column]: processStringSync(schema.formula, context),
34
+ }
35
+ }
36
+ }
21
37
  }
22
38
  return single ? rows[0] : rows
23
39
  }
@@ -1,141 +0,0 @@
1
-
2
- <!doctype html>
3
- <html lang="en">
4
-
5
- <head>
6
- <title>Code coverage report for migrations/usageQuotas</title>
7
- <meta charset="utf-8" />
8
- <link rel="stylesheet" href="../../prettify.css" />
9
- <link rel="stylesheet" href="../../base.css" />
10
- <link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
11
- <meta name="viewport" content="width=device-width, initial-scale=1" />
12
- <style type='text/css'>
13
- .coverage-summary .sorter {
14
- background-image: url(../../sort-arrow-sprite.png);
15
- }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <div class='wrapper'>
21
- <div class='pad1'>
22
- <h1><a href="../../index.html">All files</a> migrations/usageQuotas</h1>
23
- <div class='clearfix'>
24
-
25
- <div class='fl pad1y space-right2'>
26
- <span class="strong">100% </span>
27
- <span class="quiet">Statements</span>
28
- <span class='fraction'>40/40</span>
29
- </div>
30
-
31
-
32
- <div class='fl pad1y space-right2'>
33
- <span class="strong">62.5% </span>
34
- <span class="quiet">Branches</span>
35
- <span class='fraction'>5/8</span>
36
- </div>
37
-
38
-
39
- <div class='fl pad1y space-right2'>
40
- <span class="strong">100% </span>
41
- <span class="quiet">Functions</span>
42
- <span class='fraction'>5/5</span>
43
- </div>
44
-
45
-
46
- <div class='fl pad1y space-right2'>
47
- <span class="strong">100% </span>
48
- <span class="quiet">Lines</span>
49
- <span class='fraction'>39/39</span>
50
- </div>
51
-
52
-
53
- </div>
54
- <p class="quiet">
55
- Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
- </p>
57
- </div>
58
- <div class='status-line high'></div>
59
- <div class="pad1">
60
- <table class="coverage-summary">
61
- <thead>
62
- <tr>
63
- <th data-col="file" data-fmt="html" data-html="true" class="file">File</th>
64
- <th data-col="pic" data-type="number" data-fmt="html" data-html="true" class="pic"></th>
65
- <th data-col="statements" data-type="number" data-fmt="pct" class="pct">Statements</th>
66
- <th data-col="statements_raw" data-type="number" data-fmt="html" class="abs"></th>
67
- <th data-col="branches" data-type="number" data-fmt="pct" class="pct">Branches</th>
68
- <th data-col="branches_raw" data-type="number" data-fmt="html" class="abs"></th>
69
- <th data-col="functions" data-type="number" data-fmt="pct" class="pct">Functions</th>
70
- <th data-col="functions_raw" data-type="number" data-fmt="html" class="abs"></th>
71
- <th data-col="lines" data-type="number" data-fmt="pct" class="pct">Lines</th>
72
- <th data-col="lines_raw" data-type="number" data-fmt="html" class="abs"></th>
73
- </tr>
74
- </thead>
75
- <tbody><tr>
76
- <td class="file high" data-value="index.js"><a href="index.js.html">index.js</a></td>
77
- <td data-value="100" class="pic high">
78
- <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
79
- </td>
80
- <td data-value="100" class="pct high">100%</td>
81
- <td data-value="10" class="abs high">10/10</td>
82
- <td data-value="100" class="pct high">100%</td>
83
- <td data-value="2" class="abs high">2/2</td>
84
- <td data-value="100" class="pct high">100%</td>
85
- <td data-value="2" class="abs high">2/2</td>
86
- <td data-value="100" class="pct high">100%</td>
87
- <td data-value="10" class="abs high">10/10</td>
88
- </tr>
89
-
90
- <tr>
91
- <td class="file high" data-value="syncApps.js"><a href="syncApps.js.html">syncApps.js</a></td>
92
- <td data-value="100" class="pic high">
93
- <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
94
- </td>
95
- <td data-value="100" class="pct high">100%</td>
96
- <td data-value="13" class="abs high">13/13</td>
97
- <td data-value="50" class="pct medium">50%</td>
98
- <td data-value="2" class="abs medium">1/2</td>
99
- <td data-value="100" class="pct high">100%</td>
100
- <td data-value="1" class="abs high">1/1</td>
101
- <td data-value="100" class="pct high">100%</td>
102
- <td data-value="13" class="abs high">13/13</td>
103
- </tr>
104
-
105
- <tr>
106
- <td class="file high" data-value="syncRows.js"><a href="syncRows.js.html">syncRows.js</a></td>
107
- <td data-value="100" class="pic high">
108
- <div class="chart"><div class="cover-fill cover-full" style="width: 100%"></div><div class="cover-empty" style="width: 0%"></div></div>
109
- </td>
110
- <td data-value="100" class="pct high">100%</td>
111
- <td data-value="17" class="abs high">17/17</td>
112
- <td data-value="50" class="pct medium">50%</td>
113
- <td data-value="4" class="abs medium">2/4</td>
114
- <td data-value="100" class="pct high">100%</td>
115
- <td data-value="2" class="abs high">2/2</td>
116
- <td data-value="100" class="pct high">100%</td>
117
- <td data-value="16" class="abs high">16/16</td>
118
- </tr>
119
-
120
- </tbody>
121
- </table>
122
- </div>
123
- <div class='push'></div><!-- for sticky footer -->
124
- </div><!-- /wrapper -->
125
- <div class='footer quiet pad2 space-top1 center small'>
126
- Code coverage generated by
127
- <a href="https://istanbul.js.org/" target="_blank">istanbul</a>
128
- at Mon Jan 31 2022 14:38:52 GMT+0000 (Coordinated Universal Time)
129
- </div>
130
- </div>
131
- <script src="../../prettify.js"></script>
132
- <script>
133
- window.onload = function () {
134
- prettyPrint();
135
- };
136
- </script>
137
- <script src="../../sorter.js"></script>
138
- <script src="../../block-navigation.js"></script>
139
- </body>
140
- </html>
141
-
@@ -1,143 +0,0 @@
1
-
2
- <!doctype html>
3
- <html lang="en">
4
-
5
- <head>
6
- <title>Code coverage report for migrations/usageQuotas/syncRows.js</title>
7
- <meta charset="utf-8" />
8
- <link rel="stylesheet" href="../../prettify.css" />
9
- <link rel="stylesheet" href="../../base.css" />
10
- <link rel="shortcut icon" type="image/x-icon" href="../../favicon.png" />
11
- <meta name="viewport" content="width=device-width, initial-scale=1" />
12
- <style type='text/css'>
13
- .coverage-summary .sorter {
14
- background-image: url(../../sort-arrow-sprite.png);
15
- }
16
- </style>
17
- </head>
18
-
19
- <body>
20
- <div class='wrapper'>
21
- <div class='pad1'>
22
- <h1><a href="../../index.html">All files</a> / <a href="index.html">migrations/usageQuotas</a> syncRows.js</h1>
23
- <div class='clearfix'>
24
-
25
- <div class='fl pad1y space-right2'>
26
- <span class="strong">100% </span>
27
- <span class="quiet">Statements</span>
28
- <span class='fraction'>17/17</span>
29
- </div>
30
-
31
-
32
- <div class='fl pad1y space-right2'>
33
- <span class="strong">50% </span>
34
- <span class="quiet">Branches</span>
35
- <span class='fraction'>2/4</span>
36
- </div>
37
-
38
-
39
- <div class='fl pad1y space-right2'>
40
- <span class="strong">100% </span>
41
- <span class="quiet">Functions</span>
42
- <span class='fraction'>2/2</span>
43
- </div>
44
-
45
-
46
- <div class='fl pad1y space-right2'>
47
- <span class="strong">100% </span>
48
- <span class="quiet">Lines</span>
49
- <span class='fraction'>16/16</span>
50
- </div>
51
-
52
-
53
- </div>
54
- <p class="quiet">
55
- Press <em>n</em> or <em>j</em> to go to the next uncovered block, <em>b</em>, <em>p</em> or <em>k</em> for the previous block.
56
- </p>
57
- </div>
58
- <div class='status-line high'></div>
59
- <pre><table class="coverage">
60
- <tr><td class="line-count quiet"><a name='L1'></a><a href='#L1'>1</a>
61
- <a name='L2'></a><a href='#L2'>2</a>
62
- <a name='L3'></a><a href='#L3'>3</a>
63
- <a name='L4'></a><a href='#L4'>4</a>
64
- <a name='L5'></a><a href='#L5'>5</a>
65
- <a name='L6'></a><a href='#L6'>6</a>
66
- <a name='L7'></a><a href='#L7'>7</a>
67
- <a name='L8'></a><a href='#L8'>8</a>
68
- <a name='L9'></a><a href='#L9'>9</a>
69
- <a name='L10'></a><a href='#L10'>10</a>
70
- <a name='L11'></a><a href='#L11'>11</a>
71
- <a name='L12'></a><a href='#L12'>12</a>
72
- <a name='L13'></a><a href='#L13'>13</a>
73
- <a name='L14'></a><a href='#L14'>14</a>
74
- <a name='L15'></a><a href='#L15'>15</a>
75
- <a name='L16'></a><a href='#L16'>16</a>
76
- <a name='L17'></a><a href='#L17'>17</a>
77
- <a name='L18'></a><a href='#L18'>18</a>
78
- <a name='L19'></a><a href='#L19'>19</a>
79
- <a name='L20'></a><a href='#L20'>20</a>
80
- <a name='L21'></a><a href='#L21'>21</a>
81
- <a name='L22'></a><a href='#L22'>22</a></td><td class="line-coverage quiet"><span class="cline-any cline-yes">25x</span>
82
- <span class="cline-any cline-yes">25x</span>
83
- <span class="cline-any cline-yes">25x</span>
84
- <span class="cline-any cline-yes">25x</span>
85
- <span class="cline-any cline-yes">25x</span>
86
- <span class="cline-any cline-neutral">&nbsp;</span>
87
- <span class="cline-any cline-yes">25x</span>
88
- <span class="cline-any cline-yes">1x</span>
89
- <span class="cline-any cline-neutral">&nbsp;</span>
90
- <span class="cline-any cline-yes">1x</span>
91
- <span class="cline-any cline-yes">4x</span>
92
- <span class="cline-any cline-yes">1x</span>
93
- <span class="cline-any cline-yes">1x</span>
94
- <span class="cline-any cline-neutral">&nbsp;</span>
95
- <span class="cline-any cline-neutral">&nbsp;</span>
96
- <span class="cline-any cline-yes">1x</span>
97
- <span class="cline-any cline-yes">1x</span>
98
- <span class="cline-any cline-yes">1x</span>
99
- <span class="cline-any cline-yes">1x</span>
100
- <span class="cline-any cline-yes">1x</span>
101
- <span class="cline-any cline-neutral">&nbsp;</span>
102
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">const { getGlobalDB, getTenantId } = require("@budibase/backend-core/tenancy")
103
- const { getAllApps } = require("@budibase/backend-core/db")
104
- const CouchDB = require("../../db")
105
- const { getUsageQuotaDoc } = require("../../utilities/usageQuota")
106
- const { getUniqueRows } = require("../../utilities/usageQuota/rows")
107
- &nbsp;
108
- exports.run = async () =&gt; {
109
- const db = getGlobalDB()
110
- // get all rows in all apps
111
- const allApps = await getAllApps(CouchDB, { all: true })
112
- const appIds = allApps ? allApps.map(app =&gt; app.appId) : <span class="branch-1 cbranch-no" title="branch not covered" >[]</span>
113
- const rows = await getUniqueRows(appIds)
114
- const rowCount = rows ? rows.length : <span class="branch-1 cbranch-no" title="branch not covered" >0</span>
115
- &nbsp;
116
- // sync row count
117
- const tenantId = getTenantId()
118
- console.log(`[Tenant: ${tenantId}] Syncing row count: ${rowCount}`)
119
- const usageDoc = await getUsageQuotaDoc(db)
120
- usageDoc.usageQuota.rows = rowCount
121
- await db.put(usageDoc)
122
- }
123
- &nbsp;</pre></td></tr></table></pre>
124
-
125
- <div class='push'></div><!-- for sticky footer -->
126
- </div><!-- /wrapper -->
127
- <div class='footer quiet pad2 space-top1 center small'>
128
- Code coverage generated by
129
- <a href="https://istanbul.js.org/" target="_blank">istanbul</a>
130
- at Mon Jan 31 2022 14:38:52 GMT+0000 (Coordinated Universal Time)
131
- </div>
132
- </div>
133
- <script src="../../prettify.js"></script>
134
- <script>
135
- window.onload = function () {
136
- prettyPrint();
137
- };
138
- </script>
139
- <script src="../../sorter.js"></script>
140
- <script src="../../block-navigation.js"></script>
141
- </body>
142
- </html>
143
-
@@ -1,24 +0,0 @@
1
- const {
2
- MIGRATIONS,
3
- MIGRATION_DBS,
4
- migrateIfRequired,
5
- } = require("@budibase/backend-core/migrations")
6
- const { useQuotas } = require("../../utilities/usageQuota")
7
- const syncApps = require("./syncApps")
8
- const syncRows = require("./syncRows")
9
-
10
- exports.run = async () => {
11
- if (!useQuotas()) {
12
- return
13
- }
14
-
15
- // Jan 2022
16
- await migrateIfRequired(
17
- MIGRATION_DBS.GLOBAL_DB,
18
- MIGRATIONS.QUOTAS_1,
19
- async () => {
20
- await syncApps.run()
21
- await syncRows.run()
22
- }
23
- )
24
- }