@budibase/server 1.3.14 → 1.3.15-alpha.0

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 (250) hide show
  1. package/__mocks__/mongodb.ts +1 -1
  2. package/builder/assets/index.b266d29f.js +995 -0
  3. package/builder/assets/{index.a70e216a.css → index.f5c54dd2.css} +2 -2
  4. package/builder/index.html +2 -4
  5. package/coverage/clover.xml +296 -254
  6. package/coverage/coverage-final.json +17 -17
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  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/component.js.html +82 -13
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +20 -20
  14. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/index.html +30 -30
  16. package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
  17. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/screen.js.html +204 -12
  32. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  45. package/coverage/lcov-report/api/index.html +1 -1
  46. package/coverage/lcov-report/api/index.js.html +12 -12
  47. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/index.html +1 -1
  58. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  72. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  75. package/coverage/lcov-report/automations/actions.js.html +1 -1
  76. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  77. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  78. package/coverage/lcov-report/automations/index.html +1 -1
  79. package/coverage/lcov-report/automations/index.js.html +1 -1
  80. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  81. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/index.html +1 -1
  87. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  97. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  98. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  106. package/coverage/lcov-report/constants/index.html +1 -1
  107. package/coverage/lcov-report/constants/index.js.html +1 -1
  108. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  109. package/coverage/lcov-report/constants/screens.js.html +1 -1
  110. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  111. package/coverage/lcov-report/db/index.html +18 -18
  112. package/coverage/lcov-report/db/index.js.html +1 -1
  113. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  114. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  116. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  117. package/coverage/lcov-report/db/newid.js.html +2 -2
  118. package/coverage/lcov-report/db/utils.js.html +56 -20
  119. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  120. package/coverage/lcov-report/events/index.html +1 -1
  121. package/coverage/lcov-report/events/index.js.html +1 -1
  122. package/coverage/lcov-report/events/utils.js.html +1 -1
  123. package/coverage/lcov-report/index.html +28 -28
  124. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  125. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  126. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  127. package/coverage/lcov-report/middleware/builder.js.html +12 -12
  128. package/coverage/lcov-report/middleware/currentapp.js.html +33 -33
  129. package/coverage/lcov-report/middleware/index.html +1 -1
  130. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  131. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  132. package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
  133. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  134. package/coverage/lcov-report/middleware/utils.js.html +2 -2
  135. package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
  136. package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
  137. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  138. package/coverage/lcov-report/utilities/global.js.html +16 -16
  139. package/coverage/lcov-report/utilities/index.html +1 -1
  140. package/coverage/lcov-report/utilities/index.js.html +24 -24
  141. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
  142. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  143. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  144. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  145. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  146. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  148. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  149. package/coverage/lcov-report/utilities/security.js.html +2 -2
  150. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  151. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  152. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  153. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  154. package/coverage/lcov-report/utilities/users.js.html +1 -1
  155. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  156. package/coverage/lcov.info +533 -445
  157. package/dist/api/controllers/application.js +5 -4
  158. package/dist/api/controllers/component.js +18 -1
  159. package/dist/api/controllers/datasource.js +4 -4
  160. package/dist/api/controllers/integration.js +4 -4
  161. package/dist/api/controllers/plugin.js +119 -0
  162. package/dist/api/controllers/screen.js +51 -2
  163. package/dist/api/controllers/static/index.js +1 -0
  164. package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  165. package/dist/api/controllers/static/templates/preview.hbs +3 -1
  166. package/dist/api/routes/index.js +2 -0
  167. package/dist/api/routes/plugin.js +38 -0
  168. package/dist/app.js +9 -0
  169. package/dist/db/utils.js +10 -1
  170. package/dist/environment.js +1 -0
  171. package/dist/integrations/airtable.js +126 -129
  172. package/dist/integrations/arangodb.js +86 -89
  173. package/dist/integrations/base/query.js +2 -2
  174. package/dist/integrations/couchdb.js +80 -83
  175. package/dist/integrations/dynamodb.js +161 -164
  176. package/dist/integrations/elasticsearch.js +135 -138
  177. package/dist/integrations/firebase.js +154 -157
  178. package/dist/integrations/googlesheets.js +323 -327
  179. package/dist/integrations/index.js +93 -51
  180. package/dist/integrations/microsoftSqlServer.js +240 -243
  181. package/dist/integrations/mongodb.js +239 -242
  182. package/dist/integrations/mysql.js +215 -219
  183. package/dist/integrations/oracle.js +318 -322
  184. package/dist/integrations/postgres.js +262 -265
  185. package/dist/integrations/redis.js +134 -139
  186. package/dist/integrations/rest.js +289 -292
  187. package/dist/integrations/s3.js +61 -64
  188. package/dist/integrations/snowflake.js +83 -86
  189. package/dist/package.json +7 -5
  190. package/dist/threads/query.js +2 -2
  191. package/dist/tsconfig.build.tsbuildinfo +1 -1
  192. package/dist/utilities/fileSystem/index.js +65 -0
  193. package/dist/watch.js +77 -0
  194. package/package.json +8 -6
  195. package/scripts/dev/manage.js +1 -0
  196. package/src/api/controllers/application.ts +1 -1
  197. package/src/api/controllers/component.js +25 -2
  198. package/src/api/controllers/datasource.js +4 -4
  199. package/src/api/controllers/integration.js +4 -4
  200. package/src/api/controllers/plugin.ts +110 -0
  201. package/src/api/controllers/screen.js +65 -1
  202. package/src/api/controllers/static/index.ts +1 -0
  203. package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
  204. package/src/api/controllers/static/templates/preview.hbs +3 -1
  205. package/src/api/routes/index.ts +2 -0
  206. package/src/api/routes/plugin.ts +13 -0
  207. package/src/api/routes/tests/query.spec.js +8 -25
  208. package/src/app.ts +12 -0
  209. package/src/db/utils.js +12 -0
  210. package/src/environment.js +1 -0
  211. package/src/integrations/airtable.ts +116 -118
  212. package/src/integrations/arangodb.ts +87 -89
  213. package/src/integrations/base/query.ts +2 -2
  214. package/src/integrations/couchdb.ts +83 -89
  215. package/src/integrations/dynamodb.ts +173 -175
  216. package/src/integrations/elasticsearch.ts +120 -122
  217. package/src/integrations/firebase.ts +157 -159
  218. package/src/integrations/googlesheets.ts +328 -338
  219. package/src/integrations/index.ts +59 -21
  220. package/src/integrations/microsoftSqlServer.ts +249 -251
  221. package/src/integrations/mongodb.ts +261 -258
  222. package/src/integrations/mysql.ts +229 -234
  223. package/src/integrations/oracle.ts +373 -380
  224. package/src/integrations/postgres.ts +264 -268
  225. package/src/integrations/redis.ts +128 -132
  226. package/src/integrations/rest.ts +324 -329
  227. package/src/integrations/s3.ts +68 -71
  228. package/src/integrations/snowflake.ts +80 -82
  229. package/src/integrations/tests/{airtable.spec.js → airtable.spec.ts} +21 -18
  230. package/src/integrations/tests/{arangodb.spec.js → arangodb.spec.ts} +12 -9
  231. package/src/integrations/tests/{couchdb.spec.js → couchdb.spec.ts} +33 -27
  232. package/src/integrations/tests/{dynamodb.spec.js → dynamodb.spec.ts} +45 -41
  233. package/src/integrations/tests/{elasticsearch.spec.js → elasticsearch.spec.ts} +22 -21
  234. package/src/integrations/tests/{firebase.spec.js → firebase.spec.ts} +33 -28
  235. package/src/integrations/tests/{microsoftSqlServer.spec.js → microsoftSqlServer.spec.ts} +12 -11
  236. package/src/integrations/tests/{mongo.spec.js → mongo.spec.ts} +46 -35
  237. package/src/integrations/tests/{mysql.spec.js → mysql.spec.ts} +17 -15
  238. package/src/integrations/tests/{oracle.spec.js → oracle.spec.ts} +19 -17
  239. package/src/integrations/tests/{postgres.spec.js → postgres.spec.ts} +19 -17
  240. package/src/integrations/tests/{redis.spec.js → redis.spec.ts} +27 -18
  241. package/src/integrations/tests/{rest.spec.js → rest.spec.ts} +22 -14
  242. package/src/integrations/tests/{s3.spec.js → s3.spec.ts} +10 -8
  243. package/src/integrations/tests/{sql.spec.js → sql.spec.ts} +228 -177
  244. package/src/module.d.ts +1 -0
  245. package/src/threads/query.ts +2 -2
  246. package/src/utilities/fileSystem/index.js +69 -0
  247. package/src/watch.ts +38 -0
  248. package/builder/assets/index.d8428ac8.js +0 -876
  249. package/builder/assets/vendor.5e1fe644.css +0 -1
  250. package/builder/assets/vendor.67dbd8fa.js +0 -248
