@budibase/server 1.0.19-alpha.1 → 1.0.22
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__/node-fetch.ts +0 -3
- package/builder/assets/{index.2fc6da87.css → index.4fb3f887.css} +1 -1
- package/builder/assets/index.91de2761.js +1316 -0
- package/builder/assets/{vendor.a9288856.js → vendor.470042a4.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +372 -440
- package/coverage/coverage-final.json +16 -17
- package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
- 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/component.js.html +1 -1
- package/coverage/lcov-report/api/controllers/datasource.js.html +14 -14
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +38 -23
- 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/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/{query/index.js.html → query.js.html} +27 -159
- 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/index.js.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/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
- package/coverage/lcov-report/api/controllers/script.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/table/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +9 -108
- 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 +6 -18
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +1 -1
- 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/application.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/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +9 -9
- package/coverage/lcov-report/api/routes/index.js.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/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +98 -11
- 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/row.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/static.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 +2 -32
- 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/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.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/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/automations/utils.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +22 -22
- 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/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- 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 +4 -4
- package/coverage/lcov-report/db/utils.js.html +64 -91
- 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 +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +52 -67
- 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/authorized.js.html +2 -2
- package/coverage/lcov-report/middleware/builder.js.html +1 -1
- package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +3 -3
- package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +20 -20
- package/coverage/lcov-report/threads/index.js.html +1 -1
- package/coverage/lcov-report/threads/query.js.html +12 -63
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/utilities/global.js.html +1 -1
- package/coverage/lcov-report/utilities/index.html +19 -19
- package/coverage/lcov-report/utilities/index.js.html +33 -66
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
- 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/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +583 -688
- package/dist/api/controllers/{query/index.js → query.js} +6 -42
- package/dist/api/controllers/user.js +1 -37
- package/dist/api/controllers/webhook.js +0 -4
- package/dist/api/routes/query.js +32 -2
- package/dist/api/routes/user.js +1 -3
- package/dist/db/utils.js +0 -8
- package/dist/integrations/rest.js +113 -110
- package/dist/package.json +4 -8
- package/dist/threads/query.js +2 -14
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/index.js +0 -10
- package/package.json +5 -9
- package/src/api/controllers/{query/index.js → query.js} +6 -50
- package/src/api/controllers/user.js +0 -33
- package/src/api/controllers/webhook.js +0 -4
- package/src/api/routes/query.js +34 -5
- package/src/api/routes/user.js +0 -10
- package/src/db/utils.js +0 -9
- package/src/definitions/common.ts +16 -2
- package/src/definitions/datasource.ts +1 -50
- package/src/integrations/base/IntegrationBase.ts +4 -4
- package/src/integrations/oracle.ts +1 -1
- package/src/integrations/rest.ts +137 -111
- package/src/integrations/tests/rest.spec.js +7 -16
- package/src/threads/query.js +2 -19
- package/src/utilities/index.js +0 -11
- package/builder/assets/bb-spaceship.8f6e81e1.svg +0 -227
- package/builder/assets/index.b0718f41.js +0 -1320
- package/coverage/lcov-report/api/controllers/query/index.html +0 -126
- package/coverage/lcov-report/api/controllers/query/validation.js.html +0 -203
- package/dist/api/controllers/query/import/index.js +0 -79
- package/dist/api/controllers/query/import/sources/base/index.js +0 -63
- package/dist/api/controllers/query/import/sources/base/openapi.js +0 -42
- package/dist/api/controllers/query/import/sources/curl.js +0 -90
- package/dist/api/controllers/query/import/sources/openapi2.js +0 -139
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +0 -253
- package/dist/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +0 -1054
- package/dist/api/controllers/query/validation.js +0 -37
- package/src/api/controllers/query/import/index.ts +0 -85
- package/src/api/controllers/query/import/sources/base/index.ts +0 -85
- package/src/api/controllers/query/import/sources/base/openapi.ts +0 -24
- package/src/api/controllers/query/import/sources/curl.ts +0 -94
- package/src/api/controllers/query/import/sources/openapi2.ts +0 -159
- package/src/api/controllers/query/import/sources/tests/curl/curl.spec.js +0 -104
- package/src/api/controllers/query/import/sources/tests/curl/data/delete.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/curl/data/empty-body.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/get.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/curl/data/headers.txt +0 -3
- package/src/api/controllers/query/import/sources/tests/curl/data/patch.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/path.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/curl/data/post.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/put.txt +0 -2
- package/src/api/controllers/query/import/sources/tests/curl/data/query.txt +0 -1
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.json +0 -253
- package/src/api/controllers/query/import/sources/tests/openapi2/data/crud/crud.yaml +0 -160
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.json +0 -1054
- package/src/api/controllers/query/import/sources/tests/openapi2/data/petstore/petstore.yaml +0 -711
- package/src/api/controllers/query/import/sources/tests/openapi2/openapi2.spec.js +0 -239
- package/src/api/controllers/query/import/tests/index.spec.js +0 -115
- package/src/api/controllers/query/validation.js +0 -41
package/src/integrations/rest.ts
CHANGED
|
@@ -2,58 +2,29 @@ import {
|
|
|
2
2
|
Integration,
|
|
3
3
|
DatasourceFieldTypes,
|
|
4
4
|
QueryTypes,
|
|
5
|
-
RestConfig,
|
|
6
|
-
RestQueryFields as RestQuery,
|
|
7
5
|
} from "../definitions/datasource"
|
|
8
6
|
import { IntegrationBase } from "./base/IntegrationBase"
|
|
9
7
|
|
|
10
|
-
const BodyTypes = {
|
|
11
|
-
NONE: "none",
|
|
12
|
-
FORM_DATA: "form",
|
|
13
|
-
ENCODED: "encoded",
|
|
14
|
-
JSON: "json",
|
|
15
|
-
TEXT: "text",
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const coreFields = {
|
|
19
|
-
path: {
|
|
20
|
-
type: DatasourceFieldTypes.STRING,
|
|
21
|
-
display: "URL",
|
|
22
|
-
},
|
|
23
|
-
queryString: {
|
|
24
|
-
type: DatasourceFieldTypes.STRING,
|
|
25
|
-
},
|
|
26
|
-
headers: {
|
|
27
|
-
type: DatasourceFieldTypes.OBJECT,
|
|
28
|
-
},
|
|
29
|
-
enabledHeaders: {
|
|
30
|
-
type: DatasourceFieldTypes.OBJECT,
|
|
31
|
-
},
|
|
32
|
-
requestBody: {
|
|
33
|
-
type: DatasourceFieldTypes.JSON,
|
|
34
|
-
},
|
|
35
|
-
bodyType: {
|
|
36
|
-
type: DatasourceFieldTypes.STRING,
|
|
37
|
-
enum: Object.values(BodyTypes),
|
|
38
|
-
},
|
|
39
|
-
}
|
|
40
|
-
|
|
41
8
|
module RestModule {
|
|
42
9
|
const fetch = require("node-fetch")
|
|
43
|
-
|
|
44
|
-
|
|
10
|
+
|
|
11
|
+
interface RestConfig {
|
|
12
|
+
url: string
|
|
13
|
+
defaultHeaders: {
|
|
14
|
+
[key: string]: any
|
|
15
|
+
}
|
|
16
|
+
}
|
|
45
17
|
|
|
46
18
|
const SCHEMA: Integration = {
|
|
47
19
|
docs: "https://github.com/node-fetch/node-fetch",
|
|
48
20
|
description:
|
|
49
|
-
"
|
|
21
|
+
"Representational state transfer (REST) is a de-facto standard for a software architecture for interactive applications that typically use multiple Web services. ",
|
|
50
22
|
friendlyName: "REST API",
|
|
51
23
|
datasource: {
|
|
52
24
|
url: {
|
|
53
25
|
type: DatasourceFieldTypes.STRING,
|
|
54
|
-
default: "",
|
|
55
|
-
required:
|
|
56
|
-
deprecated: true,
|
|
26
|
+
default: "localhost",
|
|
27
|
+
required: true,
|
|
57
28
|
},
|
|
58
29
|
defaultHeaders: {
|
|
59
30
|
type: DatasourceFieldTypes.OBJECT,
|
|
@@ -66,30 +37,97 @@ module RestModule {
|
|
|
66
37
|
readable: true,
|
|
67
38
|
displayName: "POST",
|
|
68
39
|
type: QueryTypes.FIELDS,
|
|
69
|
-
|
|
40
|
+
urlDisplay: true,
|
|
41
|
+
fields: {
|
|
42
|
+
path: {
|
|
43
|
+
type: DatasourceFieldTypes.STRING,
|
|
44
|
+
},
|
|
45
|
+
queryString: {
|
|
46
|
+
type: DatasourceFieldTypes.STRING,
|
|
47
|
+
},
|
|
48
|
+
headers: {
|
|
49
|
+
type: DatasourceFieldTypes.OBJECT,
|
|
50
|
+
},
|
|
51
|
+
requestBody: {
|
|
52
|
+
type: DatasourceFieldTypes.JSON,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
70
55
|
},
|
|
71
56
|
read: {
|
|
72
57
|
displayName: "GET",
|
|
73
58
|
readable: true,
|
|
74
59
|
type: QueryTypes.FIELDS,
|
|
75
|
-
|
|
60
|
+
urlDisplay: true,
|
|
61
|
+
fields: {
|
|
62
|
+
path: {
|
|
63
|
+
type: DatasourceFieldTypes.STRING,
|
|
64
|
+
},
|
|
65
|
+
queryString: {
|
|
66
|
+
type: DatasourceFieldTypes.STRING,
|
|
67
|
+
},
|
|
68
|
+
headers: {
|
|
69
|
+
type: DatasourceFieldTypes.OBJECT,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
76
72
|
},
|
|
77
73
|
update: {
|
|
78
74
|
displayName: "PUT",
|
|
79
75
|
readable: true,
|
|
80
76
|
type: QueryTypes.FIELDS,
|
|
81
|
-
|
|
77
|
+
urlDisplay: true,
|
|
78
|
+
fields: {
|
|
79
|
+
path: {
|
|
80
|
+
type: DatasourceFieldTypes.STRING,
|
|
81
|
+
},
|
|
82
|
+
queryString: {
|
|
83
|
+
type: DatasourceFieldTypes.STRING,
|
|
84
|
+
},
|
|
85
|
+
headers: {
|
|
86
|
+
type: DatasourceFieldTypes.OBJECT,
|
|
87
|
+
},
|
|
88
|
+
requestBody: {
|
|
89
|
+
type: DatasourceFieldTypes.JSON,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
82
92
|
},
|
|
83
93
|
patch: {
|
|
84
94
|
displayName: "PATCH",
|
|
85
95
|
readable: true,
|
|
86
96
|
type: QueryTypes.FIELDS,
|
|
87
|
-
|
|
97
|
+
urlDisplay: true,
|
|
98
|
+
fields: {
|
|
99
|
+
path: {
|
|
100
|
+
type: DatasourceFieldTypes.STRING,
|
|
101
|
+
},
|
|
102
|
+
queryString: {
|
|
103
|
+
type: DatasourceFieldTypes.STRING,
|
|
104
|
+
},
|
|
105
|
+
headers: {
|
|
106
|
+
type: DatasourceFieldTypes.OBJECT,
|
|
107
|
+
},
|
|
108
|
+
requestBody: {
|
|
109
|
+
type: DatasourceFieldTypes.JSON,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
88
112
|
},
|
|
89
113
|
delete: {
|
|
90
114
|
displayName: "DELETE",
|
|
91
115
|
type: QueryTypes.FIELDS,
|
|
92
|
-
|
|
116
|
+
urlDisplay: true,
|
|
117
|
+
fields: {
|
|
118
|
+
path: {
|
|
119
|
+
type: DatasourceFieldTypes.STRING,
|
|
120
|
+
},
|
|
121
|
+
queryString: {
|
|
122
|
+
type: DatasourceFieldTypes.STRING,
|
|
123
|
+
},
|
|
124
|
+
headers: {
|
|
125
|
+
type: DatasourceFieldTypes.OBJECT,
|
|
126
|
+
},
|
|
127
|
+
requestBody: {
|
|
128
|
+
type: DatasourceFieldTypes.JSON,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
93
131
|
},
|
|
94
132
|
},
|
|
95
133
|
}
|
|
@@ -99,106 +137,94 @@ module RestModule {
|
|
|
99
137
|
private headers: {
|
|
100
138
|
[key: string]: string
|
|
101
139
|
} = {}
|
|
102
|
-
private startTimeMs: number = performance.now()
|
|
103
140
|
|
|
104
141
|
constructor(config: RestConfig) {
|
|
105
142
|
this.config = config
|
|
106
143
|
}
|
|
107
144
|
|
|
108
145
|
async parseResponse(response: any) {
|
|
109
|
-
let data, raw, headers
|
|
110
146
|
const contentType = response.headers.get("content-type")
|
|
111
147
|
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
112
|
-
|
|
113
|
-
raw = JSON.stringify(data)
|
|
148
|
+
return await response.json()
|
|
114
149
|
} else {
|
|
115
|
-
|
|
116
|
-
raw = data
|
|
117
|
-
}
|
|
118
|
-
const size = formatBytes(response.headers.get("content-length") || Buffer.byteLength(raw, "utf8"))
|
|
119
|
-
const time = `${Math.round(performance.now() - this.startTimeMs)}ms`
|
|
120
|
-
headers = response.headers.raw()
|
|
121
|
-
for (let [key, value] of Object.entries(headers)) {
|
|
122
|
-
headers[key] = Array.isArray(value) ? value[0] : value
|
|
123
|
-
}
|
|
124
|
-
return {
|
|
125
|
-
data,
|
|
126
|
-
info: {
|
|
127
|
-
code: response.status,
|
|
128
|
-
size,
|
|
129
|
-
time,
|
|
130
|
-
},
|
|
131
|
-
extra: {
|
|
132
|
-
raw,
|
|
133
|
-
headers,
|
|
134
|
-
},
|
|
150
|
+
return await response.text()
|
|
135
151
|
}
|
|
136
152
|
}
|
|
137
153
|
|
|
138
154
|
getUrl(path: string, queryString: string): string {
|
|
139
|
-
|
|
140
|
-
let complete = main
|
|
141
|
-
if (this.config.url && !main.startsWith(this.config.url)) {
|
|
142
|
-
complete = !this.config.url ? main : `${this.config.url}/${main}`
|
|
143
|
-
}
|
|
144
|
-
if (!complete.startsWith("http")) {
|
|
145
|
-
complete = `http://${complete}`
|
|
146
|
-
}
|
|
147
|
-
return complete
|
|
155
|
+
return `${this.config.url}/${path}?${queryString}`
|
|
148
156
|
}
|
|
149
157
|
|
|
150
|
-
async
|
|
151
|
-
const { path = "", queryString = "", headers = {}, method = "GET", disabledHeaders, bodyType, requestBody } = query
|
|
158
|
+
async create({ path = "", queryString = "", headers = {}, json = {} }) {
|
|
152
159
|
this.headers = {
|
|
153
160
|
...this.config.defaultHeaders,
|
|
154
161
|
...headers,
|
|
155
162
|
}
|
|
156
163
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
+
const response = await fetch(this.getUrl(path, queryString), {
|
|
165
|
+
method: "POST",
|
|
166
|
+
headers: this.headers,
|
|
167
|
+
body: JSON.stringify(json),
|
|
168
|
+
})
|
|
164
169
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
try {
|
|
168
|
-
json = JSON.parse(requestBody)
|
|
169
|
-
} catch (err) {
|
|
170
|
-
throw "Invalid JSON for request body"
|
|
171
|
-
}
|
|
172
|
-
}
|
|
170
|
+
return await this.parseResponse(response)
|
|
171
|
+
}
|
|
173
172
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
173
|
+
async read({ path = "", queryString = "", headers = {} }) {
|
|
174
|
+
this.headers = {
|
|
175
|
+
...this.config.defaultHeaders,
|
|
176
|
+
...headers,
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
|
|
180
|
-
|
|
179
|
+
const response = await fetch(this.getUrl(path, queryString), {
|
|
180
|
+
headers: this.headers,
|
|
181
|
+
})
|
|
182
|
+
|
|
181
183
|
return await this.parseResponse(response)
|
|
182
184
|
}
|
|
183
185
|
|
|
184
|
-
async
|
|
185
|
-
|
|
186
|
-
|
|
186
|
+
async update({ path = "", queryString = "", headers = {}, json = {} }) {
|
|
187
|
+
this.headers = {
|
|
188
|
+
...this.config.defaultHeaders,
|
|
189
|
+
...headers,
|
|
190
|
+
}
|
|
187
191
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
192
|
+
const response = await fetch(this.getUrl(path, queryString), {
|
|
193
|
+
method: "PUT",
|
|
194
|
+
headers: this.headers,
|
|
195
|
+
body: JSON.stringify(json),
|
|
196
|
+
})
|
|
191
197
|
|
|
192
|
-
|
|
193
|
-
return this._req({ ...opts, method: "PUT" })
|
|
198
|
+
return await this.parseResponse(response)
|
|
194
199
|
}
|
|
195
200
|
|
|
196
|
-
async patch(
|
|
197
|
-
|
|
201
|
+
async patch({ path = "", queryString = "", headers = {}, json = {} }) {
|
|
202
|
+
this.headers = {
|
|
203
|
+
...this.config.defaultHeaders,
|
|
204
|
+
...headers,
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
const response = await fetch(this.getUrl(path, queryString), {
|
|
208
|
+
method: "PATCH",
|
|
209
|
+
headers: this.headers,
|
|
210
|
+
body: JSON.stringify(json),
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
return await this.parseResponse(response)
|
|
198
214
|
}
|
|
199
215
|
|
|
200
|
-
async delete(
|
|
201
|
-
|
|
216
|
+
async delete({ path = "", queryString = "", headers = {} }) {
|
|
217
|
+
this.headers = {
|
|
218
|
+
...this.config.defaultHeaders,
|
|
219
|
+
...headers,
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const response = await fetch(this.getUrl(path, queryString), {
|
|
223
|
+
method: "DELETE",
|
|
224
|
+
headers: this.headers,
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
return await this.parseResponse(response)
|
|
202
228
|
}
|
|
203
229
|
}
|
|
204
230
|
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
jest.mock("node-fetch", () =>
|
|
2
2
|
jest.fn(() => ({
|
|
3
3
|
headers: {
|
|
4
|
-
raw: () => {
|
|
5
|
-
return { "content-type": ["application/json"] }
|
|
6
|
-
},
|
|
7
4
|
get: () => ["application/json"]
|
|
8
5
|
},
|
|
9
6
|
json: jest.fn(),
|
|
@@ -27,7 +24,6 @@ describe("REST Integration", () => {
|
|
|
27
24
|
config = new TestConfiguration({
|
|
28
25
|
url: BASE_URL,
|
|
29
26
|
})
|
|
30
|
-
jest.clearAllMocks()
|
|
31
27
|
})
|
|
32
28
|
|
|
33
29
|
it("calls the create method with the correct params", async () => {
|
|
@@ -37,10 +33,9 @@ describe("REST Integration", () => {
|
|
|
37
33
|
headers: {
|
|
38
34
|
Accept: "application/json",
|
|
39
35
|
},
|
|
40
|
-
|
|
41
|
-
requestBody: JSON.stringify({
|
|
36
|
+
json: {
|
|
42
37
|
name: "test",
|
|
43
|
-
}
|
|
38
|
+
},
|
|
44
39
|
}
|
|
45
40
|
const response = await config.integration.create(query)
|
|
46
41
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
|
@@ -65,7 +60,6 @@ describe("REST Integration", () => {
|
|
|
65
60
|
headers: {
|
|
66
61
|
Accept: "text/html",
|
|
67
62
|
},
|
|
68
|
-
method: "GET",
|
|
69
63
|
})
|
|
70
64
|
})
|
|
71
65
|
|
|
@@ -76,14 +70,13 @@ describe("REST Integration", () => {
|
|
|
76
70
|
headers: {
|
|
77
71
|
Accept: "application/json",
|
|
78
72
|
},
|
|
79
|
-
|
|
80
|
-
requestBody: JSON.stringify({
|
|
73
|
+
json: {
|
|
81
74
|
name: "test",
|
|
82
|
-
}
|
|
75
|
+
},
|
|
83
76
|
}
|
|
84
77
|
const response = await config.integration.update(query)
|
|
85
78
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
|
86
|
-
method: "
|
|
79
|
+
method: "POST",
|
|
87
80
|
body: '{"name":"test"}',
|
|
88
81
|
headers: {
|
|
89
82
|
Accept: "application/json",
|
|
@@ -98,10 +91,9 @@ describe("REST Integration", () => {
|
|
|
98
91
|
headers: {
|
|
99
92
|
Accept: "application/json",
|
|
100
93
|
},
|
|
101
|
-
|
|
102
|
-
requestBody: JSON.stringify({
|
|
94
|
+
json: {
|
|
103
95
|
name: "test",
|
|
104
|
-
}
|
|
96
|
+
},
|
|
105
97
|
}
|
|
106
98
|
const response = await config.integration.delete(query)
|
|
107
99
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/api?test=1`, {
|
|
@@ -109,7 +101,6 @@ describe("REST Integration", () => {
|
|
|
109
101
|
headers: {
|
|
110
102
|
Accept: "application/json",
|
|
111
103
|
},
|
|
112
|
-
body: '{"name":"test"}',
|
|
113
104
|
})
|
|
114
105
|
})
|
|
115
106
|
})
|
package/src/threads/query.js
CHANGED
|
@@ -15,15 +15,6 @@ function formatResponse(resp) {
|
|
|
15
15
|
return resp
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
function hasExtraData(response) {
|
|
19
|
-
return (
|
|
20
|
-
typeof response === "object" &&
|
|
21
|
-
!Array.isArray(response) &&
|
|
22
|
-
response.data != null &&
|
|
23
|
-
response.info != null
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
18
|
async function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
28
19
|
const Integration = integrations[datasource.source]
|
|
29
20
|
if (!Integration) {
|
|
@@ -31,15 +22,7 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
|
31
22
|
}
|
|
32
23
|
const integration = new Integration(datasource.config)
|
|
33
24
|
|
|
34
|
-
let
|
|
35
|
-
let rows = output,
|
|
36
|
-
info = undefined,
|
|
37
|
-
extra = undefined
|
|
38
|
-
if (hasExtraData(output)) {
|
|
39
|
-
rows = output.data
|
|
40
|
-
info = output.info
|
|
41
|
-
extra = output.extra
|
|
42
|
-
}
|
|
25
|
+
let rows = formatResponse(await integration[queryVerb](query))
|
|
43
26
|
|
|
44
27
|
// transform as required
|
|
45
28
|
if (transformer) {
|
|
@@ -64,7 +47,7 @@ async function runAndTransform(datasource, queryVerb, query, transformer) {
|
|
|
64
47
|
integration.end()
|
|
65
48
|
}
|
|
66
49
|
|
|
67
|
-
return { rows, keys
|
|
50
|
+
return { rows, keys }
|
|
68
51
|
}
|
|
69
52
|
|
|
70
53
|
module.exports = (input, callback) => {
|
package/src/utilities/index.js
CHANGED
|
@@ -150,14 +150,3 @@ exports.doesDatabaseExist = async dbName => {
|
|
|
150
150
|
return false
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
-
|
|
154
|
-
exports.formatBytes = bytes => {
|
|
155
|
-
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]
|
|
156
|
-
const byteIncrements = 1024
|
|
157
|
-
let unit = 0
|
|
158
|
-
let size = parseInt(bytes, 10) || 0
|
|
159
|
-
while (size >= byteIncrements && ++unit) {
|
|
160
|
-
size /= byteIncrements
|
|
161
|
-
}
|
|
162
|
-
return `${size.toFixed(size < 10 && unit > 0 ? 1 : 0)}${units[unit]}`
|
|
163
|
-
}
|