@jsreport/jsreport-core 3.1.2-test.2 → 3.2.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/LICENSE +166 -166
- package/README.md +298 -298
- package/index.js +29 -29
- package/lib/main/blobStorage/blobStorage.js +52 -52
- package/lib/main/blobStorage/inMemoryProvider.js +27 -27
- package/lib/main/blobStorage/mainActions.js +24 -24
- package/lib/main/createDefaultLoggerFormat.js +17 -17
- package/lib/main/defaults.js +14 -14
- package/lib/main/extensions/discover.js +20 -20
- package/lib/main/extensions/extensionsManager.js +264 -264
- package/lib/main/extensions/fileUtils.js +56 -56
- package/lib/main/extensions/findVersion.js +49 -49
- package/lib/main/extensions/locationCache.js +103 -103
- package/lib/main/extensions/sorter.js +10 -10
- package/lib/main/extensions/validateMinimalVersion.js +50 -50
- package/lib/main/folders/cascadeFolderRemove.js +25 -25
- package/lib/main/folders/getEntitiesInFolder.js +53 -53
- package/lib/main/folders/index.js +42 -42
- package/lib/main/folders/moveBetweenFolders.js +354 -354
- package/lib/main/folders/validateDuplicatedName.js +107 -107
- package/lib/main/folders/validateReservedName.js +53 -53
- package/lib/main/logger.js +244 -244
- package/lib/main/migration/resourcesToAssets.js +230 -230
- package/lib/main/migration/xlsxTemplatesToAssets.js +128 -128
- package/lib/main/monitoring.js +91 -91
- package/lib/main/optionsLoad.js +237 -237
- package/lib/main/optionsSchema.js +237 -237
- package/lib/main/reporter.js +574 -579
- package/lib/main/schemaValidator.js +252 -252
- package/lib/main/settings.js +154 -154
- package/lib/main/store/checkDuplicatedId.js +27 -27
- package/lib/main/store/collection.js +329 -329
- package/lib/main/store/documentStore.js +469 -469
- package/lib/main/store/mainActions.js +28 -28
- package/lib/main/store/memoryStoreProvider.js +99 -99
- package/lib/main/store/queue.js +48 -48
- package/lib/main/store/referenceUtils.js +251 -251
- package/lib/main/store/setupValidateId.js +43 -43
- package/lib/main/store/setupValidateShortid.js +71 -71
- package/lib/main/store/transaction.js +69 -69
- package/lib/main/store/typeUtils.js +180 -180
- package/lib/main/templates.js +34 -34
- package/lib/main/validateEntityName.js +62 -62
- package/lib/shared/createError.js +36 -36
- package/lib/shared/encryption.js +114 -114
- package/lib/shared/folders/index.js +11 -11
- package/lib/shared/folders/normalizeEntityPath.js +15 -15
- package/lib/shared/folders/resolveEntityFromPath.js +88 -88
- package/lib/shared/folders/resolveEntityPath.js +46 -46
- package/lib/shared/folders/resolveFolderFromPath.js +38 -38
- package/lib/shared/generateRequestId.js +4 -4
- package/lib/shared/listenerCollection.js +169 -169
- package/lib/shared/normalizeMetaFromLogs.js +30 -30
- package/lib/shared/reporter.js +128 -123
- package/lib/shared/request.js +64 -64
- package/lib/shared/tempFilesHandler.js +81 -81
- package/lib/shared/templates.js +82 -82
- package/lib/static/helpers.js +33 -33
- package/lib/worker/blobStorage.js +34 -34
- package/lib/worker/defaultProxyExtend.js +46 -46
- package/lib/worker/documentStore.js +49 -49
- package/lib/worker/extensionsManager.js +17 -17
- package/lib/worker/logger.js +48 -48
- package/lib/worker/render/diff.js +138 -138
- package/lib/worker/render/executeEngine.js +239 -207
- package/lib/worker/render/htmlRecipe.js +10 -10
- package/lib/worker/render/moduleHelper.js +45 -43
- package/lib/worker/render/noneEngine.js +12 -12
- package/lib/worker/render/profiler.js +158 -158
- package/lib/worker/render/render.js +202 -205
- package/lib/worker/render/resolveReferences.js +60 -60
- package/lib/worker/reporter.js +192 -191
- package/lib/worker/sandbox/runInSandbox.js +16 -9
- package/lib/worker/sandbox/safeSandbox.js +828 -828
- package/lib/worker/templates.js +80 -78
- package/lib/worker/workerHandler.js +54 -54
- package/package.json +92 -92
- package/test/blobStorage/common.js +21 -21
- package/test/store/common.js +1449 -1449
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
const extend = require('node.extend.without.arrays')
|
|
2
|
-
const isbinaryfile = require('isbinaryfile').isBinaryFileSync
|
|
3
|
-
const omit = require('lodash.omit')
|
|
4
|
-
const { createPatch } = require('./diff')
|
|
5
|
-
const generateRequestId = require('../../shared/generateRequestId')
|
|
6
|
-
|
|
7
|
-
class Profiler {
|
|
8
|
-
constructor (reporter) {
|
|
9
|
-
this.reporter = reporter
|
|
10
|
-
|
|
11
|
-
this.reporter.addRequestContextMetaConfig('profiling', { sandboxReadOnly: true })
|
|
12
|
-
this.reporter.addRequestContextMetaConfig('resolvedTemplate', { sandboxHidden: true })
|
|
13
|
-
|
|
14
|
-
this.reporter.beforeMainActionListeners.add('profiler', (actionName, data, req) => {
|
|
15
|
-
if (actionName === 'log' && req.context.profiling) {
|
|
16
|
-
data.previousOperationId = req.context.profiling.lastOperationId
|
|
17
|
-
}
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
this.profiledRequestsMap = new Map()
|
|
21
|
-
const profileEventsFlushInterval = setInterval(async () => {
|
|
22
|
-
for (const id of [...this.profiledRequestsMap.keys()]) {
|
|
23
|
-
const profilingInfo = this.profiledRequestsMap.get(id)
|
|
24
|
-
if (profilingInfo) {
|
|
25
|
-
const batch = profilingInfo.batch
|
|
26
|
-
profilingInfo.batch = []
|
|
27
|
-
await this.reporter.executeMainAction('profile', batch, profilingInfo.req).catch((e) => this.reporter.logger.error(e, profilingInfo.req))
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}, 100)
|
|
31
|
-
profileEventsFlushInterval.unref()
|
|
32
|
-
|
|
33
|
-
this.reporter.closeListeners.add('profiler', this, () => {
|
|
34
|
-
if (profileEventsFlushInterval) {
|
|
35
|
-
clearInterval(profileEventsFlushInterval)
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
emit (m, req, res) {
|
|
41
|
-
m.timestamp = m.timestamp || new Date().getTime()
|
|
42
|
-
|
|
43
|
-
if (m.type === 'log' && !req.context.profiling) {
|
|
44
|
-
// this means there is an action running, but not the render, and it is logging...
|
|
45
|
-
return this.reporter.executeMainAction('log', m, req)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
m.id = generateRequestId()
|
|
49
|
-
|
|
50
|
-
if (m.previousEventId == null && req.context.profiling.lastEventId && m.type !== 'log') {
|
|
51
|
-
m.previousEventId = req.context.profiling.lastEventId
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
if (m.type !== 'log') {
|
|
55
|
-
req.context.profiling.lastEventId = m.id
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
m.operationId = m.operationId || generateRequestId()
|
|
59
|
-
if (m.previousOperationId == null && req.context.profiling.lastOperationId) {
|
|
60
|
-
m.previousOperationId = req.context.profiling.lastOperationId
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (m.type === 'operationStart') {
|
|
64
|
-
req.context.profiling.lastOperationId = m.operationId
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (m.doDiffs !== false && req.context.profiling.mode === 'full' && (m.type === 'operationStart' || m.type === 'operationEnd')) {
|
|
68
|
-
let content = res.content
|
|
69
|
-
|
|
70
|
-
if (content != null) {
|
|
71
|
-
if (isbinaryfile(content)) {
|
|
72
|
-
content = {
|
|
73
|
-
content: res.content.toString('base64'),
|
|
74
|
-
encoding: 'base64'
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
content = {
|
|
78
|
-
content: createPatch('res', req.context.profiling.resLastVal ? req.context.profiling.resLastVal.toString() : '', res.content.toString(), 0),
|
|
79
|
-
encoding: 'diff'
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const stringifiedResMeta = JSON.stringify(omit(res.meta, ['logs']))
|
|
85
|
-
|
|
86
|
-
m.res = { content, meta: { diff: createPatch('resMeta', req.context.profiling.resMetaLastVal || '', stringifiedResMeta, 0) } }
|
|
87
|
-
|
|
88
|
-
const stringifiedReq = JSON.stringify({ template: req.template, data: req.data }, null, 2)
|
|
89
|
-
|
|
90
|
-
m.req = { diff: createPatch('req', req.context.profiling.reqLastVal || '', stringifiedReq, 0) }
|
|
91
|
-
|
|
92
|
-
req.context.profiling.resLastVal = res.content
|
|
93
|
-
req.context.profiling.resMetaLastVal = stringifiedResMeta
|
|
94
|
-
req.context.profiling.reqLastVal = stringifiedReq
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!this.profiledRequestsMap.has(req.context.rootId)) {
|
|
98
|
-
this.profiledRequestsMap.set(req.context.rootId, { req, batch: [] })
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
this.profiledRequestsMap.get(req.context.rootId).batch.push(m)
|
|
102
|
-
return m
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async renderStart (req, parentReq, res) {
|
|
106
|
-
let templateName = 'anonymous'
|
|
107
|
-
let template = req.context.resolvedTemplate
|
|
108
|
-
|
|
109
|
-
if (parentReq) {
|
|
110
|
-
template = await this.reporter.templates.resolveTemplate(req)
|
|
111
|
-
// store a copy to prevent side-effects
|
|
112
|
-
req.context.resolvedTemplate = extend(true, {}, template)
|
|
113
|
-
} else {
|
|
114
|
-
template = req.context.resolvedTemplate
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (template != null && template.name != null) {
|
|
118
|
-
templateName = template.name
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const profilerEvent = {
|
|
122
|
-
type: 'operationStart',
|
|
123
|
-
subtype: 'render',
|
|
124
|
-
name: templateName,
|
|
125
|
-
previousOperationId: parentReq ? parentReq.context.profiling.lastOperationId : null
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (!req.context.isChildRequest) {
|
|
129
|
-
profilerEvent.profileId = req.context.profiling.entity._id
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return this.emit(profilerEvent, req, res)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async renderEnd (operationId, req, res, err) {
|
|
136
|
-
if (err) {
|
|
137
|
-
err.previousOperationId = err.previousOperationId || req.context.profiling.lastOperationId
|
|
138
|
-
} else {
|
|
139
|
-
await this.emit({
|
|
140
|
-
type: 'operationEnd',
|
|
141
|
-
subtype: 'render',
|
|
142
|
-
operationId
|
|
143
|
-
}, req, res)
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (!req.context.isChildRequest) {
|
|
147
|
-
const profilingInfo = this.profiledRequestsMap.get(req.context.rootId)
|
|
148
|
-
if (profilingInfo) {
|
|
149
|
-
this.profiledRequestsMap.delete(req.context.rootId)
|
|
150
|
-
await this.reporter.executeMainAction('profile', profilingInfo.batch, req)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
module.exports = (reporter) => {
|
|
157
|
-
return new Profiler(reporter)
|
|
158
|
-
}
|
|
1
|
+
const extend = require('node.extend.without.arrays')
|
|
2
|
+
const isbinaryfile = require('isbinaryfile').isBinaryFileSync
|
|
3
|
+
const omit = require('lodash.omit')
|
|
4
|
+
const { createPatch } = require('./diff')
|
|
5
|
+
const generateRequestId = require('../../shared/generateRequestId')
|
|
6
|
+
|
|
7
|
+
class Profiler {
|
|
8
|
+
constructor (reporter) {
|
|
9
|
+
this.reporter = reporter
|
|
10
|
+
|
|
11
|
+
this.reporter.addRequestContextMetaConfig('profiling', { sandboxReadOnly: true })
|
|
12
|
+
this.reporter.addRequestContextMetaConfig('resolvedTemplate', { sandboxHidden: true })
|
|
13
|
+
|
|
14
|
+
this.reporter.beforeMainActionListeners.add('profiler', (actionName, data, req) => {
|
|
15
|
+
if (actionName === 'log' && req.context.profiling) {
|
|
16
|
+
data.previousOperationId = req.context.profiling.lastOperationId
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
this.profiledRequestsMap = new Map()
|
|
21
|
+
const profileEventsFlushInterval = setInterval(async () => {
|
|
22
|
+
for (const id of [...this.profiledRequestsMap.keys()]) {
|
|
23
|
+
const profilingInfo = this.profiledRequestsMap.get(id)
|
|
24
|
+
if (profilingInfo) {
|
|
25
|
+
const batch = profilingInfo.batch
|
|
26
|
+
profilingInfo.batch = []
|
|
27
|
+
await this.reporter.executeMainAction('profile', batch, profilingInfo.req).catch((e) => this.reporter.logger.error(e, profilingInfo.req))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}, 100)
|
|
31
|
+
profileEventsFlushInterval.unref()
|
|
32
|
+
|
|
33
|
+
this.reporter.closeListeners.add('profiler', this, () => {
|
|
34
|
+
if (profileEventsFlushInterval) {
|
|
35
|
+
clearInterval(profileEventsFlushInterval)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
emit (m, req, res) {
|
|
41
|
+
m.timestamp = m.timestamp || new Date().getTime()
|
|
42
|
+
|
|
43
|
+
if (m.type === 'log' && !req.context.profiling) {
|
|
44
|
+
// this means there is an action running, but not the render, and it is logging...
|
|
45
|
+
return this.reporter.executeMainAction('log', m, req)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
m.id = generateRequestId()
|
|
49
|
+
|
|
50
|
+
if (m.previousEventId == null && req.context.profiling.lastEventId && m.type !== 'log') {
|
|
51
|
+
m.previousEventId = req.context.profiling.lastEventId
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (m.type !== 'log') {
|
|
55
|
+
req.context.profiling.lastEventId = m.id
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
m.operationId = m.operationId || generateRequestId()
|
|
59
|
+
if (m.previousOperationId == null && req.context.profiling.lastOperationId) {
|
|
60
|
+
m.previousOperationId = req.context.profiling.lastOperationId
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (m.type === 'operationStart') {
|
|
64
|
+
req.context.profiling.lastOperationId = m.operationId
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (m.doDiffs !== false && req.context.profiling.mode === 'full' && (m.type === 'operationStart' || m.type === 'operationEnd')) {
|
|
68
|
+
let content = res.content
|
|
69
|
+
|
|
70
|
+
if (content != null) {
|
|
71
|
+
if (isbinaryfile(content)) {
|
|
72
|
+
content = {
|
|
73
|
+
content: res.content.toString('base64'),
|
|
74
|
+
encoding: 'base64'
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
content = {
|
|
78
|
+
content: createPatch('res', req.context.profiling.resLastVal ? req.context.profiling.resLastVal.toString() : '', res.content.toString(), 0),
|
|
79
|
+
encoding: 'diff'
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const stringifiedResMeta = JSON.stringify(omit(res.meta, ['logs']))
|
|
85
|
+
|
|
86
|
+
m.res = { content, meta: { diff: createPatch('resMeta', req.context.profiling.resMetaLastVal || '', stringifiedResMeta, 0) } }
|
|
87
|
+
|
|
88
|
+
const stringifiedReq = JSON.stringify({ template: req.template, data: req.data }, null, 2)
|
|
89
|
+
|
|
90
|
+
m.req = { diff: createPatch('req', req.context.profiling.reqLastVal || '', stringifiedReq, 0) }
|
|
91
|
+
|
|
92
|
+
req.context.profiling.resLastVal = res.content
|
|
93
|
+
req.context.profiling.resMetaLastVal = stringifiedResMeta
|
|
94
|
+
req.context.profiling.reqLastVal = stringifiedReq
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (!this.profiledRequestsMap.has(req.context.rootId)) {
|
|
98
|
+
this.profiledRequestsMap.set(req.context.rootId, { req, batch: [] })
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.profiledRequestsMap.get(req.context.rootId).batch.push(m)
|
|
102
|
+
return m
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async renderStart (req, parentReq, res) {
|
|
106
|
+
let templateName = 'anonymous'
|
|
107
|
+
let template = req.context.resolvedTemplate
|
|
108
|
+
|
|
109
|
+
if (parentReq) {
|
|
110
|
+
template = await this.reporter.templates.resolveTemplate(req)
|
|
111
|
+
// store a copy to prevent side-effects
|
|
112
|
+
req.context.resolvedTemplate = extend(true, {}, template)
|
|
113
|
+
} else {
|
|
114
|
+
template = req.context.resolvedTemplate
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (template != null && template.name != null) {
|
|
118
|
+
templateName = template.name
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const profilerEvent = {
|
|
122
|
+
type: 'operationStart',
|
|
123
|
+
subtype: 'render',
|
|
124
|
+
name: templateName,
|
|
125
|
+
previousOperationId: parentReq ? parentReq.context.profiling.lastOperationId : null
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!req.context.isChildRequest) {
|
|
129
|
+
profilerEvent.profileId = req.context.profiling.entity._id
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return this.emit(profilerEvent, req, res)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async renderEnd (operationId, req, res, err) {
|
|
136
|
+
if (err) {
|
|
137
|
+
err.previousOperationId = err.previousOperationId || req.context.profiling.lastOperationId
|
|
138
|
+
} else {
|
|
139
|
+
await this.emit({
|
|
140
|
+
type: 'operationEnd',
|
|
141
|
+
subtype: 'render',
|
|
142
|
+
operationId
|
|
143
|
+
}, req, res)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!req.context.isChildRequest) {
|
|
147
|
+
const profilingInfo = this.profiledRequestsMap.get(req.context.rootId)
|
|
148
|
+
if (profilingInfo) {
|
|
149
|
+
this.profiledRequestsMap.delete(req.context.rootId)
|
|
150
|
+
await this.reporter.executeMainAction('profile', profilingInfo.batch, req)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
module.exports = (reporter) => {
|
|
157
|
+
return new Profiler(reporter)
|
|
158
|
+
}
|