@budibase/server 1.3.15-alpha.0 → 1.3.16

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 (252) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/index.43e7aaa8.js +876 -0
  3. package/builder/assets/{index.f5c54dd2.css → index.a70e216a.css} +2 -2
  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 +254 -296
  8. package/coverage/coverage-final.json +17 -17
  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 +1 -1
  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 +30 -30
  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 +1 -1
  81. package/coverage/lcov-report/automations/index.js.html +1 -1
  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 +1 -1
  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 +28 -28
  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 +1 -1
  142. package/coverage/lcov-report/utilities/index.js.html +24 -24
  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 +1 -1
  148. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  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 +1 -1
  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 +445 -533
  159. package/dist/api/controllers/application.js +4 -5
  160. package/dist/api/controllers/component.js +1 -18
  161. package/dist/api/controllers/datasource.js +4 -4
  162. package/dist/api/controllers/integration.js +4 -4
  163. package/dist/api/controllers/row/ExternalRequest.js +3 -1
  164. package/dist/api/controllers/screen.js +2 -51
  165. package/dist/api/controllers/static/index.js +0 -1
  166. package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  167. package/dist/api/controllers/static/templates/preview.hbs +1 -3
  168. package/dist/api/routes/index.js +0 -2
  169. package/dist/app.js +0 -9
  170. package/dist/db/utils.js +1 -10
  171. package/dist/environment.js +2 -3
  172. package/dist/integrations/airtable.js +129 -126
  173. package/dist/integrations/arangodb.js +89 -86
  174. package/dist/integrations/base/query.js +2 -2
  175. package/dist/integrations/couchdb.js +83 -80
  176. package/dist/integrations/dynamodb.js +164 -161
  177. package/dist/integrations/elasticsearch.js +138 -135
  178. package/dist/integrations/firebase.js +157 -154
  179. package/dist/integrations/googlesheets.js +327 -323
  180. package/dist/integrations/index.js +51 -93
  181. package/dist/integrations/microsoftSqlServer.js +243 -240
  182. package/dist/integrations/mongodb.js +242 -239
  183. package/dist/integrations/mysql.js +219 -215
  184. package/dist/integrations/oracle.js +322 -318
  185. package/dist/integrations/postgres.js +265 -262
  186. package/dist/integrations/redis.js +139 -134
  187. package/dist/integrations/rest.js +292 -289
  188. package/dist/integrations/s3.js +64 -61
  189. package/dist/integrations/snowflake.js +86 -83
  190. package/dist/package.json +6 -8
  191. package/dist/threads/query.js +2 -2
  192. package/dist/tsconfig.build.tsbuildinfo +1 -1
  193. package/dist/utilities/fileSystem/index.js +10 -66
  194. package/package.json +7 -9
  195. package/scripts/dev/manage.js +0 -1
  196. package/src/api/controllers/application.ts +1 -1
  197. package/src/api/controllers/component.js +2 -25
  198. package/src/api/controllers/datasource.js +4 -4
  199. package/src/api/controllers/integration.js +4 -4
  200. package/src/api/controllers/row/ExternalRequest.ts +4 -1
  201. package/src/api/controllers/screen.js +1 -65
  202. package/src/api/controllers/static/index.ts +0 -1
  203. package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -10
  204. package/src/api/controllers/static/templates/preview.hbs +1 -3
  205. package/src/api/routes/index.ts +0 -2
  206. package/src/api/routes/tests/query.spec.js +25 -8
  207. package/src/app.ts +0 -12
  208. package/src/db/utils.js +0 -12
  209. package/src/environment.js +2 -3
  210. package/src/integrations/airtable.ts +118 -116
  211. package/src/integrations/arangodb.ts +89 -87
  212. package/src/integrations/base/query.ts +2 -2
  213. package/src/integrations/couchdb.ts +89 -83
  214. package/src/integrations/dynamodb.ts +175 -173
  215. package/src/integrations/elasticsearch.ts +122 -120
  216. package/src/integrations/firebase.ts +159 -157
  217. package/src/integrations/googlesheets.ts +338 -328
  218. package/src/integrations/index.ts +21 -59
  219. package/src/integrations/microsoftSqlServer.ts +251 -249
  220. package/src/integrations/mongodb.ts +258 -261
  221. package/src/integrations/mysql.ts +234 -229
  222. package/src/integrations/oracle.ts +380 -373
  223. package/src/integrations/postgres.ts +268 -264
  224. package/src/integrations/redis.ts +132 -128
  225. package/src/integrations/rest.ts +329 -324
  226. package/src/integrations/s3.ts +71 -68
  227. package/src/integrations/snowflake.ts +82 -80
  228. package/src/integrations/tests/{airtable.spec.ts → airtable.spec.js} +18 -21
  229. package/src/integrations/tests/{arangodb.spec.ts → arangodb.spec.js} +9 -12
  230. package/src/integrations/tests/{couchdb.spec.ts → couchdb.spec.js} +27 -33
  231. package/src/integrations/tests/{dynamodb.spec.ts → dynamodb.spec.js} +41 -45
  232. package/src/integrations/tests/{elasticsearch.spec.ts → elasticsearch.spec.js} +21 -22
  233. package/src/integrations/tests/{firebase.spec.ts → firebase.spec.js} +28 -33
  234. package/src/integrations/tests/{microsoftSqlServer.spec.ts → microsoftSqlServer.spec.js} +11 -12
  235. package/src/integrations/tests/{mongo.spec.ts → mongo.spec.js} +35 -46
  236. package/src/integrations/tests/{mysql.spec.ts → mysql.spec.js} +15 -17
  237. package/src/integrations/tests/{oracle.spec.ts → oracle.spec.js} +17 -19
  238. package/src/integrations/tests/{postgres.spec.ts → postgres.spec.js} +17 -19
  239. package/src/integrations/tests/{redis.spec.ts → redis.spec.js} +18 -27
  240. package/src/integrations/tests/{rest.spec.ts → rest.spec.js} +14 -22
  241. package/src/integrations/tests/{s3.spec.ts → s3.spec.js} +8 -10
  242. package/src/integrations/tests/{sql.spec.ts → sql.spec.js} +177 -228
  243. package/src/module.d.ts +0 -1
  244. package/src/threads/query.ts +2 -2
  245. package/src/utilities/fileSystem/index.js +9 -70
  246. package/builder/assets/index.b266d29f.js +0 -995
  247. package/dist/api/controllers/plugin.js +0 -119
  248. package/dist/api/routes/plugin.js +0 -38
  249. package/dist/watch.js +0 -77
  250. package/src/api/controllers/plugin.ts +0 -110
  251. package/src/api/routes/plugin.ts +0 -13
  252. package/src/watch.ts +0 -38
