@budibase/server 1.3.21 → 1.3.22-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__mocks__/mongodb.ts +1 -1
- package/builder/assets/index.96c69636.js +1008 -0
- package/builder/assets/index.c167b5c3.css +6 -0
- package/builder/index.html +2 -4
- package/coverage/clover.xml +308 -338
- package/coverage/coverage-final.json +19 -21
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +41 -8
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +73 -34
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +27 -57
- package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +13 -13
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +2 -2
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +9 -9
- package/coverage/lcov-report/api/routes/utils/validators.js.html +75 -12
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +14 -14
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +30 -18
- package/coverage/lcov-report/events/AutomationEmitter.js.html +3 -3
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +44 -44
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +12 -12
- package/coverage/lcov-report/middleware/currentapp.js.html +46 -40
- package/coverage/lcov-report/middleware/index.html +15 -15
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +16 -16
- package/coverage/lcov-report/utilities/index.html +15 -15
- package/coverage/lcov-report/utilities/index.js.html +24 -24
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +32 -8
- package/coverage/lcov.info +521 -558
- package/dist/api/controllers/application.js +5 -5
- package/dist/api/controllers/auth.js +9 -0
- package/dist/api/controllers/component.js +19 -6
- package/dist/api/controllers/datasource.js +21 -8
- package/dist/api/controllers/deploy/index.js +1 -8
- package/dist/api/controllers/integration.js +4 -4
- package/dist/{migrations/functions/usageQuotas/syncDevelopers.js → api/controllers/plugin/file.js} +13 -13
- package/dist/api/controllers/plugin/github.js +69 -0
- package/dist/api/controllers/plugin/index.js +144 -0
- package/dist/api/controllers/plugin/npm.js +58 -0
- package/dist/api/controllers/plugin/uploaders.js +11 -0
- package/dist/{migrations/functions/usageQuotas/syncPublishedApps.js → api/controllers/plugin/url.js} +13 -15
- package/dist/api/controllers/plugin/utils.js +26 -0
- package/dist/api/controllers/row/external.js +1 -1
- package/dist/api/controllers/screen.js +62 -14
- package/dist/api/controllers/static/index.js +1 -0
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -0
- package/dist/api/controllers/static/templates/preview.hbs +5 -1
- package/dist/api/index.js +1 -1
- package/dist/api/routes/application.js +3 -2
- package/dist/api/routes/index.js +2 -0
- package/dist/{migrations/functions/publishedAppsQuota.js → api/routes/plugin.js} +13 -21
- package/dist/api/routes/public/rows.js +1 -82
- package/dist/api/routes/public/tables.js +1 -1
- package/dist/api/routes/table.js +1 -1
- package/dist/api/routes/utils/validators.js +20 -2
- package/dist/app.js +16 -1
- package/dist/db/utils.js +3 -0
- package/dist/environment.js +1 -0
- package/dist/integrations/airtable.js +126 -129
- package/dist/integrations/arangodb.js +86 -89
- package/dist/integrations/base/query.js +2 -2
- package/dist/integrations/base/sqlTable.js +3 -1
- package/dist/integrations/couchdb.js +80 -83
- package/dist/integrations/dynamodb.js +161 -164
- package/dist/integrations/elasticsearch.js +135 -138
- package/dist/integrations/firebase.js +154 -157
- package/dist/integrations/googlesheets.js +323 -327
- package/dist/integrations/index.js +99 -51
- package/dist/integrations/microsoftSqlServer.js +240 -243
- package/dist/integrations/mongodb.js +239 -242
- package/dist/integrations/mysql.js +215 -219
- package/dist/integrations/oracle.js +318 -322
- package/dist/integrations/postgres.js +262 -265
- package/dist/integrations/redis.js +134 -139
- package/dist/integrations/rest.js +289 -292
- package/dist/integrations/s3.js +61 -64
- package/dist/integrations/snowflake.js +83 -86
- package/dist/middleware/currentapp.js +2 -0
- package/dist/migrations/functions/backfill/global.js +0 -3
- package/dist/migrations/index.js +0 -10
- package/dist/package.json +9 -6
- package/dist/tests/utilities/TestConfiguration.js +1 -1
- package/dist/threads/query.js +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +105 -1
- package/dist/utilities/workerRequests.js +4 -0
- package/dist/watch.js +77 -0
- package/dist/websocket.js +22 -0
- package/package.json +10 -7
- package/scripts/dev/manage.js +4 -0
- package/scripts/localdomain.js +3 -1
- package/specs/openapi.json +115 -112
- package/specs/openapi.yaml +96 -94
- package/specs/resources/misc.js +116 -0
- package/specs/resources/query.js +1 -1
- package/src/api/controllers/application.ts +1 -2
- package/src/api/controllers/auth.js +11 -0
- package/src/api/controllers/component.ts +57 -0
- package/src/api/controllers/datasource.js +21 -8
- package/src/api/controllers/deploy/index.ts +1 -6
- package/src/api/controllers/integration.js +4 -4
- package/src/api/controllers/plugin/file.ts +15 -0
- package/src/api/controllers/plugin/github.ts +75 -0
- package/src/api/controllers/plugin/index.ts +134 -0
- package/src/api/controllers/plugin/npm.ts +56 -0
- package/src/api/controllers/plugin/uploaders.ts +4 -0
- package/src/api/controllers/plugin/url.ts +12 -0
- package/src/api/controllers/plugin/utils.ts +19 -0
- package/src/api/controllers/public/mapping/types.ts +8 -0
- package/src/api/controllers/row/external.js +1 -1
- package/src/api/controllers/screen.ts +122 -0
- package/src/api/controllers/static/index.ts +1 -1
- package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
- package/src/api/controllers/static/templates/preview.hbs +5 -1
- package/src/api/index.js +1 -1
- package/src/api/routes/application.ts +13 -2
- package/src/api/routes/index.ts +2 -0
- package/src/api/routes/plugin.ts +14 -0
- package/src/api/routes/public/rows.ts +1 -82
- package/src/api/routes/public/tables.ts +1 -1
- package/src/api/routes/table.js +1 -1
- package/src/api/routes/tests/query.spec.js +8 -25
- package/src/api/routes/tests/user.spec.js +0 -2
- package/src/api/routes/utils/validators.js +26 -5
- package/src/app.ts +25 -2
- package/src/db/utils.js +4 -0
- package/src/definitions/openapi.ts +56 -55
- package/src/environment.js +1 -0
- package/src/integrations/airtable.ts +116 -118
- package/src/integrations/arangodb.ts +87 -89
- package/src/integrations/base/query.ts +2 -2
- package/src/integrations/base/sqlTable.ts +3 -1
- package/src/integrations/couchdb.ts +83 -89
- package/src/integrations/dynamodb.ts +173 -175
- package/src/integrations/elasticsearch.ts +120 -122
- package/src/integrations/firebase.ts +157 -159
- package/src/integrations/googlesheets.ts +328 -338
- package/src/integrations/index.ts +64 -21
- package/src/integrations/microsoftSqlServer.ts +249 -251
- package/src/integrations/mongodb.ts +261 -258
- package/src/integrations/mysql.ts +229 -234
- package/src/integrations/oracle.ts +373 -380
- package/src/integrations/postgres.ts +264 -268
- package/src/integrations/redis.ts +128 -132
- package/src/integrations/rest.ts +324 -329
- package/src/integrations/s3.ts +68 -71
- package/src/integrations/snowflake.ts +80 -82
- package/src/integrations/tests/{airtable.spec.js → airtable.spec.ts} +21 -18
- package/src/integrations/tests/{arangodb.spec.js → arangodb.spec.ts} +12 -9
- package/src/integrations/tests/{couchdb.spec.js → couchdb.spec.ts} +33 -27
- package/src/integrations/tests/{dynamodb.spec.js → dynamodb.spec.ts} +45 -41
- package/src/integrations/tests/{elasticsearch.spec.js → elasticsearch.spec.ts} +22 -21
- package/src/integrations/tests/{firebase.spec.js → firebase.spec.ts} +33 -28
- package/src/integrations/tests/{microsoftSqlServer.spec.js → microsoftSqlServer.spec.ts} +12 -11
- package/src/integrations/tests/{mongo.spec.js → mongo.spec.ts} +46 -35
- package/src/integrations/tests/{mysql.spec.js → mysql.spec.ts} +17 -15
- package/src/integrations/tests/{oracle.spec.js → oracle.spec.ts} +19 -17
- package/src/integrations/tests/{postgres.spec.js → postgres.spec.ts} +19 -17
- package/src/integrations/tests/{redis.spec.js → redis.spec.ts} +27 -18
- package/src/integrations/tests/{rest.spec.js → rest.spec.ts} +22 -14
- package/src/integrations/tests/{s3.spec.js → s3.spec.ts} +10 -8
- package/src/integrations/tests/{sql.spec.js → sql.spec.ts} +228 -177
- package/src/middleware/currentapp.js +2 -0
- package/src/migrations/functions/backfill/global.ts +0 -3
- package/src/migrations/index.ts +0 -16
- package/src/module.d.ts +2 -0
- package/src/tests/utilities/TestConfiguration.js +1 -1
- package/src/threads/query.ts +2 -2
- package/src/utilities/fileSystem/index.js +123 -0
- package/src/utilities/workerRequests.js +8 -0
- package/src/watch.ts +38 -0
- package/src/websocket.ts +26 -0
- package/builder/assets/index.8d12d461.css +0 -6
- package/builder/assets/index.d354271c.js +0 -879
- package/builder/assets/vendor.5e1fe644.css +0 -1
- package/builder/assets/vendor.67dbd8fa.js +0 -248
- package/coverage/lcov-report/api/controllers/component.js.html +0 -199
- package/coverage/lcov-report/api/controllers/screen.js.html +0 -259
- package/dist/migrations/functions/developerQuota.js +0 -49
- package/src/api/controllers/component.js +0 -38
- package/src/api/controllers/screen.js +0 -58
- package/src/migrations/functions/developerQuota.ts +0 -15
- package/src/migrations/functions/publishedAppsQuota.ts +0 -13
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
|
@@ -15,313 +15,316 @@ import {
|
|
|
15
15
|
CommonOptions,
|
|
16
16
|
} from "mongodb"
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
interface MongoDBConfig {
|
|
19
|
+
connectionString: string
|
|
20
|
+
db: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
interface MongoDBQuery {
|
|
24
|
+
json: object | string
|
|
25
|
+
extra: {
|
|
26
|
+
[key: string]: string
|
|
22
27
|
}
|
|
28
|
+
}
|
|
23
29
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
db: {
|
|
37
|
-
type: DatasourceFieldType.STRING,
|
|
38
|
-
required: true,
|
|
39
|
-
},
|
|
30
|
+
const SCHEMA: Integration = {
|
|
31
|
+
docs: "https://github.com/mongodb/node-mongodb-native",
|
|
32
|
+
friendlyName: "MongoDB",
|
|
33
|
+
type: "Non-relational",
|
|
34
|
+
description:
|
|
35
|
+
"MongoDB is a general purpose, document-based, distributed database built for modern application developers and for the cloud era.",
|
|
36
|
+
datasource: {
|
|
37
|
+
connectionString: {
|
|
38
|
+
type: DatasourceFieldType.STRING,
|
|
39
|
+
required: true,
|
|
40
|
+
default: "mongodb://localhost:27017",
|
|
40
41
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
},
|
|
45
|
-
read: {
|
|
46
|
-
type: QueryType.JSON,
|
|
47
|
-
},
|
|
48
|
-
update: {
|
|
49
|
-
type: QueryType.JSON,
|
|
50
|
-
},
|
|
51
|
-
delete: {
|
|
52
|
-
type: QueryType.JSON,
|
|
53
|
-
},
|
|
42
|
+
db: {
|
|
43
|
+
type: DatasourceFieldType.STRING,
|
|
44
|
+
required: true,
|
|
54
45
|
},
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
},
|
|
47
|
+
query: {
|
|
48
|
+
create: {
|
|
49
|
+
type: QueryType.JSON,
|
|
50
|
+
},
|
|
51
|
+
read: {
|
|
52
|
+
type: QueryType.JSON,
|
|
53
|
+
},
|
|
54
|
+
update: {
|
|
55
|
+
type: QueryType.JSON,
|
|
56
|
+
},
|
|
57
|
+
delete: {
|
|
58
|
+
type: QueryType.JSON,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
extra: {
|
|
62
|
+
collection: {
|
|
63
|
+
displayName: "Collection",
|
|
64
|
+
type: DatasourceFieldType.STRING,
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
actionTypes: {
|
|
68
|
+
displayName: "Action Types",
|
|
69
|
+
type: DatasourceFieldType.LIST,
|
|
70
|
+
required: true,
|
|
71
|
+
data: {
|
|
72
|
+
read: ["find", "findOne", "findOneAndUpdate", "count", "distinct"],
|
|
73
|
+
create: ["insertOne", "insertMany"],
|
|
74
|
+
update: ["updateOne", "updateMany"],
|
|
75
|
+
delete: ["deleteOne", "deleteMany"],
|
|
71
76
|
},
|
|
72
77
|
},
|
|
73
|
-
}
|
|
78
|
+
},
|
|
79
|
+
}
|
|
74
80
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
class MongoIntegration implements IntegrationBase {
|
|
82
|
+
private config: MongoDBConfig
|
|
83
|
+
private client: any
|
|
78
84
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
constructor(config: MongoDBConfig) {
|
|
86
|
+
this.config = config
|
|
87
|
+
this.client = new MongoClient(config.connectionString)
|
|
88
|
+
}
|
|
83
89
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
90
|
+
async connect() {
|
|
91
|
+
return this.client.connect()
|
|
92
|
+
}
|
|
87
93
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
if (id) {
|
|
103
|
-
json[field] = ObjectID.createFromHexString(id)
|
|
104
|
-
}
|
|
94
|
+
createObjectIds(json: any): object {
|
|
95
|
+
const self = this
|
|
96
|
+
function interpolateObjectIds(json: any) {
|
|
97
|
+
for (let field of Object.keys(json)) {
|
|
98
|
+
if (json[field] instanceof Object) {
|
|
99
|
+
json[field] = self.createObjectIds(json[field])
|
|
100
|
+
}
|
|
101
|
+
if (
|
|
102
|
+
typeof json[field] === "string" &&
|
|
103
|
+
json[field].toLowerCase().startsWith("objectid")
|
|
104
|
+
) {
|
|
105
|
+
const id = json[field].match(/(?<=objectid\(['"]).*(?=['"]\))/gi)?.[0]
|
|
106
|
+
if (id) {
|
|
107
|
+
json[field] = ObjectID.createFromHexString(id)
|
|
105
108
|
}
|
|
106
109
|
}
|
|
107
|
-
return json
|
|
108
110
|
}
|
|
111
|
+
return json
|
|
112
|
+
}
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
return json
|
|
114
|
+
if (Array.isArray(json)) {
|
|
115
|
+
for (let i = 0; i < json.length; i++) {
|
|
116
|
+
json[i] = interpolateObjectIds(json[i])
|
|
115
117
|
}
|
|
116
|
-
return
|
|
118
|
+
return json
|
|
117
119
|
}
|
|
120
|
+
return interpolateObjectIds(json)
|
|
121
|
+
}
|
|
118
122
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
if (c === "{" && !inQuotes) {
|
|
130
|
-
openCount++
|
|
131
|
-
if (openCount === 1) {
|
|
132
|
-
startIndex = i
|
|
133
|
-
}
|
|
134
|
-
} else if (c === "}" && !inQuotes) {
|
|
135
|
-
if (openCount === 1) {
|
|
136
|
-
queryParams.push(JSON.parse(params.substring(startIndex, i + 1)))
|
|
137
|
-
}
|
|
138
|
-
openCount--
|
|
139
|
-
}
|
|
140
|
-
i++
|
|
123
|
+
parseQueryParams(params: string, mode: string) {
|
|
124
|
+
let queryParams = []
|
|
125
|
+
let openCount = 0
|
|
126
|
+
let inQuotes = false
|
|
127
|
+
let i = 0
|
|
128
|
+
let startIndex = 0
|
|
129
|
+
for (let c of params) {
|
|
130
|
+
if (c === '"' && i > 0 && params[i - 1] !== "\\") {
|
|
131
|
+
inQuotes = !inQuotes
|
|
141
132
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
133
|
+
if (c === "{" && !inQuotes) {
|
|
134
|
+
openCount++
|
|
135
|
+
if (openCount === 1) {
|
|
136
|
+
startIndex = i
|
|
137
|
+
}
|
|
138
|
+
} else if (c === "}" && !inQuotes) {
|
|
139
|
+
if (openCount === 1) {
|
|
140
|
+
queryParams.push(JSON.parse(params.substring(startIndex, i + 1)))
|
|
150
141
|
}
|
|
142
|
+
openCount--
|
|
151
143
|
}
|
|
144
|
+
i++
|
|
145
|
+
}
|
|
146
|
+
let group1 = queryParams[0] ?? {}
|
|
147
|
+
let group2 = queryParams[1] ?? {}
|
|
148
|
+
let group3 = queryParams[2] ?? {}
|
|
149
|
+
if (mode === "update") {
|
|
152
150
|
return {
|
|
153
151
|
filter: group1,
|
|
154
|
-
|
|
152
|
+
update: group2,
|
|
153
|
+
options: group3,
|
|
155
154
|
}
|
|
156
155
|
}
|
|
156
|
+
return {
|
|
157
|
+
filter: group1,
|
|
158
|
+
options: group2,
|
|
159
|
+
}
|
|
160
|
+
}
|
|
157
161
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
async create(query: MongoDBQuery) {
|
|
163
|
+
try {
|
|
164
|
+
await this.connect()
|
|
165
|
+
const db = this.client.db(this.config.db)
|
|
166
|
+
const collection = db.collection(query.extra.collection)
|
|
167
|
+
let json = this.createObjectIds(query.json)
|
|
164
168
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
169
|
+
// For mongodb we add an extra actionType to specify
|
|
170
|
+
// which method we want to call on the collection
|
|
171
|
+
switch (query.extra.actionTypes) {
|
|
172
|
+
case "insertOne": {
|
|
173
|
+
return await collection.insertOne(json)
|
|
174
|
+
}
|
|
175
|
+
case "insertMany": {
|
|
176
|
+
return await collection.insertMany(json)
|
|
177
|
+
}
|
|
178
|
+
default: {
|
|
179
|
+
throw new Error(
|
|
180
|
+
`actionType ${query.extra.actionTypes} does not exist on DB for create`
|
|
181
|
+
)
|
|
179
182
|
}
|
|
180
|
-
} catch (err) {
|
|
181
|
-
console.error("Error writing to mongodb", err)
|
|
182
|
-
throw err
|
|
183
|
-
} finally {
|
|
184
|
-
await this.client.close()
|
|
185
183
|
}
|
|
184
|
+
} catch (err) {
|
|
185
|
+
console.error("Error writing to mongodb", err)
|
|
186
|
+
throw err
|
|
187
|
+
} finally {
|
|
188
|
+
await this.client.close()
|
|
186
189
|
}
|
|
190
|
+
}
|
|
187
191
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
async read(query: MongoDBQuery) {
|
|
193
|
+
try {
|
|
194
|
+
await this.connect()
|
|
195
|
+
const db = this.client.db(this.config.db)
|
|
196
|
+
const collection = db.collection(query.extra.collection)
|
|
197
|
+
let json = this.createObjectIds(query.json)
|
|
194
198
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
206
|
-
let findAndUpdateJson = this.createObjectIds(json) as {
|
|
207
|
-
filter: FilterQuery<any>
|
|
208
|
-
update: UpdateQuery<any>
|
|
209
|
-
options: FindOneAndUpdateOption<any>
|
|
210
|
-
}
|
|
211
|
-
return await collection.findOneAndUpdate(
|
|
212
|
-
findAndUpdateJson.filter,
|
|
213
|
-
findAndUpdateJson.update,
|
|
214
|
-
findAndUpdateJson.options
|
|
215
|
-
)
|
|
216
|
-
}
|
|
217
|
-
case "count": {
|
|
218
|
-
return await collection.countDocuments(json)
|
|
219
|
-
}
|
|
220
|
-
case "distinct": {
|
|
221
|
-
return await collection.distinct(json)
|
|
199
|
+
switch (query.extra.actionTypes) {
|
|
200
|
+
case "find": {
|
|
201
|
+
return await collection.find(json).toArray()
|
|
202
|
+
}
|
|
203
|
+
case "findOne": {
|
|
204
|
+
return await collection.findOne(json)
|
|
205
|
+
}
|
|
206
|
+
case "findOneAndUpdate": {
|
|
207
|
+
if (typeof query.json === "string") {
|
|
208
|
+
json = this.parseQueryParams(query.json, "update")
|
|
222
209
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
210
|
+
let findAndUpdateJson = this.createObjectIds(json) as {
|
|
211
|
+
filter: FilterQuery<any>
|
|
212
|
+
update: UpdateQuery<any>
|
|
213
|
+
options: FindOneAndUpdateOption<any>
|
|
227
214
|
}
|
|
215
|
+
return await collection.findOneAndUpdate(
|
|
216
|
+
findAndUpdateJson.filter,
|
|
217
|
+
findAndUpdateJson.update,
|
|
218
|
+
findAndUpdateJson.options
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
case "count": {
|
|
222
|
+
return await collection.countDocuments(json)
|
|
223
|
+
}
|
|
224
|
+
case "distinct": {
|
|
225
|
+
return await collection.distinct(json)
|
|
226
|
+
}
|
|
227
|
+
default: {
|
|
228
|
+
throw new Error(
|
|
229
|
+
`actionType ${query.extra.actionTypes} does not exist on DB for read`
|
|
230
|
+
)
|
|
228
231
|
}
|
|
229
|
-
} catch (err) {
|
|
230
|
-
console.error("Error querying mongodb", err)
|
|
231
|
-
throw err
|
|
232
|
-
} finally {
|
|
233
|
-
await this.client.close()
|
|
234
232
|
}
|
|
233
|
+
} catch (err) {
|
|
234
|
+
console.error("Error querying mongodb", err)
|
|
235
|
+
throw err
|
|
236
|
+
} finally {
|
|
237
|
+
await this.client.close()
|
|
235
238
|
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
async update(query: MongoDBQuery) {
|
|
242
|
+
try {
|
|
243
|
+
await this.connect()
|
|
244
|
+
const db = this.client.db(this.config.db)
|
|
245
|
+
const collection = db.collection(query.extra.collection)
|
|
246
|
+
let queryJson = query.json
|
|
247
|
+
if (typeof queryJson === "string") {
|
|
248
|
+
queryJson = this.parseQueryParams(queryJson, "update")
|
|
249
|
+
}
|
|
250
|
+
let json = this.createObjectIds(queryJson) as {
|
|
251
|
+
filter: FilterQuery<any>
|
|
252
|
+
update: UpdateQuery<any>
|
|
253
|
+
options: object
|
|
254
|
+
}
|
|
236
255
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
queryJson = this.parseQueryParams(queryJson, "update")
|
|
256
|
+
switch (query.extra.actionTypes) {
|
|
257
|
+
case "updateOne": {
|
|
258
|
+
return await collection.updateOne(
|
|
259
|
+
json.filter,
|
|
260
|
+
json.update,
|
|
261
|
+
json.options as UpdateOneOptions
|
|
262
|
+
)
|
|
245
263
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
264
|
+
case "updateMany": {
|
|
265
|
+
return await collection.updateMany(
|
|
266
|
+
json.filter,
|
|
267
|
+
json.update,
|
|
268
|
+
json.options as UpdateManyOptions
|
|
269
|
+
)
|
|
250
270
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
json.filter,
|
|
256
|
-
json.update,
|
|
257
|
-
json.options as UpdateOneOptions
|
|
258
|
-
)
|
|
259
|
-
}
|
|
260
|
-
case "updateMany": {
|
|
261
|
-
return await collection.updateMany(
|
|
262
|
-
json.filter,
|
|
263
|
-
json.update,
|
|
264
|
-
json.options as UpdateManyOptions
|
|
265
|
-
)
|
|
266
|
-
}
|
|
267
|
-
default: {
|
|
268
|
-
throw new Error(
|
|
269
|
-
`actionType ${query.extra.actionTypes} does not exist on DB for update`
|
|
270
|
-
)
|
|
271
|
-
}
|
|
271
|
+
default: {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`actionType ${query.extra.actionTypes} does not exist on DB for update`
|
|
274
|
+
)
|
|
272
275
|
}
|
|
273
|
-
} catch (err) {
|
|
274
|
-
console.error("Error writing to mongodb", err)
|
|
275
|
-
throw err
|
|
276
|
-
} finally {
|
|
277
|
-
await this.client.close()
|
|
278
276
|
}
|
|
277
|
+
} catch (err) {
|
|
278
|
+
console.error("Error writing to mongodb", err)
|
|
279
|
+
throw err
|
|
280
|
+
} finally {
|
|
281
|
+
await this.client.close()
|
|
279
282
|
}
|
|
283
|
+
}
|
|
280
284
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
285
|
+
async delete(query: MongoDBQuery) {
|
|
286
|
+
try {
|
|
287
|
+
await this.connect()
|
|
288
|
+
const db = this.client.db(this.config.db)
|
|
289
|
+
const collection = db.collection(query.extra.collection)
|
|
290
|
+
let queryJson = query.json
|
|
291
|
+
if (typeof queryJson === "string") {
|
|
292
|
+
queryJson = this.parseQueryParams(queryJson, "delete")
|
|
293
|
+
}
|
|
294
|
+
let json = this.createObjectIds(queryJson) as {
|
|
295
|
+
filter: FilterQuery<any>
|
|
296
|
+
options: CommonOptions
|
|
297
|
+
}
|
|
298
|
+
if (!json.options) {
|
|
299
|
+
json = {
|
|
300
|
+
filter: json,
|
|
301
|
+
options: {},
|
|
289
302
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
switch (query.extra.actionTypes) {
|
|
306
|
+
case "deleteOne": {
|
|
307
|
+
return await collection.deleteOne(json.filter, json.options)
|
|
293
308
|
}
|
|
294
|
-
|
|
295
|
-
json
|
|
296
|
-
filter: json,
|
|
297
|
-
options: {},
|
|
298
|
-
}
|
|
309
|
+
case "deleteMany": {
|
|
310
|
+
return await collection.deleteMany(json.filter, json.options)
|
|
299
311
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
case "deleteMany": {
|
|
306
|
-
return await collection.deleteMany(json.filter, json.options)
|
|
307
|
-
}
|
|
308
|
-
default: {
|
|
309
|
-
throw new Error(
|
|
310
|
-
`actionType ${query.extra.actionTypes} does not exist on DB for delete`
|
|
311
|
-
)
|
|
312
|
-
}
|
|
312
|
+
default: {
|
|
313
|
+
throw new Error(
|
|
314
|
+
`actionType ${query.extra.actionTypes} does not exist on DB for delete`
|
|
315
|
+
)
|
|
313
316
|
}
|
|
314
|
-
} catch (err) {
|
|
315
|
-
console.error("Error writing to mongodb", err)
|
|
316
|
-
throw err
|
|
317
|
-
} finally {
|
|
318
|
-
await this.client.close()
|
|
319
317
|
}
|
|
318
|
+
} catch (err) {
|
|
319
|
+
console.error("Error writing to mongodb", err)
|
|
320
|
+
throw err
|
|
321
|
+
} finally {
|
|
322
|
+
await this.client.close()
|
|
320
323
|
}
|
|
321
324
|
}
|
|
325
|
+
}
|
|
322
326
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
+
export default {
|
|
328
|
+
schema: SCHEMA,
|
|
329
|
+
integration: MongoIntegration,
|
|
327
330
|
}
|