@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
@@ -19,274 +19,269 @@ import dayjs from "dayjs"
19
19
  const { NUMBER_REGEX } = require("../utilities")
20
20
  import Sql from "./base/sql"
21
21
 
22
- module MySQLModule {
23
- const mysql = require("mysql2/promise")
22
+ const mysql = require("mysql2/promise")
24
23
 
25
- interface MySQLConfig {
26
- host: string
27
- port: number
28
- user: string
29
- password: string
30
- database: string
31
- ssl?: { [key: string]: any }
32
- rejectUnauthorized: boolean
33
- typeCast: Function
34
- }
24
+ interface MySQLConfig {
25
+ host: string
26
+ port: number
27
+ user: string
28
+ password: string
29
+ database: string
30
+ ssl?: { [key: string]: any }
31
+ rejectUnauthorized: boolean
32
+ typeCast: Function
33
+ }
35
34
 
36
- const SCHEMA: Integration = {
37
- docs: "https://github.com/sidorares/node-mysql2",
38
- plus: true,
39
- friendlyName: "MySQL",
40
- type: "Relational",
41
- description:
42
- "MySQL Database Service is a fully managed database service to deploy cloud-native applications. ",
43
- datasource: {
44
- host: {
45
- type: DatasourceFieldType.STRING,
46
- default: "localhost",
47
- required: true,
48
- },
49
- port: {
50
- type: DatasourceFieldType.NUMBER,
51
- default: 3306,
52
- required: false,
53
- },
54
- user: {
55
- type: DatasourceFieldType.STRING,
56
- default: "root",
57
- required: true,
58
- },
59
- password: {
60
- type: DatasourceFieldType.PASSWORD,
61
- default: "root",
62
- required: true,
63
- },
64
- database: {
65
- type: DatasourceFieldType.STRING,
66
- required: true,
67
- },
68
- ssl: {
69
- type: DatasourceFieldType.OBJECT,
70
- required: false,
71
- },
72
- rejectUnauthorized: {
73
- type: DatasourceFieldType.BOOLEAN,
74
- default: true,
75
- required: false,
76
- },
35
+ const SCHEMA: Integration = {
36
+ docs: "https://github.com/sidorares/node-mysql2",
37
+ plus: true,
38
+ friendlyName: "MySQL",
39
+ type: "Relational",
40
+ description:
41
+ "MySQL Database Service is a fully managed database service to deploy cloud-native applications. ",
42
+ datasource: {
43
+ host: {
44
+ type: DatasourceFieldType.STRING,
45
+ default: "localhost",
46
+ required: true,
77
47
  },
78
- query: {
79
- create: {
80
- type: QueryType.SQL,
81
- },
82
- read: {
83
- type: QueryType.SQL,
84
- },
85
- update: {
86
- type: QueryType.SQL,
87
- },
88
- delete: {
89
- type: QueryType.SQL,
90
- },
48
+ port: {
49
+ type: DatasourceFieldType.NUMBER,
50
+ default: 3306,
51
+ required: false,
91
52
  },
92
- }
53
+ user: {
54
+ type: DatasourceFieldType.STRING,
55
+ default: "root",
56
+ required: true,
57
+ },
58
+ password: {
59
+ type: DatasourceFieldType.PASSWORD,
60
+ default: "root",
61
+ required: true,
62
+ },
63
+ database: {
64
+ type: DatasourceFieldType.STRING,
65
+ required: true,
66
+ },
67
+ ssl: {
68
+ type: DatasourceFieldType.OBJECT,
69
+ required: false,
70
+ },
71
+ rejectUnauthorized: {
72
+ type: DatasourceFieldType.BOOLEAN,
73
+ default: true,
74
+ required: false,
75
+ },
76
+ },
77
+ query: {
78
+ create: {
79
+ type: QueryType.SQL,
80
+ },
81
+ read: {
82
+ type: QueryType.SQL,
83
+ },
84
+ update: {
85
+ type: QueryType.SQL,
86
+ },
87
+ delete: {
88
+ type: QueryType.SQL,
89
+ },
90
+ },
91
+ }
93
92
 
94
- const TimezoneAwareDateTypes = ["timestamp"]
93
+ const TimezoneAwareDateTypes = ["timestamp"]
95
94
 
96
- function bindingTypeCoerce(bindings: any[]) {
97
- for (let i = 0; i < bindings.length; i++) {
98
- const binding = bindings[i]
99
- if (typeof binding !== "string") {
100
- continue
101
- }
102
- const matches = binding.match(NUMBER_REGEX)
103
- // check if number first
104
- if (matches && matches[0] !== "" && !isNaN(Number(matches[0]))) {
105
- bindings[i] = parseFloat(binding)
106
- }
107
- // if not a number, see if it is a date - important to do in this order as any
108
- // integer will be considered a valid date
109
- else if (/^\d/.test(binding) && dayjs(binding).isValid()) {
110
- bindings[i] = dayjs(binding).toDate()
111
- }
95
+ function bindingTypeCoerce(bindings: any[]) {
96
+ for (let i = 0; i < bindings.length; i++) {
97
+ const binding = bindings[i]
98
+ if (typeof binding !== "string") {
99
+ continue
100
+ }
101
+ const matches = binding.match(NUMBER_REGEX)
102
+ // check if number first
103
+ if (matches && matches[0] !== "" && !isNaN(Number(matches[0]))) {
104
+ bindings[i] = parseFloat(binding)
105
+ }
106
+ // if not a number, see if it is a date - important to do in this order as any
107
+ // integer will be considered a valid date
108
+ else if (/^\d/.test(binding) && dayjs(binding).isValid()) {
109
+ bindings[i] = dayjs(binding).toDate()
112
110
  }
113
- return bindings
114
111
  }
112
+ return bindings
113
+ }
115
114
 
116
- class MySQLIntegration extends Sql implements DatasourcePlus {
117
- private config: MySQLConfig
118
- private client: any
119
- public tables: Record<string, Table> = {}
120
- public schemaErrors: Record<string, string> = {}
115
+ class MySQLIntegration extends Sql implements DatasourcePlus {
116
+ private config: MySQLConfig
117
+ private client: any
118
+ public tables: Record<string, Table> = {}
119
+ public schemaErrors: Record<string, string> = {}
121
120
 
122
- constructor(config: MySQLConfig) {
123
- super(SqlClient.MY_SQL)
124
- this.config = config
125
- if (config.ssl && Object.keys(config.ssl).length === 0) {
126
- delete config.ssl
127
- }
128
- // make sure this defaults to true
129
- if (
130
- config.rejectUnauthorized != null &&
131
- !config.rejectUnauthorized &&
132
- config.ssl
133
- ) {
134
- config.ssl.rejectUnauthorized = config.rejectUnauthorized
135
- }
136
- // @ts-ignore
137
- delete config.rejectUnauthorized
138
- this.config = {
139
- ...config,
140
- typeCast: function (field: any, next: any) {
141
- if (
142
- field.type == "DATETIME" ||
143
- field.type === "DATE" ||
144
- field.type === "TIMESTAMP"
145
- ) {
146
- return field.string()
147
- }
148
- return next()
149
- },
150
- }
121
+ constructor(config: MySQLConfig) {
122
+ super(SqlClient.MY_SQL)
123
+ this.config = config
124
+ if (config.ssl && Object.keys(config.ssl).length === 0) {
125
+ delete config.ssl
151
126
  }
152
-
153
- getBindingIdentifier(): string {
154
- return "?"
127
+ // make sure this defaults to true
128
+ if (
129
+ config.rejectUnauthorized != null &&
130
+ !config.rejectUnauthorized &&
131
+ config.ssl
132
+ ) {
133
+ config.ssl.rejectUnauthorized = config.rejectUnauthorized
155
134
  }
156
-
157
- getStringConcat(parts: string[]): string {
158
- return `concat(${parts.join(", ")})`
135
+ // @ts-ignore
136
+ delete config.rejectUnauthorized
137
+ this.config = {
138
+ ...config,
139
+ typeCast: function (field: any, next: any) {
140
+ if (
141
+ field.type == "DATETIME" ||
142
+ field.type === "DATE" ||
143
+ field.type === "TIMESTAMP"
144
+ ) {
145
+ return field.string()
146
+ }
147
+ return next()
148
+ },
159
149
  }
150
+ }
160
151
 
161
- async connect() {
162
- this.client = await mysql.createConnection(this.config)
163
- }
152
+ getBindingIdentifier(): string {
153
+ return "?"
154
+ }
164
155
 
165
- async disconnect() {
166
- await this.client.end()
167
- }
156
+ getStringConcat(parts: string[]): string {
157
+ return `concat(${parts.join(", ")})`
158
+ }
159
+
160
+ async connect() {
161
+ this.client = await mysql.createConnection(this.config)
162
+ }
163
+
164
+ async disconnect() {
165
+ await this.client.end()
166
+ }
168
167
 
169
- async internalQuery(
170
- query: SqlQuery,
171
- opts: { connect?: boolean; disableCoercion?: boolean } = {
172
- connect: true,
173
- disableCoercion: false,
168
+ async internalQuery(
169
+ query: SqlQuery,
170
+ opts: { connect?: boolean; disableCoercion?: boolean } = {
171
+ connect: true,
172
+ disableCoercion: false,
173
+ }
174
+ ): Promise<any[] | any> {
175
+ try {
176
+ if (opts?.connect) {
177
+ await this.connect()
174
178
  }
175
- ): Promise<any[] | any> {
176
- try {
177
- if (opts?.connect) {
178
- await this.connect()
179
- }
180
- const baseBindings = query.bindings || []
181
- const bindings = opts?.disableCoercion
182
- ? baseBindings
183
- : bindingTypeCoerce(baseBindings)
184
- // Node MySQL is callback based, so we must wrap our call in a promise
185
- const response = await this.client.query(query.sql, bindings)
186
- return response[0]
187
- } finally {
188
- if (opts?.connect) {
189
- await this.disconnect()
190
- }
179
+ const baseBindings = query.bindings || []
180
+ const bindings = opts?.disableCoercion
181
+ ? baseBindings
182
+ : bindingTypeCoerce(baseBindings)
183
+ // Node MySQL is callback based, so we must wrap our call in a promise
184
+ const response = await this.client.query(query.sql, bindings)
185
+ return response[0]
186
+ } finally {
187
+ if (opts?.connect) {
188
+ await this.disconnect()
191
189
  }
192
190
  }
191
+ }
193
192
 
194
- async buildSchema(datasourceId: string, entities: Record<string, Table>) {
195
- const tables: { [key: string]: Table } = {}
196
- const database = this.config.database
197
- await this.connect()
193
+ async buildSchema(datasourceId: string, entities: Record<string, Table>) {
194
+ const tables: { [key: string]: Table } = {}
195
+ const database = this.config.database
196
+ await this.connect()
198
197
 
199
- try {
200
- // get the tables first
201
- const tablesResp = await this.internalQuery(
202
- { sql: "SHOW TABLES;" },
198
+ try {
199
+ // get the tables first
200
+ const tablesResp = await this.internalQuery(
201
+ { sql: "SHOW TABLES;" },
202
+ { connect: false }
203
+ )
204
+ const tableNames = tablesResp.map(
205
+ (obj: any) =>
206
+ obj[`Tables_in_${database}`] ||
207
+ obj[`Tables_in_${database.toLowerCase()}`]
208
+ )
209
+ for (let tableName of tableNames) {
210
+ const primaryKeys = []
211
+ const schema: TableSchema = {}
212
+ const descResp = await this.internalQuery(
213
+ { sql: `DESCRIBE \`${tableName}\`;` },
203
214
  { connect: false }
204
215
  )
205
- const tableNames = tablesResp.map(
206
- (obj: any) =>
207
- obj[`Tables_in_${database}`] ||
208
- obj[`Tables_in_${database.toLowerCase()}`]
209
- )
210
- for (let tableName of tableNames) {
211
- const primaryKeys = []
212
- const schema: TableSchema = {}
213
- const descResp = await this.internalQuery(
214
- { sql: `DESCRIBE \`${tableName}\`;` },
215
- { connect: false }
216
- )
217
- for (let column of descResp) {
218
- const columnName = column.Field
219
- if (
220
- column.Key === "PRI" &&
221
- primaryKeys.indexOf(column.Key) === -1
222
- ) {
223
- primaryKeys.push(columnName)
224
- }
225
- const constraints = {
226
- presence: column.Null !== "YES",
227
- }
228
- const isAuto: boolean =
229
- typeof column.Extra === "string" &&
230
- (column.Extra === "auto_increment" ||
231
- column.Extra.toLowerCase().includes("generated"))
232
- schema[columnName] = {
233
- name: columnName,
234
- autocolumn: isAuto,
235
- constraints,
236
- ...convertSqlType(column.Type),
237
- externalType: column.Type,
238
- }
216
+ for (let column of descResp) {
217
+ const columnName = column.Field
218
+ if (column.Key === "PRI" && primaryKeys.indexOf(column.Key) === -1) {
219
+ primaryKeys.push(columnName)
239
220
  }
240
- if (!tables[tableName]) {
241
- tables[tableName] = {
242
- _id: buildExternalTableId(datasourceId, tableName),
243
- primary: primaryKeys,
244
- name: tableName,
245
- schema,
246
- }
221
+ const constraints = {
222
+ presence: column.Null !== "YES",
223
+ }
224
+ const isAuto: boolean =
225
+ typeof column.Extra === "string" &&
226
+ (column.Extra === "auto_increment" ||
227
+ column.Extra.toLowerCase().includes("generated"))
228
+ schema[columnName] = {
229
+ name: columnName,
230
+ autocolumn: isAuto,
231
+ constraints,
232
+ ...convertSqlType(column.Type),
233
+ externalType: column.Type,
234
+ }
235
+ }
236
+ if (!tables[tableName]) {
237
+ tables[tableName] = {
238
+ _id: buildExternalTableId(datasourceId, tableName),
239
+ primary: primaryKeys,
240
+ name: tableName,
241
+ schema,
247
242
  }
248
243
  }
249
- } finally {
250
- await this.disconnect()
251
244
  }
252
- const final = finaliseExternalTables(tables, entities)
253
- this.tables = final.tables
254
- this.schemaErrors = final.errors
245
+ } finally {
246
+ await this.disconnect()
255
247
  }
248
+ const final = finaliseExternalTables(tables, entities)
249
+ this.tables = final.tables
250
+ this.schemaErrors = final.errors
251
+ }
256
252
 
257
- async create(query: SqlQuery | string) {
258
- const results = await this.internalQuery(getSqlQuery(query))
259
- return results.length ? results : [{ created: true }]
260
- }
253
+ async create(query: SqlQuery | string) {
254
+ const results = await this.internalQuery(getSqlQuery(query))
255
+ return results.length ? results : [{ created: true }]
256
+ }
261
257
 
262
- async read(query: SqlQuery | string) {
263
- return this.internalQuery(getSqlQuery(query))
264
- }
258
+ async read(query: SqlQuery | string) {
259
+ return this.internalQuery(getSqlQuery(query))
260
+ }
265
261
 
266
- async update(query: SqlQuery | string) {
267
- const results = await this.internalQuery(getSqlQuery(query))
268
- return results.length ? results : [{ updated: true }]
269
- }
262
+ async update(query: SqlQuery | string) {
263
+ const results = await this.internalQuery(getSqlQuery(query))
264
+ return results.length ? results : [{ updated: true }]
265
+ }
270
266
 
271
- async delete(query: SqlQuery | string) {
272
- const results = await this.internalQuery(getSqlQuery(query))
273
- return results.length ? results : [{ deleted: true }]
274
- }
267
+ async delete(query: SqlQuery | string) {
268
+ const results = await this.internalQuery(getSqlQuery(query))
269
+ return results.length ? results : [{ deleted: true }]
270
+ }
275
271
 
276
- async query(json: QueryJson) {
277
- await this.connect()
278
- try {
279
- const queryFn = (query: any) =>
280
- this.internalQuery(query, { connect: false, disableCoercion: true })
281
- return await this.queryWithReturning(json, queryFn)
282
- } finally {
283
- await this.disconnect()
284
- }
272
+ async query(json: QueryJson) {
273
+ await this.connect()
274
+ try {
275
+ const queryFn = (query: any) =>
276
+ this.internalQuery(query, { connect: false, disableCoercion: true })
277
+ return await this.queryWithReturning(json, queryFn)
278
+ } finally {
279
+ await this.disconnect()
285
280
  }
286
281
  }
282
+ }
287
283
 
288
- module.exports = {
289
- schema: SCHEMA,
290
- integration: MySQLIntegration,
291
- }
284
+ export default {
285
+ schema: SCHEMA,
286
+ integration: MySQLIntegration,
292
287
  }