@budibase/server 1.3.21 → 1.3.22-alpha.1

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 (310) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/index.96c69636.js +1008 -0
  3. package/builder/assets/index.c167b5c3.css +6 -0
  4. package/builder/index.html +2 -4
  5. package/coverage/clover.xml +308 -338
  6. package/coverage/coverage-final.json +19 -21
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/auth.js.html +41 -8
  9. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/datasource.js.html +73 -34
  13. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/index.html +27 -57
  15. package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
  16. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +2 -2
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  34. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  43. package/coverage/lcov-report/api/index.html +1 -1
  44. package/coverage/lcov-report/api/index.js.html +13 -13
  45. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  46. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/index.html +1 -1
  56. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/table.js.html +2 -2
  67. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/utils/index.html +9 -9
  70. package/coverage/lcov-report/api/routes/utils/validators.js.html +75 -12
  71. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  73. package/coverage/lcov-report/automations/actions.js.html +1 -1
  74. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  75. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  76. package/coverage/lcov-report/automations/index.html +1 -1
  77. package/coverage/lcov-report/automations/index.js.html +1 -1
  78. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  79. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/index.html +1 -1
  85. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  95. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  96. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  104. package/coverage/lcov-report/constants/index.html +1 -1
  105. package/coverage/lcov-report/constants/index.js.html +1 -1
  106. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  107. package/coverage/lcov-report/constants/screens.js.html +1 -1
  108. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  109. package/coverage/lcov-report/db/index.html +14 -14
  110. package/coverage/lcov-report/db/index.js.html +1 -1
  111. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  112. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  115. package/coverage/lcov-report/db/newid.js.html +2 -2
  116. package/coverage/lcov-report/db/utils.js.html +30 -18
  117. package/coverage/lcov-report/events/AutomationEmitter.js.html +3 -3
  118. package/coverage/lcov-report/events/index.html +1 -1
  119. package/coverage/lcov-report/events/index.js.html +1 -1
  120. package/coverage/lcov-report/events/utils.js.html +1 -1
  121. package/coverage/lcov-report/index.html +44 -44
  122. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  123. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  124. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  125. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  126. package/coverage/lcov-report/middleware/currentapp.js.html +46 -40
  127. package/coverage/lcov-report/middleware/index.html +15 -15
  128. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  129. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  130. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  131. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  132. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  133. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  134. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  135. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  136. package/coverage/lcov-report/utilities/global.js.html +16 -16
  137. package/coverage/lcov-report/utilities/index.html +15 -15
  138. package/coverage/lcov-report/utilities/index.js.html +24 -24
  139. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  140. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  141. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  142. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  143. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  144. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  145. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  146. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  147. package/coverage/lcov-report/utilities/security.js.html +2 -2
  148. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  149. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  150. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  151. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  152. package/coverage/lcov-report/utilities/users.js.html +1 -1
  153. package/coverage/lcov-report/utilities/workerRequests.js.html +32 -8
  154. package/coverage/lcov.info +521 -558
  155. package/dist/api/controllers/application.js +5 -5
  156. package/dist/api/controllers/auth.js +9 -0
  157. package/dist/api/controllers/component.js +19 -6
  158. package/dist/api/controllers/datasource.js +21 -8
  159. package/dist/api/controllers/deploy/index.js +1 -8
  160. package/dist/api/controllers/integration.js +4 -4
  161. package/dist/{migrations/functions/usageQuotas/syncDevelopers.js → api/controllers/plugin/file.js} +13 -13
  162. package/dist/api/controllers/plugin/github.js +69 -0
  163. package/dist/api/controllers/plugin/index.js +144 -0
  164. package/dist/api/controllers/plugin/npm.js +58 -0
  165. package/dist/api/controllers/plugin/uploaders.js +11 -0
  166. package/dist/{migrations/functions/usageQuotas/syncPublishedApps.js → api/controllers/plugin/url.js} +13 -15
  167. package/dist/api/controllers/plugin/utils.js +26 -0
  168. package/dist/api/controllers/row/external.js +1 -1
  169. package/dist/api/controllers/screen.js +62 -14
  170. package/dist/api/controllers/static/index.js +1 -0
  171. package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  172. package/dist/api/controllers/static/templates/preview.hbs +5 -1
  173. package/dist/api/index.js +1 -1
  174. package/dist/api/routes/application.js +3 -2
  175. package/dist/api/routes/index.js +2 -0
  176. package/dist/{migrations/functions/publishedAppsQuota.js → api/routes/plugin.js} +13 -21
  177. package/dist/api/routes/public/rows.js +1 -82
  178. package/dist/api/routes/public/tables.js +1 -1
  179. package/dist/api/routes/table.js +1 -1
  180. package/dist/api/routes/utils/validators.js +20 -2
  181. package/dist/app.js +16 -1
  182. package/dist/db/utils.js +3 -0
  183. package/dist/environment.js +1 -0
  184. package/dist/integrations/airtable.js +126 -129
  185. package/dist/integrations/arangodb.js +86 -89
  186. package/dist/integrations/base/query.js +2 -2
  187. package/dist/integrations/base/sqlTable.js +3 -1
  188. package/dist/integrations/couchdb.js +80 -83
  189. package/dist/integrations/dynamodb.js +161 -164
  190. package/dist/integrations/elasticsearch.js +135 -138
  191. package/dist/integrations/firebase.js +154 -157
  192. package/dist/integrations/googlesheets.js +323 -327
  193. package/dist/integrations/index.js +99 -51
  194. package/dist/integrations/microsoftSqlServer.js +240 -243
  195. package/dist/integrations/mongodb.js +239 -242
  196. package/dist/integrations/mysql.js +215 -219
  197. package/dist/integrations/oracle.js +318 -322
  198. package/dist/integrations/postgres.js +262 -265
  199. package/dist/integrations/redis.js +134 -139
  200. package/dist/integrations/rest.js +289 -292
  201. package/dist/integrations/s3.js +61 -64
  202. package/dist/integrations/snowflake.js +83 -86
  203. package/dist/middleware/currentapp.js +2 -0
  204. package/dist/migrations/functions/backfill/global.js +0 -3
  205. package/dist/migrations/index.js +0 -10
  206. package/dist/package.json +9 -6
  207. package/dist/tests/utilities/TestConfiguration.js +1 -1
  208. package/dist/threads/query.js +2 -2
  209. package/dist/tsconfig.build.tsbuildinfo +1 -1
  210. package/dist/utilities/fileSystem/index.js +105 -1
  211. package/dist/utilities/workerRequests.js +4 -0
  212. package/dist/watch.js +77 -0
  213. package/dist/websocket.js +22 -0
  214. package/package.json +10 -7
  215. package/scripts/dev/manage.js +4 -0
  216. package/scripts/localdomain.js +3 -1
  217. package/specs/openapi.json +115 -112
  218. package/specs/openapi.yaml +96 -94
  219. package/specs/resources/misc.js +116 -0
  220. package/specs/resources/query.js +1 -1
  221. package/src/api/controllers/application.ts +1 -2
  222. package/src/api/controllers/auth.js +11 -0
  223. package/src/api/controllers/component.ts +57 -0
  224. package/src/api/controllers/datasource.js +21 -8
  225. package/src/api/controllers/deploy/index.ts +1 -6
  226. package/src/api/controllers/integration.js +4 -4
  227. package/src/api/controllers/plugin/file.ts +15 -0
  228. package/src/api/controllers/plugin/github.ts +75 -0
  229. package/src/api/controllers/plugin/index.ts +134 -0
  230. package/src/api/controllers/plugin/npm.ts +56 -0
  231. package/src/api/controllers/plugin/uploaders.ts +4 -0
  232. package/src/api/controllers/plugin/url.ts +12 -0
  233. package/src/api/controllers/plugin/utils.ts +19 -0
  234. package/src/api/controllers/public/mapping/types.ts +8 -0
  235. package/src/api/controllers/row/external.js +1 -1
  236. package/src/api/controllers/screen.ts +122 -0
  237. package/src/api/controllers/static/index.ts +1 -1
  238. package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  239. package/src/api/controllers/static/templates/preview.hbs +5 -1
  240. package/src/api/index.js +1 -1
  241. package/src/api/routes/application.ts +13 -2
  242. package/src/api/routes/index.ts +2 -0
  243. package/src/api/routes/plugin.ts +14 -0
  244. package/src/api/routes/public/rows.ts +1 -82
  245. package/src/api/routes/public/tables.ts +1 -1
  246. package/src/api/routes/table.js +1 -1
  247. package/src/api/routes/tests/query.spec.js +8 -25
  248. package/src/api/routes/tests/user.spec.js +0 -2
  249. package/src/api/routes/utils/validators.js +26 -5
  250. package/src/app.ts +25 -2
  251. package/src/db/utils.js +4 -0
  252. package/src/definitions/openapi.ts +56 -55
  253. package/src/environment.js +1 -0
  254. package/src/integrations/airtable.ts +116 -118
  255. package/src/integrations/arangodb.ts +87 -89
  256. package/src/integrations/base/query.ts +2 -2
  257. package/src/integrations/base/sqlTable.ts +3 -1
  258. package/src/integrations/couchdb.ts +83 -89
  259. package/src/integrations/dynamodb.ts +173 -175
  260. package/src/integrations/elasticsearch.ts +120 -122
  261. package/src/integrations/firebase.ts +157 -159
  262. package/src/integrations/googlesheets.ts +328 -338
  263. package/src/integrations/index.ts +64 -21
  264. package/src/integrations/microsoftSqlServer.ts +249 -251
  265. package/src/integrations/mongodb.ts +261 -258
  266. package/src/integrations/mysql.ts +229 -234
  267. package/src/integrations/oracle.ts +373 -380
  268. package/src/integrations/postgres.ts +264 -268
  269. package/src/integrations/redis.ts +128 -132
  270. package/src/integrations/rest.ts +324 -329
  271. package/src/integrations/s3.ts +68 -71
  272. package/src/integrations/snowflake.ts +80 -82
  273. package/src/integrations/tests/{airtable.spec.js → airtable.spec.ts} +21 -18
  274. package/src/integrations/tests/{arangodb.spec.js → arangodb.spec.ts} +12 -9
  275. package/src/integrations/tests/{couchdb.spec.js → couchdb.spec.ts} +33 -27
  276. package/src/integrations/tests/{dynamodb.spec.js → dynamodb.spec.ts} +45 -41
  277. package/src/integrations/tests/{elasticsearch.spec.js → elasticsearch.spec.ts} +22 -21
  278. package/src/integrations/tests/{firebase.spec.js → firebase.spec.ts} +33 -28
  279. package/src/integrations/tests/{microsoftSqlServer.spec.js → microsoftSqlServer.spec.ts} +12 -11
  280. package/src/integrations/tests/{mongo.spec.js → mongo.spec.ts} +46 -35
  281. package/src/integrations/tests/{mysql.spec.js → mysql.spec.ts} +17 -15
  282. package/src/integrations/tests/{oracle.spec.js → oracle.spec.ts} +19 -17
  283. package/src/integrations/tests/{postgres.spec.js → postgres.spec.ts} +19 -17
  284. package/src/integrations/tests/{redis.spec.js → redis.spec.ts} +27 -18
  285. package/src/integrations/tests/{rest.spec.js → rest.spec.ts} +22 -14
  286. package/src/integrations/tests/{s3.spec.js → s3.spec.ts} +10 -8
  287. package/src/integrations/tests/{sql.spec.js → sql.spec.ts} +228 -177
  288. package/src/middleware/currentapp.js +2 -0
  289. package/src/migrations/functions/backfill/global.ts +0 -3
  290. package/src/migrations/index.ts +0 -16
  291. package/src/module.d.ts +2 -0
  292. package/src/tests/utilities/TestConfiguration.js +1 -1
  293. package/src/threads/query.ts +2 -2
  294. package/src/utilities/fileSystem/index.js +123 -0
  295. package/src/utilities/workerRequests.js +8 -0
  296. package/src/watch.ts +38 -0
  297. package/src/websocket.ts +26 -0
  298. package/builder/assets/index.8d12d461.css +0 -6
  299. package/builder/assets/index.d354271c.js +0 -879
  300. package/builder/assets/vendor.5e1fe644.css +0 -1
  301. package/builder/assets/vendor.67dbd8fa.js +0 -248
  302. package/coverage/lcov-report/api/controllers/component.js.html +0 -199
  303. package/coverage/lcov-report/api/controllers/screen.js.html +0 -259
  304. package/dist/migrations/functions/developerQuota.js +0 -49
  305. package/src/api/controllers/component.js +0 -38
  306. package/src/api/controllers/screen.js +0 -58
  307. package/src/migrations/functions/developerQuota.ts +0 -15
  308. package/src/migrations/functions/publishedAppsQuota.ts +0 -13
  309. package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
  310. package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
