@jsreport/jsreport-core 3.4.0 → 3.5.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/README.md +19 -1
- package/lib/main/blobStorage/blobStorage.js +9 -0
- package/lib/main/optionsSchema.js +16 -1
- package/lib/main/profiler.js +166 -75
- package/lib/main/reporter.js +90 -82
- package/lib/main/request.js +21 -0
- package/lib/main/schemaValidator.js +30 -0
- package/lib/main/settings.js +1 -2
- package/lib/main/store/collection.js +10 -8
- package/lib/main/store/documentStore.js +19 -0
- package/lib/main/store/setupValidateId.js +7 -1
- package/lib/main/store/setupValidateShortid.js +4 -0
- package/lib/shared/normalizeMetaFromLogs.js +1 -1
- package/lib/shared/reporter.js +16 -0
- package/lib/worker/render/executeEngine.js +30 -7
- package/lib/worker/render/profiler.js +14 -12
- package/lib/worker/render/render.js +0 -4
- package/lib/worker/sandbox/runInSandbox.js +2 -5
- package/lib/worker/sandbox/safeSandbox.js +8 -30
- package/lib/worker/workerHandler.js +1 -0
- package/package.json +7 -7
- package/lib/main/monitoring.js +0 -92
|
@@ -10,7 +10,6 @@ const Request = require('../../shared/request')
|
|
|
10
10
|
const generateRequestId = require('../../shared/generateRequestId')
|
|
11
11
|
const resolveReferences = require('./resolveReferences.js')
|
|
12
12
|
const moduleHelper = require('./moduleHelper')
|
|
13
|
-
let reportCounter = 0
|
|
14
13
|
|
|
15
14
|
module.exports = (reporter) => {
|
|
16
15
|
moduleHelper(reporter)
|
|
@@ -127,9 +126,6 @@ module.exports = (reporter) => {
|
|
|
127
126
|
response.meta.reportName = 'report'
|
|
128
127
|
}
|
|
129
128
|
|
|
130
|
-
request.context.reportCounter = ++reportCounter
|
|
131
|
-
request.context.startTimestamp = new Date().getTime()
|
|
132
|
-
|
|
133
129
|
if (parentReq == null) {
|
|
134
130
|
reporter.requestModulesCache.set(request.context.rootId, Object.create(null))
|
|
135
131
|
}
|
|
@@ -28,7 +28,7 @@ module.exports = (reporter) => {
|
|
|
28
28
|
context.__topLevelFunctions = {}
|
|
29
29
|
context.__handleError = (err) => handleError(reporter, err)
|
|
30
30
|
|
|
31
|
-
const { sourceFilesInfo, run, restore,
|
|
31
|
+
const { sourceFilesInfo, run, restore, sandbox, safeRequire } = safeSandbox(context, {
|
|
32
32
|
onLog: (log) => {
|
|
33
33
|
reporter.logger[log.level](log.message, { ...req, timestamp: log.timestamp })
|
|
34
34
|
},
|
|
@@ -113,13 +113,10 @@ module.exports = (reporter) => {
|
|
|
113
113
|
// we don't attach these methods to the sandbox, and instead share them through a "manager" object that should
|
|
114
114
|
// be passed in options
|
|
115
115
|
manager.restore = restore
|
|
116
|
-
manager.contextifyValue = contextifyValue
|
|
117
|
-
manager.decontextifyValue = decontextifyValue
|
|
118
|
-
manager.unproxyValue = unproxyValue
|
|
119
116
|
|
|
120
117
|
const functionNames = getTopLevelFunctions(userCode)
|
|
121
118
|
const functionsCode = `return {${functionNames.map(h => `"${h}": ${h}`).join(',')}}`
|
|
122
|
-
const executionCode = `;(async () => { ${userCode}
|
|
119
|
+
const executionCode = `;(async () => { ${userCode} \n\n;${functionsCode} })()
|
|
123
120
|
.then((topLevelFunctions) => {
|
|
124
121
|
const mergedTopLevelFunctions = { ...topLevelFunctions, ...__topLevelFunctions }
|
|
125
122
|
|
|
@@ -113,26 +113,12 @@ module.exports = (_sandbox, options = {}) => {
|
|
|
113
113
|
|
|
114
114
|
const vm = new VM()
|
|
115
115
|
|
|
116
|
-
//
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
const wrapAndSaveProxyResult = (originalFn, thisArg) => {
|
|
120
|
-
return (value, ...args) => {
|
|
121
|
-
const result = originalFn.call(thisArg, value, ...args)
|
|
122
|
-
|
|
123
|
-
if (result != null && result.isVMProxy === true) {
|
|
124
|
-
proxiesInVM.set(result, value)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return result
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
vm._internal.Contextify.object = wrapAndSaveProxyResult(vm._internal.Contextify.object, vm._internal.Contextify)
|
|
132
|
-
vm._internal.Decontextify.object = wrapAndSaveProxyResult(vm._internal.Decontextify.object, vm._internal.Decontextify)
|
|
116
|
+
// delete the vm.sandbox.global because it introduces json stringify issues
|
|
117
|
+
// and we don't need such global in context
|
|
118
|
+
delete vm.sandbox.global
|
|
133
119
|
|
|
134
120
|
for (const name in sandbox) {
|
|
135
|
-
vm.
|
|
121
|
+
vm.setGlobal(name, sandbox[name])
|
|
136
122
|
}
|
|
137
123
|
|
|
138
124
|
// processing top level props because getter/setter descriptors
|
|
@@ -141,27 +127,18 @@ module.exports = (_sandbox, options = {}) => {
|
|
|
141
127
|
const currentConfig = propsConfig[key]
|
|
142
128
|
|
|
143
129
|
if (currentConfig.root && currentConfig.root.sandboxReadOnly) {
|
|
144
|
-
readOnlyProp(vm.
|
|
130
|
+
readOnlyProp(vm.sandbox, key, [], customProxies, { onlyTopLevel: true })
|
|
145
131
|
}
|
|
146
132
|
})
|
|
147
133
|
|
|
148
134
|
const sourceFilesInfo = new Map()
|
|
149
135
|
|
|
150
136
|
return {
|
|
151
|
-
sandbox: vm.
|
|
137
|
+
sandbox: vm.sandbox,
|
|
152
138
|
console: _console,
|
|
153
139
|
sourceFilesInfo,
|
|
154
|
-
contextifyValue: (value) => {
|
|
155
|
-
return vm._internal.Contextify.value(value)
|
|
156
|
-
},
|
|
157
|
-
decontextifyValue: (value) => {
|
|
158
|
-
return vm._internal.Decontextify.value(value)
|
|
159
|
-
},
|
|
160
140
|
restore: () => {
|
|
161
|
-
return restoreProperties(vm.
|
|
162
|
-
},
|
|
163
|
-
unproxyValue: (value) => {
|
|
164
|
-
return getOriginalFromProxy(proxiesInVM, customProxies, value)
|
|
141
|
+
return restoreProperties(vm.sandbox, originalValues, proxiesInVM, customProxies)
|
|
165
142
|
},
|
|
166
143
|
safeRequire: (modulePath) => _require(modulePath, { context: _sandbox, allowAllModules: true }),
|
|
167
144
|
run: async (code, { filename, errorLineNumberOffset = 0, source, entity, entitySet } = {}) => {
|
|
@@ -177,6 +154,7 @@ module.exports = (_sandbox, options = {}) => {
|
|
|
177
154
|
// to show nice error when the compile of a script fails
|
|
178
155
|
script._compile = function (prefix, suffix) {
|
|
179
156
|
return new originalVM.Script(prefix + this.getCompiledCode() + suffix, {
|
|
157
|
+
__proto__: null,
|
|
180
158
|
filename: this.filename,
|
|
181
159
|
displayErrors: true,
|
|
182
160
|
lineOffset: this.lineOffset,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsreport/jsreport-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "javascript based business reporting",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"report",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"@babel/code-frame": "7.12.13",
|
|
33
33
|
"@babel/parser": "7.14.4",
|
|
34
34
|
"@babel/traverse": "7.12.9",
|
|
35
|
-
"@jsreport/advanced-workers": "1.2.
|
|
35
|
+
"@jsreport/advanced-workers": "1.2.1",
|
|
36
36
|
"@jsreport/mingo": "2.4.1",
|
|
37
37
|
"ajv": "6.12.6",
|
|
38
38
|
"app-root-path": "2.0.1",
|
|
39
|
-
"
|
|
39
|
+
"bytes": "3.1.2",
|
|
40
40
|
"camelcase": "5.0.0",
|
|
41
41
|
"debug": "4.3.2",
|
|
42
42
|
"decamelize": "2.0.0",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"enhanced-resolve": "5.8.3",
|
|
47
47
|
"has-own-deep": "1.1.0",
|
|
48
48
|
"isbinaryfile": "4.0.0",
|
|
49
|
-
"listener-collection": "
|
|
49
|
+
"listener-collection": "2.0.0",
|
|
50
50
|
"lodash.get": "4.4.2",
|
|
51
51
|
"lodash.groupby": "4.6.0",
|
|
52
52
|
"lodash.omit": "4.5.0",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"lru-cache": "4.1.1",
|
|
55
55
|
"ms": "2.1.3",
|
|
56
56
|
"nanoid": "3.2.0",
|
|
57
|
-
"nconf": "0.
|
|
57
|
+
"nconf": "0.12.0",
|
|
58
58
|
"node.extend.without.arrays": "1.1.6",
|
|
59
59
|
"reap2": "1.0.1",
|
|
60
60
|
"semver": "7.3.5",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"triple-beam": "1.3.0",
|
|
64
64
|
"unset-value": "1.0.0",
|
|
65
65
|
"uuid": "8.3.2",
|
|
66
|
-
"vm2": "3.9.
|
|
66
|
+
"vm2": "3.9.7",
|
|
67
67
|
"winston": "3.3.3",
|
|
68
68
|
"winston-transport": "4.4.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"mocha": "
|
|
71
|
+
"mocha": "9.2.2",
|
|
72
72
|
"should": "13.2.3",
|
|
73
73
|
"standard": "16.0.4",
|
|
74
74
|
"std-mocks": "1.0.1",
|
package/lib/main/monitoring.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const os = require('os')
|
|
2
|
-
|
|
3
|
-
function cpu () {
|
|
4
|
-
// Create function to get CPU information
|
|
5
|
-
function cpuAverage () {
|
|
6
|
-
// Initialise sum of idle and time of cores and fetch CPU info
|
|
7
|
-
let totalIdle = 0; let totalTick = 0
|
|
8
|
-
const cpus = os.cpus()
|
|
9
|
-
|
|
10
|
-
// Loop through CPU cores
|
|
11
|
-
for (let i = 0, len = cpus.length; i < len; i++) {
|
|
12
|
-
// Select CPU core
|
|
13
|
-
const cpu = cpus[i]
|
|
14
|
-
|
|
15
|
-
// Total up the time in the cores tick
|
|
16
|
-
for (const type in cpu.times) {
|
|
17
|
-
totalTick += cpu.times[type]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Total up the idle time of the core
|
|
21
|
-
totalIdle += cpu.times.idle
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Return the average Idle and Tick times
|
|
25
|
-
return { idle: totalIdle / cpus.length, total: totalTick / cpus.length }
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Grab first CPU Measure
|
|
29
|
-
const startMeasure = cpuAverage()
|
|
30
|
-
|
|
31
|
-
return new Promise((resolve) => {
|
|
32
|
-
// Set delay for second Measure
|
|
33
|
-
setTimeout(function () {
|
|
34
|
-
// Grab second Measure
|
|
35
|
-
const endMeasure = cpuAverage()
|
|
36
|
-
|
|
37
|
-
// Calculate the difference in idle and total time between the measures
|
|
38
|
-
const idleDifference = endMeasure.idle - startMeasure.idle
|
|
39
|
-
const totalDifference = endMeasure.total - startMeasure.total
|
|
40
|
-
|
|
41
|
-
// Calculate the average percentage CPU usage
|
|
42
|
-
const percentageCPU = 100 - ~~(100 * idleDifference / totalDifference)
|
|
43
|
-
|
|
44
|
-
// Output result to console
|
|
45
|
-
resolve(percentageCPU)
|
|
46
|
-
}, 1000)
|
|
47
|
-
})
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
class Monitoring {
|
|
51
|
-
constructor (reporter) {
|
|
52
|
-
this.reporter = reporter
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async execute () {
|
|
56
|
-
const monitoring = {
|
|
57
|
-
cpu: await cpu(),
|
|
58
|
-
freemem: Math.round(os.freemem() / 1024 / 1024),
|
|
59
|
-
timestamp: new Date(),
|
|
60
|
-
hostname: os.hostname()
|
|
61
|
-
}
|
|
62
|
-
return this.reporter.documentStore.collection('monitoring').insert(monitoring)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
init () {
|
|
66
|
-
this._interval = setInterval(() => {
|
|
67
|
-
this.execute().catch((e) => this.reporter.logger.warn('unable to persist monitoring info, but no need to worry, we will retry, details:' + e.stack))
|
|
68
|
-
}, 60000)
|
|
69
|
-
this._interval.unref()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
close () {
|
|
73
|
-
clearInterval(this._interval)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
module.exports = (reporter) => {
|
|
78
|
-
reporter.documentStore.registerEntityType('MonitoringType', {
|
|
79
|
-
cpu: { type: 'Edm.Int32' },
|
|
80
|
-
freemem: { type: 'Edm.Int32' },
|
|
81
|
-
timestamp: { type: 'Edm.DateTimeOffset', schema: { type: 'null' } },
|
|
82
|
-
hostname: { type: 'Edm.String' }
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
reporter.documentStore.registerEntitySet('monitoring', {
|
|
86
|
-
entityType: 'jsreport.MonitoringType',
|
|
87
|
-
exportable: false,
|
|
88
|
-
shared: true
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
reporter.monitoring = new Monitoring(reporter)
|
|
92
|
-
}
|