@budibase/server 1.3.12-alpha.3 → 1.3.14

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 (274) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/{index.7886c551.css → index.a70e216a.css} +2 -2
  3. package/builder/assets/index.d8428ac8.js +876 -0
  4. package/builder/assets/vendor.5e1fe644.css +1 -0
  5. package/builder/assets/vendor.67dbd8fa.js +248 -0
  6. package/builder/index.html +4 -2
  7. package/coverage/clover.xml +335 -355
  8. package/coverage/coverage-final.json +22 -22
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/backup.js.html +8 -5
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +13 -82
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +20 -20
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +32 -32
  18. package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
  19. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/screen.js.html +12 -204
  34. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  47. package/coverage/lcov-report/api/index.html +1 -1
  48. package/coverage/lcov-report/api/index.js.html +12 -12
  49. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/index.html +1 -1
  60. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  74. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  77. package/coverage/lcov-report/automations/actions.js.html +1 -1
  78. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  79. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  80. package/coverage/lcov-report/automations/index.html +24 -24
  81. package/coverage/lcov-report/automations/index.js.html +18 -9
  82. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/index.html +1 -1
  89. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggers.js.html +126 -24
  108. package/coverage/lcov-report/constants/index.html +1 -1
  109. package/coverage/lcov-report/constants/index.js.html +1 -1
  110. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  111. package/coverage/lcov-report/constants/screens.js.html +1 -1
  112. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  113. package/coverage/lcov-report/db/index.html +18 -18
  114. package/coverage/lcov-report/db/index.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  116. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  117. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  118. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  119. package/coverage/lcov-report/db/newid.js.html +2 -2
  120. package/coverage/lcov-report/db/utils.js.html +20 -56
  121. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  122. package/coverage/lcov-report/events/index.html +1 -1
  123. package/coverage/lcov-report/events/index.js.html +1 -1
  124. package/coverage/lcov-report/events/utils.js.html +1 -1
  125. package/coverage/lcov-report/index.html +48 -48
  126. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  127. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  128. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  129. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  130. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  131. package/coverage/lcov-report/middleware/index.html +1 -1
  132. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  133. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  134. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  135. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  136. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  137. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  138. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  139. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  140. package/coverage/lcov-report/utilities/global.js.html +16 -16
  141. package/coverage/lcov-report/utilities/index.html +19 -19
  142. package/coverage/lcov-report/utilities/index.js.html +66 -42
  143. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  144. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  145. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  146. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/rowProcessor/index.html +5 -5
  148. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +4 -4
  150. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  151. package/coverage/lcov-report/utilities/security.js.html +2 -2
  152. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  153. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  154. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +6 -3
  155. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  156. package/coverage/lcov-report/utilities/users.js.html +1 -1
  157. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  158. package/coverage/lcov.info +604 -652
  159. package/dist/api/controllers/application.js +5 -10
  160. package/dist/api/controllers/backup.js +2 -1
  161. package/dist/api/controllers/component.js +1 -18
  162. package/dist/api/controllers/datasource.js +4 -4
  163. package/dist/api/controllers/deploy/index.js +17 -2
  164. package/dist/api/controllers/integration.js +4 -4
  165. package/dist/api/controllers/row/ExternalRequest.js +1 -1
  166. package/dist/api/controllers/screen.js +2 -51
  167. package/dist/api/controllers/static/index.js +0 -1
  168. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  169. package/dist/api/controllers/static/templates/preview.hbs +1 -3
  170. package/dist/api/routes/index.js +0 -2
  171. package/dist/api/routes/static.js +1 -1
  172. package/dist/app.js +0 -9
  173. package/dist/automations/index.js +10 -5
  174. package/dist/automations/triggers.js +39 -5
  175. package/dist/automations/utils.js +16 -7
  176. package/dist/db/utils.js +1 -10
  177. package/dist/environment.js +0 -1
  178. package/dist/integrations/airtable.js +129 -126
  179. package/dist/integrations/arangodb.js +89 -86
  180. package/dist/integrations/base/query.js +2 -2
  181. package/dist/integrations/couchdb.js +83 -80
  182. package/dist/integrations/dynamodb.js +164 -161
  183. package/dist/integrations/elasticsearch.js +138 -135
  184. package/dist/integrations/firebase.js +157 -154
  185. package/dist/integrations/googlesheets.js +327 -323
  186. package/dist/integrations/index.js +51 -93
  187. package/dist/integrations/microsoftSqlServer.js +243 -240
  188. package/dist/integrations/mongodb.js +242 -239
  189. package/dist/integrations/mysql.js +219 -215
  190. package/dist/integrations/oracle.js +322 -318
  191. package/dist/integrations/postgres.js +265 -262
  192. package/dist/integrations/redis.js +139 -134
  193. package/dist/integrations/rest.js +296 -278
  194. package/dist/integrations/s3.js +64 -61
  195. package/dist/integrations/snowflake.js +86 -83
  196. package/dist/package.json +6 -8
  197. package/dist/threads/automation.js +6 -0
  198. package/dist/threads/query.js +2 -2
  199. package/dist/tsconfig.build.tsbuildinfo +1 -1
  200. package/dist/utilities/fileSystem/index.js +6 -71
  201. package/dist/utilities/index.js +8 -0
  202. package/dist/utilities/rowProcessor/utils.js +1 -1
  203. package/dist/utilities/usageQuota/rows.js +2 -1
  204. package/package.json +7 -9
  205. package/scripts/dev/manage.js +0 -1
  206. package/src/api/controllers/application.ts +2 -6
  207. package/src/api/controllers/backup.js +2 -1
  208. package/src/api/controllers/component.js +2 -25
  209. package/src/api/controllers/datasource.js +4 -4
  210. package/src/api/controllers/deploy/index.ts +17 -4
  211. package/src/api/controllers/integration.js +4 -4
  212. package/src/api/controllers/row/ExternalRequest.ts +1 -1
  213. package/src/api/controllers/screen.js +1 -65
  214. package/src/api/controllers/static/index.ts +0 -1
  215. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  216. package/src/api/controllers/static/templates/preview.hbs +1 -3
  217. package/src/api/routes/index.ts +0 -2
  218. package/src/api/routes/static.ts +1 -1
  219. package/src/api/routes/tests/query.spec.js +28 -11
  220. package/src/api/routes/tests/static.spec.js +2 -2
  221. package/src/app.ts +0 -12
  222. package/src/automations/index.js +6 -3
  223. package/src/automations/triggers.js +44 -10
  224. package/src/automations/utils.ts +21 -9
  225. package/src/db/utils.js +0 -12
  226. package/src/definitions/datasource.ts +1 -0
  227. package/src/environment.js +0 -1
  228. package/src/integrations/airtable.ts +118 -116
  229. package/src/integrations/arangodb.ts +89 -87
  230. package/src/integrations/base/query.ts +2 -2
  231. package/src/integrations/couchdb.ts +89 -83
  232. package/src/integrations/dynamodb.ts +175 -173
  233. package/src/integrations/elasticsearch.ts +122 -120
  234. package/src/integrations/firebase.ts +159 -157
  235. package/src/integrations/googlesheets.ts +338 -328
  236. package/src/integrations/index.ts +21 -59
  237. package/src/integrations/microsoftSqlServer.ts +251 -249
  238. package/src/integrations/mongodb.ts +258 -261
  239. package/src/integrations/mysql.ts +234 -229
  240. package/src/integrations/oracle.ts +380 -373
  241. package/src/integrations/postgres.ts +268 -264
  242. package/src/integrations/redis.ts +132 -128
  243. package/src/integrations/rest.ts +330 -312
  244. package/src/integrations/s3.ts +71 -68
  245. package/src/integrations/snowflake.ts +82 -80
  246. package/src/integrations/tests/{airtable.spec.ts → airtable.spec.js} +18 -21
  247. package/src/integrations/tests/{arangodb.spec.ts → arangodb.spec.js} +9 -12
  248. package/src/integrations/tests/{couchdb.spec.ts → couchdb.spec.js} +27 -33
  249. package/src/integrations/tests/{dynamodb.spec.ts → dynamodb.spec.js} +41 -45
  250. package/src/integrations/tests/{elasticsearch.spec.ts → elasticsearch.spec.js} +21 -22
  251. package/src/integrations/tests/{firebase.spec.ts → firebase.spec.js} +28 -33
  252. package/src/integrations/tests/{microsoftSqlServer.spec.ts → microsoftSqlServer.spec.js} +11 -12
  253. package/src/integrations/tests/{mongo.spec.ts → mongo.spec.js} +35 -46
  254. package/src/integrations/tests/{mysql.spec.ts → mysql.spec.js} +15 -17
  255. package/src/integrations/tests/{oracle.spec.ts → oracle.spec.js} +17 -19
  256. package/src/integrations/tests/{postgres.spec.ts → postgres.spec.js} +17 -19
  257. package/src/integrations/tests/{redis.spec.ts → redis.spec.js} +18 -27
  258. package/src/integrations/tests/{rest.spec.ts → rest.spec.js} +49 -22
  259. package/src/integrations/tests/{s3.spec.ts → s3.spec.js} +8 -10
  260. package/src/integrations/tests/{sql.spec.ts → sql.spec.js} +177 -228
  261. package/src/module.d.ts +0 -1
  262. package/src/threads/automation.ts +6 -0
  263. package/src/threads/query.ts +2 -2
  264. package/src/utilities/fileSystem/index.js +6 -75
  265. package/src/utilities/index.js +8 -0
  266. package/src/utilities/rowProcessor/utils.js +1 -1
  267. package/src/utilities/usageQuota/rows.js +2 -1
  268. package/builder/assets/index.e759397f.js +0 -994
  269. package/dist/api/controllers/plugin.js +0 -119
  270. package/dist/api/routes/plugin.js +0 -38
  271. package/dist/watch.js +0 -77
  272. package/src/api/controllers/plugin.ts +0 -110
  273. package/src/api/routes/plugin.ts +0 -13
  274. package/src/watch.ts +0 -38