@@ -11,277 +11,274 @@ 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
- 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
- },
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",
31
24
  },
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
- },
25
+ db: {
26
+ type: types_1.DatasourceFieldType.STRING,
27
+ required: true,
45
28
  },
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
- },
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,
42
+ },
43
+ },
44
+ extra: {
45
+ collection: {
46
+ displayName: "Collection",
47
+ type: types_1.DatasourceFieldType.STRING,
48
+ required: true,
49
+ },
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"],
62
59
  },
63
60
  },
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
- }
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);
89
86
  }
90
87
  }
91
- return json;
92
88
  }
93
- if (Array.isArray(json)) {
94
- for (let i = 0; i < json.length; i++) {
95
- json[i] = interpolateObjectIds(json[i]);
96
- }
97
- return json;
89
+ return json;
90
+ }
91
+ if (Array.isArray(json)) {
92
+ for (let i = 0; i < json.length; i++) {
93
+ json[i] = interpolateObjectIds(json[i]);
98
94
  }
99
- return interpolateObjectIds(json);
95
+ return json;
100
96
  }
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;
111
- }
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--;
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;
123
114
  }
124
- i++;
125
115
  }
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
- };
116
+ else if (c === "}" && !inQuotes) {
117
+ if (openCount === 1) {
118
+ queryParams.push(JSON.parse(params.substring(startIndex, i + 1)));
119
+ }
120
+ openCount--;
135
121
  }
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") {
136
128
  return {
137
129
  filter: group1,
138
- options: group2,
130
+ update: group2,
131
+ options: group3,
139
132
  };