@@ -11,274 +11,277 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const types_1 = require("@budibase/types");
13
13
  const mongodb_1 = require("mongodb");
14
- const SCHEMA = {
15
- docs: "https://github.com/mongodb/node-mongodb-native",
16
- friendlyName: "MongoDB",
17
- type: "Non-relational",
18
- description: "MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.",
19
- datasource: {
20
- connectionString: {
21
- type: types_1.DatasourceFieldType.STRING,
22
- required: true,
23
- default: "mongodb://localhost:27017",
24
- },
25
- db: {
26
- type: types_1.DatasourceFieldType.STRING,
27
- required: true,
28
- },
29
- },
30
- query: {
31
- create: {
32
- type: types_1.QueryType.JSON,
33
- },
34
- read: {
35
- type: types_1.QueryType.JSON,
36
- },
37
- update: {
38
- type: types_1.QueryType.JSON,
39
- },
40
- delete: {
41
- type: types_1.QueryType.JSON,
14
+ var MongoDBModule;
15
+ (function (MongoDBModule) {
16
+ const SCHEMA = {
17
+ docs: "https://github.com/mongodb/node-mongodb-native",
18
+ friendlyName: "MongoDB",
19
+ type: "Non-relational",
20
+ description: "MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.",
21
+ datasource: {
22
+ connectionString: {
23
+ type: types_1.DatasourceFieldType.STRING,
24
+ required: true,
25
+ default: "mongodb://localhost:27017",
26
+ },
27
+ db: {
28
+ type: types_1.DatasourceFieldType.STRING,
29
+ required: true,
30
+ },
42
31
  },
43
- },
44
- extra: {
45
- collection: {
46
- displayName: "Collection",
47
- type: types_1.DatasourceFieldType.STRING,
48
- required: true,
32
+ query: {
33
+ create: {
34
+ type: types_1.QueryType.JSON,
35
+ },
36
+ read: {
37
+ type: types_1.QueryType.JSON,
38
+ },
39
+ update: {
40
+ type: types_1.QueryType.JSON,
41
+ },
42
+ delete: {
43
+ type: types_1.QueryType.JSON,
44
+ },
49
45
  },
50
- actionTypes: {
51
- displayName: "Action Types",
52
- type: types_1.DatasourceFieldType.LIST,
53
- required: true,
54
- data: {
55
- read: ["find", "findOne", "findOneAndUpdate", "count", "distinct"],
56
- create: ["insertOne", "insertMany"],
57
- update: ["updateOne", "updateMany"],
58
- delete: ["deleteOne", "deleteMany"],
46
+ extra: {
47
+ collection: {
48
+ displayName: "Collection",
49
+ type: types_1.DatasourceFieldType.STRING,
50
+ required: true,
51
+ },
52
+ actionTypes: {
53
+ displayName: "Action Types",
54
+ type: types_1.DatasourceFieldType.LIST,
55
+ required: true,
56
+ data: {
57
+ read: ["find", "findOne", "findOneAndUpdate", "count", "distinct"],
58
+ create: ["insertOne", "insertMany"],
59
+ update: ["updateOne", "updateMany"],
60
+ delete: ["deleteOne", "deleteMany"],
61
+ },
59
62
  },
60
63
  },
61
- },
62
- };
63
- class MongoIntegration {
64
- constructor(config) {
65
- this.config = config;
66
- this.client = new mongodb_1.MongoClient(config.connectionString);
67
- }
68
- connect() {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- return this.client.connect();
71
- });
72
- }
73
- createObjectIds(json) {
74
- const self = this;
75
- function interpolateObjectIds(json) {
76
- var _a;
77
- for (let field of Object.keys(json)) {
78
- if (json[field] instanceof Object) {
79
- json[field] = self.createObjectIds(json[field]);
80
- }
81
- if (typeof json[field] === "string" &&
82
- json[field].toLowerCase().startsWith("objectid")) {
83
- const id = (_a = json[field].match(/(?<=objectid\(['"]).*(?=['"]\))/gi)) === null || _a === void 0 ? void 0 : _a[0];
84
- if (id) {
85
- json[field] = mongodb_1.ObjectID.createFromHexString(id);
64
+ };
65
+ class MongoIntegration {
66
+ constructor(config) {
67
+ this.config = config;
68
+ this.client = new mongodb_1.MongoClient(config.connectionString);
69
+ }
70
+ connect() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ return this.client.connect();
73
+ });
74
+ }
75
+ createObjectIds(json) {
76
+ const self = this;
77
+ function interpolateObjectIds(json) {
78
+ var _a;
79
+ for (let field of Object.keys(json)) {
80
+ if (json[field] instanceof Object) {
81
+ json[field] = self.createObjectIds(json[field]);
82
+ }
83
+ if (typeof json[field] === "string" &&
84
+ json[field].toLowerCase().startsWith("objectid")) {
85
+ const id = (_a = json[field].match(/(?<=objectid\(['"]).*(?=['"]\))/gi)) === null || _a === void 0 ? void 0 : _a[0];
86
+ if (id) {
87
+ json[field] = mongodb_1.ObjectID.createFromHexString(id);
88
+ }
86
89
  }
87
90
  }
91
+ return json;
88
92
  }
89
- return json;
90
- }
91
- if (Array.isArray(json)) {
92
- for (let i = 0; i < json.length; i++) {
93
- json[i] = interpolateObjectIds(json[i]);
93
+ if (Array.isArray(json)) {
94
+ for (let i = 0; i < json.length; i++) {
95
+ json[i] = interpolateObjectIds(json[i]);
96
+ }
97
+ return json;
94
98
  }
95
- return json;
99
+ return interpolateObjectIds(json);
96
100
  }
97
- return interpolateObjectIds(json);
98
- }
99
- parseQueryParams(params, mode) {
100
- var _a, _b, _c;
101
- let queryParams = [];
102
- let openCount = 0;
103
- let inQuotes = false;
104
- let i = 0;
105
- let startIndex = 0;
106
- for (let c of params) {
107
- if (c === '"' && i > 0 && params[i - 1] !== "\\") {
108
- inQuotes = !inQuotes;
109
- }
110
- if (c === "{" && !inQuotes) {
111
- openCount++;
112
- if (openCount === 1) {
113
- startIndex = i;
101
+ parseQueryParams(params, mode) {
102
+ var _a, _b, _c;
103
+ let queryParams = [];
104
+ let openCount = 0;
105
+ let inQuotes = false;
106
+ let i = 0;
107
+ let startIndex = 0;
108
+ for (let c of params) {
109
+ if (c === '"' && i > 0 && params[i - 1] !== "\\") {
110
+ inQuotes = !inQuotes;
114
111
  }
115
- }
116
- else if (c === "}" && !inQuotes) {
117
- if (openCount === 1) {
118
- queryParams.push(JSON.parse(params.substring(startIndex, i + 1)));
112
+ if (c === "{" && !inQuotes) {
113
+ openCount++;
114
+ if (openCount === 1) {
115
+ startIndex = i;
116
+ }
117
+ }
118
+ else if (c === "}" && !inQuotes) {
119
+ if (openCount === 1) {
120
+ queryParams.push(JSON.parse(params.substring(startIndex, i + 1)));
121
+ }
122
+ openCount--;
119
123
  }
120
- openCount--;
124
+ i++;
125
+ }
126
+ let group1 = (_a = queryParams[0]) !== null && _a !== void 0 ? _a : {};
127
+ let group2 = (_b = queryParams[1]) !== null && _b !== void 0 ? _b : {};
128
+ let group3 = (_c = queryParams[2]) !== null && _c !== void 0 ? _c : {};
129
+ if (mode === "update") {
130
+ return {
131
+ filter: group1,
132
+ update: group2,
133
+ options: group3,
134
+ };
121
135
  }
122
- i++;
123
- }
124
- let group1 = (_a = queryParams[0]) !== null && _a !== void 0 ? _a : {};
125
- let group2 = (_b = queryParams[1]) !== null && _b !== void 0 ? _b : {};
126
- let group3 = (_c = queryParams[2]) !== null && _c !== void 0 ? _c : {};
127
- if (mode === "update") {
128
136
  return {
129
137
  filter: group1,
130
- update: group2,
131
- options: group3,
138
+ options: group2,
132
139
  };
133
140
  }
134
- return {
135
- filter: group1,
136
- options: group2,
137
- };
138
- }
139
- create(query) {
140
- return __awaiter(this, void 0, void 0, function* () {
141
- try {
142
- yield this.connect();
143
- const db = this.client.db(this.config.db);
144
- const collection = db.collection(query.extra.collection);
145
- let json = this.createObjectIds(query.json);
146
- // For mongodb we add an extra actionType to specify
147
- // which method we want to call on the collection
148
- switch (query.extra.actionTypes) {
149
- case "insertOne": {
150
- return yield collection.insertOne(json);
151
- }
152
- case "insertMany": {
153
- return yield collection.insertMany(json);
154
- }
155
- default: {
156
- throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for create`);
141
+ create(query) {
142
+ return __awaiter(this, void 0, void 0, function* () {
143
+ try {
144
+ yield this.connect();
145
+ const db = this.client.db(this.config.db);
146
+ const collection = db.collection(query.extra.collection);
147
+ let json = this.createObjectIds(query.json);
148
+ // For mongodb we add an extra actionType to specify
149
+ // which method we want to call on the collection
150
+ switch (query.extra.actionTypes) {
151
+ case "insertOne": {
152
+ return yield collection.insertOne(json);
153
+ }
154
+ case "insertMany": {
155
+ return yield collection.insertMany(json);
156
+ }
157
+ default: {
158
+ throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for create`);
159
+ }
157
160
  }
158
161
  }
159
- }
160
- catch (err) {
161
- console.error("Error writing to mongodb", err);
162
- throw err;
163
- }
164
- finally {
165
- yield this.client.close();
166
- }
167
- });
168
- }
169
- read(query) {
170
- return __awaiter(this, void 0, void 0, function* () {
171
- try {
172
- yield this.connect();
173
- const db = this.client.db(this.config.db);
174
- const collection = db.collection(query.extra.collection);
175
- let json = this.createObjectIds(query.json);
176
- switch (query.extra.actionTypes) {
177
- case "find": {
178
- return yield collection.find(json).toArray();
179
- }
180
- case "findOne": {
181
- return yield collection.findOne(json);
182
- }
183
- case "findOneAndUpdate": {
184
- if (typeof query.json === "string") {
185
- json = this.parseQueryParams(query.json, "update");
162
+ catch (err) {
163
+ console.error("Error writing to mongodb", err);
164
+ throw err;
165
+ }
166
+ finally {
167
+ yield this.client.close();
168
+ }
169
+ });
170
+ }
171
+ read(query) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ try {
174
+ yield this.connect();
175
+ const db = this.client.db(this.config.db);
176
+ const collection = db.collection(query.extra.collection);
177
+ let json = this.createObjectIds(query.json);
178
+ switch (query.extra.actionTypes) {
179
+ case "find": {
180
+ return yield collection.find(json).toArray();
181
+ }
182
+ case "findOne": {
183
+ return yield collection.findOne(json);
184
+ }
185
+ case "findOneAndUpdate": {
186
+ if (typeof query.json === "string") {
187
+ json = this.parseQueryParams(query.json, "update");
188
+ }
189
+ let findAndUpdateJson = this.createObjectIds(json);
190
+ return yield collection.findOneAndUpdate(findAndUpdateJson.filter, findAndUpdateJson.update, findAndUpdateJson.options);
191
+ }
192
+ case "count": {
193
+ return yield collection.countDocuments(json);
194
+ }
195
+ case "distinct": {
196
+ return yield collection.distinct(json);
197
+ }
198
+ default: {
199
+ throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for read`);
186
200
  }
187
- let findAndUpdateJson = this.createObjectIds(json);
188
- return yield collection.findOneAndUpdate(findAndUpdateJson.filter, findAndUpdateJson.update, findAndUpdateJson.options);
189
- }
190
- case "count": {
191
- return yield collection.countDocuments(json);
192
- }
193
- case "distinct": {
194
- return yield collection.distinct(json);
195
- }
196
- default: {
197
- throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for read`);
198
201
  }
199
202
  }
200
- }
201
- catch (err) {
202
- console.error("Error querying mongodb", err);
203
- throw err;
204
- }
205
- finally {
206
- yield this.client.close();
207
- }
208
- });
209
- }
210
- update(query) {
211
- return __awaiter(this, void 0, void 0, function* () {
212
- try {
213
- yield this.connect();
214
- const db = this.client.db(this.config.db);
215
- const collection = db.collection(query.extra.collection);
216
- let queryJson = query.json;
217
- if (typeof queryJson === "string") {
218
- queryJson = this.parseQueryParams(queryJson, "update");
203
+ catch (err) {
204
+ console.error("Error querying mongodb", err);
205
+ throw err;
219
206
  }
220
- let json = this.createObjectIds(queryJson);
221
- switch (query.extra.actionTypes) {
222
- case "updateOne": {
223
- return yield collection.updateOne(json.filter, json.update, json.options);
224
- }
225
- case "updateMany": {
226
- return yield collection.updateMany(json.filter, json.update, json.options);
207
+ finally {
208
+ yield this.client.close();
209
+ }
210
+ });
211
+ }
212
+ update(query) {
213
+ return __awaiter(this, void 0, void 0, function* () {
214
+ try {
215
+ yield this.connect();
216
+ const db = this.client.db(this.config.db);
217
+ const collection = db.collection(query.extra.collection);
218
+ let queryJson = query.json;
219
+ if (typeof queryJson === "string") {
220
+ queryJson = this.parseQueryParams(queryJson, "update");
227
221
  }
228
- default: {
229
- throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for update`);
222
+ let json = this.createObjectIds(queryJson);
223
+ switch (query.extra.actionTypes) {
224
+ case "updateOne": {
225
+ return yield collection.updateOne(json.filter, json.update, json.options);
226
+ }
227
+ case "updateMany": {
228
+ return yield collection.updateMany(json.filter, json.update, json.options);
229
+ }
230
+ default: {
231
+ throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for update`);
232
+ }
230
233
  }
231
234
  }
232
- }
233
- catch (err) {
234
- console.error("Error writing to mongodb", err);
235
- throw err;
236
- }
237
- finally {
238
- yield this.client.close();
239
- }
240
- });
241
- }
242
- delete(query) {
243
- return __awaiter(this, void 0, void 0, function* () {
244
- try {
245
- yield this.connect();
246
- const db = this.client.db(this.config.db);
247
- const collection = db.collection(query.extra.collection);
248
- let queryJson = query.json;
249
- if (typeof queryJson === "string") {
250
- queryJson = this.parseQueryParams(queryJson, "delete");
235
+ catch (err) {
236
+ console.error("Error writing to mongodb", err);
237
+ throw err;
251
238
  }
252
- let json = this.createObjectIds(queryJson);
253
- if (!json.options) {
254
- json = {
255
- filter: json,
256
- options: {},
257
- };
239
+ finally {
240
+ yield this.client.close();
258
241
  }
259
- switch (query.extra.actionTypes) {
260
- case "deleteOne": {
261
- return yield collection.deleteOne(json.filter, json.options);
242
+ });
243
+ }
244
+ delete(query) {
245
+ return __awaiter(this, void 0, void 0, function* () {
246
+ try {
247
+ yield this.connect();
248
+ const db = this.client.db(this.config.db);
249
+ const collection = db.collection(query.extra.collection);
250
+ let queryJson = query.json;
251
+ if (typeof queryJson === "string") {
252
+ queryJson = this.parseQueryParams(queryJson, "delete");
262
253
  }
263
- case "deleteMany": {
264
- return yield collection.deleteMany(json.filter, json.options);
254
+ let json = this.createObjectIds(queryJson);
255
+ if (!json.options) {
256
+ json = {
257
+ filter: json,
258
+ options: {},
259
+ };
265
260
  }
266
- default: {
267
- throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for delete`);
261
+ switch (query.extra.actionTypes) {
262
+ case "deleteOne": {
263
+ return yield collection.deleteOne(json.filter, json.options);
264
+ }
265
+ case "deleteMany": {
266
+ return yield collection.deleteMany(json.filter, json.options);
267
+ }
268
+ default: {
269
+ throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for delete`);
270
+ }
268
271
  }
269
272
  }
270
- }
271
- catch (err) {
272
- console.error("Error writing to mongodb", err);
273
- throw err;
274
- }
275
- finally {
276
- yield this.client.close();
277
- }
278
- });
273
+ catch (err) {
274
+ console.error("Error writing to mongodb", err);
275
+ throw err;
276
+ }
277
+ finally {
278
+ yield this.client.close();
279
+ }
280
+ });
281
+ }
279
282
  }
280
- }
281
- exports.default = {
282
- schema: SCHEMA,
283
- integration: MongoIntegration,
284
- };
283
+ module.exports = {
284
+ schema: SCHEMA,
285
+ integration: MongoIntegration,
286
+ };
287
+ })(MongoDBModule || (MongoDBModule = {}));