@@ -19,269 +19,274 @@ import dayjs from "dayjs"
19
19
  const { NUMBER_REGEX } = require("../utilities")
20
20
  import Sql from "./base/sql"
21
21
 
22
- const mysql = require("mysql2/promise")
22
+ module MySQLModule {
23
+ const mysql = require("mysql2/promise")
23
24
 
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
- }
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
+ }
34
35
 
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,
47
- },
48
- port: {
49
- type: DatasourceFieldType.NUMBER,
50
- default: 3306,
51
- required: false,
52
- },
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,
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
+ },
86
77
  },
87
- delete: {
88
- type: QueryType.SQL,
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
+ },
89
91
  },
90
- },
91
- }
92
+ }
92
93
 
93
- const TimezoneAwareDateTypes = ["timestamp"]
94
+ const TimezoneAwareDateTypes = ["timestamp"]
94
95
 
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()
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
+ }
110
112
  }
113
+ return bindings
111
114
  }
112
- return bindings
113
- }
114
115
 
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> = {}
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> = {}
120
121
 
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
126
- }
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
134
- }
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
- },
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
+ }
149
151
  }
150
- }
151
152
 
152
- getBindingIdentifier(): string {
153
- return "?"
154
- }
155
-
156
- getStringConcat(parts: string[]): string {
157
- return `concat(${parts.join(", ")})`
158
- }
153
+ getBindingIdentifier(): string {
154
+ return "?"
155
+ }
159
156
 