@@ -1,22 +1,25 @@
1
- const postgres = require("./postgres")
2
- const dynamodb = require("./dynamodb")
3
- const mongodb = require("./mongodb")
4
- const elasticsearch = require("./elasticsearch")
5
- const couchdb = require("./couchdb")
6
- const sqlServer = require("./microsoftSqlServer")
7
- const s3 = require("./s3")
8
- const airtable = require("./airtable")
9
- const mysql = require("./mysql")
10
- const arangodb = require("./arangodb")
11
- const rest = require("./rest")
12
- const googlesheets = require("./googlesheets")
13
- const firebase = require("./firebase")
14
- const redis = require("./redis")
15
- const snowflake = require("./snowflake")
16
- const { SourceName } = require("@budibase/types")
1
+ import postgres from "./postgres"
2
+ import dynamodb from "./dynamodb"
3
+ import mongodb from "./mongodb"
4
+ import elasticsearch from "./elasticsearch"
5
+ import couchdb from "./couchdb"
6
+ import sqlServer from "./microsoftSqlServer"
7
+ import s3 from "./s3"
8
+ import airtable from "./airtable"
9
+ import mysql from "./mysql"
10
+ import arangodb from "./arangodb"
11
+ import rest from "./rest"
12
+ import googlesheets from "./googlesheets"
13
+ import firebase from "./firebase"
14
+ import redis from "./redis"
15
+ import snowflake from "./snowflake"
16
+ import { getPlugins } from "../api/controllers/plugin"
17
+ import { SourceName, Integration, PluginType } from "@budibase/types"
18
+ import { getDatasourcePlugin } from "../utilities/fileSystem"
17
19
  const environment = require("../environment")
