@budibase/server 2.0.33 → 2.0.34-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.
- package/__mocks__/mongodb.ts +1 -1
- package/builder/assets/backups-default.8c011f1b.png +0 -0
- package/builder/assets/{index.dfa4073c.css → index.b15ffe95.css} +2 -2
- package/builder/assets/{index.ce49a649.js → index.d09d1931.js} +340 -332
- package/builder/index.html +2 -2
- package/coverage/clover.xml +634 -689
- package/coverage/coverage-final.json +34 -36
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +74 -62
- package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +2 -2
- package/coverage/lcov-report/api/controllers/index.html +17 -32
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +12 -12
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +15 -15
- package/coverage/lcov-report/api/controllers/row/utils.js.html +13 -13
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +12 -9
- package/coverage/lcov-report/api/controllers/table/external.js.html +10 -10
- package/coverage/lcov-report/api/controllers/table/index.html +16 -16
- package/coverage/lcov-report/api/controllers/table/index.js.html +5 -5
- 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 +3 -3
- 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 +7 -7
- 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/automation.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 +5 -20
- 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 +1 -1
- 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 +1 -1
- package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
- 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 +6 -6
- package/coverage/lcov-report/automations/bullboard.js.html +17 -92
- package/coverage/lcov-report/automations/index.html +18 -18
- package/coverage/lcov-report/automations/index.js.html +9 -9
- 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 +3 -3
- 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 +26 -26
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +10 -16
- 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 +19 -19
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +11 -11
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +3 -3
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +37 -316
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +2 -2
- package/coverage/lcov-report/events/utils.js.html +9 -9
- package/coverage/lcov-report/index.html +77 -77
- 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 +11 -11
- package/coverage/lcov-report/middleware/currentapp.js.html +34 -34
- package/coverage/lcov-report/middleware/index.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +11 -8
- 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 +7 -7
- package/coverage/lcov-report/utilities/plugins.js.html +1 -1
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +52 -52
- package/coverage/lcov-report/utilities/queue/index.html +21 -21
- 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 +54 -39
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +10 -10
- 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 +14 -14
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +23 -11
- 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 +1 -1
- package/coverage/lcov.info +1141 -1246
- package/dist/api/controllers/application.js +4 -7
- package/dist/api/controllers/backup.js +19 -13
- package/dist/api/controllers/cloud.js +38 -35
- package/dist/api/controllers/deploy/index.js +11 -2
- package/dist/api/controllers/dev.js +1 -1
- package/dist/api/controllers/query/index.js +7 -2
- package/dist/api/controllers/row/index.js +30 -10
- package/dist/api/controllers/static/index.js +2 -2
- package/dist/api/controllers/static/templates/preview.hbs +10 -0
- package/dist/api/controllers/table/bulkFormula.js +4 -3
- package/dist/api/controllers/table/external.js +5 -4
- package/dist/api/controllers/table/index.js +4 -4
- package/dist/api/controllers/table/internal.js +10 -3
- package/dist/api/controllers/table/utils.js +7 -49
- package/dist/api/controllers/view/index.js +2 -2
- package/dist/api/routes/backup.js +34 -7
- package/dist/api/routes/index.js +9 -4
- package/dist/app.js +14 -0
- package/dist/automations/automationUtils.js +2 -2
- package/dist/automations/bullboard.js +5 -33
- package/dist/automations/index.js +4 -4
- package/dist/automations/steps/updateRow.js +2 -2
- package/dist/automations/triggers.js +4 -4
- package/dist/automations/utils.js +18 -12
- package/dist/constants/index.js +4 -5
- package/dist/db/utils.js +10 -75
- package/dist/index.js +1 -0
- package/dist/integrations/arangodb.js +2 -0
- package/dist/integrations/base/sqlTable.js +1 -0
- package/dist/integrations/mongodb.js +300 -11
- package/dist/integrations/rest.js +38 -5
- package/dist/migrations/functions/backfill/app/tables.js +5 -8
- package/dist/migrations/functions/{quotas1.js → syncQuotas.js} +3 -7
- package/dist/migrations/functions/usageQuotas/syncApps.js +0 -1
- package/dist/migrations/functions/{pluginCount.js → usageQuotas/syncPlugins.js} +1 -3
- package/dist/migrations/functions/usageQuotas/syncRows.js +9 -5
- package/dist/migrations/index.js +9 -38
- package/dist/package.json +14 -14
- package/dist/sdk/app/backups/constants.js +5 -0
- package/dist/sdk/app/backups/exports.js +172 -0
- package/dist/sdk/app/backups/imports.js +162 -0
- package/dist/sdk/app/backups/index.js +29 -0
- package/dist/sdk/app/backups/statistics.js +73 -0
- package/dist/sdk/app/tables/index.js +61 -0
- package/dist/sdk/index.js +15 -0
- package/dist/tests/utilities/TestConfiguration.js +4 -2
- package/dist/threads/automation.js +12 -17
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +1 -0
- package/dist/utilities/fileSystem/index.js +3 -95
- package/dist/utilities/fileSystem/utilities.js +2 -1
- package/dist/utilities/rowProcessor/index.js +5 -0
- package/dist/utilities/usageQuota/rows.js +6 -4
- package/package.json +15 -15
- package/specs/openapi.json +3 -0
- package/specs/openapi.yaml +3 -0
- package/src/api/controllers/application.ts +5 -12
- package/src/api/controllers/{backup.js → backup.ts} +7 -7
- package/src/api/controllers/cloud.js +44 -40
- package/src/api/controllers/deploy/index.ts +20 -8
- package/src/api/controllers/dev.js +1 -1
- package/src/api/controllers/query/index.ts +8 -2
- package/src/api/controllers/row/index.ts +36 -13
- package/src/api/controllers/static/index.ts +2 -2
- package/src/api/controllers/static/templates/preview.hbs +10 -0
- package/src/api/controllers/table/bulkFormula.js +4 -3
- package/src/api/controllers/table/external.js +4 -4
- package/src/api/controllers/table/index.js +4 -4
- package/src/api/controllers/table/internal.ts +8 -9
- package/src/api/controllers/table/utils.ts +4 -53
- package/src/api/controllers/view/index.js +2 -2
- package/src/api/routes/backup.ts +10 -0
- package/src/api/routes/index.ts +11 -5
- package/src/api/routes/tests/backup.spec.js +1 -1
- package/src/api/routes/tests/{deployment.spec.js → deployment.spec.ts} +4 -4
- package/src/api/routes/tests/row.spec.js +22 -27
- package/src/app.ts +15 -0
- package/src/automations/automationUtils.js +2 -2
- package/src/automations/bullboard.js +8 -33
- package/src/automations/index.js +4 -4
- package/src/automations/steps/updateRow.js +2 -2
- package/src/automations/tests/automation.spec.js +1 -6
- package/src/automations/triggers.js +4 -4
- package/src/automations/utils.ts +18 -12
- package/src/constants/index.js +4 -6
- package/src/db/utils.js +17 -110
- package/src/definitions/automations.ts +0 -12
- package/src/definitions/datasource.ts +1 -0
- package/src/index.ts +1 -0
- package/src/integrations/arangodb.ts +2 -0
- package/src/integrations/base/sqlTable.ts +1 -0
- package/src/integrations/mongodb.ts +290 -27
- package/src/integrations/rest.ts +17 -5
- package/src/integrations/tests/mongo.spec.ts +19 -19
- package/src/integrations/tests/rest.spec.ts +38 -22
- package/src/migrations/functions/backfill/app/tables.ts +7 -13
- package/src/migrations/functions/backfill/global.ts +1 -1
- package/src/migrations/functions/{quotas1.ts → syncQuotas.ts} +3 -8
- package/src/migrations/functions/tests/{quotas1.spec.js → syncQuotas.spec.js} +5 -2
- package/src/migrations/functions/usageQuotas/syncApps.ts +0 -1
- package/src/migrations/functions/usageQuotas/syncPlugins.ts +10 -0
- package/src/migrations/functions/usageQuotas/syncRows.ts +15 -6
- package/src/migrations/functions/usageQuotas/tests/syncRows.spec.ts +9 -1
- package/src/migrations/index.ts +20 -45
- package/src/migrations/tests/index.spec.ts +0 -1
- package/src/sdk/app/backups/constants.ts +2 -0
- package/src/sdk/app/backups/exports.ts +171 -0
- package/src/sdk/app/backups/imports.ts +169 -0
- package/src/sdk/app/backups/index.ts +9 -0
- package/src/sdk/app/backups/statistics.ts +78 -0
- package/src/sdk/app/tables/index.ts +61 -0
- package/src/sdk/index.ts +13 -0
- package/src/tests/utilities/TestConfiguration.js +5 -2
- package/src/threads/automation.ts +20 -27
- package/src/utilities/csvParser.js +1 -0
- package/src/utilities/fileSystem/index.js +2 -119
- package/src/utilities/fileSystem/utilities.js +2 -0
- package/src/utilities/rowProcessor/index.js +5 -0
- package/src/utilities/usageQuota/rows.js +7 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +0 -142
- package/coverage/lcov-report/api/routes/backup.js.html +0 -115
- package/dist/automations/listeners.js +0 -102
- package/src/api/routes/backup.js +0 -10
- package/src/automations/listeners.ts +0 -78
- package/src/migrations/functions/pluginCount.ts +0 -12
package/dist/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/server",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.33",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -77,23 +77,23 @@
|
|
|
77
77
|
"license": "GPL-3.0",
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
80
|
-
"@budibase/backend-core": "^2.0.
|
|
81
|
-
"@budibase/client": "^2.0.
|
|
82
|
-
"@budibase/pro": "2.0.
|
|
83
|
-
"@budibase/string-templates": "^2.0.
|
|
84
|
-
"@budibase/types": "^2.0.
|
|
80
|
+
"@budibase/backend-core": "^2.0.33",
|
|
81
|
+
"@budibase/client": "^2.0.33",
|
|
82
|
+
"@budibase/pro": "2.0.33",
|
|
83
|
+
"@budibase/string-templates": "^2.0.33",
|
|
84
|
+
"@budibase/types": "^2.0.33",
|
|
85
85
|
"@bull-board/api": "3.7.0",
|
|
86
86
|
"@bull-board/koa": "3.9.4",
|
|
87
87
|
"@elastic/elasticsearch": "7.10.0",
|
|
88
88
|
"@google-cloud/firestore": "5.0.2",
|
|
89
|
-
"@koa/router": "8.0.
|
|
89
|
+
"@koa/router": "8.0.8",
|
|
90
90
|
"@sendgrid/mail": "7.1.1",
|
|
91
91
|
"@sentry/node": "6.17.7",
|
|
92
92
|
"airtable": "0.10.1",
|
|
93
93
|
"arangojs": "7.2.0",
|
|
94
94
|
"aws-sdk": "2.1030.0",
|
|
95
95
|
"bcryptjs": "2.4.3",
|
|
96
|
-
"bull": "4.
|
|
96
|
+
"bull": "4.10.1",
|
|
97
97
|
"chmodr": "1.2.0",
|
|
98
98
|
"chokidar": "3.5.3",
|
|
99
99
|
"csvtojson": "2.0.10",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"js-yaml": "4.1.0",
|
|
113
113
|
"jsonschema": "1.4.0",
|
|
114
114
|
"knex": "0.95.15",
|
|
115
|
-
"koa": "2.
|
|
115
|
+
"koa": "2.13.4",
|
|
116
116
|
"koa-body": "4.2.0",
|
|
117
117
|
"koa-compress": "4.0.1",
|
|
118
118
|
"koa-connect": "2.1.0",
|
|
@@ -123,7 +123,7 @@
|
|
|
123
123
|
"koa2-ratelimit": "1.1.1",
|
|
124
124
|
"lodash": "4.17.21",
|
|
125
125
|
"memorystream": "0.3.1",
|
|
126
|
-
"mongodb": "
|
|
126
|
+
"mongodb": "4.9",
|
|
127
127
|
"mssql": "6.2.3",
|
|
128
128
|
"mysql2": "2.3.3",
|
|
129
129
|
"node-fetch": "2.6.7",
|
|
@@ -146,7 +146,7 @@
|
|
|
146
146
|
"to-json-schema": "0.2.5",
|
|
147
147
|
"uuid": "3.3.2",
|
|
148
148
|
"validate.js": "0.13.1",
|
|
149
|
-
"vm2": "3.9.
|
|
149
|
+
"vm2": "3.9.11",
|
|
150
150
|
"worker-farm": "1.7.0",
|
|
151
151
|
"xml2js": "0.4.23",
|
|
152
152
|
"yargs": "13.2.4",
|
|
@@ -159,17 +159,17 @@
|
|
|
159
159
|
"@jest/test-sequencer": "24.9.0",
|
|
160
160
|
"@types/apidoc": "0.50.0",
|
|
161
161
|
"@types/bson": "4.2.0",
|
|
162
|
-
"@types/bull": "3.15.8",
|
|
163
162
|
"@types/global-agent": "2.1.1",
|
|
164
163
|
"@types/google-spreadsheet": "3.1.5",
|
|
164
|
+
"@types/ioredis": "4.28.10",
|
|
165
165
|
"@types/jest": "27.5.1",
|
|
166
166
|
"@types/koa": "2.13.4",
|
|
167
|
-
"@types/koa__router": "8.0.
|
|
167
|
+
"@types/koa__router": "8.0.11",
|
|
168
168
|
"@types/lodash": "4.14.180",
|
|
169
|
-
"@types/mongodb": "3.6.3",
|
|
170
169
|
"@types/node": "14.18.20",
|
|
171
170
|
"@types/node-fetch": "2.6.1",
|
|
172
171
|
"@types/oracledb": "5.2.2",
|
|
172
|
+
"@types/pouchdb": "6.4.0",
|
|
173
173
|
"@types/redis": "4.0.11",
|
|
174
174
|
"@typescript-eslint/parser": "5.12.0",
|
|
175
175
|
"apidoc": "0.50.4",
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.streamExportApp = exports.exportMultipleApps = exports.exportApp = exports.exportDB = void 0;
|
|
16
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
17
|
+
const budibaseDir_1 = require("../../../utilities/budibaseDir");
|
|
18
|
+
const utilities_1 = require("../../../utilities/fileSystem/utilities");
|
|
19
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
20
|
+
const constants_1 = require("../../../constants");
|
|
21
|
+
const utils_1 = require("../../../db/utils");
|
|
22
|
+
const constants_2 = require("./constants");
|
|
23
|
+
const fs_1 = __importDefault(require("fs"));
|
|
24
|
+
const path_1 = require("path");
|
|
25
|
+
const environment_1 = __importDefault(require("../../../environment"));
|
|
26
|
+
const uuid = require("uuid/v4");
|
|
27
|
+
const tar = require("tar");
|
|
28
|
+
const MemoryStream = require("memorystream");
|
|
29
|
+
function tarFilesToTmp(tmpDir, files) {
|
|
30
|
+
const exportFile = (0, path_1.join)((0, budibaseDir_1.budibaseTempDir)(), `${uuid()}.tar.gz`);
|
|
31
|
+
tar.create({
|
|
32
|
+
sync: true,
|
|
33
|
+
gzip: true,
|
|
34
|
+
file: exportFile,
|
|
35
|
+
recursive: true,
|
|
36
|
+
cwd: tmpDir,
|
|
37
|
+
}, files);
|
|
38
|
+
return exportFile;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Exports a DB to either file or a variable (memory).
|
|
42
|
+
* @param {string} dbName the DB which is to be exported.
|
|
43
|
+
* @param {object} opts various options for the export, e.g. whether to stream,
|
|
44
|
+
* a filter function or the name of the export.
|
|
45
|
+
* @return {*} either a readable stream or a string
|
|
46
|
+
*/
|
|
47
|
+
function exportDB(dbName, opts = {}) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return backend_core_1.db.doWithDB(dbName, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
// Write the dump to file if required
|
|
51
|
+
if (opts === null || opts === void 0 ? void 0 : opts.exportPath) {
|
|
52
|
+
const path = opts === null || opts === void 0 ? void 0 : opts.exportPath;
|
|
53
|
+
const writeStream = fs_1.default.createWriteStream(path);
|
|
54
|
+
yield db.dump(writeStream, { filter: opts === null || opts === void 0 ? void 0 : opts.filter });
|
|
55
|
+
return path;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
// Stringify the dump in memory if required
|
|
59
|
+
const memStream = new MemoryStream();
|
|
60
|
+
let appString = "";
|
|
61
|
+
memStream.on("data", (chunk) => {
|
|
62
|
+
appString += chunk.toString();
|
|
63
|
+
});
|
|
64
|
+
yield db.dump(memStream, { filter: opts === null || opts === void 0 ? void 0 : opts.filter });
|
|
65
|
+
return appString;
|
|
66
|
+
}
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
exports.exportDB = exportDB;
|
|
71
|
+
function defineFilter(excludeRows) {
|
|
72
|
+
const ids = [utils_1.USER_METDATA_PREFIX, utils_1.LINK_USER_METADATA_PREFIX];
|
|
73
|
+
if (excludeRows) {
|
|
74
|
+
ids.push(utils_1.TABLE_ROW_PREFIX);
|
|
75
|
+
}
|
|
76
|
+
return (doc) => !ids.map(key => doc._id.includes(key)).reduce((prev, curr) => prev || curr);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Local utility to back up the database state for an app, excluding global user
|
|
80
|
+
* data or user relationships.
|
|
81
|
+
* @param {string} appId The app to back up
|
|
82
|
+
* @param {object} config Config to send to export DB/attachment export
|
|
83
|
+
* @returns {*} either a string or a stream of the backup
|
|
84
|
+
*/
|
|
85
|
+
function exportApp(appId, config) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
const prodAppId = backend_core_1.db.getProdAppID(appId);
|
|
88
|
+
const appPath = `${prodAppId}/`;
|
|
89
|
+
// export bucket contents
|
|
90
|
+
let tmpPath;
|
|
91
|
+
if (!environment_1.default.isTest()) {
|
|
92
|
+
tmpPath = yield (0, utilities_1.retrieveDirectory)(constants_1.ObjectStoreBuckets.APPS, appPath);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
tmpPath = (0, fileSystem_1.createTempFolder)(uuid());
|
|
96
|
+
}
|
|
97
|
+
const downloadedPath = (0, path_1.join)(tmpPath, appPath);
|
|
98
|
+
if (fs_1.default.existsSync(downloadedPath)) {
|
|
99
|
+
const allFiles = fs_1.default.readdirSync(downloadedPath);
|
|
100
|
+
for (let file of allFiles) {
|
|
101
|
+
const path = (0, path_1.join)(downloadedPath, file);
|
|
102
|
+
// move out of app directory, simplify structure
|
|
103
|
+
fs_1.default.renameSync(path, (0, path_1.join)(downloadedPath, "..", file));
|
|
104
|
+
}
|
|
105
|
+
// remove the old app directory created by object export
|
|
106
|
+
fs_1.default.rmdirSync(downloadedPath);
|
|
107
|
+
}
|
|
108
|
+
// enforce an export of app DB to the tmp path
|
|
109
|
+
const dbPath = (0, path_1.join)(tmpPath, constants_2.DB_EXPORT_FILE);
|
|
110
|
+
yield exportDB(appId, Object.assign(Object.assign({}, config), { filter: defineFilter(config === null || config === void 0 ? void 0 : config.excludeRows), exportPath: dbPath }));
|
|
111
|
+
// if tar requested, return where the tarball is
|
|
112
|
+
if (config === null || config === void 0 ? void 0 : config.tar) {
|
|
113
|
+
// now the tmpPath contains both the DB export and attachments, tar this
|
|
114
|
+
const tarPath = tarFilesToTmp(tmpPath, fs_1.default.readdirSync(tmpPath));
|
|
115
|
+
// cleanup the tmp export files as tarball returned
|
|
116
|
+
fs_1.default.rmSync(tmpPath, { recursive: true, force: true });
|
|
117
|
+
return tarPath;
|
|
118
|
+
}
|
|
119
|
+
// tar not requested, turn the directory where export is
|
|
120
|
+
else {
|
|
121
|
+
return tmpPath;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
exports.exportApp = exportApp;
|
|
126
|
+
/**
|
|
127
|
+
* Export all apps + global DB (if supplied) to a single tarball, this includes
|
|
128
|
+
* the attachments for each app as well.
|
|
129
|
+
* @param {object[]} appMetadata The IDs and names of apps to export.
|
|
130
|
+
* @param {string} globalDbContents The contents of the global DB to export as well.
|
|
131
|
+
* @return {string} The path to the tarball.
|
|
132
|
+
*/
|
|
133
|
+
function exportMultipleApps(appMetadata, globalDbContents) {
|
|
134
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
135
|
+
const tmpPath = (0, path_1.join)((0, budibaseDir_1.budibaseTempDir)(), uuid());
|
|
136
|
+
fs_1.default.mkdirSync(tmpPath);
|
|
137
|
+
let exportPromises = [];
|
|
138
|
+
// export each app to a directory, then move it into the complete export
|
|
139
|
+
const exportAndMove = (appId, appName) => __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
const path = yield exportApp(appId);
|
|
141
|
+
yield fs_1.default.promises.rename(path, (0, path_1.join)(tmpPath, appName));
|
|
142
|
+
});
|
|
143
|
+
for (let metadata of appMetadata) {
|
|
144
|
+
exportPromises.push(exportAndMove(metadata.appId, metadata.name));
|
|
145
|
+
}
|
|
146
|
+
// wait for all exports to finish
|
|
147
|
+
yield Promise.all(exportPromises);
|
|
148
|
+
// add the global DB contents
|
|
149
|
+
if (globalDbContents) {
|
|
150
|
+
fs_1.default.writeFileSync((0, path_1.join)(tmpPath, constants_2.GLOBAL_DB_EXPORT_FILE), globalDbContents);
|
|
151
|
+
}
|
|
152
|
+
const appNames = appMetadata.map(metadata => metadata.name);
|
|
153
|
+
const tarPath = tarFilesToTmp(tmpPath, [...appNames, constants_2.GLOBAL_DB_EXPORT_FILE]);
|
|
154
|
+
// clear up the tmp path now tarball generated
|
|
155
|
+
fs_1.default.rmSync(tmpPath, { recursive: true, force: true });
|
|
156
|
+
return tarPath;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
exports.exportMultipleApps = exportMultipleApps;
|
|
160
|
+
/**
|
|
161
|
+
* Streams a backup of the database state for an app
|
|
162
|
+
* @param {string} appId The ID of the app which is to be backed up.
|
|
163
|
+
* @param {boolean} excludeRows Flag to state whether the export should include data.
|
|
164
|
+
* @returns {*} a readable stream of the backup which is written in real time
|
|
165
|
+
*/
|
|
166
|
+
function streamExportApp(appId, excludeRows) {
|
|
167
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
168
|
+
const tmpPath = yield exportApp(appId, { excludeRows, tar: true });
|
|
169
|
+
return (0, fileSystem_1.streamFile)(tmpPath);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
exports.streamExportApp = streamExportApp;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.importApp = exports.getListOfAppsInMulti = exports.getGlobalDBFile = exports.untarFile = void 0;
|
|
16
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
17
|
+
const utils_1 = require("../../../db/utils");
|
|
18
|
+
const budibaseDir_1 = require("../../../utilities/budibaseDir");
|
|
19
|
+
const constants_1 = require("./constants");
|
|
20
|
+
const utilities_1 = require("../../../utilities/fileSystem/utilities");
|
|
21
|
+
const fileSystem_1 = require("../../../utilities/fileSystem");
|
|
22
|
+
const constants_2 = require("../../../constants");
|
|
23
|
+
const path_1 = require("path");
|
|
24
|
+
const fs_1 = __importDefault(require("fs"));
|
|
25
|
+
const __1 = __importDefault(require("../../"));
|
|
26
|
+
const uuid = require("uuid/v4");
|
|
27
|
+
const tar = require("tar");
|
|
28
|
+
function updateAttachmentColumns(prodAppId, db) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
// iterate through attachment documents and update them
|
|
31
|
+
const tables = yield __1.default.tables.getAllInternalTables(db);
|
|
32
|
+
for (let table of tables) {
|
|
33
|
+
const attachmentCols = [];
|
|
34
|
+
for (let [key, column] of Object.entries(table.schema)) {
|
|
35
|
+
if (column.type === constants_2.FieldTypes.ATTACHMENT) {
|
|
36
|
+
attachmentCols.push(key);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// no attachment columns, nothing to do
|
|
40
|
+
if (attachmentCols.length === 0) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
// use the CouchDB Mango query API to lookup rows that have attachments
|
|
44
|
+
const params = {
|
|
45
|
+
selector: {
|
|
46
|
+
_id: {
|
|
47
|
+
$regex: `^${utils_1.TABLE_ROW_PREFIX}`,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
attachmentCols.forEach(col => (params.selector[col] = { $exists: true }));
|
|
52
|
+
const { rows } = yield backend_core_1.db.directCouchFind(db.name, params);
|
|
53
|
+
for (let row of rows) {
|
|
54
|
+
for (let column of attachmentCols) {
|
|
55
|
+
if (!Array.isArray(row[column])) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
row[column] = row[column].map((attachment) => {
|
|
59
|
+
// URL looks like: /prod-budi-app-assets/appId/attachments/file.csv
|
|
60
|
+
const urlParts = attachment.url.split("/");
|
|
61
|
+
// drop the first empty element
|
|
62
|
+
urlParts.shift();
|
|
63
|
+
// get the prefix
|
|
64
|
+
const prefix = urlParts.shift();
|
|
65
|
+
// remove the app ID
|
|
66
|
+
urlParts.shift();
|
|
67
|
+
// add new app ID
|
|
68
|
+
urlParts.unshift(prodAppId);
|
|
69
|
+
const key = urlParts.join("/");
|
|
70
|
+
return Object.assign(Object.assign({}, attachment), { key, url: `/${prefix}/${key}` });
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// write back the updated attachments
|
|
75
|
+
yield db.bulkDocs(rows);
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* This function manages temporary template files which are stored by Koa.
|
|
81
|
+
* @param {Object} template The template object retrieved from the Koa context object.
|
|
82
|
+
* @returns {Object} Returns a fs read stream which can be loaded into the database.
|
|
83
|
+
*/
|
|
84
|
+
function getTemplateStream(template) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
if (template.file) {
|
|
87
|
+
return fs_1.default.createReadStream(template.file.path);
|
|
88
|
+
}
|
|
89
|
+
else if (template.key) {
|
|
90
|
+
const [type, name] = template.key.split("/");
|
|
91
|
+
const tmpPath = yield (0, fileSystem_1.downloadTemplate)(type, name);
|
|
92
|
+
return fs_1.default.createReadStream((0, path_1.join)(tmpPath, name, "db", "dump.txt"));
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function untarFile(file) {
|
|
97
|
+
const tmpPath = (0, path_1.join)((0, budibaseDir_1.budibaseTempDir)(), uuid());
|
|
98
|
+
fs_1.default.mkdirSync(tmpPath);
|
|
99
|
+
// extract the tarball
|
|
100
|
+
tar.extract({
|
|
101
|
+
sync: true,
|
|
102
|
+
cwd: tmpPath,
|
|
103
|
+
file: file.path,
|
|
104
|
+
});
|
|
105
|
+
return tmpPath;
|
|
106
|
+
}
|
|
107
|
+
exports.untarFile = untarFile;
|
|
108
|
+
function getGlobalDBFile(tmpPath) {
|
|
109
|
+
return fs_1.default.readFileSync((0, path_1.join)(tmpPath, constants_1.GLOBAL_DB_EXPORT_FILE), "utf8");
|
|
110
|
+
}
|
|
111
|
+
exports.getGlobalDBFile = getGlobalDBFile;
|
|
112
|
+
function getListOfAppsInMulti(tmpPath) {
|
|
113
|
+
return fs_1.default.readdirSync(tmpPath).filter(dir => dir !== constants_1.GLOBAL_DB_EXPORT_FILE);
|
|
114
|
+
}
|
|
115
|
+
exports.getListOfAppsInMulti = getListOfAppsInMulti;
|
|
116
|
+
function importApp(appId, db, template) {
|
|
117
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
let prodAppId = backend_core_1.db.getProdAppID(appId);
|
|
119
|
+
let dbStream;
|
|
120
|
+
const isTar = template.file && template.file.type === "application/gzip";
|
|
121
|
+
const isDirectory = template.file && fs_1.default.lstatSync(template.file.path).isDirectory();
|
|
122
|
+
if (template.file && (isTar || isDirectory)) {
|
|
123
|
+
const tmpPath = isTar ? untarFile(template.file) : template.file.path;
|
|
124
|
+
const contents = fs_1.default.readdirSync(tmpPath);
|
|
125
|
+
// have to handle object import
|
|
126
|
+
if (contents.length) {
|
|
127
|
+
let promises = [];
|
|
128
|
+
let excludedFiles = [constants_1.GLOBAL_DB_EXPORT_FILE, constants_1.DB_EXPORT_FILE];
|
|
129
|
+
for (let filename of contents) {
|
|
130
|
+
const path = (0, path_1.join)(tmpPath, filename);
|
|
131
|
+
if (excludedFiles.includes(filename)) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
filename = (0, path_1.join)(prodAppId, filename);
|
|
135
|
+
if (fs_1.default.lstatSync(path).isDirectory()) {
|
|
136
|
+
promises.push((0, utilities_1.uploadDirectory)(constants_2.ObjectStoreBuckets.APPS, path, filename));
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
promises.push((0, utilities_1.upload)({
|
|
140
|
+
bucket: constants_2.ObjectStoreBuckets.APPS,
|
|
141
|
+
path,
|
|
142
|
+
filename,
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
yield Promise.all(promises);
|
|
147
|
+
}
|
|
148
|
+
dbStream = fs_1.default.createReadStream((0, path_1.join)(tmpPath, constants_1.DB_EXPORT_FILE));
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
dbStream = yield getTemplateStream(template);
|
|
152
|
+
}
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
const { ok } = yield db.load(dbStream);
|
|
155
|
+
if (!ok) {
|
|
156
|
+
throw "Error loading database dump from template.";
|
|
157
|
+
}
|
|
158
|
+
yield updateAttachmentColumns(prodAppId, db);
|
|
159
|
+
return ok;
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
exports.importApp = importApp;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const exportApps = __importStar(require("./exports"));
|
|
27
|
+
const importApps = __importStar(require("./imports"));
|
|
28
|
+
const statistics = __importStar(require("./statistics"));
|
|
29
|
+
exports.default = Object.assign(Object.assign(Object.assign({}, exportApps), importApps), statistics);
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.calculateBackupStats = exports.calculateScreenCount = exports.calculateAutomationCount = exports.calculateDatasourceCount = void 0;
|
|
13
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
14
|
+
const utils_1 = require("../../../db/utils");
|
|
15
|
+
function runInContext(appId, cb, db) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (db) {
|
|
18
|
+
return cb(db);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const devAppId = backend_core_1.db.getDevAppID(appId);
|
|
22
|
+
return backend_core_1.context.doInAppContext(devAppId, () => {
|
|
23
|
+
const db = backend_core_1.context.getAppDB();
|
|
24
|
+
return cb(db);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function calculateDatasourceCount(appId, db) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
const datasourceList = yield db.allDocs((0, utils_1.getDatasourceParams)());
|
|
33
|
+
const tableList = yield db.allDocs((0, utils_1.getTableParams)());
|
|
34
|
+
return datasourceList.rows.length + tableList.rows.length;
|
|
35
|
+
}), db);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.calculateDatasourceCount = calculateDatasourceCount;
|
|
39
|
+
function calculateAutomationCount(appId, db) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
const automationList = yield db.allDocs((0, utils_1.getAutomationParams)());
|
|
43
|
+
return automationList.rows.length;
|
|
44
|
+
}), db);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.calculateAutomationCount = calculateAutomationCount;
|
|
48
|
+
function calculateScreenCount(appId, db) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
const screenList = yield db.allDocs((0, utils_1.getScreenParams)());
|
|
52
|
+
return screenList.rows.length;
|
|
53
|
+
}), db);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.calculateScreenCount = calculateScreenCount;
|
|
57
|
+
function calculateBackupStats(appId) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return runInContext(appId, (db) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
const promises = [];
|
|
61
|
+
promises.push(calculateDatasourceCount(appId, db));
|
|
62
|
+
promises.push(calculateAutomationCount(appId, db));
|
|
63
|
+
promises.push(calculateScreenCount(appId, db));
|
|
64
|
+
const responses = yield Promise.all(promises);
|
|
65
|
+
return {
|
|
66
|
+
datasources: responses[0],
|
|
67
|
+
automations: responses[1],
|
|
68
|
+
screens: responses[2],
|
|
69
|
+
};
|
|
70
|
+
}));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
exports.calculateBackupStats = calculateBackupStats;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const context_1 = require("@budibase/backend-core/context");
|
|
13
|
+
const utils_1 = require("../../../db/utils");
|
|
14
|
+
const utils_2 = require("../../../integrations/utils");
|
|
15
|
+
function getAllInternalTables(db) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
if (!db) {
|
|
18
|
+
db = (0, context_1.getAppDB)();
|
|
19
|
+
}
|
|
20
|
+
const internalTables = yield db.allDocs((0, utils_1.getTableParams)(null, {
|
|
21
|
+
include_docs: true,
|
|
22
|
+
}));
|
|
23
|
+
return internalTables.rows.map((tableDoc) => (Object.assign(Object.assign({}, tableDoc.doc), { type: "internal", sourceId: utils_1.BudibaseInternalDB._id })));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function getAllExternalTables(datasourceId) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const db = (0, context_1.getAppDB)();
|
|
29
|
+
const datasource = yield db.get(datasourceId);
|
|
30
|
+
if (!datasource || !datasource.entities) {
|
|
31
|
+
throw "Datasource is not configured fully.";
|
|
32
|
+
}
|
|
33
|
+
return datasource.entities;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function getExternalTable(datasourceId, tableName) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const entities = yield getAllExternalTables(datasourceId);
|
|
39
|
+
return entities[tableName];
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function getTable(tableId) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const db = (0, context_1.getAppDB)();
|
|
45
|
+
if ((0, utils_2.isExternalTable)(tableId)) {
|
|
46
|
+
let { datasourceId, tableName } = (0, utils_2.breakExternalTableId)(tableId);
|
|
47
|
+
const datasource = yield db.get(datasourceId);
|
|
48
|
+
const table = yield getExternalTable(datasourceId, tableName);
|
|
49
|
+
return Object.assign(Object.assign({}, table), { sql: (0, utils_2.isSQL)(datasource) });
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
return db.get(tableId);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
exports.default = {
|
|
57
|
+
getAllInternalTables,
|
|
58
|
+
getAllExternalTables,
|
|
59
|
+
getExternalTable,
|
|
60
|
+
getTable,
|
|
61
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const backups_1 = __importDefault(require("./app/backups"));
|
|
7
|
+
const tables_1 = __importDefault(require("./app/tables"));
|
|
8
|
+
const sdk = {
|
|
9
|
+
backups: backups_1.default,
|
|
10
|
+
tables: tables_1.default,
|
|
11
|
+
};
|
|
12
|
+
// default export for TS
|
|
13
|
+
exports.default = sdk;
|
|
14
|
+
// default export for JS
|
|
15
|
+
module.exports = sdk;
|
|
@@ -24,7 +24,7 @@ const newid = require("../../db/newid");
|
|
|
24
24
|
const context = require("@budibase/backend-core/context");
|
|
25
25
|
const { generateDevInfoID, SEPARATOR } = require("@budibase/backend-core/db");
|
|
26
26
|
const { encrypt } = require("@budibase/backend-core/encryption");
|
|
27
|
-
const { DocumentType } = require("../../db/utils");
|
|
27
|
+
const { DocumentType, generateUserMetadataID } = require("../../db/utils");
|
|
28
28
|
const GLOBAL_USER_ID = "us_uuid1";
|
|
29
29
|
const EMAIL = "babs@babs.com";
|
|
30
30
|
const FIRSTNAME = "Barbara";
|
|
@@ -87,7 +87,9 @@ class TestConfiguration {
|
|
|
87
87
|
// use a new id as the name to avoid name collisions
|
|
88
88
|
init(appName = newid()) {
|
|
89
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
yield this.globalUser();
|
|
90
|
+
this.user = yield this.globalUser();
|
|
91
|
+
this.globalUserId = this.user._id;
|
|
92
|
+
this.userMetadataId = generateUserMetadataID(this.globalUserId);
|
|
91
93
|
return this.createApp(appName);
|
|
92
94
|
});
|
|
93
95
|
}
|