160
- async connect() {
161
- this.client = await mysql.createConnection(this.config)
162
- }
157
+ getStringConcat(parts: string[]): string {
158
+ return `concat(${parts.join(", ")})`
159
+ }
163
160
 
164
- async disconnect() {
165
- await this.client.end()
166
- }
161
+ async connect() {
162
+ this.client = await mysql.createConnection(this.config)
163
+ }
167
164
 
168
- async internalQuery(
169
- query: SqlQuery,
170
- opts: { connect?: boolean; disableCoercion?: boolean } = {
171
- connect: true,
172
- disableCoercion: false,
165
+ async disconnect() {
166
+ await this.client.end()
173
167
  }
174
- ): Promise<any[] | any> {
175
- try {
176
- if (opts?.connect) {
177
- await this.connect()
168
+
169
+ async internalQuery(
170
+ query: SqlQuery,
171
+ opts: { connect?: boolean; disableCoercion?: boolean } = {
172
+ connect: true,
173
+ disableCoercion: false,
178
174
  }
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()
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
+ }
189
191
  }
190
192
  }
191
- }
192
193
 
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()
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()
197
198
 
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}\`;` },
199
+ try {
200
+ // get the tables first
201
+ const tablesResp = await this.internalQuery(
202
+ { sql: "SHOW TABLES;" },
214
203
  { connect: false }
215
204
  )
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)
220
- }
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,
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
+ }
234
239
  }