20
+ const { cloneDeep } = require("lodash")
18
21
 
19
- const DEFINITIONS = {
22
+ const DEFINITIONS: { [key: string]: Integration } = {
20
23
  [SourceName.POSTGRES]: postgres.schema,
21
24
  [SourceName.DYNAMODB]: dynamodb.schema,
22
25
  [SourceName.MONGODB]: mongodb.schema,
@@ -33,7 +36,7 @@ const DEFINITIONS = {
33
36
  [SourceName.SNOWFLAKE]: snowflake.schema,
34
37
  }
35
38
 
36
- const INTEGRATIONS = {
39
+ const INTEGRATIONS: { [key: string]: any } = {
37
40
  [SourceName.POSTGRES]: postgres.integration,
38
41
  [SourceName.DYNAMODB]: dynamodb.integration,
39
42
  [SourceName.MONGODB]: mongodb.integration,
@@ -48,7 +51,7 @@ const INTEGRATIONS = {
48
51
  [SourceName.FIRESTORE]: firebase.integration,
49
52
  [SourceName.GOOGLE_SHEETS]: googlesheets.integration,
50
53
  [SourceName.REDIS]: redis.integration,
51
- [SourceName.FIREBASE]: firebase.integration,
54
+ [SourceName.FIRESTORE]: firebase.integration,
52
55
  [SourceName.SNOWFLAKE]: snowflake.integration,
53
56
  }
54
57
 
@@ -64,6 +67,46 @@ if (environment.SELF_HOSTED) {
64
67
  }
65
68
 
66
69
  module.exports = {
67
- definitions: DEFINITIONS,
68
- integrations: INTEGRATIONS,
70
+ getDefinitions: async () => {
71
+ const pluginSchemas: { [key: string]: Integration } = {}
72
+ if (environment.SELF_HOSTED) {
73
+ const plugins = await getPlugins(PluginType.DATASOURCE)
74
+ // extract the actual schema from each custom
75
+ for (let plugin of plugins) {
76
+ const sourceId = plugin.name
77
+ pluginSchemas[sourceId] = {
78
+ ...plugin.schema["schema"],
79
+ custom: true,
80
+ }
81
+ }
82
+ }
83
+ return {
84
+ ...cloneDeep(DEFINITIONS),
85
+ ...pluginSchemas,
86
+ }
87
+ },
88
+ getIntegration: async (integration: string) => {
89
+ if (INTEGRATIONS[integration]) {
90
+ return INTEGRATIONS[integration]
91
+ }
92
+ if (environment.SELF_HOSTED) {
93
+ const plugins = await getPlugins(PluginType.DATASOURCE)
94
+ for (let plugin of plugins) {
95
+ if (plugin.name === integration) {
96
+ // need to use commonJS require due to its dynamic runtime nature
97
+ const retrieved: any = await getDatasourcePlugin(
98
+ plugin.name,
99
+ plugin.jsUrl,
100
+ plugin.schema?.hash
101
+ )
102
+ if (retrieved.integration) {
103
+ return retrieved.integration
104
+ } else {
105
+ return retrieved
106
+ }
107
+ }
108
+ }
109
+ }
110
+ throw new Error("No datasource implementation found.")
111
+ },
69
112
  }
@@ -18,292 +18,290 @@ import {
18
18
  } from "./utils"
19
19
  import Sql from "./base/sql"
20
20
 
21
- module MSSQLModule {
22
- const sqlServer = require("mssql")
23
- const DEFAULT_SCHEMA = "dbo"
21
+ const sqlServer = require("mssql")
22
+ const DEFAULT_SCHEMA = "dbo"
24
23
 
25
- interface MSSQLConfig {
26
- user: string
27
- password: string
28
- server: string
29
- port: number
30
- database: string
31
- schema: string
32
- encrypt?: boolean
33
- }
24
+ interface MSSQLConfig {
25
+ user: string
26
+ password: string
27
+ server: string
28
+ port: number
29
+ database: string
30
+ schema: string
31
+ encrypt?: boolean
32
+ }
34
33
 
35
- interface TablesResponse {
36
- TABLE_CATALOG: string
37
- TABLE_SCHEMA: string
38
- TABLE_NAME: string
39
- TABLE_TYPE: string
40
- }
34
+ interface TablesResponse {
35
+ TABLE_CATALOG: string
36
+ TABLE_SCHEMA: string
37
+ TABLE_NAME: string
38
+ TABLE_TYPE: string
39
+ }
41
40
 
42
- const SCHEMA: Integration = {
43
- docs: "https://github.com/tediousjs/node-mssql",
44
- plus: true,
45
- description:
46
- "Microsoft SQL Server is a relational database management system developed by Microsoft. ",
47
- friendlyName: "MS SQL Server",
48
- type: "Relational",
49
- datasource: {
50
- user: {
51
- type: DatasourceFieldType.STRING,
52
- required: true,
53
- default: "localhost",
54
- },
55
- password: {
56
- type: DatasourceFieldType.PASSWORD,
57
- required: true,
58
- },
59
- server: {
60
- type: DatasourceFieldType.STRING,
61
- default: "localhost",
62
- },
63
- port: {
64
- type: DatasourceFieldType.NUMBER,
65
- required: false,
66
- default: 1433,
67
- },
68
- database: {
69
- type: DatasourceFieldType.STRING,
70
- default: "root",
71
- },
72
- schema: {
73
- type: DatasourceFieldType.STRING,
74
- default: DEFAULT_SCHEMA,
75
- },
76
- encrypt: {
77
- type: DatasourceFieldType.BOOLEAN,
78
- default: true,
79
- },
41
+ const SCHEMA: Integration = {
42
+ docs: "https://github.com/tediousjs/node-mssql",
43
+ plus: true,
44
+ description:
45
+ "Microsoft SQL Server is a relational database management system developed by Microsoft. ",
46
+ friendlyName: "MS SQL Server",
47
+ type: "Relational",
48
+ datasource: {
49
+ user: {
50
+ type: DatasourceFieldType.STRING,
51
+ required: true,
52
+ default: "localhost",
80
53
  },
81
- query: {
82
- create: {
83
- type: QueryType.SQL,
84
- },
85
- read: {
86
- type: QueryType.SQL,
87
- },
88
- update: {
89
- type: QueryType.SQL,
90
- },
91
- delete: {
92
- type: QueryType.SQL,
93
- },
54
+ password: {
55
+ type: DatasourceFieldType.PASSWORD,
56
+ required: true,
94
57
  },
95
- }
58
+ server: {
59
+ type: DatasourceFieldType.STRING,
60
+ default: "localhost",
61
+ },
62
+ port: {
63
+ type: DatasourceFieldType.NUMBER,
64
+ required: false,
65
+ default: 1433,
66
+ },
67
+ database: {
68
+ type: DatasourceFieldType.STRING,
69
+ default: "root",
70
+ },
71
+ schema: {
72
+ type: DatasourceFieldType.STRING,
73
+ default: DEFAULT_SCHEMA,
74
+ },
75
+ encrypt: {
76
+ type: DatasourceFieldType.BOOLEAN,
77
+ default: true,
78
+ },
79
+ },
80
+ query: {
81
+ create: {
82
+ type: QueryType.SQL,
83
+ },
84
+ read: {
85
+ type: QueryType.SQL,
86
+ },
87
+ update: {
88
+ type: QueryType.SQL,
89
+ },
90
+ delete: {
91
+ type: QueryType.SQL,
92
+ },
93
+ },
94
+ }
96
95
 
97
- class SqlServerIntegration extends Sql implements DatasourcePlus {
98
- private readonly config: MSSQLConfig
99
- private index: number = 0
100
- private readonly pool: any
101
- private client: any
102
- public tables: Record<string, Table> = {}
103
- public schemaErrors: Record<string, string> = {}
96
+ class SqlServerIntegration extends Sql implements DatasourcePlus {
97
+ private readonly config: MSSQLConfig
98
+ private index: number = 0
99
+ private readonly pool: any
100
+ private client: any
101
+ public tables: Record<string, Table> = {}
102
+ public schemaErrors: Record<string, string> = {}
104
103
 
105
- MASTER_TABLES = [
106
- "spt_fallback_db",
107
- "spt_fallback_dev",
108
- "spt_fallback_usg",
109
- "spt_monitor",
110
- "MSreplication_options",
111
- ]
112
- TABLES_SQL =
113
- "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'"
104
+ MASTER_TABLES = [
105
+ "spt_fallback_db",
106
+ "spt_fallback_dev",
107
+ "spt_fallback_usg",
108
+ "spt_monitor",
109
+ "MSreplication_options",
110
+ ]
111
+ TABLES_SQL =
112
+ "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'"
114
113
 
115
- constructor(config: MSSQLConfig) {
116
- super(SqlClient.MS_SQL)
117
- this.config = config
118
- const clientCfg = {
119
- ...this.config,
120
- options: {
121
- encrypt: this.config.encrypt,
122
- enableArithAbort: true,
123
- },
124
- }
125
- delete clientCfg.encrypt
126
- if (!this.pool) {
127
- this.pool = new sqlServer.ConnectionPool(clientCfg)
128
- }
114
+ constructor(config: MSSQLConfig) {
115
+ super(SqlClient.MS_SQL)
116
+ this.config = config
117
+ const clientCfg = {
118
+ ...this.config,
119
+ options: {
120
+ encrypt: this.config.encrypt,
121
+ enableArithAbort: true,
122
+ },
129
123
  }
130
-
131
- getBindingIdentifier(): string {
132
- return `@p${this.index++}`
124
+ delete clientCfg.encrypt
125
+ if (!this.pool) {
126
+ this.pool = new sqlServer.ConnectionPool(clientCfg)
133
127
  }
128
+ }
134
129
 
135
- getStringConcat(parts: string[]): string {
136
- return `concat(${parts.join(", ")})`
137
- }
130
+ getBindingIdentifier(): string {
131
+ return `@p${this.index++}`
132
+ }
138
133
 
139
- async connect() {
140
- try {
141
- this.client = await this.pool.connect()
142
- } catch (err) {
143
- // @ts-ignore
144
- throw new Error(err)
145
- }
134
+ getStringConcat(parts: string[]): string {
135
+ return `concat(${parts.join(", ")})`
136
+ }
137
+
138
+ async connect() {
139
+ try {
140
+ this.client = await this.pool.connect()
141
+ } catch (err) {
142
+ // @ts-ignore
143
+ throw new Error(err)
146
144
  }
145
+ }
147
146
 
148
- async internalQuery(
149
- query: SqlQuery,
150
- operation: string | undefined = undefined
151
- ) {
152
- const client = this.client
153
- const request = client.request()
154
- this.index = 0
155
- try {
156
- if (Array.isArray(query.bindings)) {
157
- let count = 0
158
- for (let binding of query.bindings) {
159
- request.input(`p${count++}`, binding)
160
- }
147
+ async internalQuery(
148
+ query: SqlQuery,
149
+ operation: string | undefined = undefined
150
+ ) {
151
+ const client = this.client
152
+ const request = client.request()
153
+ this.index = 0
154
+ try {
155
+ if (Array.isArray(query.bindings)) {
156
+ let count = 0
157
+ for (let binding of query.bindings) {
158
+ request.input(`p${count++}`, binding)
161
159
  }
162
- // this is a hack to get the inserted ID back,
163
- // no way to do this with Knex nicely
164
- const sql =
165
- operation === Operation.CREATE
166
- ? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`
167
- : query.sql
168
- return await request.query(sql)
169
- } catch (err) {
170
- // @ts-ignore
171
- throw new Error(err)
172
160
  }
161
+ // this is a hack to get the inserted ID back,
162
+ // no way to do this with Knex nicely
163
+ const sql =
164
+ operation === Operation.CREATE
165
+ ? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`
166
+ : query.sql
167
+ return await request.query(sql)
168
+ } catch (err) {
169
+ // @ts-ignore
170
+ throw new Error(err)
173
171
  }
172
+ }
174
173
 
175
- getDefinitionSQL(tableName: string) {
176
- return `select *
177
- from INFORMATION_SCHEMA.COLUMNS
178
- where TABLE_NAME='${tableName}'`
179
- }
174
+ getDefinitionSQL(tableName: string) {
175
+ return `select *
176
+ from INFORMATION_SCHEMA.COLUMNS
177
+ where TABLE_NAME='${tableName}'`
178
+ }
180
179
 
181
- getConstraintsSQL(tableName: string) {
182
- return `SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC
183
- INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KU
184
- ON TC.CONSTRAINT_TYPE = 'PRIMARY KEY'
185
- AND TC.CONSTRAINT_NAME = KU.CONSTRAINT_NAME
186
- AND KU.table_name='${tableName}'
187
- ORDER BY
188
- KU.TABLE_NAME,
189
- KU.ORDINAL_POSITION;`
190
- }
180
+ getConstraintsSQL(tableName: string) {
181
+ return `SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS AS TC
182
+ INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KU
183
+ ON TC.CONSTRAINT_TYPE = 'PRIMARY KEY'
184
+ AND TC.CONSTRAINT_NAME = KU.CONSTRAINT_NAME
185
+ AND KU.table_name='${tableName}'
186
+ ORDER BY
187
+ KU.TABLE_NAME,
188
+ KU.ORDINAL_POSITION;`
189
+ }
191
190
 
192
- getAutoColumnsSQL(tableName: string) {
193
- return `SELECT
194
- COLUMNPROPERTY(OBJECT_ID(TABLE_SCHEMA+'.'+TABLE_NAME),COLUMN_NAME,'IsComputed')
195
- AS IS_COMPUTED,
196
- COLUMNPROPERTY(object_id(TABLE_SCHEMA+'.'+TABLE_NAME), COLUMN_NAME, 'IsIdentity')
197
- AS IS_IDENTITY,
198
- *
199
- FROM INFORMATION_SCHEMA.COLUMNS
200
- WHERE TABLE_NAME='${tableName}'`
201
- }
191
+ getAutoColumnsSQL(tableName: string) {
192
+ return `SELECT
193
+ COLUMNPROPERTY(OBJECT_ID(TABLE_SCHEMA+'.'+TABLE_NAME),COLUMN_NAME,'IsComputed')
194
+ AS IS_COMPUTED,
195
+ COLUMNPROPERTY(object_id(TABLE_SCHEMA+'.'+TABLE_NAME), COLUMN_NAME, 'IsIdentity')
196
+ AS IS_IDENTITY,
197
+ *
198
+ FROM INFORMATION_SCHEMA.COLUMNS
199
+ WHERE TABLE_NAME='${tableName}'`
200
+ }
202
201
 
203
- async runSQL(sql: string) {
204
- return (await this.internalQuery(getSqlQuery(sql))).recordset
205
- }
202
+ async runSQL(sql: string) {
203
+ return (await this.internalQuery(getSqlQuery(sql))).recordset
204
+ }
206
205
 
207
- /**
208
- * Fetches the tables from the sql server database and assigns them to the datasource.
209
- * @param {*} datasourceId - datasourceId to fetch
210
- * @param entities - the tables that are to be built
211
- */
212
- async buildSchema(datasourceId: string, entities: Record<string, Table>) {
213
- await this.connect()
214
- let tableInfo: TablesResponse[] = await this.runSQL(this.TABLES_SQL)
215
- if (tableInfo == null || !Array.isArray(tableInfo)) {
216
- throw "Unable to get list of tables in database"
217
- }
206
+ /**
207
+ * Fetches the tables from the sql server database and assigns them to the datasource.
208
+ * @param {*} datasourceId - datasourceId to fetch
209
+ * @param entities - the tables that are to be built
210
+ */
211
+ async buildSchema(datasourceId: string, entities: Record<string, Table>) {
212
+ await this.connect()
213
+ let tableInfo: TablesResponse[] = await this.runSQL(this.TABLES_SQL)
214
+ if (tableInfo == null || !Array.isArray(tableInfo)) {
215
+ throw "Unable to get list of tables in database"
216
+ }
218
217
 
219
- const schema = this.config.schema || DEFAULT_SCHEMA
220
- const tableNames = tableInfo
221
- .filter((record: any) => record.TABLE_SCHEMA === schema)
222
- .map((record: any) => record.TABLE_NAME)
223
- .filter((name: string) => this.MASTER_TABLES.indexOf(name) === -1)
218
+ const schema = this.config.schema || DEFAULT_SCHEMA
219
+ const tableNames = tableInfo
220
+ .filter((record: any) => record.TABLE_SCHEMA === schema)
221
+ .map((record: any) => record.TABLE_NAME)
222
+ .filter((name: string) => this.MASTER_TABLES.indexOf(name) === -1)
224
223
 
225
- const tables: Record<string, Table> = {}
226
- for (let tableName of tableNames) {
227
- // get the column definition (type)
228
- const definition = await this.runSQL(this.getDefinitionSQL(tableName))
229
- // find primary key constraints
230
- const constraints = await this.runSQL(this.getConstraintsSQL(tableName))
231
- // find the computed and identity columns (auto columns)
232
- const columns = await this.runSQL(this.getAutoColumnsSQL(tableName))
233
- const primaryKeys = constraints
234
- .filter(
235
- (constraint: any) => constraint.CONSTRAINT_TYPE === "PRIMARY KEY"
236
- )
237
- .map((constraint: any) => constraint.COLUMN_NAME)
238
- const autoColumns = columns
239
- .filter((col: any) => col.IS_COMPUTED || col.IS_IDENTITY)
240
- .map((col: any) => col.COLUMN_NAME)
224
+ const tables: Record<string, Table> = {}
225
+ for (let tableName of tableNames) {
226
+ // get the column definition (type)
227
+ const definition = await this.runSQL(this.getDefinitionSQL(tableName))
228
+ // find primary key constraints
229
+ const constraints = await this.runSQL(this.getConstraintsSQL(tableName))
230
+ // find the computed and identity columns (auto columns)
231
+ const columns = await this.runSQL(this.getAutoColumnsSQL(tableName))
232
+ const primaryKeys = constraints
233
+ .filter(
234
+ (constraint: any) => constraint.CONSTRAINT_TYPE === "PRIMARY KEY"
235
+ )
236
+ .map((constraint: any) => constraint.COLUMN_NAME)
237
+ const autoColumns = columns
238
+ .filter((col: any) => col.IS_COMPUTED || col.IS_IDENTITY)
239
+ .map((col: any) => col.COLUMN_NAME)
241
240
 
242
- let schema: TableSchema = {}
243
- for (let def of definition) {
244
- const name = def.COLUMN_NAME
245
- if (typeof name !== "string") {
246
- continue
247
- }
248
- schema[name] = {
249
- autocolumn: !!autoColumns.find((col: string) => col === name),
250
- name: name,
251
- ...convertSqlType(def.DATA_TYPE),
252
- externalType: def.DATA_TYPE,
253
- }
241
+ let schema: TableSchema = {}
242
+ for (let def of definition) {
243
+ const name = def.COLUMN_NAME
244
+ if (typeof name !== "string") {
245
+ continue
254
246
  }
255
- tables[tableName] = {
256
- _id: buildExternalTableId(datasourceId, tableName),
257
- primary: primaryKeys,
258
- name: tableName,
259
- schema,
247
+ schema[name] = {
248
+ autocolumn: !!autoColumns.find((col: string) => col === name),
249
+ name: name,
250
+ ...convertSqlType(def.DATA_TYPE),
251
+ externalType: def.DATA_TYPE,
260
252
  }
261
253
  }
262
- const final = finaliseExternalTables(tables, entities)
263
- this.tables = final.tables
264
- this.schemaErrors = final.errors
254
+ tables[tableName] = {
255
+ _id: buildExternalTableId(datasourceId, tableName),
256
+ primary: primaryKeys,
257
+ name: tableName,
258
+ schema,
259
+ }
265
260
  }
261
+ const final = finaliseExternalTables(tables, entities)
262
+ this.tables = final.tables
263
+ this.schemaErrors = final.errors
264
+ }
266
265
 
267
- async read(query: SqlQuery | string) {
268
- await this.connect()
269
- const response = await this.internalQuery(getSqlQuery(query))
270
- return response.recordset
271
- }
266
+ async read(query: SqlQuery | string) {
267
+ await this.connect()
268
+ const response = await this.internalQuery(getSqlQuery(query))
269
+ return response.recordset
270
+ }
272
271
 
273
- async create(query: SqlQuery | string) {
274
- await this.connect()
275
- const response = await this.internalQuery(getSqlQuery(query))
276
- return response.recordset || [{ created: true }]
277
- }
272
+ async create(query: SqlQuery | string) {
273
+ await this.connect()
274
+ const response = await this.internalQuery(getSqlQuery(query))
275
+ return response.recordset || [{ created: true }]
276
+ }
278
277
 
279
- async update(query: SqlQuery | string) {
280
- await this.connect()
281
- const response = await this.internalQuery(getSqlQuery(query))
282
- return response.recordset || [{ updated: true }]
283
- }
278
+ async update(query: SqlQuery | string) {
279
+ await this.connect()
280
+ const response = await this.internalQuery(getSqlQuery(query))
281
+ return response.recordset || [{ updated: true }]
282
+ }
284
283
 
285
- async delete(query: SqlQuery | string) {
286
- await this.connect()
287
- const response = await this.internalQuery(getSqlQuery(query))
288
- return response.recordset || [{ deleted: true }]
289
- }
284
+ async delete(query: SqlQuery | string) {
285
+ await this.connect()
286
+ const response = await this.internalQuery(getSqlQuery(query))
287
+ return response.recordset || [{ deleted: true }]
288
+ }
290
289
 
291
- async query(json: QueryJson) {
292
- const schema = this.config.schema
293
- await this.connect()
294
- if (schema && schema !== DEFAULT_SCHEMA && json?.endpoint) {
295
- json.endpoint.schema = schema
296
- }
297
- const operation = this._operation(json)
298
- const queryFn = (query: any, op: string) => this.internalQuery(query, op)
299
- const processFn = (result: any) =>
300
- result.recordset ? result.recordset : [{ [operation]: true }]
301
- return this.queryWithReturning(json, queryFn, processFn)
290
+ async query(json: QueryJson) {
291
+ const schema = this.config.schema
292
+ await this.connect()
293
+ if (schema && schema !== DEFAULT_SCHEMA && json?.endpoint) {
294
+ json.endpoint.schema = schema
302
295
  }
296
+ const operation = this._operation(json)
297
+ const queryFn = (query: any, op: string) => this.internalQuery(query, op)
298
+ const processFn = (result: any) =>
299
+ result.recordset ? result.recordset : [{ [operation]: true }]
300
+ return this.queryWithReturning(json, queryFn, processFn)
303
301
  }
302
+ }
304
303
 
305
- module.exports = {
306
- schema: SCHEMA,
307
- integration: SqlServerIntegration,
308
- }
304
+ export default {
305
+ schema: SCHEMA,
306
+ integration: SqlServerIntegration,
309
307
  }