@budibase/server 2.2.12-alpha.5 → 2.2.12-alpha.51

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 (578) hide show
  1. package/__mocks__/node-fetch.ts +2 -0
  2. package/builder/assets/{bb-emblem.4e4717da.svg → bb-emblem.05f7ae7a.svg} +1 -1
  3. package/builder/assets/bg.c1563288.png +0 -0
  4. package/builder/assets/bulgaria.bd68393d.png +0 -0
  5. package/builder/assets/covanta.72c46c1e.png +0 -0
  6. package/builder/assets/index.f29fb244.js +1031 -0
  7. package/builder/assets/index.ff7b1aa7.css +6 -0
  8. package/builder/assets/schnellecke.cf1837a8.png +0 -0
  9. package/builder/index.html +2 -2
  10. package/coverage/clover.xml +5670 -5622
  11. package/coverage/coverage-final.json +282 -279
  12. package/coverage/lcov-report/index.html +458 -413
  13. package/coverage/lcov-report/src/api/controllers/analytics.ts.html +9 -9
  14. package/coverage/lcov-report/src/api/controllers/apikeys.ts.html +6 -6
  15. package/coverage/lcov-report/src/api/controllers/application.ts.html +199 -178
  16. package/coverage/lcov-report/src/api/controllers/auth.ts.html +10 -10
  17. package/coverage/lcov-report/src/api/controllers/automation.ts.html +37 -37
  18. package/coverage/lcov-report/src/api/controllers/backup.ts.html +8 -8
  19. package/coverage/lcov-report/src/api/controllers/cloud.ts.html +19 -19
  20. package/coverage/lcov-report/src/api/controllers/component.ts.html +12 -12
  21. package/coverage/lcov-report/src/api/controllers/datasource.ts.html +117 -93
  22. package/coverage/lcov-report/src/api/controllers/deploy/Deployment.ts.html +18 -18
  23. package/coverage/lcov-report/src/api/controllers/deploy/index.html +7 -7
  24. package/coverage/lcov-report/src/api/controllers/deploy/index.ts.html +83 -83
  25. package/coverage/lcov-report/src/api/controllers/dev.ts.html +28 -28
  26. package/coverage/lcov-report/src/api/controllers/index.html +105 -105
  27. package/coverage/lcov-report/src/api/controllers/integration.ts.html +5 -5
  28. package/coverage/lcov-report/src/api/controllers/layout.ts.html +9 -9
  29. package/coverage/lcov-report/src/api/controllers/metadata.ts.html +11 -11
  30. package/coverage/lcov-report/src/api/controllers/migrations.ts.html +6 -6
  31. package/coverage/lcov-report/src/api/controllers/permission.ts.html +14 -14
  32. package/coverage/lcov-report/src/api/controllers/plugin/file.ts.html +4 -4
  33. package/coverage/lcov-report/src/api/controllers/plugin/github.ts.html +20 -20
  34. package/coverage/lcov-report/src/api/controllers/plugin/index.html +31 -31
  35. package/coverage/lcov-report/src/api/controllers/plugin/index.ts.html +32 -32
  36. package/coverage/lcov-report/src/api/controllers/plugin/npm.ts.html +10 -10
  37. package/coverage/lcov-report/src/api/controllers/plugin/uploaders.ts.html +5 -5
  38. package/coverage/lcov-report/src/api/controllers/plugin/url.ts.html +4 -4
  39. package/coverage/lcov-report/src/api/controllers/plugin/utils.ts.html +4 -4
  40. package/coverage/lcov-report/src/api/controllers/public/applications.ts.html +31 -31
  41. package/coverage/lcov-report/src/api/controllers/public/index.html +58 -58
  42. package/coverage/lcov-report/src/api/controllers/public/mapping/applications.ts.html +7 -7
  43. package/coverage/lcov-report/src/api/controllers/public/mapping/index.html +25 -25
  44. package/coverage/lcov-report/src/api/controllers/public/mapping/index.ts.html +9 -9
  45. package/coverage/lcov-report/src/api/controllers/public/mapping/queries.ts.html +8 -8
  46. package/coverage/lcov-report/src/api/controllers/public/mapping/rows.ts.html +4 -4
  47. package/coverage/lcov-report/src/api/controllers/public/mapping/tables.ts.html +4 -4
  48. package/coverage/lcov-report/src/api/controllers/public/mapping/users.ts.html +4 -4
  49. package/coverage/lcov-report/src/api/controllers/public/queries.ts.html +15 -15
  50. package/coverage/lcov-report/src/api/controllers/public/rows.ts.html +21 -21
  51. package/coverage/lcov-report/src/api/controllers/public/tables.ts.html +21 -21
  52. package/coverage/lcov-report/src/api/controllers/public/users.ts.html +27 -27
  53. package/coverage/lcov-report/src/api/controllers/public/utils.ts.html +8 -8
  54. package/coverage/lcov-report/src/api/controllers/query/import/index.html +8 -8
  55. package/coverage/lcov-report/src/api/controllers/query/import/index.ts.html +11 -11
  56. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.html +14 -14
  57. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/index.ts.html +14 -14
  58. package/coverage/lcov-report/src/api/controllers/query/import/sources/base/openapi.ts.html +8 -8
  59. package/coverage/lcov-report/src/api/controllers/query/import/sources/curl.ts.html +12 -12
  60. package/coverage/lcov-report/src/api/controllers/query/import/sources/index.html +23 -23
  61. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi2.ts.html +16 -16
  62. package/coverage/lcov-report/src/api/controllers/query/import/sources/openapi3.ts.html +20 -20
  63. package/coverage/lcov-report/src/api/controllers/query/index.html +16 -16
  64. package/coverage/lcov-report/src/api/controllers/query/index.ts.html +94 -70
  65. package/coverage/lcov-report/src/api/controllers/query/validation.ts.html +9 -9
  66. package/coverage/lcov-report/src/api/controllers/role.ts.html +9 -9
  67. package/coverage/lcov-report/src/api/controllers/routing.ts.html +10 -10
  68. package/coverage/lcov-report/src/api/controllers/row/ExternalRequest.ts.html +58 -40
  69. package/coverage/lcov-report/src/api/controllers/row/external.ts.html +87 -57
  70. package/coverage/lcov-report/src/api/controllers/row/index.html +66 -66
  71. package/coverage/lcov-report/src/api/controllers/row/index.ts.html +36 -36
  72. package/coverage/lcov-report/src/api/controllers/row/internal.ts.html +155 -83
  73. package/coverage/lcov-report/src/api/controllers/row/internalSearch.ts.html +146 -146
  74. package/coverage/lcov-report/src/api/controllers/row/staticFormula.ts.html +33 -33
  75. package/coverage/lcov-report/src/api/controllers/row/utils.ts.html +153 -39
  76. package/coverage/lcov-report/src/api/controllers/screen.ts.html +12 -12
  77. package/coverage/lcov-report/src/api/controllers/script.ts.html +11 -11
  78. package/coverage/lcov-report/src/api/controllers/static/index.html +15 -15
  79. package/coverage/lcov-report/src/api/controllers/static/index.ts.html +49 -52
  80. package/coverage/lcov-report/src/api/controllers/table/bulkFormula.ts.html +60 -60
  81. package/coverage/lcov-report/src/api/controllers/table/external.ts.html +56 -50
  82. package/coverage/lcov-report/src/api/controllers/table/index.html +48 -48
  83. package/coverage/lcov-report/src/api/controllers/table/index.ts.html +155 -68
  84. package/coverage/lcov-report/src/api/controllers/table/internal.ts.html +58 -61
  85. package/coverage/lcov-report/src/api/controllers/table/utils.ts.html +93 -96
  86. package/coverage/lcov-report/src/api/controllers/templates.ts.html +21 -21
  87. package/coverage/lcov-report/src/api/controllers/user.ts.html +103 -79
  88. package/coverage/lcov-report/src/api/controllers/view/exporters.ts.html +64 -19
  89. package/coverage/lcov-report/src/api/controllers/view/index.html +38 -38
  90. package/coverage/lcov-report/src/api/controllers/view/index.ts.html +57 -96
  91. package/coverage/lcov-report/src/api/controllers/view/utils.ts.html +22 -22
  92. package/coverage/lcov-report/src/api/controllers/view/viewBuilder.ts.html +8 -8
  93. package/coverage/lcov-report/src/api/controllers/webhook.ts.html +69 -63
  94. package/coverage/lcov-report/src/api/index.html +15 -15
  95. package/coverage/lcov-report/src/api/index.ts.html +35 -35
  96. package/coverage/lcov-report/src/api/routes/analytics.ts.html +10 -10
  97. package/coverage/lcov-report/src/api/routes/apikeys.ts.html +11 -11
  98. package/coverage/lcov-report/src/api/routes/application.ts.html +13 -13
  99. package/coverage/lcov-report/src/api/routes/auth.ts.html +9 -9
  100. package/coverage/lcov-report/src/api/routes/automation.ts.html +14 -14
  101. package/coverage/lcov-report/src/api/routes/backup.ts.html +11 -11
  102. package/coverage/lcov-report/src/api/routes/cloud.ts.html +11 -11
  103. package/coverage/lcov-report/src/api/routes/component.ts.html +11 -11
  104. package/coverage/lcov-report/src/api/routes/datasource.ts.html +12 -12
  105. package/coverage/lcov-report/src/api/routes/deploy.ts.html +11 -11
  106. package/coverage/lcov-report/src/api/routes/dev.ts.html +17 -17
  107. package/coverage/lcov-report/src/api/routes/index.html +67 -67
  108. package/coverage/lcov-report/src/api/routes/index.ts.html +43 -37
  109. package/coverage/lcov-report/src/api/routes/integration.ts.html +11 -11
  110. package/coverage/lcov-report/src/api/routes/layout.ts.html +11 -11
  111. package/coverage/lcov-report/src/api/routes/metadata.ts.html +12 -12
  112. package/coverage/lcov-report/src/api/routes/migrations.ts.html +10 -10
  113. package/coverage/lcov-report/src/api/routes/permission.ts.html +12 -12
  114. package/coverage/lcov-report/src/api/routes/plugin.ts.html +10 -10
  115. package/coverage/lcov-report/src/api/routes/public/applications.ts.html +16 -16
  116. package/coverage/lcov-report/src/api/routes/public/index.html +24 -24
  117. package/coverage/lcov-report/src/api/routes/public/index.ts.html +60 -60
  118. package/coverage/lcov-report/src/api/routes/public/middleware/index.html +5 -5
  119. package/coverage/lcov-report/src/api/routes/public/middleware/mapper.ts.html +12 -12
  120. package/coverage/lcov-report/src/api/routes/public/queries.ts.html +11 -11
  121. package/coverage/lcov-report/src/api/routes/public/rows.ts.html +14 -14
  122. package/coverage/lcov-report/src/api/routes/public/tables.ts.html +14 -14
  123. package/coverage/lcov-report/src/api/routes/public/tests/index.html +7 -7
  124. package/coverage/lcov-report/src/api/routes/public/tests/utils.ts.html +5 -5
  125. package/coverage/lcov-report/src/api/routes/public/users.ts.html +14 -14
  126. package/coverage/lcov-report/src/api/routes/public/utils/Endpoint.ts.html +21 -21
  127. package/coverage/lcov-report/src/api/routes/public/utils/index.html +5 -5
  128. package/coverage/lcov-report/src/api/routes/query.ts.html +14 -14
  129. package/coverage/lcov-report/src/api/routes/role.ts.html +12 -12
  130. package/coverage/lcov-report/src/api/routes/routing.ts.html +11 -11
  131. package/coverage/lcov-report/src/api/routes/row.ts.html +14 -14
  132. package/coverage/lcov-report/src/api/routes/screen.ts.html +12 -12
  133. package/coverage/lcov-report/src/api/routes/script.ts.html +13 -13
  134. package/coverage/lcov-report/src/api/routes/static.ts.html +18 -18
  135. package/coverage/lcov-report/src/api/routes/table.ts.html +29 -98
  136. package/coverage/lcov-report/src/api/routes/templates.ts.html +11 -11
  137. package/coverage/lcov-report/src/api/routes/tests/utilities/TestFunctions.ts.html +13 -13
  138. package/coverage/lcov-report/src/api/routes/tests/utilities/index.html +23 -23
  139. package/coverage/lcov-report/src/api/routes/tests/utilities/index.ts.html +14 -14
  140. package/coverage/lcov-report/src/api/routes/user.ts.html +12 -12
  141. package/coverage/lcov-report/src/api/routes/utils/index.html +3 -3
  142. package/coverage/lcov-report/src/api/routes/utils/validators.ts.html +44 -44
  143. package/coverage/lcov-report/src/api/routes/view.ts.html +13 -13
  144. package/coverage/lcov-report/src/api/routes/webhook.ts.html +13 -13
  145. package/coverage/lcov-report/src/app.ts.html +22 -16
  146. package/coverage/lcov-report/src/automations/actions.ts.html +31 -31
  147. package/coverage/lcov-report/src/automations/automationUtils.ts.html +61 -61
  148. package/coverage/lcov-report/src/automations/bullboard.ts.html +19 -19
  149. package/coverage/lcov-report/src/automations/index.html +54 -54
  150. package/coverage/lcov-report/src/automations/index.ts.html +23 -23
  151. package/coverage/lcov-report/src/automations/logging/index.html +3 -3
  152. package/coverage/lcov-report/src/automations/logging/index.ts.html +10 -10
  153. package/coverage/lcov-report/src/automations/steps/bash.ts.html +11 -11
  154. package/coverage/lcov-report/src/automations/steps/createRow.ts.html +9 -9
  155. package/coverage/lcov-report/src/automations/steps/delay.ts.html +7 -7
  156. package/coverage/lcov-report/src/automations/steps/deleteRow.ts.html +9 -9
  157. package/coverage/lcov-report/src/automations/steps/discord.ts.html +11 -11
  158. package/coverage/lcov-report/src/automations/steps/executeQuery.ts.html +9 -9
  159. package/coverage/lcov-report/src/automations/steps/executeScript.ts.html +9 -9
  160. package/coverage/lcov-report/src/automations/steps/filter.ts.html +12 -12
  161. package/coverage/lcov-report/src/automations/steps/index.html +75 -75
  162. package/coverage/lcov-report/src/automations/steps/integromat.ts.html +10 -10
  163. package/coverage/lcov-report/src/automations/steps/loop.ts.html +5 -5
  164. package/coverage/lcov-report/src/automations/steps/outgoingWebhook.ts.html +19 -19
  165. package/coverage/lcov-report/src/automations/steps/queryRows.ts.html +43 -43
  166. package/coverage/lcov-report/src/automations/steps/sendSmtpEmail.ts.html +9 -9
  167. package/coverage/lcov-report/src/automations/steps/serverLog.ts.html +10 -10
  168. package/coverage/lcov-report/src/automations/steps/slack.ts.html +10 -10
  169. package/coverage/lcov-report/src/automations/steps/updateRow.ts.html +9 -9
  170. package/coverage/lcov-report/src/automations/steps/utils.ts.html +12 -12
  171. package/coverage/lcov-report/src/automations/steps/zapier.ts.html +8 -8
  172. package/coverage/lcov-report/src/automations/tests/utilities/index.html +15 -15
  173. package/coverage/lcov-report/src/automations/tests/utilities/index.ts.html +24 -24
  174. package/coverage/lcov-report/src/automations/triggerInfo/app.ts.html +6 -6
  175. package/coverage/lcov-report/src/automations/triggerInfo/cron.ts.html +6 -6
  176. package/coverage/lcov-report/src/automations/triggerInfo/index.html +17 -17
  177. package/coverage/lcov-report/src/automations/triggerInfo/index.ts.html +10 -10
  178. package/coverage/lcov-report/src/automations/triggerInfo/rowDeleted.ts.html +6 -6
  179. package/coverage/lcov-report/src/automations/triggerInfo/rowSaved.ts.html +6 -6
  180. package/coverage/lcov-report/src/automations/triggerInfo/rowUpdated.ts.html +6 -6
  181. package/coverage/lcov-report/src/automations/triggerInfo/webhook.ts.html +6 -6
  182. package/coverage/lcov-report/src/automations/triggers.ts.html +53 -38
  183. package/coverage/lcov-report/src/automations/utils.ts.html +69 -69
  184. package/coverage/lcov-report/src/constants/index.html +19 -19
  185. package/coverage/lcov-report/src/constants/index.ts.html +80 -80
  186. package/coverage/lcov-report/src/constants/layouts.ts.html +9 -9
  187. package/coverage/lcov-report/src/constants/screens.ts.html +4 -4
  188. package/coverage/lcov-report/src/db/defaultData/datasource_bb_default.ts.html +45 -45
  189. package/coverage/lcov-report/src/db/defaultData/employeeImport.ts.html +8 -8
  190. package/coverage/lcov-report/src/db/defaultData/expensesImport.ts.html +8 -8
  191. package/coverage/lcov-report/src/db/defaultData/index.html +43 -43
  192. package/coverage/lcov-report/src/db/defaultData/inventoryImport.ts.html +8 -8
  193. package/coverage/lcov-report/src/db/defaultData/jobsImport.ts.html +8 -8
  194. package/coverage/lcov-report/src/db/dynamoClient.ts.html +26 -26
  195. package/coverage/lcov-report/src/db/inMemoryView.ts.html +13 -13
  196. package/coverage/lcov-report/src/db/index.html +32 -32
  197. package/coverage/lcov-report/src/db/index.ts.html +10 -10
  198. package/coverage/lcov-report/src/db/linkedRows/LinkController.ts.html +38 -38
  199. package/coverage/lcov-report/src/db/linkedRows/LinkDocument.ts.html +7 -7
  200. package/coverage/lcov-report/src/db/linkedRows/index.html +37 -37
  201. package/coverage/lcov-report/src/db/linkedRows/index.ts.html +40 -40
  202. package/coverage/lcov-report/src/db/linkedRows/linkUtils.ts.html +25 -25
  203. package/coverage/lcov-report/src/db/newid.ts.html +5 -5
  204. package/coverage/lcov-report/src/db/utils.ts.html +76 -76
  205. package/coverage/lcov-report/src/definitions/automations.ts.html +9 -6
  206. package/coverage/lcov-report/src/definitions/index.html +5 -20
  207. package/coverage/lcov-report/src/environment.ts.html +16 -16
  208. package/coverage/lcov-report/src/events/AutomationEmitter.ts.html +14 -14
  209. package/coverage/lcov-report/src/events/BudibaseEmitter.ts.html +8 -8
  210. package/coverage/lcov-report/src/events/index.html +20 -20
  211. package/coverage/lcov-report/src/events/index.ts.html +7 -7
  212. package/coverage/lcov-report/src/events/utils.ts.html +11 -11
  213. package/coverage/lcov-report/src/index.html +36 -36
  214. package/coverage/lcov-report/src/index.ts.html +8 -8
  215. package/coverage/lcov-report/src/integrations/airtable.ts.html +10 -10
  216. package/coverage/lcov-report/src/integrations/arangodb.ts.html +9 -9
  217. package/coverage/lcov-report/src/integrations/base/index.html +28 -28
  218. package/coverage/lcov-report/src/integrations/base/query.ts.html +15 -9
  219. package/coverage/lcov-report/src/integrations/base/sql.ts.html +37 -37
  220. package/coverage/lcov-report/src/integrations/base/sqlTable.ts.html +22 -22
  221. package/coverage/lcov-report/src/integrations/base/utils.ts.html +5 -5
  222. package/coverage/lcov-report/src/integrations/couchdb.ts.html +10 -10
  223. package/coverage/lcov-report/src/integrations/dynamodb.ts.html +17 -17
  224. package/coverage/lcov-report/src/integrations/elasticsearch.ts.html +9 -9
  225. package/coverage/lcov-report/src/integrations/firebase.ts.html +12 -12
  226. package/coverage/lcov-report/src/integrations/googlesheets.ts.html +41 -41
  227. package/coverage/lcov-report/src/integrations/index.html +124 -124
  228. package/coverage/lcov-report/src/integrations/index.ts.html +47 -47
  229. package/coverage/lcov-report/src/integrations/microsoftSqlServer.ts.html +31 -31
  230. package/coverage/lcov-report/src/integrations/mongodb.ts.html +421 -289
  231. package/coverage/lcov-report/src/integrations/mysql.ts.html +28 -28
  232. package/coverage/lcov-report/src/integrations/oracle.ts.html +31 -31
  233. package/coverage/lcov-report/src/integrations/postgres.ts.html +22 -22
  234. package/coverage/lcov-report/src/integrations/queries/index.html +19 -19
  235. package/coverage/lcov-report/src/integrations/queries/sql.ts.html +18 -153
  236. package/coverage/lcov-report/src/integrations/redis.ts.html +8 -8
  237. package/coverage/lcov-report/src/integrations/rest.ts.html +43 -52
  238. package/coverage/lcov-report/src/integrations/s3.ts.html +17 -17
  239. package/coverage/lcov-report/src/integrations/snowflake.ts.html +15 -15
  240. package/coverage/lcov-report/src/integrations/tests/TestConfiguration.js.html +1 -1
  241. package/coverage/lcov-report/src/integrations/tests/index.html +1 -1
  242. package/coverage/lcov-report/src/integrations/utils.ts.html +49 -49
  243. package/coverage/lcov-report/src/middleware/appInfo.ts.html +11 -11
  244. package/coverage/lcov-report/src/middleware/authorized.ts.html +49 -37
  245. package/coverage/lcov-report/src/middleware/builder.ts.html +26 -26
  246. package/coverage/lcov-report/src/middleware/currentapp.ts.html +50 -47
  247. package/coverage/lcov-report/src/middleware/index.html +40 -40
  248. package/coverage/lcov-report/src/middleware/joi-validator.ts.html +10 -10
  249. package/coverage/lcov-report/src/middleware/publicApi.ts.html +9 -9
  250. package/coverage/lcov-report/src/middleware/resourceId.ts.html +23 -23
  251. package/coverage/lcov-report/src/middleware/selfhost.ts.html +2 -2
  252. package/coverage/lcov-report/src/middleware/utils.ts.html +4 -4
  253. package/coverage/lcov-report/src/migrations/functions/appUrls.ts.html +6 -6
  254. package/coverage/lcov-report/src/migrations/functions/backfill/app/automations.ts.html +7 -7
  255. package/coverage/lcov-report/src/migrations/functions/backfill/app/datasources.ts.html +7 -7
  256. package/coverage/lcov-report/src/migrations/functions/backfill/app/index.html +31 -31
  257. package/coverage/lcov-report/src/migrations/functions/backfill/app/layouts.ts.html +8 -8
  258. package/coverage/lcov-report/src/migrations/functions/backfill/app/queries.ts.html +13 -13
  259. package/coverage/lcov-report/src/migrations/functions/backfill/app/roles.ts.html +7 -7
  260. package/coverage/lcov-report/src/migrations/functions/backfill/app/screens.ts.html +7 -7
  261. package/coverage/lcov-report/src/migrations/functions/backfill/app/tables.ts.html +8 -8
  262. package/coverage/lcov-report/src/migrations/functions/backfill/app.ts.html +21 -21
  263. package/coverage/lcov-report/src/migrations/functions/backfill/global/configs.ts.html +10 -10
  264. package/coverage/lcov-report/src/migrations/functions/backfill/global/index.html +19 -19
  265. package/coverage/lcov-report/src/migrations/functions/backfill/global/quotas.ts.html +9 -9
  266. package/coverage/lcov-report/src/migrations/functions/backfill/global/users.ts.html +13 -13
  267. package/coverage/lcov-report/src/migrations/functions/backfill/global.ts.html +23 -23
  268. package/coverage/lcov-report/src/migrations/functions/backfill/index.html +26 -26
  269. package/coverage/lcov-report/src/migrations/functions/backfill/index.ts.html +7 -7
  270. package/coverage/lcov-report/src/migrations/functions/backfill/installation.ts.html +14 -14
  271. package/coverage/lcov-report/src/migrations/functions/index.html +18 -18
  272. package/coverage/lcov-report/src/migrations/functions/syncQuotas.ts.html +8 -8
  273. package/coverage/lcov-report/src/migrations/functions/tableSettings.ts.html +11 -11
  274. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.html +11 -11
  275. package/coverage/lcov-report/src/migrations/functions/usageQuotas/index.ts.html +3 -3
  276. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncApps.ts.html +6 -6
  277. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncPlugins.ts.html +8 -8
  278. package/coverage/lcov-report/src/migrations/functions/usageQuotas/syncRows.ts.html +7 -7
  279. package/coverage/lcov-report/src/migrations/functions/userEmailViewCasing.ts.html +4 -4
  280. package/coverage/lcov-report/src/migrations/index.html +15 -15
  281. package/coverage/lcov-report/src/migrations/index.ts.html +43 -43
  282. package/coverage/lcov-report/src/migrations/tests/helpers.ts.html +4 -4
  283. package/coverage/lcov-report/src/migrations/tests/index.html +6 -6
  284. package/coverage/lcov-report/src/migrations/tests/structures.ts.html +3 -3
  285. package/coverage/lcov-report/src/sdk/app/applications/index.html +11 -11
  286. package/coverage/lcov-report/src/sdk/app/applications/index.ts.html +6 -6
  287. package/coverage/lcov-report/src/sdk/app/applications/sync.ts.html +24 -24
  288. package/coverage/lcov-report/src/sdk/app/applications/utils.ts.html +15 -15
  289. package/coverage/lcov-report/src/sdk/app/automations/index.html +7 -7
  290. package/coverage/lcov-report/src/sdk/app/automations/index.ts.html +5 -5
  291. package/coverage/lcov-report/src/sdk/app/automations/webhook.ts.html +8 -8
  292. package/coverage/lcov-report/src/sdk/app/backups/constants.ts.html +5 -5
  293. package/coverage/lcov-report/src/sdk/app/backups/exports.ts.html +30 -30
  294. package/coverage/lcov-report/src/sdk/app/backups/imports.ts.html +24 -24
  295. package/coverage/lcov-report/src/sdk/app/backups/index.html +27 -27
  296. package/coverage/lcov-report/src/sdk/app/backups/index.ts.html +7 -7
  297. package/coverage/lcov-report/src/sdk/app/backups/statistics.ts.html +12 -12
  298. package/coverage/lcov-report/src/sdk/app/datasources/datasources.ts.html +493 -0
  299. package/coverage/lcov-report/src/sdk/app/datasources/index.html +131 -0
  300. package/coverage/lcov-report/src/sdk/app/datasources/index.ts.html +100 -0
  301. package/coverage/lcov-report/src/sdk/app/queries/index.html +131 -0
  302. package/coverage/lcov-report/src/{utilities/statusCodes.ts.html → sdk/app/queries/index.ts.html} +22 -28
  303. package/coverage/lcov-report/src/{definitions/datasource.ts.html → sdk/app/queries/queries.ts.html} +82 -82
  304. package/coverage/lcov-report/src/sdk/app/rows/attachments.ts.html +8 -8
  305. package/coverage/lcov-report/src/sdk/app/rows/index.html +8 -8
  306. package/coverage/lcov-report/src/sdk/app/rows/index.ts.html +6 -6
  307. package/coverage/lcov-report/src/sdk/app/rows/rows.ts.html +4 -4
  308. package/coverage/lcov-report/src/sdk/app/tables/index.html +15 -15
  309. package/coverage/lcov-report/src/sdk/app/tables/index.ts.html +29 -20
  310. package/coverage/lcov-report/src/sdk/index.html +7 -7
  311. package/coverage/lcov-report/src/sdk/index.ts.html +24 -12
  312. package/coverage/lcov-report/src/sdk/users/index.html +6 -6
  313. package/coverage/lcov-report/src/sdk/users/index.ts.html +5 -5
  314. package/coverage/lcov-report/src/sdk/users/utils.ts.html +29 -29
  315. package/coverage/lcov-report/src/sdk/utils/index.html +116 -0
  316. package/coverage/lcov-report/src/sdk/utils/index.ts.html +133 -0
  317. package/coverage/lcov-report/src/startup.ts.html +40 -55
  318. package/coverage/lcov-report/src/tests/utilities/TestConfiguration.ts.html +141 -132
  319. package/coverage/lcov-report/src/tests/utilities/controllers.ts.html +20 -20
  320. package/coverage/lcov-report/src/tests/utilities/index.html +30 -30
  321. package/coverage/lcov-report/src/tests/utilities/index.ts.html +2 -2
  322. package/coverage/lcov-report/src/tests/utilities/structures.ts.html +232 -43
  323. package/coverage/lcov-report/src/threads/automation.ts.html +225 -195
  324. package/coverage/lcov-report/src/threads/index.html +46 -46
  325. package/coverage/lcov-report/src/threads/index.ts.html +38 -38
  326. package/coverage/lcov-report/src/threads/query.ts.html +73 -34
  327. package/coverage/lcov-report/src/threads/utils.ts.html +26 -26
  328. package/coverage/lcov-report/src/utilities/budibaseDir.ts.html +4 -4
  329. package/coverage/lcov-report/src/utilities/centralPath.ts.html +10 -10
  330. package/coverage/lcov-report/src/utilities/fileSystem/app.ts.html +11 -11
  331. package/coverage/lcov-report/src/utilities/fileSystem/clientLibrary.ts.html +12 -12
  332. package/coverage/lcov-report/src/utilities/fileSystem/filesystem.ts.html +32 -26
  333. package/coverage/lcov-report/src/utilities/fileSystem/index.html +42 -42
  334. package/coverage/lcov-report/src/utilities/fileSystem/index.ts.html +1 -1
  335. package/coverage/lcov-report/src/utilities/fileSystem/plugin.ts.html +10 -13
  336. package/coverage/lcov-report/src/utilities/fileSystem/processor.ts.html +9 -9
  337. package/coverage/lcov-report/src/utilities/fileSystem/template.ts.html +7 -7
  338. package/coverage/lcov-report/src/utilities/global.ts.html +61 -61
  339. package/coverage/lcov-report/src/utilities/index.html +80 -95
  340. package/coverage/lcov-report/src/utilities/index.ts.html +32 -32
  341. package/coverage/lcov-report/src/utilities/redis.ts.html +35 -35
  342. package/coverage/lcov-report/src/utilities/routing/index.html +1 -1
  343. package/coverage/lcov-report/src/utilities/routing/index.ts.html +5 -5
  344. package/coverage/lcov-report/src/utilities/rowProcessor/index.html +32 -32
  345. package/coverage/lcov-report/src/utilities/rowProcessor/index.ts.html +67 -67
  346. package/coverage/lcov-report/src/utilities/rowProcessor/map.ts.html +9 -9
  347. package/coverage/lcov-report/src/utilities/rowProcessor/utils.ts.html +26 -26
  348. package/coverage/lcov-report/src/utilities/{csvParser.ts.html → schema.ts.html} +173 -233
  349. package/coverage/lcov-report/src/utilities/scriptRunner.ts.html +8 -8
  350. package/coverage/lcov-report/src/utilities/security.ts.html +13 -13
  351. package/coverage/lcov-report/src/utilities/usageQuota/index.html +9 -9
  352. package/coverage/lcov-report/src/utilities/usageQuota/rows.ts.html +8 -8
  353. package/coverage/lcov-report/src/utilities/usageQuota/usageQuoteReset.ts.html +3 -3
  354. package/coverage/lcov-report/src/utilities/users.ts.html +7 -7
  355. package/coverage/lcov-report/src/utilities/workerRequests.ts.html +61 -34
  356. package/coverage/lcov-report/src/watch.ts.html +20 -20
  357. package/coverage/lcov-report/src/websocket.ts.html +5 -5
  358. package/coverage/lcov.info +11919 -11276
  359. package/dist/api/controllers/application.js +73 -74
  360. package/dist/api/controllers/cloud.js +1 -1
  361. package/dist/api/controllers/datasource.js +24 -15
  362. package/dist/api/controllers/query/index.js +23 -13
  363. package/dist/api/controllers/row/ExternalRequest.js +12 -3
  364. package/dist/api/controllers/row/external.js +20 -13
  365. package/dist/api/controllers/row/internal.js +40 -15
  366. package/dist/api/controllers/row/utils.js +35 -3
  367. package/dist/api/controllers/static/index.js +45 -42
  368. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -1
  369. package/dist/api/controllers/table/external.js +16 -35
  370. package/dist/api/controllers/table/index.js +44 -15
  371. package/dist/api/controllers/table/internal.js +6 -7
  372. package/dist/api/controllers/table/utils.js +9 -9
  373. package/dist/api/controllers/user.js +14 -6
  374. package/dist/api/controllers/view/exporters.js +22 -6
  375. package/dist/api/controllers/view/index.js +20 -56
  376. package/dist/api/controllers/view/viewBuilder.js +15 -2
  377. package/dist/api/controllers/webhook.js +45 -43
  378. package/dist/api/routes/analytics.js +2 -1
  379. package/dist/api/routes/apikeys.js +2 -1
  380. package/dist/api/routes/application.js +2 -1
  381. package/dist/api/routes/auth.js +2 -1
  382. package/dist/api/routes/automation.js +2 -1
  383. package/dist/api/routes/backup.js +2 -1
  384. package/dist/api/routes/cloud.js +2 -1
  385. package/dist/api/routes/component.js +2 -1
  386. package/dist/api/routes/datasource.js +2 -1
  387. package/dist/api/routes/deploy.js +2 -1
  388. package/dist/api/routes/dev.js +2 -1
  389. package/dist/api/routes/index.js +2 -0
  390. package/dist/api/routes/integration.js +2 -1
  391. package/dist/api/routes/layout.js +2 -1
  392. package/dist/api/routes/metadata.js +2 -1
  393. package/dist/api/routes/migrations.js +2 -1
  394. package/dist/api/routes/permission.js +2 -1
  395. package/dist/api/routes/query.js +2 -1
  396. package/dist/api/routes/role.js +2 -1
  397. package/dist/api/routes/routing.js +2 -1
  398. package/dist/api/routes/row.js +2 -2
  399. package/dist/api/routes/screen.js +2 -1
  400. package/dist/api/routes/script.js +2 -1
  401. package/dist/api/routes/static.js +6 -5
  402. package/dist/api/routes/table.js +8 -38
  403. package/dist/api/routes/templates.js +2 -1
  404. package/dist/api/routes/user.js +2 -1
  405. package/dist/api/routes/utils/validators.js +1 -1
  406. package/dist/api/routes/view.js +2 -1
  407. package/dist/api/routes/webhook.js +2 -1
  408. package/dist/app.js +9 -7
  409. package/dist/automations/logging/index.js +5 -25
  410. package/dist/automations/triggers.js +1 -0
  411. package/dist/db/index.js +5 -2
  412. package/dist/db/linkedRows/LinkController.js +2 -1
  413. package/dist/db/linkedRows/LinkDocument.js +2 -1
  414. package/dist/db/newid.js +4 -2
  415. package/dist/definitions/datasource.js +0 -6
  416. package/dist/environment.js +2 -1
  417. package/dist/events/AutomationEmitter.js +2 -1
  418. package/dist/events/BudibaseEmitter.js +2 -1
  419. package/dist/events/index.js +2 -1
  420. package/dist/index.js +2 -2
  421. package/dist/integrations/base/query.js +7 -2
  422. package/dist/integrations/base/sqlTable.js +14 -14
  423. package/dist/integrations/dynamodb.js +8 -5
  424. package/dist/integrations/index.js +5 -5
  425. package/dist/integrations/mongodb.js +311 -271
  426. package/dist/integrations/mysql.js +2 -2
  427. package/dist/integrations/queries/sql.js +73 -100
  428. package/dist/integrations/rest.js +16 -18
  429. package/dist/middleware/authorized.js +2 -1
  430. package/dist/middleware/builder.js +4 -2
  431. package/dist/middleware/currentapp.js +6 -3
  432. package/dist/middleware/publicApi.js +4 -2
  433. package/dist/middleware/selfhost.js +4 -1
  434. package/dist/package.json +9 -7
  435. package/dist/sdk/app/datasources/datasources.js +147 -0
  436. package/dist/sdk/app/datasources/index.js +27 -0
  437. package/dist/sdk/app/queries/index.js +27 -0
  438. package/dist/sdk/app/queries/queries.js +60 -0
  439. package/dist/sdk/app/tables/index.js +6 -2
  440. package/dist/sdk/index.js +4 -0
  441. package/dist/sdk/utils/index.js +29 -0
  442. package/dist/startup.js +17 -17
  443. package/dist/threads/automation.js +18 -7
  444. package/dist/threads/index.js +4 -4
  445. package/dist/threads/query.js +27 -13
  446. package/dist/tsconfig.build.tsbuildinfo +1 -1
  447. package/dist/utilities/fileSystem/filesystem.js +38 -36
  448. package/dist/utilities/fileSystem/plugin.js +17 -14
  449. package/dist/utilities/fileSystem/template.js +7 -4
  450. package/dist/utilities/schema.js +108 -0
  451. package/dist/utilities/scriptRunner.js +2 -1
  452. package/dist/utilities/statusCodes.js +2 -1
  453. package/dist/utilities/workerRequests.js +2 -0
  454. package/dist/watch.js +2 -25
  455. package/jest.config.ts +5 -2
  456. package/package.json +10 -8
  457. package/scripts/dev/manage.js +1 -0
  458. package/src/api/controllers/application.ts +81 -74
  459. package/src/api/controllers/cloud.ts +1 -1
  460. package/src/api/controllers/datasource.ts +33 -25
  461. package/src/api/controllers/query/index.ts +49 -41
  462. package/src/api/controllers/row/ExternalRequest.ts +8 -2
  463. package/src/api/controllers/row/external.ts +24 -14
  464. package/src/api/controllers/row/internal.ts +42 -18
  465. package/src/api/controllers/row/utils.ts +40 -2
  466. package/src/api/controllers/static/index.ts +18 -19
  467. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -1
  468. package/src/api/controllers/table/external.ts +18 -16
  469. package/src/api/controllers/table/index.ts +46 -17
  470. package/src/api/controllers/table/internal.ts +6 -7
  471. package/src/api/controllers/table/utils.ts +12 -13
  472. package/src/api/controllers/user.ts +21 -13
  473. package/src/api/controllers/view/exporters.ts +20 -5
  474. package/src/api/controllers/view/index.ts +22 -35
  475. package/src/api/controllers/view/tests/viewBuilder.spec.js +1 -1
  476. package/src/api/controllers/view/viewBuilder.ts +1 -1
  477. package/src/api/controllers/webhook.ts +48 -46
  478. package/src/api/routes/analytics.ts +1 -1
  479. package/src/api/routes/apikeys.ts +1 -1
  480. package/src/api/routes/application.ts +1 -1
  481. package/src/api/routes/auth.ts +1 -1
  482. package/src/api/routes/automation.ts +1 -1
  483. package/src/api/routes/backup.ts +1 -1
  484. package/src/api/routes/cloud.ts +1 -1
  485. package/src/api/routes/component.ts +1 -1
  486. package/src/api/routes/datasource.ts +1 -1
  487. package/src/api/routes/deploy.ts +1 -1
  488. package/src/api/routes/dev.ts +1 -1
  489. package/src/api/routes/index.ts +2 -0
  490. package/src/api/routes/integration.ts +1 -1
  491. package/src/api/routes/layout.ts +1 -1
  492. package/src/api/routes/metadata.ts +1 -1
  493. package/src/api/routes/migrations.ts +1 -1
  494. package/src/api/routes/permission.ts +1 -1
  495. package/src/api/routes/query.ts +1 -1
  496. package/src/api/routes/role.ts +1 -1
  497. package/src/api/routes/routing.ts +1 -1
  498. package/src/api/routes/row.ts +1 -1
  499. package/src/api/routes/screen.ts +1 -1
  500. package/src/api/routes/script.ts +1 -1
  501. package/src/api/routes/static.ts +2 -2
  502. package/src/api/routes/table.ts +16 -39
  503. package/src/api/routes/templates.ts +1 -1
  504. package/src/api/routes/tests/datasource.spec.ts +35 -1
  505. package/src/api/routes/tests/misc.spec.js +4 -10
  506. package/src/api/routes/tests/plugin.spec.ts +10 -10
  507. package/src/api/routes/tests/table.spec.js +8 -30
  508. package/src/api/routes/tests/user.spec.js +20 -1
  509. package/src/api/routes/tests/utilities/TestFunctions.ts +1 -1
  510. package/src/api/routes/user.ts +1 -1
  511. package/src/api/routes/utils/validators.ts +1 -1
  512. package/src/api/routes/view.ts +1 -1
  513. package/src/api/routes/webhook.ts +1 -1
  514. package/src/app.ts +5 -3
  515. package/src/automations/logging/index.ts +1 -1
  516. package/src/automations/tests/loop.spec.ts +45 -0
  517. package/src/automations/triggers.ts +6 -1
  518. package/src/db/index.ts +1 -1
  519. package/src/db/linkedRows/LinkController.ts +1 -1
  520. package/src/db/linkedRows/LinkDocument.ts +1 -1
  521. package/src/db/newid.ts +1 -1
  522. package/src/db/tests/linkController.spec.js +1 -1
  523. package/src/definitions/automations.ts +1 -0
  524. package/src/definitions/datasource.ts +0 -41
  525. package/src/environment.ts +1 -1
  526. package/src/events/AutomationEmitter.ts +1 -1
  527. package/src/events/BudibaseEmitter.ts +1 -1
  528. package/src/events/index.ts +1 -1
  529. package/src/index.ts +1 -1
  530. package/src/integrations/base/query.ts +3 -1
  531. package/src/integrations/base/sqlTable.ts +1 -1
  532. package/src/integrations/dynamodb.ts +3 -3
  533. package/src/integrations/index.ts +4 -4
  534. package/src/integrations/mongodb.ts +315 -271
  535. package/src/integrations/mysql.ts +1 -1
  536. package/src/integrations/queries/sql.ts +5 -50
  537. package/src/integrations/rest.ts +16 -19
  538. package/src/integrations/tests/rest.spec.ts +19 -15
  539. package/src/middleware/authorized.ts +5 -1
  540. package/src/middleware/builder.ts +1 -1
  541. package/src/middleware/currentapp.ts +4 -3
  542. package/src/middleware/publicApi.ts +1 -1
  543. package/src/middleware/selfhost.ts +1 -1
  544. package/src/middleware/tests/authorized.spec.js +1 -1
  545. package/src/middleware/tests/currentapp.spec.js +1 -1
  546. package/src/middleware/tests/selfhost.spec.js +1 -1
  547. package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +10 -6
  548. package/src/sdk/app/datasources/datasources.ts +136 -0
  549. package/src/sdk/app/datasources/index.ts +5 -0
  550. package/src/sdk/app/queries/index.ts +5 -0
  551. package/src/sdk/app/queries/queries.ts +50 -0
  552. package/src/sdk/app/tables/index.ts +6 -3
  553. package/src/sdk/index.ts +4 -0
  554. package/src/sdk/utils/index.ts +16 -0
  555. package/src/startup.ts +3 -8
  556. package/src/tests/jestEnv.ts +13 -0
  557. package/src/tests/jestSetup.ts +0 -14
  558. package/src/tests/utilities/TestConfiguration.ts +16 -13
  559. package/src/tests/utilities/structures.ts +65 -2
  560. package/src/threads/automation.ts +18 -8
  561. package/src/threads/definitions.ts +3 -0
  562. package/src/threads/index.ts +1 -1
  563. package/src/threads/query.ts +28 -15
  564. package/src/utilities/fileSystem/filesystem.ts +7 -5
  565. package/src/utilities/fileSystem/plugin.ts +3 -4
  566. package/src/utilities/fileSystem/template.ts +2 -2
  567. package/src/utilities/schema.ts +141 -0
  568. package/src/utilities/scriptRunner.ts +1 -1
  569. package/src/utilities/statusCodes.ts +1 -1
  570. package/src/utilities/workerRequests.ts +10 -1
  571. package/src/watch.ts +1 -1
  572. package/tsconfig.json +2 -1
  573. package/builder/assets/index.d930bfc5.js +0 -1023
  574. package/builder/assets/index.fa480d5b.css +0 -6
  575. package/dist/utilities/csvParser.js +0 -152
  576. package/src/utilities/csvParser.ts +0 -161
  577. package/src/utilities/tests/__snapshots__/csvParser.spec.js.snap +0 -15
  578. package/src/utilities/tests/csvParser.spec.js +0 -112
