@budibase/server 0.9.171 → 0.9.173-alpha.2
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__/{mysql.ts → mysql2.ts} +0 -0
- package/builder/assets/{index.dbc6728e.css → index.7469e1e4.css} +2 -2
- package/builder/assets/{index.cf0febb9.js → index.8a8f7849.js} +34 -34
- package/builder/assets/{vendor.54435e8f.js → vendor.278a305c.js} +1 -1
- package/builder/index.html +3 -3
- package/coverage/clover.xml +973 -849
- package/coverage/coverage-final.json +47 -46
- package/coverage/lcov-report/api/controllers/analytics.js.html +21 -9
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/application.js.html +186 -84
- package/coverage/lcov-report/api/controllers/auth.js.html +37 -10
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/backup.js.html +6 -9
- 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 +1 -1
- package/coverage/lcov-report/api/controllers/dev.js.html +41 -17
- package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +71 -71
- 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 +7 -4
- package/coverage/lcov-report/api/controllers/query.js.html +129 -24
- 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 +5 -5
- package/coverage/lcov-report/api/controllers/row/index.js.html +15 -15
- 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 +9 -9
- package/coverage/lcov-report/api/controllers/script.js.html +12 -57
- package/coverage/lcov-report/api/controllers/table/index.html +28 -28
- package/coverage/lcov-report/api/controllers/table/index.js.html +16 -37
- package/coverage/lcov-report/api/controllers/table/utils.js.html +279 -33
- package/coverage/lcov-report/api/controllers/templates.js.html +49 -13
- package/coverage/lcov-report/api/controllers/user.js.html +3 -3
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +19 -19
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +8 -8
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +54 -15
- 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 +3 -3
- 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 +5 -2
- 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 +26 -11
- 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 +9 -3
- 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 +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 +31 -10
- package/coverage/lcov-report/automations/automationUtils.js.html +14 -86
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +37 -37
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +10 -7
- package/coverage/lcov-report/automations/steps/createRow.js.html +2 -2
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +8 -5
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +10 -7
- package/coverage/lcov-report/automations/steps/executeScript.js.html +10 -7
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +57 -57
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +10 -7
- package/coverage/lcov-report/automations/steps/queryRows.js.html +10 -7
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +10 -7
- 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 +14 -14
- package/coverage/lcov-report/automations/steps/utils.js.html +10 -10
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/thread.js.html +54 -12
- 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 +28 -28
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +5 -2
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +2 -2
- package/coverage/lcov-report/db/client.js.html +1 -1
- package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +1 -1
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +12 -12
- package/coverage/lcov-report/db/linkedRows/index.html +18 -18
- package/coverage/lcov-report/db/linkedRows/index.js.html +47 -26
- 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 +17 -17
- 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 +107 -107
- 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 +52 -25
- 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/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/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 +27 -27
- package/coverage/lcov-report/utilities/index.html +32 -17
- package/coverage/lcov-report/utilities/index.js.html +4 -4
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +29 -8
- package/coverage/lcov-report/utilities/queue/index.html +15 -15
- 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 +14 -14
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +38 -8
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +143 -0
- package/coverage/lcov-report/utilities/security.js.html +1 -1
- 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 +19 -19
- package/coverage/lcov.info +1692 -1452
- package/dist/api/controllers/analytics.js +4 -0
- package/dist/api/controllers/application.js +185 -171
- package/dist/api/controllers/auth.js +12 -2
- package/dist/api/controllers/backup.js +4 -4
- package/dist/api/controllers/deploy/index.js +3 -16
- package/dist/api/controllers/dev.js +17 -11
- package/dist/api/controllers/permission.js +1 -0
- package/dist/api/controllers/query.js +26 -8
- package/dist/api/controllers/row/ExternalRequest.js +46 -5
- package/dist/api/controllers/script.js +4 -16
- package/dist/api/controllers/table/index.js +5 -10
- package/dist/api/controllers/table/utils.js +83 -10
- package/dist/api/controllers/templates.js +18 -3
- package/dist/api/controllers/view/viewBuilder.js +15 -1
- package/dist/api/routes/application.js +1 -0
- package/dist/api/routes/dev.js +8 -4
- package/dist/api/routes/query.js +3 -1
- package/dist/api/routes/tests/utilities/TestFunctions.js +7 -9
- package/dist/automations/actions.js +9 -3
- package/dist/automations/automationUtils.js +8 -29
- package/dist/automations/steps/bash.js +2 -1
- package/dist/automations/steps/createRow.js +1 -1
- package/dist/automations/steps/deleteRow.js +2 -1
- package/dist/automations/steps/executeQuery.js +2 -1
- package/dist/automations/steps/executeScript.js +2 -1
- package/dist/automations/steps/outgoingWebhook.js +2 -1
- package/dist/automations/steps/queryRows.js +2 -1
- package/dist/automations/steps/sendSmtpEmail.js +2 -1
- package/dist/automations/steps/updateRow.js +6 -2
- package/dist/automations/thread.js +14 -3
- package/dist/constants/index.js +1 -0
- package/dist/db/linkedRows/index.js +9 -6
- package/dist/integrations/base/sql.js +4 -4
- package/dist/integrations/mysql.js +1 -1
- package/dist/integrations/utils.js +17 -1
- package/dist/middleware/currentapp.js +8 -2
- package/dist/package.json +7 -6
- package/dist/tests/utilities/TestConfiguration.js +34 -19
- package/dist/tests/utilities/controllers.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +49 -33
- package/dist/utilities/global.js +1 -1
- package/dist/utilities/queue/inMemoryQueue.js +6 -0
- package/dist/utilities/rowProcessor/index.js +8 -0
- package/dist/utilities/scriptRunner.js +19 -0
- package/package.json +8 -7
- package/scripts/jestSetup.js +2 -0
- package/src/api/controllers/analytics.js +4 -0
- package/src/api/controllers/application.js +43 -9
- package/src/api/controllers/auth.js +12 -3
- package/src/api/controllers/backup.js +4 -5
- package/src/api/controllers/deploy/index.js +3 -18
- package/src/api/controllers/dev.js +16 -8
- package/src/api/controllers/permission.js +1 -0
- package/src/api/controllers/query.js +46 -11
- package/src/api/controllers/row/ExternalRequest.ts +53 -4
- package/src/api/controllers/script.js +4 -19
- package/src/api/controllers/table/index.js +5 -12
- package/src/api/controllers/table/utils.js +94 -12
- package/src/api/controllers/templates.js +17 -5
- package/src/api/controllers/view/tests/__snapshots__/viewBuilder.spec.js.snap +1 -1
- package/src/api/controllers/view/viewBuilder.js +14 -1
- package/src/api/routes/application.js +1 -0
- package/src/api/routes/dev.js +9 -4
- package/src/api/routes/query.js +3 -1
- package/src/api/routes/tests/auth.spec.js +1 -2
- package/src/api/routes/tests/permissions.spec.js +3 -0
- package/src/api/routes/tests/query.spec.js +2 -2
- package/src/api/routes/tests/routing.spec.js +24 -8
- package/src/api/routes/tests/user.spec.js +1 -1
- package/src/api/routes/tests/utilities/TestFunctions.js +7 -9
- package/src/api/routes/tests/webhook.spec.js +4 -1
- package/src/automations/actions.js +10 -3
- package/src/automations/automationUtils.js +7 -31
- package/src/automations/steps/bash.js +2 -1
- package/src/automations/steps/createRow.js +1 -1
- package/src/automations/steps/deleteRow.js +2 -1
- package/src/automations/steps/executeQuery.js +2 -1
- package/src/automations/steps/executeScript.js +2 -1
- package/src/automations/steps/outgoingWebhook.js +2 -1
- package/src/automations/steps/queryRows.js +2 -1
- package/src/automations/steps/sendSmtpEmail.js +2 -1
- package/src/automations/steps/updateRow.js +6 -6
- package/src/automations/thread.js +17 -3
- package/src/constants/index.js +1 -0
- package/src/db/linkedRows/index.js +14 -7
- package/src/integrations/base/sql.ts +11 -3
- package/src/integrations/mysql.ts +1 -1
- package/src/integrations/tests/mongo.spec.js +10 -6
- package/src/integrations/tests/mysql.spec.js +1 -1
- package/src/integrations/utils.ts +18 -0
- package/src/middleware/currentapp.js +11 -2
- package/src/middleware/tests/currentapp.spec.js +3 -3
- package/src/tests/utilities/TestConfiguration.js +47 -19
- package/src/tests/utilities/controllers.js +1 -0
- package/src/utilities/fileSystem/index.js +65 -43
- package/src/utilities/global.js +1 -1
- package/src/utilities/queue/inMemoryQueue.js +7 -0
- package/src/utilities/rowProcessor/index.js +10 -0
- package/src/utilities/scriptRunner.js +21 -0
|
@@ -106,64 +106,86 @@ exports.apiFileReturn = contents => {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
/**
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* @param {string}
|
|
112
|
-
* @
|
|
113
|
-
*
|
|
109
|
+
* Local utility to back up the database state for an app, excluding global user
|
|
110
|
+
* data or user relationships.
|
|
111
|
+
* @param {string} appId The app to backup
|
|
112
|
+
* @param {object} config Config to send to export DB
|
|
113
|
+
* @returns {*} either a string or a stream of the backup
|
|
114
114
|
*/
|
|
115
|
-
|
|
116
|
-
return exports.exportDB(appId, {
|
|
117
|
-
|
|
115
|
+
const backupAppData = async (appId, config) => {
|
|
116
|
+
return await exports.exportDB(appId, {
|
|
117
|
+
...config,
|
|
118
118
|
filter: doc =>
|
|
119
119
|
!(
|
|
120
120
|
doc._id.includes(USER_METDATA_PREFIX) ||
|
|
121
|
-
doc.includes(LINK_USER_METADATA_PREFIX)
|
|
121
|
+
doc._id.includes(LINK_USER_METADATA_PREFIX)
|
|
122
122
|
),
|
|
123
123
|
})
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
|
-
*
|
|
127
|
+
* Takes a copy of the database state for an app to the object store.
|
|
128
|
+
* @param {string} appId The ID of the app which is to be backed up.
|
|
129
|
+
* @param {string} backupName The name of the backup located in the object store.
|
|
130
|
+
* @return {*} a readable stream to the completed backup file
|
|
131
|
+
*/
|
|
132
|
+
exports.performBackup = async (appId, backupName) => {
|
|
133
|
+
return await backupAppData(appId, { exportName: backupName })
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Streams a backup of the database state for an app
|
|
138
|
+
* @param {string} appId The ID of the app which is to be backed up.
|
|
139
|
+
* @returns {*} a readable stream of the backup which is written in real time
|
|
140
|
+
*/
|
|
141
|
+
exports.streamBackup = async appId => {
|
|
142
|
+
return await backupAppData(appId, { stream: true })
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Exports a DB to either file or a variable (memory).
|
|
128
147
|
* @param {string} dbName the DB which is to be exported.
|
|
129
|
-
* @param {string} exportName optional -
|
|
148
|
+
* @param {string} exportName optional - provide a filename to write the backup to a file
|
|
149
|
+
* @param {boolean} stream optional - whether to perform a full backup
|
|
130
150
|
* @param {function} filter optional - a filter function to clear out any un-wanted docs.
|
|
131
|
-
* @return
|
|
151
|
+
* @return {*} either a readable stream or a string
|
|
132
152
|
*/
|
|
133
|
-
exports.exportDB = async (
|
|
134
|
-
dbName,
|
|
135
|
-
{ exportName, filter } = { exportName: undefined, filter: undefined }
|
|
136
|
-
) => {
|
|
137
|
-
let stream,
|
|
138
|
-
appString = "",
|
|
139
|
-
path = null
|
|
140
|
-
if (exportName) {
|
|
141
|
-
path = join(budibaseTempDir(), exportName)
|
|
142
|
-
stream = fs.createWriteStream(path)
|
|
143
|
-
} else {
|
|
144
|
-
stream = new MemoryStream()
|
|
145
|
-
stream.on("data", chunk => {
|
|
146
|
-
appString += chunk.toString()
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
// perform couch dump
|
|
153
|
+
exports.exportDB = async (dbName, { stream, filter, exportName } = {}) => {
|
|
150
154
|
const instanceDb = new CouchDB(dbName)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return
|
|
155
|
+
|
|
156
|
+
// Stream the dump if required
|
|
157
|
+
if (stream) {
|
|
158
|
+
const memStream = new MemoryStream()
|
|
159
|
+
instanceDb.dump(memStream, { filter })
|
|
160
|
+
return memStream
|
|
157
161
|
}
|
|
158
|
-
|
|
159
|
-
if
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
162
|
+
|
|
163
|
+
// Write the dump to file if required
|
|
164
|
+
if (exportName) {
|
|
165
|
+
const path = join(budibaseTempDir(), exportName)
|
|
166
|
+
const writeStream = fs.createWriteStream(path)
|
|
167
|
+
await instanceDb.dump(writeStream, { filter })
|
|
168
|
+
|
|
169
|
+
// Upload the dump to the object store if self hosted
|
|
170
|
+
if (env.SELF_HOSTED) {
|
|
171
|
+
await streamUpload(
|
|
172
|
+
ObjectStoreBuckets.BACKUPS,
|
|
173
|
+
join(dbName, exportName),
|
|
174
|
+
fs.createReadStream(path)
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return fs.createReadStream(path)
|
|
165
179
|
}
|
|
166
|
-
|
|
180
|
+
|
|
181
|
+
// Stringify the dump in memory if required
|
|
182
|
+
const memStream = new MemoryStream()
|
|
183
|
+
let appString = ""
|
|
184
|
+
memStream.on("data", chunk => {
|
|
185
|
+
appString += chunk.toString()
|
|
186
|
+
})
|
|
187
|
+
await instanceDb.dump(memStream, { filter })
|
|
188
|
+
return appString
|
|
167
189
|
}
|
|
168
190
|
|
|
169
191
|
/**
|
package/src/utilities/global.js
CHANGED
|
@@ -26,7 +26,7 @@ exports.updateAppRole = (appId, user) => {
|
|
|
26
26
|
if (!user.roleId && user.builder && user.builder.global) {
|
|
27
27
|
user.roleId = BUILTIN_ROLE_IDS.ADMIN
|
|
28
28
|
} else if (!user.roleId) {
|
|
29
|
-
user.roleId = BUILTIN_ROLE_IDS.
|
|
29
|
+
user.roleId = BUILTIN_ROLE_IDS.PUBLIC
|
|
30
30
|
}
|
|
31
31
|
delete user.roles
|
|
32
32
|
return user
|
|
@@ -150,6 +150,10 @@ exports.processAutoColumn = processAutoColumn
|
|
|
150
150
|
* @returns {object} The coerced value
|
|
151
151
|
*/
|
|
152
152
|
exports.coerce = (row, type) => {
|
|
153
|
+
// no coercion specified for type, skip it
|
|
154
|
+
if (!TYPE_TRANSFORM_MAP[type]) {
|
|
155
|
+
return row
|
|
156
|
+
}
|
|
153
157
|
// eslint-disable-next-line no-prototype-builtins
|
|
154
158
|
if (TYPE_TRANSFORM_MAP[type].hasOwnProperty(row)) {
|
|
155
159
|
return TYPE_TRANSFORM_MAP[type][row]
|
|
@@ -196,6 +200,12 @@ exports.inputProcessing = (
|
|
|
196
200
|
clonedRow[key] = exports.coerce(value, field.type)
|
|
197
201
|
}
|
|
198
202
|
}
|
|
203
|
+
|
|
204
|
+
if (!clonedRow._id || !clonedRow._rev) {
|
|
205
|
+
clonedRow._id = row._id
|
|
206
|
+
clonedRow._rev = row._rev
|
|
207
|
+
}
|
|
208
|
+
|
|
199
209
|
// handle auto columns - this returns an object like {table, row}
|
|
200
210
|
return processAutoColumn(user, copiedTable, clonedRow, opts)
|
|
201
211
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const fetch = require("node-fetch")
|
|
2
|
+
const { VM, VMScript } = require("vm2")
|
|
3
|
+
|
|
4
|
+
class ScriptRunner {
|
|
5
|
+
constructor(script, context) {
|
|
6
|
+
const code = `let fn = () => {\n${script}\n}; results.out = fn();`
|
|
7
|
+
this.vm = new VM()
|
|
8
|
+
this.results = { out: "" }
|
|
9
|
+
this.vm.setGlobals(context)
|
|
10
|
+
this.vm.setGlobal("fetch", fetch)
|
|
11
|
+
this.vm.setGlobal("results", this.results)
|
|
12
|
+
this.script = new VMScript(code)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
execute() {
|
|
16
|
+
this.vm.run(this.script)
|
|
17
|
+
return this.results.out
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = ScriptRunner
|