235
- }
236
- if (!tables[tableName]) {
237
- tables[tableName] = {
238
- _id: buildExternalTableId(datasourceId, tableName),
239
- primary: primaryKeys,
240
- name: tableName,
241
- schema,
240
+ if (!tables[tableName]) {
241
+ tables[tableName] = {
242
+ _id: buildExternalTableId(datasourceId, tableName),
243
+ primary: primaryKeys,
244
+ name: tableName,
245
+ schema,
246
+ }
242
247
  }
243
248
  }
249
+ } finally {
250
+ await this.disconnect()
244
251
  }
245
- } finally {
246
- await this.disconnect()
252
+ const final = finaliseExternalTables(tables, entities)
253
+ this.tables = final.tables
254
+ this.schemaErrors = final.errors
247
255
  }
248
- const final = finaliseExternalTables(tables, entities)
249
- this.tables = final.tables
250
- this.schemaErrors = final.errors
251
- }
252
256
 
253
- async create(query: SqlQuery | string) {
254
- const results = await this.internalQuery(getSqlQuery(query))
255
- return results.length ? results : [{ created: true }]
256
- }
257
+ async create(query: SqlQuery | string) {
258
+ const results = await this.internalQuery(getSqlQuery(query))
259
+ return results.length ? results : [{ created: true }]
260
+ }
257
261
 
258
- async read(query: SqlQuery | string) {
259
- return this.internalQuery(getSqlQuery(query))
260
- }
262
+ async read(query: SqlQuery | string) {
263
+ return this.internalQuery(getSqlQuery(query))
264
+ }
261
265
 
262
- async update(query: SqlQuery | string) {
263
- const results = await this.internalQuery(getSqlQuery(query))
264
- return results.length ? results : [{ updated: true }]
265
- }
266
+ async update(query: SqlQuery | string) {
267
+ const results = await this.internalQuery(getSqlQuery(query))
268
+ return results.length ? results : [{ updated: true }]
269
+ }
266
270
 
267
- async delete(query: SqlQuery | string) {
268
- const results = await this.internalQuery(getSqlQuery(query))
269
- return results.length ? results : [{ deleted: true }]
270
- }
271
+ async delete(query: SqlQuery | string) {
272
+ const results = await this.internalQuery(getSqlQuery(query))
273
+ return results.length ? results : [{ deleted: true }]
274
+ }
271
275
 
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()
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
+ }
280
285
  }
281
286
  }
282
- }
283
287
 
284
- export default {
285
- schema: SCHEMA,
286
- integration: MySQLIntegration,
288
+ module.exports = {
289
+ schema: SCHEMA,
290
+ integration: MySQLIntegration,
291
+ }
287
292
  }