@@ -75,12 +75,8 @@ function checkAppName(ctx, apps, name, currentAppId) {
75
75
  ctx.throw(400, "App name is already in use.");
76
76
  }
77
77
  }
78
- function createInstance(template, includeSampleData) {
78
+ function createInstance(appId, template, includeSampleData) {
79
79
  return __awaiter(this, void 0, void 0, function* () {
80
- const tenantId = backend_core_1.tenancy.isMultiTenant() ? backend_core_1.tenancy.getTenantId() : null;
81
- const baseAppId = (0, utils_1.generateAppID)(tenantId);
82
- const appId = (0, utils_1.generateDevAppID)(baseAppId);
83
- yield backend_core_1.context.updateAppId(appId);
84
80
  const db = backend_core_1.context.getAppDB();
85
81
  yield db.put({
86
82
  _id: "_design/database",
@@ -203,77 +199,80 @@ function performAppCreate(ctx) {
203
199
  instanceConfig.file = ctx.request.files.templateFile;
204
200
  }
205
201
  const includeSampleData = (0, utilities_1.isQsTrue)(ctx.request.body.sampleData);
206
- const instance = yield createInstance(instanceConfig, includeSampleData);
207
- const appId = instance._id;
208
- const db = backend_core_1.context.getAppDB();
209
- let newApplication = {
210
- _id: utils_1.DocumentType.APP_METADATA,
211
- _rev: undefined,
212
- appId,
213
- type: "app",
214
- version: package_json_1.default.version,
215
- componentLibraries: ["@budibase/standard-components"],
216
- name: name,
217
- url: url,
218
- template: templateKey,
219
- instance,
220
- tenantId: backend_core_1.tenancy.getTenantId(),
221
- updatedAt: new Date().toISOString(),
222
- createdAt: new Date().toISOString(),
223
- status: utils_1.AppStatus.DEV,
224
- navigation: {
225
- navigation: "Top",
226
- title: name,
227
- navWidth: "Large",
228
- navBackground: "var(--spectrum-global-color-gray-100)",
229
- links: [
230
- {
231
- url: "/home",
232
- text: "Home",
233
- },
234
- ],
235
- },
236
- theme: "spectrum--light",
237
- customTheme: {
238
- buttonBorderRadius: "16px",
239
- },
240
- };
241
- // If we used a template or imported an app there will be an existing doc.
242
- // Fetch and migrate some metadata from the existing app.
243
- try {
244
- const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
245
- const keys = [
246
- "_rev",
247
- "navigation",
248
- "theme",
249
- "customTheme",
250
- "icon",
251
- ];
252
- keys.forEach(key => {
253
- if (existing[key]) {
254
- // @ts-ignore
255
- newApplication[key] = existing[key];
256
- }
257
- });
258
- // Migrate navigation settings and screens if required
259
- if (existing) {
260
- const navigation = yield migrateAppNavigation();
261
- if (navigation) {
262
- newApplication.navigation = navigation;
202
+ const tenantId = backend_core_1.tenancy.isMultiTenant() ? backend_core_1.tenancy.getTenantId() : null;
203
+ const appId = (0, utils_1.generateDevAppID)((0, utils_1.generateAppID)(tenantId));
204
+ return yield backend_core_1.context.doInAppContext(appId, () => __awaiter(this, void 0, void 0, function* () {
205
+ const instance = yield createInstance(appId, instanceConfig, includeSampleData);
206
+ const db = backend_core_1.context.getAppDB();
207
+ let newApplication = {
208
+ _id: utils_1.DocumentType.APP_METADATA,
209
+ _rev: undefined,
210
+ appId,
211
+ type: "app",
212
+ version: package_json_1.default.version,
213
+ componentLibraries: ["@budibase/standard-components"],
214
+ name: name,
215
+ url: url,
216
+ template: templateKey,
217
+ instance,
218
+ tenantId: backend_core_1.tenancy.getTenantId(),
219
+ updatedAt: new Date().toISOString(),
220
+ createdAt: new Date().toISOString(),
221
+ status: utils_1.AppStatus.DEV,
222
+ navigation: {
223
+ navigation: "Top",
224
+ title: name,
225
+ navWidth: "Large",
226
+ navBackground: "var(--spectrum-global-color-gray-100)",
227
+ links: [
228
+ {
229
+ url: "/home",
230
+ text: "Home",
231
+ },
232
+ ],
233
+ },
234
+ theme: "spectrum--light",
235
+ customTheme: {
236
+ buttonBorderRadius: "16px",
237
+ },
238
+ };
239
+ // If we used a template or imported an app there will be an existing doc.
240
+ // Fetch and migrate some metadata from the existing app.
241
+ try {
242
+ const existing = yield db.get(utils_1.DocumentType.APP_METADATA);
243
+ const keys = [
244
+ "_rev",
245
+ "navigation",
246
+ "theme",
247
+ "customTheme",
248
+ "icon",
249
+ ];
250
+ keys.forEach(key => {
251
+ if (existing[key]) {
252
+ // @ts-ignore
253
+ newApplication[key] = existing[key];
254
+ }
255
+ });
256
+ // Migrate navigation settings and screens if required
257
+ if (existing) {
258
+ const navigation = yield migrateAppNavigation();
259
+ if (navigation) {
260
+ newApplication.navigation = navigation;
261
+ }
263
262
  }
264
263
  }
265
- }
266
- catch (err) {
267
- // Nothing to do
268
- }
269
- const response = yield db.put(newApplication, { force: true });
270
- newApplication._rev = response.rev;
271
- /* istanbul ignore next */
272
- if (!environment_1.default.isTest()) {
273
- yield (0, fileSystem_1.createApp)(appId);
274
- }
275
- yield backend_core_1.cache.app.invalidateAppMetadata(appId, newApplication);
276
- return newApplication;
264
+ catch (err) {
265
+ // Nothing to do
266
+ }
267
+ const response = yield db.put(newApplication, { force: true });
268
+ newApplication._rev = response.rev;
269
+ /* istanbul ignore next */
270
+ if (!environment_1.default.isTest()) {
271
+ yield (0, fileSystem_1.createApp)(appId);
272
+ }
273
+ yield backend_core_1.cache.app.invalidateAppMetadata(appId, newApplication);
274
+ return newApplication;
275
+ }));
277
276
  });
278
277
  }
279
278
  function creationEvents(request, app) {
@@ -99,7 +99,7 @@ function importApps(ctx) {
99
99
  if (Array.isArray(file)) {
100
100
  ctx.throw(400, "Single file is required");
101
101
  }
102
- if (file.type !== "application/gzip") {
102
+ if (file.type !== "application/gzip" && file.type !== "application/x-gzip") {
103
103
  ctx.throw(400, "Import file must be a gzipped tarball.");
104
104
  }
105
105
  // initially get all the app databases out of the tarball
@@ -8,6 +8,9 @@ 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
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.query = exports.find = exports.destroy = exports.save = exports.update = exports.buildSchemaFromDb = exports.fetch = void 0;
13
16
  const utils_1 = require("../../db/utils");
@@ -17,6 +20,7 @@ const integrations_1 = require("../../integrations");
17
20
  const utils_2 = require("./row/utils");
18
21
  const utils_3 = require("../../threads/utils");
19
22
  const backend_core_1 = require("@budibase/backend-core");
23
+ const sdk_1 = __importDefault(require("../../sdk"));
20
24
  function fetch(ctx) {
21
25
  return __awaiter(this, void 0, void 0, function* () {
22
26
  // Get internal tables
@@ -35,12 +39,11 @@ function fetch(ctx) {
35
39
  const datasources = (yield db.allDocs((0, utils_1.getDatasourceParams)(null, {
36
40
  include_docs: true,
37
41
  }))).rows.map(row => row.doc);
38
- const allDatasources = [bbInternalDb, ...datasources];
42
+ const allDatasources = yield sdk_1.default.datasources.removeSecrets([
43
+ bbInternalDb,
44
+ ...datasources,
45
+ ]);
39
46
  for (let datasource of allDatasources) {
40
- if (datasource.config && datasource.config.auth) {
41
- // strip secrets from response so they don't show in the network request
42
- delete datasource.config.auth;
43
- }
44
47
  if (datasource.type === backend_core_1.db.BUDIBASE_DATASOURCE_TYPE) {
45
48
  datasource.entities = internal[datasource._id];
46
49
  }
@@ -52,7 +55,7 @@ exports.fetch = fetch;
52
55
  function buildSchemaFromDb(ctx) {
53
56
  return __awaiter(this, void 0, void 0, function* () {
54
57
  const db = backend_core_1.context.getAppDB();
55
- const datasource = yield db.get(ctx.params.datasourceId);
58
+ const datasource = yield sdk_1.default.datasources.get(ctx.params.datasourceId);
56
59
  const tablesFilter = ctx.request.body.tablesFilter;
57
60
  let { tables, error } = yield buildSchemaHelper(datasource);
58
61
  if (tablesFilter) {
@@ -125,18 +128,18 @@ function invalidateVariables(existingDatasource, updatedDatasource) {
125
128
  });
126
129
  }
127
130
  function update(ctx) {
128
- var _a;
131
+ var _a, _b;
129
132
  return __awaiter(this, void 0, void 0, function* () {
130
133
  const db = backend_core_1.context.getAppDB();
131
134
  const datasourceId = ctx.params.datasourceId;
132
- let datasource = yield db.get(datasourceId);
133
- const auth = datasource.config.auth;
135
+ let datasource = yield sdk_1.default.datasources.get(datasourceId);
136
+ const auth = (_a = datasource.config) === null || _a === void 0 ? void 0 : _a.auth;
134
137
  yield invalidateVariables(datasource, ctx.request.body);
135
138
  const isBudibaseSource = datasource.type === backend_core_1.db.BUDIBASE_DATASOURCE_TYPE;
136
139
  const dataSourceBody = isBudibaseSource
137
- ? { name: (_a = ctx.request.body) === null || _a === void 0 ? void 0 : _a.name }
140
+ ? { name: (_b = ctx.request.body) === null || _b === void 0 ? void 0 : _b.name }
138
141
  : ctx.request.body;
139
- datasource = Object.assign(Object.assign({}, datasource), dataSourceBody);
142
+ datasource = Object.assign(Object.assign({}, datasource), sdk_1.default.datasources.mergeConfigs(dataSourceBody, datasource));
140
143
  if (auth && !ctx.request.body.auth) {
141
144
  // don't strip auth config from DB
142
145
  datasource.config.auth = auth;
@@ -153,7 +156,9 @@ function update(ctx) {
153
156
  }
154
157
  ctx.status = 200;
155
158
  ctx.message = "Datasource saved successfully.";
156
- ctx.body = { datasource };
159
+ ctx.body = {
160
+ datasource: yield sdk_1.default.datasources.removeSecretSingle(datasource),
161
+ };
157
162
  });
158
163
  }
159
164
  exports.update = update;
@@ -180,7 +185,9 @@ function save(ctx) {
180
185
  yield source.pool.end();
181
186
  }
182
187
  }
183
- const response = { datasource };
188
+ const response = {
189
+ datasource: yield sdk_1.default.datasources.removeSecretSingle(datasource),
190
+ };
184
191
  if (schemaError) {
185
192
  response.error = schemaError;
186
193
  }
@@ -216,7 +223,7 @@ function destroy(ctx) {
216
223
  return __awaiter(this, void 0, void 0, function* () {
217
224
  const db = backend_core_1.context.getAppDB();
218
225
  const datasourceId = ctx.params.datasourceId;
219
- const datasource = yield db.get(datasourceId);
226
+ const datasource = yield sdk_1.default.datasources.get(datasourceId);
220
227
  // Delete all queries for the datasource
221
228
  if (datasource.type === backend_core_1.db.BUDIBASE_DATASOURCE_TYPE) {
222
229
  yield destroyInternalTablesBySourceId(datasourceId);
@@ -240,7 +247,8 @@ exports.destroy = destroy;
240
247
  function find(ctx) {
241
248
  return __awaiter(this, void 0, void 0, function* () {
242
249
  const database = backend_core_1.context.getAppDB();
243
- ctx.body = yield database.get(ctx.params.datasourceId);
250
+ const datasource = yield database.get(ctx.params.datasourceId);
251
+ ctx.body = yield sdk_1.default.datasources.removeSecretSingle(datasource);
244
252
  });
245
253
  }
246
254
  exports.find = find;
@@ -275,6 +283,7 @@ function updateError(error, newError, tables) {
275
283
  function buildSchemaHelper(datasource) {
276
284
  return __awaiter(this, void 0, void 0, function* () {
277
285
  const Connector = yield (0, integrations_1.getIntegration)(datasource.source);
286
+ datasource = yield sdk_1.default.datasources.enrich(datasource);
278
287
  // Connect to the DB and build the schema
279
288
  const connector = new Connector(datasource.config);
280
289
  yield connector.buildSchema(datasource._id, datasource.entities);
@@ -8,6 +8,9 @@ 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
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.destroy = exports.executeV2 = exports.executeV1 = exports.preview = exports.find = exports.save = exports.import = exports.fetch = void 0;
13
16
  const utils_1 = require("../../../db/utils");
@@ -16,11 +19,12 @@ const threads_1 = require("../../../threads");
16
19
  const datasource_1 = require("../datasource");
17
20
  const import_1 = require("./import");
18
21
  const utils_2 = require("../../../threads/utils");
19
- const environment_1 = require("../../../environment");
22
+ const environment_1 = __importDefault(require("../../../environment"));
20
23
  const pro_1 = require("@budibase/pro");
21
24
  const backend_core_1 = require("@budibase/backend-core");
25
+ const sdk_1 = __importDefault(require("../../../sdk"));
22
26
  const Runner = new threads_1.Thread(threads_1.ThreadType.QUERY, {
23
- timeoutMs: environment_1.QUERY_THREAD_TIMEOUT || 10000,
27
+ timeoutMs: environment_1.default.QUERY_THREAD_TIMEOUT || 10000,
24
28
  });
25
29
  // simple function to append "readable" to all read queries
26
30
  function enrichQueries(input) {
@@ -81,7 +85,7 @@ function save(ctx) {
81
85
  return __awaiter(this, void 0, void 0, function* () {
82
86
  const db = backend_core_1.context.getAppDB();
83
87
  const query = ctx.request.body;
84
- const datasource = yield db.get(query.datasourceId);
88
+ const datasource = yield sdk_1.default.datasources.get(query.datasourceId);
85
89
  let eventFn;
86
90
  if (!query._id) {
87
91
  query._id = (0, utils_1.generateQueryID)(query.datasourceId);
@@ -126,15 +130,14 @@ function getAuthConfig(ctx) {
126
130
  }
127
131
  function preview(ctx) {
128
132
  return __awaiter(this, void 0, void 0, function* () {
129
- const db = backend_core_1.context.getAppDB();
130
- const datasource = yield db.get(ctx.request.body.datasourceId);
133
+ const { datasource, envVars } = yield sdk_1.default.datasources.getWithEnvVars(ctx.request.body.datasourceId);
131
134
  const query = ctx.request.body;
132
135
  // preview may not have a queryId as it hasn't been saved, but if it does
133
136
  // this stops dynamic variables from calling the same query
134
137
  const { fields, parameters, queryVerb, transformer, queryId } = query;
135
138
  const authConfigCtx = getAuthConfig(ctx);
136
139
  try {
137
- const runFn = () => Runner.run({
140
+ const inputs = {
138
141
  appId: ctx.appId,
139
142
  datasource,
140
143
  queryVerb,
@@ -142,11 +145,14 @@ function preview(ctx) {
142
145
  parameters,
143
146
  transformer,
144
147
  queryId,
148
+ // have to pass down to the thread runner - can't put into context now
149
+ environmentVariables: envVars,
145
150
  ctx: {
146
151
  user: ctx.user,
147
152
  auth: Object.assign({}, authConfigCtx),
148
153
  },
149
- });
154
+ };
155
+ const runFn = () => Runner.run(inputs);
150
156
  const { rows, keys, info, extra } = yield pro_1.quotas.addQuery(runFn, {
151
157
  datasourceId: datasource._id,
152
158
  });
@@ -196,7 +202,7 @@ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
196
202
  return __awaiter(this, void 0, void 0, function* () {
197
203
  const db = backend_core_1.context.getAppDB();
198
204
  const query = yield db.get(ctx.params.queryId);
199
- const datasource = yield db.get(query.datasourceId);
205
+ const { datasource, envVars } = yield sdk_1.default.datasources.getWithEnvVars(query.datasourceId);
200
206
  let authConfigCtx = {};
201
207
  if (!opts.isAutomation) {
202
208
  authConfigCtx = getAuthConfig(ctx);
@@ -212,7 +218,7 @@ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
212
218
  }
213
219
  // call the relevant CRUD method on the integration class
214
220
  try {
215
- const runFn = () => Runner.run({
221
+ const inputs = {
216
222
  appId: ctx.appId,
217
223
  datasource,
218
224
  queryVerb: query.queryVerb,
@@ -221,11 +227,14 @@ function execute(ctx, opts = { rowsOnly: false, isAutomation: false }) {
221
227
  parameters: enrichedParameters,
222
228
  transformer: query.transformer,
223
229
  queryId: ctx.params.queryId,
230
+ // have to pass down to the thread runner - can't put into context now
231
+ environmentVariables: envVars,
224
232
  ctx: {
225
233
  user: ctx.user,
226
234
  auth: Object.assign({}, authConfigCtx),
227
235
  },
228
- });
236
+ };
237
+ const runFn = () => Runner.run(inputs);
229
238
  const { rows, pagination, extra } = yield pro_1.quotas.addQuery(runFn, {
230
239
  datasourceId: datasource._id,
231
240
  });
@@ -258,10 +267,11 @@ function executeV2(ctx, { isAutomation } = {}) {
258
267
  }
259
268
  exports.executeV2 = executeV2;
260
269
  const removeDynamicVariables = (queryId) => __awaiter(void 0, void 0, void 0, function* () {
270
+ var _a;
261
271
  const db = backend_core_1.context.getAppDB();
262
272
  const query = yield db.get(queryId);
263
- const datasource = yield db.get(query.datasourceId);
264
- const dynamicVariables = datasource.config.dynamicVariables;
273
+ const datasource = yield sdk_1.default.datasources.get(query.datasourceId);
274
+ const dynamicVariables = (_a = datasource.config) === null || _a === void 0 ? void 0 : _a.dynamicVariables;
265
275
  if (dynamicVariables) {
266
276
  // delete dynamic variables from the datasource
267
277
  datasource.config.dynamicVariables = dynamicVariables.filter((dv) => dv.queryId !== queryId);
@@ -277,7 +287,7 @@ function destroy(ctx) {
277
287
  const queryId = ctx.params.queryId;
278
288
  yield removeDynamicVariables(queryId);
279
289
  const query = yield db.get(queryId);
280
- const datasource = yield db.get(query.datasourceId);
290
+ const datasource = yield sdk_1.default.datasources.get(query.datasourceId);
281
291
  yield db.remove(ctx.params.queryId, ctx.params.revId);
282
292
  ctx.message = `Query deleted.`;
283
293
  ctx.status = 200;
@@ -19,6 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  }
20
20
  return t;
21
21
  };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
22
25
  Object.defineProperty(exports, "__esModule", { value: true });
23
26
  exports.ExternalRequest = void 0;
24
27
  const types_1 = require("@budibase/types");
@@ -29,8 +32,8 @@ const utils_3 = require("../../../integrations/utils");
29
32
  const string_templates_1 = require("@budibase/string-templates");
30
33
  const fp_1 = require("lodash/fp");
31
34
  const rowProcessor_1 = require("../../../utilities/rowProcessor");
32
- const backend_core_1 = require("@budibase/backend-core");
33
35
  const utils_4 = require("./utils");
36
+ const sdk_1 = __importDefault(require("../../../sdk"));
34
37
  function buildFilters(id, filters, table) {
35
38
  const primary = table.primary;
36
39
  // if passed in array need to copy for shifting etc
@@ -562,6 +565,7 @@ class ExternalRequest {
562
565
  return fields;
563
566
  }
564
567
  run(config) {
568
+ var _a;
565
569
  return __awaiter(this, void 0, void 0, function* () {
566
570
  const { operation, tableId } = this;
567
571
  let { datasourceId, tableName } = (0, utils_3.breakExternalTableId)(tableId);
@@ -569,8 +573,7 @@ class ExternalRequest {
569
573
  throw "Unable to run without a table name";
570
574
  }
571
575
  if (!this.datasource) {
572
- const db = backend_core_1.context.getAppDB();
573
- this.datasource = yield db.get(datasourceId);
576
+ this.datasource = yield sdk_1.default.datasources.get(datasourceId);
574
577
  if (!this.datasource || !this.datasource.entities) {
575
578
  throw "No tables found, fetch tables before query.";
576
579
  }
@@ -583,6 +586,12 @@ class ExternalRequest {
583
586
  }
584
587
  // look for specific components of config which may not be considered acceptable
585
588
  let { id, row, filters, sort, paginate, rows } = cleanupConfig(config, table);
589
+ //if the sort column is a formula, remove it
590
+ for (let sortColumn of Object.keys(sort || {})) {
591
+ if (((_a = table.schema[sortColumn]) === null || _a === void 0 ? void 0 : _a.type) === "formula") {
592
+ sort === null || sort === void 0 ? true : delete sort[sortColumn];
593
+ }
594
+ }
586
595
  filters = buildFilters(id, filters || {}, table);
587
596
  const relationships = this.buildRelationships(table);
588
597
  // clean up row on ingress using schema
@@ -42,15 +42,19 @@ var __rest = (this && this.__rest) || function (s, e) {
42
42
  }
43
43
  return t;
44
44
  };
45
+ var __importDefault = (this && this.__importDefault) || function (mod) {
46
+ return (mod && mod.__esModule) ? mod : { "default": mod };
47
+ };
45
48
  Object.defineProperty(exports, "__esModule", { value: true });
46
49
  exports.fetchEnrichedRow = exports.exportRows = exports.validate = exports.search = exports.bulkDestroy = exports.destroy = exports.find = exports.fetch = exports.fetchView = exports.save = exports.patch = exports.handleRequest = void 0;
47
50
  const constants_1 = require("../../../constants");
48
51
  const utils_1 = require("../../../integrations/utils");
49
52
  const ExternalRequest_1 = require("./ExternalRequest");
50
- const backend_core_1 = require("@budibase/backend-core");
51
53
  const exporters = __importStar(require("../view/exporters"));
52
54
  const fileSystem_1 = require("../../../utilities/fileSystem");
53
55
  const types_1 = require("@budibase/types");
56
+ const sdk_1 = __importDefault(require("../../../sdk"));
57
+ const { cleanExportRows } = require("./utils");
54
58
  function handleRequest(operation, tableId, opts) {
55
59
  return __awaiter(this, void 0, void 0, function* () {
56
60
  // make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
@@ -222,20 +226,21 @@ exports.validate = validate;
222
226
  function exportRows(ctx) {
223
227
  return __awaiter(this, void 0, void 0, function* () {
224
228
  const { datasourceId } = (0, utils_1.breakExternalTableId)(ctx.params.tableId);
225
- const db = backend_core_1.context.getAppDB();
226
229
  const format = ctx.query.format;
227
230
  const { columns } = ctx.request.body;
228
- const datasource = yield db.get(datasourceId);
231
+ const datasource = yield sdk_1.default.datasources.get(datasourceId);
229
232
  if (!datasource || !datasource.entities) {
230
233
  ctx.throw(400, "Datasource has not been configured for plus API.");
231
234
  }
232
- ctx.request.body = {
233
- query: {
234
- oneOf: {
235
- _id: ctx.request.body.rows.map((row) => JSON.parse(decodeURI(row))[0]),
235
+ if (ctx.request.body.rows) {
236
+ ctx.request.body = {
237
+ query: {
238
+ oneOf: {
239
+ _id: ctx.request.body.rows.map((row) => JSON.parse(decodeURI(row))[0]),
240
+ },
236
241
  },
237
- },
238
- };
242
+ };
243
+ }
239
244
  let result = yield search(ctx);
240
245
  let rows = [];
241
246
  // Filter data to only specified columns if required
@@ -250,13 +255,16 @@ function exportRows(ctx) {
250
255
  else {
251
256
  rows = result.rows;
252
257
  }
253
- let headers = Object.keys(rows[0]);
258
+ // @ts-ignore
259
+ let schema = datasource.entities[tableName].schema;
260
+ let exportRows = cleanExportRows(rows, schema, format, columns);
261
+ let headers = Object.keys(schema);
254
262
  // @ts-ignore
255
263
  const exporter = exporters[format];
256
264
  const filename = `export.${format}`;
257
265
  // send down the file
258
266
  ctx.attachment(filename);
259
- return (0, fileSystem_1.apiFileReturn)(exporter(headers, rows));
267
+ return (0, fileSystem_1.apiFileReturn)(exporter(headers, exportRows));
260
268
  });
261
269
  }
262
270
  exports.exportRows = exportRows;
@@ -266,8 +274,7 @@ function fetchEnrichedRow(ctx) {
266
274
  const id = ctx.params.rowId;
267
275
  const tableId = ctx.params.tableId;
268
276
  const { datasourceId, tableName } = (0, utils_1.breakExternalTableId)(tableId);
269
- const db = backend_core_1.context.getAppDB();
270
- const datasource = yield db.get(datasourceId);
277
+ const datasource = yield sdk_1.default.datasources.get(datasourceId);
271
278
  if (!tableName) {
272
279
  ctx.throw(400, "Unable to find table.");
273
280
  }
@@ -61,8 +61,9 @@ const utils_2 = require("../view/utils");
61
61
  const fp_1 = require("lodash/fp");
62
62
  const backend_core_1 = require("@budibase/backend-core");
63
63
  const staticFormula_1 = require("./staticFormula");
64
- const exporters = __importStar(require("../view/exporters"));
64
+ const exporters_1 = require("../view/exporters");
65
65
  const fileSystem_1 = require("../../../utilities/fileSystem");
66
+ const { cleanExportRows } = require("./utils");
66
67
  const CALCULATION_TYPES = {
67
68
  SUM: "sum",
68
69
  COUNT: "count",
@@ -364,6 +365,13 @@ function search(ctx) {
364
365
  const _a = ctx.request.body, { paginate, query } = _a, params = __rest(_a, ["paginate", "query"]);
365
366
  params.version = ctx.version;
366
367
  params.tableId = tableId;
368
+ let table;
369
+ if (params.sort && !params.sortType) {
370
+ table = yield db.get(tableId);
371
+ const schema = table.schema;
372
+ const sortField = schema[params.sort];
373
+ params.sortType = sortField.type == "number" ? "number" : "string";
374
+ }
367
375
  let response;
368
376
  if (paginate) {
369
377
  response = yield (0, internalSearch_1.paginatedSearch)(query, params);
@@ -377,7 +385,7 @@ function search(ctx) {
377
385
  if (tableId === utils_1.InternalTables.USER_METADATA) {
378
386
  response.rows = yield (0, global_1.getGlobalUsersFromMetadata)(response.rows);
379
387
  }
380
- const table = yield db.get(tableId);
388
+ table = table || (yield db.get(tableId));
381
389
  response.rows = yield (0, rowProcessor_1.outputProcessing)(table, response.rows);
382
390
  }
383
391
  return response;
@@ -399,13 +407,21 @@ function exportRows(ctx) {
399
407
  const table = yield db.get(ctx.params.tableId);
400
408
  const rowIds = ctx.request.body.rows;
401
409
  let format = ctx.query.format;
402
- const { columns } = ctx.request.body;
403
- let response = (yield db.allDocs({
404
- include_docs: true,
405
- keys: rowIds,
406
- })).rows.map(row => row.doc);
407
- let result = (yield (0, rowProcessor_1.outputProcessing)(table, response));
410
+ const { columns, query } = ctx.request.body;
411
+ let result;
412
+ if (rowIds) {
413
+ let response = (yield db.allDocs({
414
+ include_docs: true,
415
+ keys: rowIds,
416
+ })).rows.map(row => row.doc);
417
+ result = yield (0, rowProcessor_1.outputProcessing)(table, response);
418
+ }
419
+ else if (query) {
420
+ let searchResponse = yield exports.search(ctx);
421
+ result = searchResponse.rows;
422
+ }
408
423
  let rows = [];
424
+ let schema = table.schema;
409
425
  // Filter data to only specified columns if required
410
426
  if (columns && columns.length) {
411
427
  for (let i = 0; i < result.length; i++) {
@@ -418,13 +434,22 @@ function exportRows(ctx) {
418
434
  else {
419
435
  rows = result;
420
436
  }
421
- let headers = Object.keys(rows[0]);
422
- // @ts-ignore
423
- const exporter = exporters[format];
424
- const filename = `export.${format}`;
425
- // send down the file
426
- ctx.attachment(filename);
427
- return (0, fileSystem_1.apiFileReturn)(exporter(headers, rows));
437
+ let exportRows = cleanExportRows(rows, schema, format, columns);
438
+ if (format === exporters_1.Format.CSV) {
439
+ ctx.attachment("export.csv");
440
+ return (0, fileSystem_1.apiFileReturn)((0, exporters_1.csv)(Object.keys(rows[0]), exportRows));
441
+ }
442
+ else if (format === exporters_1.Format.JSON) {
443
+ ctx.attachment("export.json");
444
+ return (0, fileSystem_1.apiFileReturn)((0, exporters_1.json)(exportRows));
445
+ }
446
+ else if (format === exporters_1.Format.JSON_WITH_SCHEMA) {
447
+ ctx.attachment("export.json");
448
+ return (0, fileSystem_1.apiFileReturn)((0, exporters_1.jsonWithSchema)(schema, exportRows));
449
+ }
450
+ else {
451
+ throw "Format not recognised";
452
+ }
428
453
  });
429
454
  }
430
455
  exports.exportRows = exportRows;