@budibase/server 1.0.123-alpha.0 → 1.0.123

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 (330) hide show
  1. package/builder/assets/index.68a7f4e3.css +6 -0
  2. package/builder/assets/index.8d4a5b33.js +1291 -0
  3. package/builder/assets/{vendor.5240f480.js → vendor.8e34a169.js} +1 -1
  4. package/builder/index.html +3 -3
  5. package/coverage/clover.xml +1763 -758
  6. package/coverage/coverage-final.json +43 -28
  7. package/coverage/lcov-report/api/controllers/analytics.js.html +3 -8
  8. package/coverage/lcov-report/api/controllers/apikeys.js.html +4 -9
  9. package/coverage/lcov-report/api/controllers/application.js.html +1436 -0
  10. package/coverage/lcov-report/api/controllers/auth.js.html +3 -8
  11. package/coverage/lcov-report/api/controllers/automation.js.html +3 -8
  12. package/coverage/lcov-report/api/controllers/backup.js.html +3 -8
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +3 -8
  14. package/coverage/lcov-report/api/controllers/component.js.html +3 -8
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +6 -11
  16. package/coverage/lcov-report/api/controllers/dev.js.html +3 -8
  17. package/coverage/lcov-report/api/controllers/index.html +26 -16
  18. package/coverage/lcov-report/api/controllers/integration.js.html +3 -8
  19. package/coverage/lcov-report/api/controllers/layout.js.html +3 -8
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +3 -8
  21. package/coverage/lcov-report/api/controllers/migrations.js.html +3 -8
  22. package/coverage/lcov-report/api/controllers/permission.js.html +3 -8
  23. package/coverage/lcov-report/api/controllers/query/index.html +26 -16
  24. package/coverage/lcov-report/api/controllers/query/index.js.html +713 -0
  25. package/coverage/lcov-report/api/controllers/query/validation.js.html +3 -8
  26. package/coverage/lcov-report/api/controllers/role.js.html +5 -10
  27. package/coverage/lcov-report/api/controllers/routing.js.html +4 -9
  28. package/coverage/lcov-report/api/controllers/row/external.js.html +3 -8
  29. package/coverage/lcov-report/api/controllers/row/index.html +35 -25
  30. package/coverage/lcov-report/api/controllers/row/index.js.html +524 -0
  31. package/coverage/lcov-report/api/controllers/row/internal.js.html +24 -32
  32. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +16 -21
  33. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +19 -24
  34. package/coverage/lcov-report/api/controllers/row/utils.js.html +19 -33
  35. package/coverage/lcov-report/api/controllers/screen.js.html +4 -9
  36. package/coverage/lcov-report/api/controllers/script.js.html +3 -8
  37. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +50 -55
  38. package/coverage/lcov-report/api/controllers/table/external.js.html +3 -8
  39. package/coverage/lcov-report/api/controllers/table/index.html +44 -19
  40. package/coverage/lcov-report/api/controllers/table/index.js.html +15 -20
  41. package/coverage/lcov-report/api/controllers/table/internal.js.html +620 -0
  42. package/coverage/lcov-report/api/controllers/table/utils.js.html +1331 -0
  43. package/coverage/lcov-report/api/controllers/templates.js.html +3 -8
  44. package/coverage/lcov-report/api/controllers/user.js.html +3 -8
  45. package/coverage/lcov-report/api/controllers/view/exporters.js.html +3 -8
  46. package/coverage/lcov-report/api/controllers/view/index.html +3 -8
  47. package/coverage/lcov-report/api/controllers/view/index.js.html +5 -10
  48. package/coverage/lcov-report/api/controllers/view/utils.js.html +3 -8
  49. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -8
  50. package/coverage/lcov-report/api/controllers/webhook.js.html +5 -10
  51. package/coverage/lcov-report/api/index.html +13 -18
  52. package/coverage/lcov-report/api/index.js.html +8 -28
  53. package/coverage/lcov-report/api/routes/analytics.js.html +3 -8
  54. package/coverage/lcov-report/api/routes/apikeys.js.html +3 -8
  55. package/coverage/lcov-report/api/routes/application.js.html +179 -0
  56. package/coverage/lcov-report/api/routes/auth.js.html +3 -8
  57. package/coverage/lcov-report/api/routes/automation.js.html +3 -8
  58. package/coverage/lcov-report/api/routes/backup.js.html +3 -8
  59. package/coverage/lcov-report/api/routes/cloud.js.html +3 -8
  60. package/coverage/lcov-report/api/routes/component.js.html +3 -8
  61. package/coverage/lcov-report/api/routes/datasource.js.html +3 -8
  62. package/coverage/lcov-report/api/routes/deploy.js.html +3 -8
  63. package/coverage/lcov-report/api/routes/dev.js.html +4 -9
  64. package/coverage/lcov-report/api/routes/index.html +68 -13
  65. package/coverage/lcov-report/api/routes/index.js.html +266 -0
  66. package/coverage/lcov-report/api/routes/integration.js.html +3 -8
  67. package/coverage/lcov-report/api/routes/layout.js.html +3 -8
  68. package/coverage/lcov-report/api/routes/metadata.js.html +3 -8
  69. package/coverage/lcov-report/api/routes/migrations.js.html +3 -8
  70. package/coverage/lcov-report/api/routes/permission.js.html +3 -8
  71. package/coverage/lcov-report/api/routes/query.js.html +3 -8
  72. package/coverage/lcov-report/api/routes/role.js.html +3 -8
  73. package/coverage/lcov-report/api/routes/routing.js.html +3 -8
  74. package/coverage/lcov-report/api/routes/row.js.html +908 -0
  75. package/coverage/lcov-report/api/routes/screen.js.html +3 -8
  76. package/coverage/lcov-report/api/routes/script.js.html +3 -8
  77. package/coverage/lcov-report/{automations/steps/loop.js.html → api/routes/static.js.html} +80 -70
  78. package/coverage/lcov-report/api/routes/table.js.html +3 -8
  79. package/coverage/lcov-report/api/routes/templates.js.html +3 -8
  80. package/coverage/lcov-report/api/routes/user.js.html +3 -8
  81. package/coverage/lcov-report/api/routes/utils/index.html +3 -8
  82. package/coverage/lcov-report/api/routes/utils/validators.js.html +3 -8
  83. package/coverage/lcov-report/api/routes/view.js.html +3 -8
  84. package/coverage/lcov-report/api/routes/webhook.js.html +3 -8
  85. package/coverage/lcov-report/automations/actions.js.html +7 -21
  86. package/coverage/lcov-report/automations/automationUtils.js.html +23 -64
  87. package/coverage/lcov-report/automations/bullboard.js.html +3 -8
  88. package/coverage/lcov-report/automations/index.html +37 -27
  89. package/coverage/lcov-report/automations/index.js.html +3 -8
  90. package/coverage/lcov-report/automations/steps/bash.js.html +3 -8
  91. package/coverage/lcov-report/automations/steps/createRow.js.html +380 -0
  92. package/coverage/lcov-report/automations/steps/delay.js.html +3 -8
  93. package/coverage/lcov-report/automations/steps/deleteRow.js.html +347 -0
  94. package/coverage/lcov-report/automations/steps/discord.js.html +3 -8
  95. package/coverage/lcov-report/automations/steps/executeQuery.js.html +3 -8
  96. package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -8
  97. package/coverage/lcov-report/automations/steps/filter.js.html +3 -8
  98. package/coverage/lcov-report/automations/steps/index.html +41 -31
  99. package/coverage/lcov-report/automations/steps/integromat.js.html +3 -8
  100. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +4 -9
  101. package/coverage/lcov-report/automations/steps/queryRows.js.html +4 -9
  102. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +3 -8
  103. package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -8
  104. package/coverage/lcov-report/automations/steps/slack.js.html +3 -8
  105. package/coverage/lcov-report/automations/steps/updateRow.js.html +3 -8
  106. package/coverage/lcov-report/automations/steps/utils.js.html +9 -14
  107. package/coverage/lcov-report/automations/steps/zapier.js.html +3 -8
  108. package/coverage/lcov-report/automations/triggerInfo/app.js.html +3 -8
  109. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +3 -8
  110. package/coverage/lcov-report/automations/triggerInfo/index.html +3 -8
  111. package/coverage/lcov-report/automations/triggerInfo/index.js.html +3 -8
  112. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +3 -8
  113. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +3 -8
  114. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +3 -8
  115. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +3 -8
  116. package/coverage/lcov-report/automations/triggers.js.html +11 -16
  117. package/coverage/lcov-report/automations/utils.js.html +665 -0
  118. package/coverage/lcov-report/block-navigation.js +0 -8
  119. package/coverage/lcov-report/constants/index.html +3 -8
  120. package/coverage/lcov-report/constants/index.js.html +42 -41
  121. package/coverage/lcov-report/constants/layouts.js.html +3 -8
  122. package/coverage/lcov-report/constants/screens.js.html +3 -8
  123. package/coverage/lcov-report/db/inMemoryView.js.html +3 -8
  124. package/coverage/lcov-report/db/index.html +3 -8
  125. package/coverage/lcov-report/db/index.js.html +4 -9
  126. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +23 -25
  127. package/coverage/lcov-report/db/linkedRows/index.html +12 -17
  128. package/coverage/lcov-report/db/linkedRows/index.js.html +17 -22
  129. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +7 -12
  130. package/coverage/lcov-report/db/newid.js.html +6 -11
  131. package/coverage/lcov-report/db/utils.js.html +79 -84
  132. package/coverage/lcov-report/events/AutomationEmitter.js.html +9 -14
  133. package/coverage/lcov-report/events/index.html +3 -8
  134. package/coverage/lcov-report/events/index.js.html +4 -9
  135. package/coverage/lcov-report/events/utils.js.html +13 -18
  136. package/coverage/lcov-report/index.html +132 -137
  137. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +3 -8
  138. package/coverage/lcov-report/integrations/tests/index.html +3 -8
  139. package/coverage/lcov-report/middleware/appInfo.js.html +3 -8
  140. package/coverage/lcov-report/middleware/authorized.js.html +458 -0
  141. package/coverage/lcov-report/middleware/builder.js.html +3 -8
  142. package/coverage/lcov-report/middleware/currentapp.js.html +15 -65
  143. package/coverage/lcov-report/middleware/index.html +50 -25
  144. package/coverage/lcov-report/middleware/joi-validator.js.html +4 -9
  145. package/coverage/lcov-report/middleware/publicApi.js.html +3 -8
  146. package/coverage/lcov-report/middleware/resourceId.js.html +3 -8
  147. package/coverage/lcov-report/middleware/selfhost.js.html +4 -9
  148. package/coverage/lcov-report/middleware/usageQuota.js.html +572 -0
  149. package/coverage/lcov-report/middleware/utils.js.html +3 -8
  150. package/coverage/lcov-report/sorter.js +0 -26
  151. package/coverage/lcov-report/threads/automation.js.html +90 -581
  152. package/coverage/lcov-report/threads/index.html +40 -30
  153. package/coverage/lcov-report/threads/index.js.html +296 -0
  154. package/coverage/lcov-report/threads/query.js.html +4 -9
  155. package/coverage/lcov-report/threads/utils.js.html +9 -17
  156. package/coverage/lcov-report/utilities/bcrypt.js.html +3 -8
  157. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -8
  158. package/coverage/lcov-report/utilities/centralPath.js.html +3 -8
  159. package/coverage/lcov-report/utilities/csvParser.js.html +5 -10
  160. package/coverage/lcov-report/utilities/global.js.html +4 -9
  161. package/coverage/lcov-report/utilities/index.html +3 -8
  162. package/coverage/lcov-report/utilities/index.js.html +6 -11
  163. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -32
  164. package/coverage/lcov-report/utilities/queue/index.html +7 -12
  165. package/coverage/lcov-report/utilities/routing/index.html +3 -8
  166. package/coverage/lcov-report/utilities/routing/index.js.html +3 -8
  167. package/coverage/lcov-report/utilities/rowProcessor/index.html +27 -32
  168. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +71 -67
  169. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +106 -27
  170. package/coverage/lcov-report/utilities/scriptRunner.js.html +3 -8
  171. package/coverage/lcov-report/utilities/security.js.html +4 -9
  172. package/coverage/lcov-report/utilities/statusCodes.js.html +3 -8
  173. package/coverage/lcov-report/utilities/usageQuota/index.html +34 -24
  174. package/coverage/lcov-report/utilities/usageQuota/index.js.html +359 -0
  175. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +39 -44
  176. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +3 -8
  177. package/coverage/lcov-report/utilities/users.js.html +3 -8
  178. package/coverage/lcov-report/utilities/workerRequests.js.html +4 -9
  179. package/coverage/lcov.info +3061 -1290
  180. package/dist/api/controllers/application.js +73 -145
  181. package/dist/api/controllers/deploy/index.js +36 -68
  182. package/dist/api/controllers/public/applications.js +9 -29
  183. package/dist/api/controllers/public/queries.js +7 -27
  184. package/dist/api/controllers/public/rows.js +12 -32
  185. package/dist/api/controllers/public/tables.js +2 -2
  186. package/dist/api/controllers/public/users.js +8 -8
  187. package/dist/api/controllers/public/utils.js +1 -1
  188. package/dist/api/controllers/query/import/index.js +3 -3
  189. package/dist/api/controllers/query/index.js +44 -57
  190. package/dist/api/controllers/row/ExternalRequest.js +27 -27
  191. package/dist/api/controllers/row/index.js +60 -83
  192. package/dist/api/controllers/row/internal.js +1 -2
  193. package/dist/api/controllers/row/utils.js +1 -2
  194. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -3
  195. package/dist/api/controllers/table/bulkFormula.js +1 -2
  196. package/dist/api/controllers/table/internal.js +55 -40
  197. package/dist/api/controllers/table/utils.js +229 -271
  198. package/dist/api/index.js +0 -5
  199. package/dist/api/routes/application.js +13 -39
  200. package/dist/api/routes/index.js +56 -61
  201. package/dist/api/routes/public/index.js +9 -6
  202. package/dist/api/routes/public/queries.js +1 -1
  203. package/dist/api/routes/public/rows.js +1 -1
  204. package/dist/api/routes/public/tables.js +3 -3
  205. package/dist/api/routes/public/users.js +1 -1
  206. package/dist/api/routes/row.js +17 -43
  207. package/dist/api/routes/static.js +13 -40
  208. package/dist/api/routes/tests/utilities/TestFunctions.js +33 -75
  209. package/dist/app.js +4 -8
  210. package/dist/automations/actions.js +0 -3
  211. package/dist/automations/automationUtils.js +0 -10
  212. package/dist/automations/steps/createRow.js +12 -12
  213. package/dist/automations/steps/deleteRow.js +16 -13
  214. package/dist/automations/tests/utilities/index.js +11 -13
  215. package/dist/automations/utils.js +133 -187
  216. package/dist/constants/index.js +7 -5
  217. package/dist/db/linkedRows/LinkController.js +1 -0
  218. package/dist/definitions/datasource.js +0 -1
  219. package/dist/environment.js +3 -2
  220. package/dist/index.js +0 -4
  221. package/dist/integrations/base/sql.js +2 -2
  222. package/dist/integrations/base/sqlTable.js +2 -2
  223. package/dist/integrations/googlesheets.js +1 -1
  224. package/dist/integrations/index.js +0 -4
  225. package/dist/integrations/microsoftSqlServer.js +8 -8
  226. package/dist/integrations/mysql.js +9 -9
  227. package/dist/integrations/oracle.js +7 -7
  228. package/dist/integrations/postgres.js +7 -7
  229. package/dist/integrations/queries/sql.js +2 -2
  230. package/dist/integrations/rest.js +1 -1
  231. package/dist/middleware/authorized.js +51 -51
  232. package/dist/middleware/currentapp.js +1 -15
  233. package/dist/middleware/usageQuota.js +154 -0
  234. package/dist/migrations/functions/appUrls.js +1 -1
  235. package/dist/migrations/functions/quotas1.js +2 -6
  236. package/dist/migrations/functions/usageQuotas/index.js +4 -0
  237. package/dist/migrations/functions/usageQuotas/syncApps.js +7 -4
  238. package/dist/migrations/functions/usageQuotas/syncRows.js +8 -5
  239. package/dist/migrations/index.js +1 -17
  240. package/dist/package.json +4 -10
  241. package/dist/threads/automation.js +27 -149
  242. package/dist/threads/index.js +10 -36
  243. package/dist/threads/utils.js +0 -1
  244. package/dist/tsconfig.tsbuildinfo +1 -0
  245. package/dist/utilities/queue/inMemoryQueue.js +1 -6
  246. package/dist/utilities/rowProcessor/index.js +11 -6
  247. package/dist/utilities/rowProcessor/utils.js +27 -1
  248. package/dist/utilities/usageQuota/index.js +86 -0
  249. package/nodemon.json +1 -1
  250. package/package.json +9 -15
  251. package/scripts/dev/manage.js +0 -2
  252. package/src/api/controllers/{application.ts → application.js} +51 -118
  253. package/src/api/controllers/deploy/{index.ts → index.js} +29 -53
  254. package/src/api/controllers/public/applications.ts +2 -2
  255. package/src/api/controllers/public/queries.ts +1 -1
  256. package/src/api/controllers/public/rows.ts +1 -1
  257. package/src/api/controllers/query/{index.ts → index.js} +48 -51
  258. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  259. package/src/api/controllers/row/{index.ts → index.js} +17 -24
  260. package/src/api/controllers/row/internal.js +1 -2
  261. package/src/api/controllers/row/utils.js +1 -4
  262. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -3
  263. package/src/api/controllers/table/bulkFormula.js +1 -1
  264. package/src/api/controllers/table/{internal.ts → internal.js} +48 -27
  265. package/src/api/controllers/table/{utils.ts → utils.js} +69 -86
  266. package/src/api/index.js +0 -5
  267. package/src/api/routes/{application.ts → application.js} +14 -8
  268. package/src/api/routes/index.js +62 -0
  269. package/src/api/routes/public/index.ts +4 -1
  270. package/src/api/routes/{row.ts → row.js} +15 -7
  271. package/src/api/routes/{static.ts → static.js} +11 -11
  272. package/src/api/routes/tests/misc.spec.js +37 -39
  273. package/src/api/routes/tests/routing.spec.js +0 -1
  274. package/src/api/routes/tests/utilities/{TestFunctions.ts → TestFunctions.js} +33 -57
  275. package/src/app.ts +2 -1
  276. package/src/automations/actions.js +0 -3
  277. package/src/automations/automationUtils.js +0 -12
  278. package/src/automations/steps/{createRow.ts → createRow.js} +15 -9
  279. package/src/automations/steps/{deleteRow.ts → deleteRow.js} +16 -10
  280. package/src/automations/tests/automation.spec.js +1 -0
  281. package/src/automations/tests/{createRow.spec.ts → createRow.spec.js} +15 -4
  282. package/src/automations/tests/{deleteRow.spec.ts → deleteRow.spec.js} +5 -3
  283. package/src/automations/tests/utilities/index.js +10 -12
  284. package/src/automations/{utils.ts → utils.js} +28 -39
  285. package/src/constants/index.js +8 -6
  286. package/src/db/linkedRows/LinkController.js +1 -0
  287. package/src/definitions/datasource.ts +0 -1
  288. package/src/environment.js +3 -2
  289. package/src/index.ts +0 -3
  290. package/src/integrations/index.ts +0 -4
  291. package/src/middleware/{authorized.ts → authorized.js} +14 -20
  292. package/src/middleware/currentapp.js +1 -16
  293. package/src/middleware/tests/usageQuota.spec.js +120 -0
  294. package/src/middleware/usageQuota.js +164 -0
  295. package/src/migrations/functions/tests/quotas1.spec.js +2 -0
  296. package/src/migrations/functions/usageQuotas/index.ts +5 -0
  297. package/src/migrations/functions/usageQuotas/syncApps.ts +6 -3
  298. package/src/migrations/functions/usageQuotas/syncRows.ts +6 -3
  299. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.js +41 -0
  300. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.js +45 -0
  301. package/src/migrations/index.ts +1 -13
  302. package/src/threads/automation.js +34 -196
  303. package/src/threads/{index.ts → index.js} +14 -18
  304. package/src/threads/utils.js +0 -1
  305. package/src/utilities/queue/inMemoryQueue.js +1 -7
  306. package/src/utilities/rowProcessor/index.js +12 -9
  307. package/src/utilities/rowProcessor/utils.js +29 -1
  308. package/src/utilities/tests/usageQuota/usageQuota.spec.js +72 -0
  309. package/src/utilities/usageQuota/index.js +93 -0
  310. package/tsconfig.json +2 -2
  311. package/builder/assets/index.89795487.css +0 -6
  312. package/builder/assets/index.be9a1b80.js +0 -1299
  313. package/dist/automations/steps/loop.js +0 -51
  314. package/dist/integrations/redis.js +0 -158
  315. package/dist/migrations/functions/developerQuota.js +0 -49
  316. package/dist/migrations/functions/publishedAppsQuota.js +0 -47
  317. package/dist/migrations/functions/usageQuotas/syncDevelopers.js +0 -24
  318. package/dist/migrations/functions/usageQuotas/syncPublishedApps.js +0 -26
  319. package/dist/tsconfig.build.tsbuildinfo +0 -1
  320. package/src/api/routes/index.ts +0 -60
  321. package/src/automations/steps/loop.js +0 -50
  322. package/src/integrations/redis.ts +0 -152
  323. package/src/integrations/tests/redis.spec.js +0 -60
  324. package/src/migrations/functions/developerQuota.ts +0 -15
  325. package/src/migrations/functions/publishedAppsQuota.ts +0 -13
  326. package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
  327. package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
  328. package/src/migrations/functions/usageQuotas/tests/syncApps.spec.ts +0 -34
  329. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +0 -40
  330. package/tsconfig.build.json +0 -10