140
133
  }
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
- }
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`);
160
157
  }
161
158
  }
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`);
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");
200
186
  }
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`);
201
198
  }
202
199
  }
203
- catch (err) {
204
- console.error("Error querying mongodb", err);
205
- throw err;
206
- }
207
- finally {
208
- yield this.client.close();
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");
209
219
  }
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");
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);
221
224
  }
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
- }
225
+ case "updateMany": {
226
+ return yield collection.updateMany(json.filter, json.update, json.options);
227
+ }
228
+ default: {
229
+ throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for update`);
233
230
  }
234
231
  }
235
- catch (err) {
236
- console.error("Error writing to mongodb", err);
237
- throw err;
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");
238
251
  }
239
- finally {
240
- yield this.client.close();
252
+ let json = this.createObjectIds(queryJson);
253
+ if (!json.options) {
254
+ json = {
255
+ filter: json,
256
+ options: {},
257
+ };
241
258
  }
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");
259
+ switch (query.extra.actionTypes) {
260
+ case "deleteOne": {
261
+ return yield collection.deleteOne(json.filter, json.options);
253
262
  }
254
- let json = this.createObjectIds(queryJson);
255
- if (!json.options) {
256
- json = {
257
- filter: json,
258
- options: {},
259
- };
263
+ case "deleteMany": {
264
+ return yield collection.deleteMany(json.filter, json.options);
260
265
  }
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
- }
266
+ default: {
267
+ throw new Error(`actionType ${query.extra.actionTypes} does not exist on DB for delete`);
271
268
  }
272
269
  }
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
- }
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
+ });
282
279
  }
283
- module.exports = {
284
- schema: SCHEMA,
285
- integration: MongoIntegration,
286
- };
287
- })(MongoDBModule || (MongoDBModule = {}));
280
+ }
281
+ exports.default = {
282
+ schema: SCHEMA,
283
+ integration: MongoIntegration,
284
+ };