@@ -36,12 +36,12 @@ var External;
36
36
  function buildFilters(id, filters, table) {
37
37
  const primary = table.primary;
38
38
  // if passed in array need to copy for shifting etc
39
- let idCopy = (0, fp_1.cloneDeep)(id);
39
+ let idCopy = fp_1.cloneDeep(id);
40
40
  if (filters) {
41
41
  // need to map over the filters and make sure the _id field isn't present
42
42
  for (let filter of Object.values(filters)) {
43
43
  if (filter._id && primary) {
44
- const parts = (0, utils_1.breakRowIdField)(filter._id);
44
+ const parts = utils_1.breakRowIdField(filter._id);
45
45
  for (let field of primary) {
46
46
  filter[field] = parts.shift();
47
47
  }
@@ -56,7 +56,7 @@ var External;
56
56
  }
57
57
  // if used as URL parameter it will have been joined
58
58
  if (!Array.isArray(idCopy)) {
59
- idCopy = (0, utils_1.breakRowIdField)(idCopy);
59
+ idCopy = utils_1.breakRowIdField(idCopy);
60
60
  }
61
61
  const equal = {};
62
62
  if (primary && idCopy) {
@@ -90,8 +90,8 @@ var External;
90
90
  .map(([fieldName]) => fieldName);
91
91
  const iterateObject = (obj) => {
92
92
  for (let [field, value] of Object.entries(obj)) {
93
- if (fieldNames.find(name => name === field) && (0, utils_1.isRowId)(value)) {
94
- obj[field] = (0, utils_1.convertRowId)(value);
93
+ if (fieldNames.find(name => name === field) && utils_1.isRowId(value)) {
94
+ obj[field] = utils_1.convertRowId(value);
95
95
  }
96
96
  }
97
97
  };
@@ -129,13 +129,13 @@ var External;
129
129
  if (idParts.length === 0) {
130
130
  return "";
131
131
  }
132
- return (0, utils_1.generateRowIdField)(idParts);
132
+ return utils_1.generateRowIdField(idParts);
133
133
  }
134
134
  function getEndpoint(tableId, operation) {
135
135
  if (!tableId) {
136
136
  return {};
137
137
  }
138
- const { datasourceId, tableName } = (0, utils_3.breakExternalTableId)(tableId);
138
+ const { datasourceId, tableName } = utils_3.breakExternalTableId(tableId);
139
139
  return {
140
140
  datasourceId,
141
141
  entityId: tableName,
@@ -155,7 +155,7 @@ var External;
155
155
  thisRow._id = generateIdForRow(row, table);
156
156
  thisRow.tableId = table._id;
157
157
  thisRow._rev = "rev";
158
- return (0, utils_4.processFormulas)(table, thisRow);
158
+ return utils_4.processFormulas(table, thisRow);
159
159
  }
160
160
  function fixArrayTypes(row, table) {
161
161
  for (let [fieldName, schema] of Object.entries(table.schema)) {
@@ -189,7 +189,7 @@ var External;
189
189
  if (!tableId) {
190
190
  throw "Table ID is unknown, cannot find table";
191
191
  }
192
- const { tableName } = (0, utils_3.breakExternalTableId)(tableId);
192
+ const { tableName } = utils_3.breakExternalTableId(tableId);
193
193
  if (tableName) {
194
194
  return this.tables[tableName];
195
195
  }
@@ -224,7 +224,7 @@ var External;
224
224
  newRow[key] = row[key];
225
225
  continue;
226
226
  }
227
- const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field === null || field === void 0 ? void 0 : field.tableId);
227
+ const { tableName: linkTableName } = utils_3.breakExternalTableId(field === null || field === void 0 ? void 0 : field.tableId);
228
228
  // table has to exist for many to many
229
229
  if (!linkTableName || !this.tables[linkTableName]) {
230
230
  continue;
@@ -234,7 +234,7 @@ var External;
234
234
  const linkTablePrimary = linkTable.primary[0];
235
235
  // one to many
236
236
  if (isOneSide(field)) {
237
- newRow[field.foreignKey || linkTablePrimary] = (0, utils_1.breakRowIdField)(row[key][0])[0];
237
+ newRow[field.foreignKey || linkTablePrimary] = utils_1.breakRowIdField(row[key][0])[0];
238
238
  }
239
239
  // many to many
240
240
  else if (field.through) {
@@ -246,7 +246,7 @@ var External;
246
246
  tableId: field.through || field.tableId,
247
247
  isUpdate: false,
248
248
  key: otherKey,
249
- [otherKey]: (0, utils_1.breakRowIdField)(relationship)[0],
249
+ [otherKey]: utils_1.breakRowIdField(relationship)[0],
250
250
  // leave the ID for enrichment later
251
251
  [thisKey]: `{{ literal ${tablePrimary} }}`,
252
252
  });
@@ -262,7 +262,7 @@ var External;
262
262
  tableId: field.tableId,
263
263
  isUpdate: true,
264
264
  key: otherKey,
265
- [thisKey]: (0, utils_1.breakRowIdField)(relationship)[0],
265
+ [thisKey]: utils_1.breakRowIdField(relationship)[0],
266
266
  // leave the ID for enrichment later
267
267
  [otherKey]: `{{ literal ${tablePrimary} }}`,
268
268
  });
@@ -355,7 +355,7 @@ var External;
355
355
  // do this at end once its been added to the final rows
356
356
  finalRows = this.updateRelationshipColumns(table, row, finalRows, relationships);
357
357
  }
358
- return (0, utils_4.processFormulas)(table, Object.values(finalRows)).map((row) => this.squashRelationshipColumns(table, row, relationships));
358
+ return utils_4.processFormulas(table, Object.values(finalRows)).map((row) => this.squashRelationshipColumns(table, row, relationships));
359
359
  }
360
360
  /**
361
361
  * Gets the list of relationship JSON structures based on the columns in the table,
@@ -368,7 +368,7 @@ var External;
368
368
  if (field.type !== constants_1.FieldTypes.LINK) {
369
369
  continue;
370
370
  }
371
- const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field.tableId);
371
+ const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
372
372
  // no table to link to, this is not a valid relationships
373
373
  if (!linkTableName || !this.tables[linkTableName]) {
374
374
  continue;
@@ -386,7 +386,7 @@ var External;
386
386
  column: fieldName,
387
387
  };
388
388
  if (field.through) {
389
- const { tableName: throughTableName } = (0, utils_3.breakExternalTableId)(field.through);
389
+ const { tableName: throughTableName } = utils_3.breakExternalTableId(field.through);
390
390
  definition.through = throughTableName;
391
391
  // don't support composite keys for relationships
392
392
  definition.from = field.throughTo || table.primary[0];
@@ -405,7 +405,7 @@ var External;
405
405
  lookupRelations(tableId, row) {
406
406
  return __awaiter(this, void 0, void 0, function* () {
407
407
  const related = {};
408
- const { tableName } = (0, utils_3.breakExternalTableId)(tableId);
408
+ const { tableName } = utils_3.breakExternalTableId(tableId);
409
409
  if (!tableName) {
410
410
  return related;
411
411
  }
@@ -422,7 +422,7 @@ var External;
422
422
  }
423
423
  const isMany = field.relationshipType === constants_1.RelationshipTypes.MANY_TO_MANY;
424
424
  const tableId = isMany ? field.through : field.tableId;
425
- const { tableName: relatedTableName } = (0, utils_3.breakExternalTableId)(tableId);
425
+ const { tableName: relatedTableName } = utils_3.breakExternalTableId(tableId);
426
426
  // @ts-ignore
427
427
  const linkPrimaryKey = this.tables[relatedTableName].primary[0];
428
428
  const manyKey = field.throughTo || primaryKey;
@@ -431,7 +431,7 @@ var External;
431
431
  if (!lookupField || !row[lookupField]) {
432
432
  continue;
433
433
  }
434
- const response = yield (0, utils_2.getDatasourceAndQuery)({
434
+ const response = yield utils_2.getDatasourceAndQuery({
435
435
  endpoint: getEndpoint(tableId, constants_1.DataSourceOperation.READ),
436
436
  filters: {
437
437
  equal: {
@@ -465,7 +465,7 @@ var External;
465
465
  const related = yield this.lookupRelations(mainTableId, row);
466
466
  for (let relationship of relationships) {
467
467
  const { key, tableId, isUpdate, id } = relationship, rest = __rest(relationship, ["key", "tableId", "isUpdate", "id"]);
468
- const body = (0, string_templates_1.processObjectSync)(rest, row, {});
468
+ const body = string_templates_1.processObjectSync(rest, row, {});
469
469
  const linkTable = this.getTable(tableId);
470
470
  // @ts-ignore
471
471
  const linkPrimary = linkTable === null || linkTable === void 0 ? void 0 : linkTable.primary[0];
@@ -479,7 +479,7 @@ var External;
479
479
  ? constants_1.DataSourceOperation.UPDATE
480
480
  : constants_1.DataSourceOperation.CREATE;
481
481
  if (!found) {
482
- promises.push((0, utils_2.getDatasourceAndQuery)({
482
+ promises.push(utils_2.getDatasourceAndQuery({
483
483
  endpoint: getEndpoint(tableId, operation),
484
484
  // if we're doing many relationships then we're writing, only one response
485
485
  body,
@@ -507,7 +507,7 @@ var External;
507
507
  ? constants_1.DataSourceOperation.DELETE
508
508
  : constants_1.DataSourceOperation.UPDATE;
509
509
  const body = isMany ? null : { [colName]: null };
510
- promises.push((0, utils_2.getDatasourceAndQuery)({
510
+ promises.push(utils_2.getDatasourceAndQuery({
511
511
  endpoint: getEndpoint(tableId, op),
512
512
  body,
513
513
  filters,
@@ -538,7 +538,7 @@ var External;
538
538
  if (field.type !== constants_1.FieldTypes.LINK || !includeRelations) {
539
539
  continue;
540
540
  }
541
- const { tableName: linkTableName } = (0, utils_3.breakExternalTableId)(field.tableId);
541
+ const { tableName: linkTableName } = utils_3.breakExternalTableId(field.tableId);
542
542
  if (linkTableName) {
543
543
  const linkTable = this.tables[linkTableName];
544
544
  if (linkTable) {
@@ -552,12 +552,12 @@ var External;
552
552
  run(config) {
553
553
  return __awaiter(this, void 0, void 0, function* () {
554
554
  const { operation, tableId } = this;
555
- let { datasourceId, tableName } = (0, utils_3.breakExternalTableId)(tableId);
555
+ let { datasourceId, tableName } = utils_3.breakExternalTableId(tableId);
556
556
  if (!tableName) {
557
557
  throw "Unable to run without a table name";
558
558
  }
559
559
  if (!this.datasource) {
560
- const db = (0, context_1.getAppDB)();
560
+ const db = context_1.getAppDB();
561
561
  this.datasource = yield db.get(datasourceId);
562
562
  if (!this.datasource || !this.datasource.entities) {
563
563
  throw "No tables found, fetch tables before query.";
@@ -565,7 +565,7 @@ var External;
565
565
  this.tables = this.datasource.entities;
566
566
  }
567
567
  const table = this.tables[tableName];
568
- let isSql = (0, utils_3.isSQL)(this.datasource);
568
+ let isSql = utils_3.isSQL(this.datasource);
569
569
  if (!table) {
570
570
  throw `Unable to process query, table "${tableName}" not defined.`;
571
571
  }
@@ -604,7 +604,7 @@ var External;
604
604
  },
605
605
  };
606
606
  // can't really use response right now
607
- const response = yield (0, utils_2.getDatasourceAndQuery)(json);
607
+ const response = yield utils_2.getDatasourceAndQuery(json);
608
608
  // handle many to many relationships now if we know the ID (could be auto increment)
609
609
  if (operation !== constants_1.DataSourceOperation.READ &&
610
610
  processed.manyRelationships) {
@@ -8,20 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.exportRows = exports.fetchEnrichedRow = exports.validate = exports.search = exports.destroy = exports.find = exports.fetch = exports.fetchView = exports.save = exports.patch = void 0;
16
- const pro_1 = require("@budibase/pro");
17
- const internal_1 = __importDefault(require("./internal"));
18
- const external_1 = __importDefault(require("./external"));
19
- const utils_1 = require("../../../integrations/utils");
11
+ const internal = require("./internal");
12
+ const external = require("./external");
13
+ const { isExternalTable } = require("../../../integrations/utils");
20
14
  function pickApi(tableId) {
21
- if ((0, utils_1.isExternalTable)(tableId)) {
22
- return external_1.default;
15
+ if (isExternalTable(tableId)) {
16
+ return external;
23
17
  }
24
- return internal_1.default;
18
+ return internal;
25
19
  }
26
20
  function getTableId(ctx) {
27
21
  if (ctx.request.body && ctx.request.body.tableId) {
@@ -34,55 +28,48 @@ function getTableId(ctx) {
34
28
  return ctx.params.viewName;
35
29
  }
36
30
  }
37
- function patch(ctx) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const appId = ctx.appId;
40
- const tableId = getTableId(ctx);
41
- const body = ctx.request.body;
42
- // if it doesn't have an _id then its save
43
- if (body && !body._id) {
44
- return save(ctx);
45
- }
46
- try {
47
- const { row, table } = yield pickApi(tableId).patch(ctx);
48
- ctx.status = 200;
49
- ctx.eventEmitter &&
50
- ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
51
- ctx.message = `${table.name} updated successfully.`;
52
- ctx.body = row;
53
- }
54
- catch (err) {
55
- ctx.throw(400, err);
56
- }
57
- });
58
- }
59
- exports.patch = patch;
60
- const saveRow = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
31
+ exports.patch = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
61
32
  const appId = ctx.appId;
62
33
  const tableId = getTableId(ctx);
63
34
  const body = ctx.request.body;
64
- // if it has an ID already then its a patch
65
- if (body && body._id) {
66
- return patch(ctx);
35
+ // if it doesn't have an _id then its save
36
+ if (body && !body._id) {
37
+ return exports.save(ctx);
67
38
  }
68
39
  try {
69
- const { row, table } = yield pickApi(tableId).save(ctx);
40
+ const { row, table } = yield pickApi(tableId).patch(ctx);
70
41
  ctx.status = 200;
71
- ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
72
- ctx.message = `${table.name} saved successfully`;
42
+ ctx.eventEmitter &&
43
+ ctx.eventEmitter.emitRow(`row:update`, appId, row, table);
44
+ ctx.message = `${table.name} updated successfully.`;
73
45
  ctx.body = row;
74
46
  }
75
47
  catch (err) {
76
48
  ctx.throw(400, err);
77
49
  }
78
50
  });
79
- function save(ctx) {
51
+ exports.save = function (ctx) {
80
52
  return __awaiter(this, void 0, void 0, function* () {
81
- yield pro_1.quotas.addRow(() => saveRow(ctx));
53
+ const appId = ctx.appId;
54
+ const tableId = getTableId(ctx);
55
+ const body = ctx.request.body;
56
+ // if it has an ID already then its a patch
57
+ if (body && body._id) {
58
+ return exports.patch(ctx);
59
+ }
60
+ try {
61
+ const { row, table } = yield pickApi(tableId).save(ctx);
62
+ ctx.status = 200;
63
+ ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table);
64
+ ctx.message = `${table.name} saved successfully`;
65
+ ctx.body = row;
66
+ }
67
+ catch (err) {
68
+ ctx.throw(400, err);
69
+ }
82
70
  });
83
- }
84
- exports.save = save;
85
- function fetchView(ctx) {
71
+ };
72
+ exports.fetchView = function (ctx) {
86
73
  return __awaiter(this, void 0, void 0, function* () {
87
74
  const tableId = getTableId(ctx);
88
75
  try {
@@ -92,9 +79,8 @@ function fetchView(ctx) {
92
79
  ctx.throw(400, err);
93
80
  }
94
81
  });
95
- }
96
- exports.fetchView = fetchView;
97
- function fetch(ctx) {
82
+ };
83
+ exports.fetch = function (ctx) {
98
84
  return __awaiter(this, void 0, void 0, function* () {
99
85
  const tableId = getTableId(ctx);
100
86
  try {
@@ -104,9 +90,8 @@ function fetch(ctx) {
104
90
  ctx.throw(400, err);
105
91
  }
106
92
  });
107
- }
108
- exports.fetch = fetch;
109
- function find(ctx) {
93
+ };
94
+ exports.find = function (ctx) {
110
95
  return __awaiter(this, void 0, void 0, function* () {
111
96
  const tableId = getTableId(ctx);
112
97
  try {
@@ -116,9 +101,8 @@ function find(ctx) {
116
101
  ctx.throw(400, err);
117
102
  }
118
103
  });
119
- }
120
- exports.find = find;
121
- function destroy(ctx) {
104
+ };
105
+ exports.destroy = function (ctx) {
122
106
  return __awaiter(this, void 0, void 0, function* () {
123
107
  const appId = ctx.appId;
124
108
  const inputs = ctx.request.body;
@@ -126,7 +110,6 @@ function destroy(ctx) {
126
110
  let response, row;
127
111
  if (inputs.rows) {
128
112
  let { rows } = yield pickApi(tableId).bulkDestroy(ctx);
129
- yield pro_1.quotas.removeRows(rows.length);
130
113
  response = rows;
131
114
  for (let row of rows) {
132
115
  ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row);
@@ -134,7 +117,6 @@ function destroy(ctx) {
134
117
  }
135
118
  else {
136
119
  let resp = yield pickApi(tableId).destroy(ctx);
137
- yield pro_1.quotas.removeRow();
138
120
  response = resp.response;
139
121
  row = resp.row;
140
122
  ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row);
@@ -144,52 +126,47 @@ function destroy(ctx) {
144
126
  ctx.row = row || {};
145
127
  ctx.body = response;
146
128
  });
147
- }
148
- exports.destroy = destroy;
149
- function search(ctx) {
129
+ };
130
+ exports.search = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
131
+ const tableId = getTableId(ctx);
132
+ try {
133
+ ctx.status = 200;
134
+ ctx.body = yield pickApi(tableId).search(ctx);
135
+ }
136
+ catch (err) {
137
+ ctx.throw(400, err);
138
+ }
139
+ });
140
+ exports.validate = function (ctx) {
150
141
  return __awaiter(this, void 0, void 0, function* () {
151
142
  const tableId = getTableId(ctx);
152
143
  try {
153
- ctx.status = 200;
154
- ctx.body = yield pickApi(tableId).search(ctx);
144
+ ctx.body = yield pickApi(tableId).validate(ctx);
155
145
  }
156
146
  catch (err) {
157
147
  ctx.throw(400, err);
158
148
  }
159
149
  });
160
- }
161
- exports.search = search;
162
- function validate(ctx) {
150
+ };
151
+ exports.fetchEnrichedRow = function (ctx) {
163
152
  return __awaiter(this, void 0, void 0, function* () {
164
153
  const tableId = getTableId(ctx);
165
154
  try {
166
- ctx.body = yield pickApi(tableId).validate(ctx);
155
+ ctx.body = yield pickApi(tableId).fetchEnrichedRow(ctx);
167
156
  }
168
157
  catch (err) {
169
158
  ctx.throw(400, err);
170
159
  }
171
160
  });
172
- }
173
- exports.validate = validate;
174
- function fetchEnrichedRow(ctx) {
161
+ };
162
+ exports.export = function (ctx) {
175
163
  return __awaiter(this, void 0, void 0, function* () {
176
164
  const tableId = getTableId(ctx);
177
165
  try {
178
- ctx.body = yield pickApi(tableId).fetchEnrichedRow(ctx);
166
+ ctx.body = yield pickApi(tableId).exportRows(ctx);
179
167
  }
180
168
  catch (err) {
181
169
  ctx.throw(400, err);
182
170
  }
183
171
  });
184
- }
185
- exports.fetchEnrichedRow = fetchEnrichedRow;
186
- const exportRows = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
187
- const tableId = getTableId(ctx);
188
- try {
189
- ctx.body = yield pickApi(tableId).exportRows(ctx);
190
- }
191
- catch (err) {
192
- ctx.throw(400, err);
193
- }
194
- });
195
- exports.exportRows = exportRows;
172
+ };
@@ -243,9 +243,8 @@ exports.find = (ctx) => __awaiter(void 0, void 0, void 0, function* () {
243
243
  exports.destroy = function (ctx) {
244
244
  return __awaiter(this, void 0, void 0, function* () {
245
245
  const db = getAppDB();
246
- const { _id } = ctx.request.body;
246
+ const { _id, _rev } = ctx.request.body;
247
247
  let row = yield db.get(_id);
248
- let _rev = ctx.request.body._rev || row._rev;
249
248
  if (row.tableId !== ctx.params.tableId) {
250
249
  throw "Supplied tableId doesn't match the row's tableId";
251
250
  }
@@ -71,8 +71,7 @@ exports.validate = ({ tableId, row, table }) => __awaiter(void 0, void 0, void 0
71
71
  if (type === FieldTypes.ARRAY && row[fieldName]) {
72
72
  if (row[fieldName].length) {
73
73
  row[fieldName].map(val => {
74
- if (!constraints.inclusion.includes(val) &&
75
- constraints.inclusion.length !== 0) {
74
+ if (!constraints.inclusion.includes(val)) {
76
75
  errors[fieldName] = "Field not in list";
77
76
  }
78
77
  });
@@ -78,9 +78,6 @@
78
78
  app.
79
79
  </h2>
80
80
  </div>
81
- <script type="application/javascript">
82
- window.INIT_TIME = Date.now()
83
- </script>
84
81
  <script type="application/javascript" src={clientLibPath}>
85
82
  </script>
86
83
  <script type="application/javascript">
@@ -24,7 +24,6 @@ function isStaticFormula(column) {
24
24
  * in the formula.
25
25
  */
26
26
  function getFormulaThatUseColumn(table, columnNames) {
27
- var _a;
28
27
  let formula = [];
29
28
  columnNames = Array.isArray(columnNames) ? columnNames : [columnNames];
30
29
  for (let column of Object.values(table.schema)) {
@@ -32,7 +31,7 @@ function getFormulaThatUseColumn(table, columnNames) {
32
31
  if (!isStaticFormula(column)) {
33
32
  continue;
34
33
  }
35
- if (!doesContainStrings((_a = column === null || column === void 0 ? void 0 : column.formula) !== null && _a !== void 0 ? _a : "", columnNames)) {
34
+ if (!doesContainStrings(column.formula, columnNames)) {
36
35
  continue;
37
36
  }
38
37
  formula.push(column.name);
@@ -19,33 +19,52 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.bulkImport = exports.destroy = exports.save = void 0;
24
- const linkedRows_1 = require("../../../db/linkedRows");
25
- const utils_1 = require("../../../db/utils");
26
- const constants_1 = require("../../../constants");
27
- const utils_2 = require("./utils");
22
+ const linkRows = require("../../../db/linkedRows");
23
+ const { getRowParams, generateTableID } = require("../../../db/utils");
24
+ const { FieldTypes } = require("../../../constants");
25
+ const { TableSaveFunctions, hasTypeChanged, getTable, handleDataImport, } = require("./utils");
26
+ const usageQuota = require("../../../utilities/usageQuota");
28
27
  const { getAppDB } = require("@budibase/backend-core/context");
29
- const environment_1 = require("../../../environment");
30
- const rowProcessor_1 = require("../../../utilities/rowProcessor");
31
- const bulkFormula_1 = require("./bulkFormula");
32
- const pro_1 = require("@budibase/pro");
33
- function save(ctx) {
28
+ const env = require("../../../environment");
29
+ const { cleanupAttachments, fixAutoColumnSubType, } = require("../../../utilities/rowProcessor");
30
+ const { runStaticFormulaChecks } = require("./bulkFormula");
31
+ function checkAutoColumns(table, oldTable) {
32
+ if (!table.schema) {
33
+ return table;
34
+ }
35
+ for (let [key, schema] of Object.entries(table.schema)) {
36
+ if (!schema.autocolumn || schema.subtype) {
37
+ continue;
38
+ }
39
+ const oldSchema = oldTable && oldTable.schema[key];
40
+ if (oldSchema && oldSchema.subtype) {
41
+ table.schema[key].subtype = oldSchema.subtype;
42
+ }
43
+ else {
44
+ table.schema[key] = fixAutoColumnSubType(schema);
45
+ }
46
+ }
47
+ return table;
48
+ }
49
+ exports.save = function (ctx) {
34
50
  return __awaiter(this, void 0, void 0, function* () {
35
51
  const db = getAppDB();
36
52
  const _a = ctx.request.body, { dataImport } = _a, rest = __rest(_a, ["dataImport"]);
37
- let tableToSave = Object.assign({ type: "table", _id: (0, utils_1.generateTableID)(), views: {} }, rest);
53
+ let tableToSave = Object.assign({ type: "table", _id: generateTableID(), views: {} }, rest);
38
54
  // if the table obj had an _id then it will have been retrieved
39
55
  let oldTable;
40
56
  if (ctx.request.body && ctx.request.body._id) {
41
57
  oldTable = yield db.get(ctx.request.body._id);
42
58
  }
43
- if ((0, utils_2.hasTypeChanged)(tableToSave, oldTable)) {
59
+ // check all types are correct
60
+ if (hasTypeChanged(tableToSave, oldTable)) {
44
61
  ctx.throw(400, "A column type has changed.");
45
62
  }
63
+ // check that subtypes have been maintained
64
+ tableToSave = checkAutoColumns(tableToSave, oldTable);
46
65
  // saving a table is a complex operation, involving many different steps, this
47
66
  // has been broken out into a utility to make it more obvious/easier to manipulate
48
- const tableSaveFunctions = new utils_2.TableSaveFunctions({
67
+ const tableSaveFunctions = new TableSaveFunctions({
49
68
  user: ctx.user,
50
69
  oldTable,
51
70
  dataImport,
@@ -70,7 +89,7 @@ function save(ctx) {
70
89
  }
71
90
  // rename row fields when table column is renamed
72
91
  /* istanbul ignore next */
73
- if (_rename && tableToSave.schema[_rename.updated].type === constants_1.FieldTypes.LINK) {
92
+ if (_rename && tableToSave.schema[_rename.updated].type === FieldTypes.LINK) {
74
93
  ctx.throw(400, "Cannot rename a linked column.");
75
94
  }
76
95
  tableToSave = yield tableSaveFunctions.mid(tableToSave);
@@ -85,8 +104,10 @@ function save(ctx) {
85
104
  }
86
105
  // update linked rows
87
106
  try {
88
- const linkResp = yield (0, linkedRows_1.updateLinks)({
89
- eventType: oldTable ? linkedRows_1.EventType.TABLE_UPDATED : linkedRows_1.EventType.TABLE_SAVE,
107
+ const linkResp = yield linkRows.updateLinks({
108
+ eventType: oldTable
109
+ ? linkRows.EventType.TABLE_UPDATED
110
+ : linkRows.EventType.TABLE_SAVE,
90
111
  table: tableToSave,
91
112
  oldTable: oldTable,
92
113
  });
@@ -107,52 +128,46 @@ function save(ctx) {
107
128
  tableToSave._rev = result.rev;
108
129
  tableToSave = yield tableSaveFunctions.after(tableToSave);
109
130
  // has to run after, make sure it has _id
110
- yield (0, bulkFormula_1.runStaticFormulaChecks)(tableToSave, { oldTable, deletion: null });
131
+ yield runStaticFormulaChecks(tableToSave, { oldTable });
111
132
  return tableToSave;
112
133
  });
113
- }
114
- exports.save = save;
115
- function destroy(ctx) {
134
+ };
135
+ exports.destroy = function (ctx) {
116
136
  return __awaiter(this, void 0, void 0, function* () {
117
137
  const db = getAppDB();
118
138
  const tableToDelete = yield db.get(ctx.params.tableId);
119
139
  // Delete all rows for that table
120
- const rows = yield db.allDocs((0, utils_1.getRowParams)(ctx.params.tableId, null, {
140
+ const rows = yield db.allDocs(getRowParams(ctx.params.tableId, null, {
121
141
  include_docs: true,
122
142
  }));
123
- yield db.bulkDocs(rows.rows.map((row) => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
124
- yield pro_1.quotas.removeRows(rows.rows.length);
143
+ yield db.bulkDocs(rows.rows.map(row => (Object.assign(Object.assign({}, row.doc), { _deleted: true }))));
144
+ yield usageQuota.update(usageQuota.Properties.ROW, -rows.rows.length);
125
145
  // update linked rows
126
- yield (0, linkedRows_1.updateLinks)({
127
- eventType: linkedRows_1.EventType.TABLE_DELETE,
146
+ yield linkRows.updateLinks({
147
+ eventType: linkRows.EventType.TABLE_DELETE,
128
148
  table: tableToDelete,
129
149
  });
130
150
  // don't remove the table itself until very end
131
151
  yield db.remove(tableToDelete);
132
152
  // remove table search index
133
- if (!(0, environment_1.isTest)()) {
153
+ if (!env.isTest()) {
134
154
  const currentIndexes = yield db.getIndexes();
135
- const existingIndex = currentIndexes.indexes.find((existing) => existing.name === `search:${ctx.params.tableId}`);
155
+ const existingIndex = currentIndexes.indexes.find(existing => existing.name === `search:${ctx.params.tableId}`);
136
156
  if (existingIndex) {
137
157
  yield db.deleteIndex(existingIndex);
138
158
  }
139
159
  }
140
160
  // has to run after, make sure it has _id
141
- yield (0, bulkFormula_1.runStaticFormulaChecks)(tableToDelete, {
142
- oldTable: null,
143
- deletion: true,
144
- });
145
- yield (0, rowProcessor_1.cleanupAttachments)(tableToDelete, { rows });
161
+ yield runStaticFormulaChecks(tableToDelete, { deletion: true });
162
+ yield cleanupAttachments(tableToDelete, { rows });
146
163
  return tableToDelete;
147
164
  });
148
- }
149
- exports.destroy = destroy;
150
- function bulkImport(ctx) {
165
+ };
166
+ exports.bulkImport = function (ctx) {
151
167
  return __awaiter(this, void 0, void 0, function* () {
152
- const table = yield (0, utils_2.getTable)(ctx.params.tableId);
168
+ const table = yield getTable(ctx.params.tableId);
153
169
  const { dataImport } = ctx.request.body;
154
- yield (0, utils_2.handleDataImport)(ctx.user, table, dataImport);
170
+ yield handleDataImport(ctx.user, table, dataImport);
155
171
  return table;
156
172
  });
157
- }
158
- exports.bulkImport = bulkImport;
173
+ };