@jsreport/jsreport-core 3.0.1 → 3.1.2-test.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.
Files changed (79) hide show
  1. package/LICENSE +166 -166
  2. package/README.md +298 -284
  3. package/index.js +29 -27
  4. package/lib/main/blobStorage/blobStorage.js +52 -47
  5. package/lib/main/blobStorage/inMemoryProvider.js +27 -27
  6. package/lib/main/blobStorage/mainActions.js +24 -24
  7. package/lib/main/createDefaultLoggerFormat.js +17 -17
  8. package/lib/main/defaults.js +14 -14
  9. package/lib/main/extensions/discover.js +20 -20
  10. package/lib/main/extensions/extensionsManager.js +264 -265
  11. package/lib/main/extensions/fileUtils.js +56 -55
  12. package/lib/main/extensions/findVersion.js +49 -53
  13. package/lib/main/extensions/locationCache.js +103 -97
  14. package/lib/main/extensions/sorter.js +10 -10
  15. package/lib/main/extensions/validateMinimalVersion.js +50 -50
  16. package/lib/main/folders/cascadeFolderRemove.js +25 -25
  17. package/lib/main/folders/getEntitiesInFolder.js +53 -53
  18. package/lib/main/folders/index.js +42 -42
  19. package/lib/main/folders/moveBetweenFolders.js +354 -354
  20. package/lib/main/folders/validateDuplicatedName.js +107 -107
  21. package/lib/main/folders/validateReservedName.js +53 -53
  22. package/lib/main/logger.js +244 -244
  23. package/lib/main/migration/resourcesToAssets.js +230 -210
  24. package/lib/main/migration/xlsxTemplatesToAssets.js +128 -118
  25. package/lib/main/monitoring.js +91 -91
  26. package/lib/main/optionsLoad.js +237 -237
  27. package/lib/main/optionsSchema.js +237 -237
  28. package/lib/main/reporter.js +579 -578
  29. package/lib/main/schemaValidator.js +252 -252
  30. package/lib/main/settings.js +154 -154
  31. package/lib/main/store/checkDuplicatedId.js +27 -27
  32. package/lib/main/store/collection.js +329 -329
  33. package/lib/main/store/documentStore.js +469 -469
  34. package/lib/main/store/mainActions.js +28 -28
  35. package/lib/main/store/memoryStoreProvider.js +99 -99
  36. package/lib/main/store/queue.js +48 -48
  37. package/lib/main/store/referenceUtils.js +251 -251
  38. package/lib/main/store/setupValidateId.js +43 -43
  39. package/lib/main/store/setupValidateShortid.js +71 -71
  40. package/lib/main/store/transaction.js +69 -69
  41. package/lib/main/store/typeUtils.js +180 -180
  42. package/lib/main/templates.js +34 -34
  43. package/lib/main/validateEntityName.js +62 -62
  44. package/lib/shared/createError.js +36 -36
  45. package/lib/shared/encryption.js +114 -114
  46. package/lib/shared/folders/index.js +11 -11
  47. package/lib/shared/folders/normalizeEntityPath.js +15 -15
  48. package/lib/shared/folders/resolveEntityFromPath.js +88 -88
  49. package/lib/shared/folders/resolveEntityPath.js +46 -46
  50. package/lib/shared/folders/resolveFolderFromPath.js +38 -38
  51. package/lib/shared/generateRequestId.js +4 -4
  52. package/lib/shared/listenerCollection.js +169 -0
  53. package/lib/shared/normalizeMetaFromLogs.js +30 -30
  54. package/lib/shared/reporter.js +123 -123
  55. package/lib/shared/request.js +64 -64
  56. package/lib/shared/tempFilesHandler.js +81 -81
  57. package/lib/shared/templates.js +82 -82
  58. package/lib/static/helpers.js +33 -33
  59. package/lib/worker/blobStorage.js +34 -34
  60. package/lib/worker/defaultProxyExtend.js +46 -46
  61. package/lib/worker/documentStore.js +49 -49
  62. package/lib/worker/extensionsManager.js +17 -17
  63. package/lib/worker/logger.js +48 -48
  64. package/lib/worker/render/diff.js +138 -138
  65. package/lib/worker/render/executeEngine.js +207 -200
  66. package/lib/worker/render/htmlRecipe.js +10 -10
  67. package/lib/worker/render/moduleHelper.js +43 -43
  68. package/lib/worker/render/noneEngine.js +12 -12
  69. package/lib/worker/render/profiler.js +158 -158
  70. package/lib/worker/render/render.js +205 -209
  71. package/lib/worker/render/resolveReferences.js +60 -60
  72. package/lib/worker/reporter.js +191 -187
  73. package/lib/worker/sandbox/runInSandbox.js +13 -4
  74. package/lib/worker/sandbox/safeSandbox.js +828 -822
  75. package/lib/worker/templates.js +78 -78
  76. package/lib/worker/workerHandler.js +54 -54
  77. package/package.json +92 -92
  78. package/test/blobStorage/common.js +21 -21
  79. package/test/store/common.js +1449 -1449
@@ -1,123 +1,123 @@
1
- const EventEmitter = require('events')
2
- const ListenerCollection = require('listener-collection')
3
- const Request = require('./request')
4
- const Templates = require('./templates')
5
- const Folders = require('./folders')
6
- const createOrExtendError = require('./createError')
7
- const tempFilesHandler = require('./tempFilesHandler')
8
- const encryption = require('./encryption')
9
-
10
- class Reporter extends EventEmitter {
11
- constructor (options) {
12
- super()
13
-
14
- this.options = options || {}
15
- this.Request = Request
16
-
17
- // since `reporter` instance will be used for other extensions,
18
- // it will quickly reach the limit of `10` listeners,
19
- // we increase the limit to Infinity for now,
20
- // later we should probably design
21
- // a way to detect possible memory leaks from extensions
22
- this.setMaxListeners(Infinity)
23
-
24
- const coreVersion = require('../../package.json').version
25
-
26
- this.version = coreVersion
27
- this.coreVersion = coreVersion
28
-
29
- this.initializeListeners = this.createListenerCollection()
30
- this.afterRenderListeners = this.createListenerCollection()
31
- this.renderErrorListeners = this.createListenerCollection()
32
- this.beforeRenderListeners = this.createListenerCollection()
33
- this.closeListeners = this.createListenerCollection()
34
- }
35
-
36
- createListenerCollection () {
37
- return new ListenerCollection()
38
- }
39
-
40
- /**
41
- * Creates a custom error or extends an existing one
42
- *
43
- * @public
44
- */
45
- createError (message, options = {}) {
46
- return createOrExtendError(message, options)
47
- }
48
-
49
- /**
50
- * Ensures that the jsreport autocleanup temp directory (options.tempAutoCleanupDirectory) exists by doing a mkdir call
51
- *
52
- * @public
53
- */
54
- async ensureTempDirectoryExists () {
55
- if (this.options.tempAutoCleanupDirectory == null) {
56
- throw new Error('Can not use ensureTempDirectoryExists when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
57
- }
58
-
59
- return tempFilesHandler.ensureTempDirectoryExists(this.options.tempAutoCleanupDirectory)
60
- }
61
-
62
- /**
63
- * Reads a file from the jsreport autocleanup temp directory (options.tempAutoCleanupDirectory)
64
- *
65
- * @public
66
- */
67
- async readTempFile (filename, opts) {
68
- if (this.options.tempAutoCleanupDirectory == null) {
69
- throw new Error('Can not use readTempFile when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
70
- }
71
-
72
- return tempFilesHandler.readTempFile(this.options.tempAutoCleanupDirectory, filename, opts)
73
- }
74
-
75
- /**
76
- * Creates a file into the jsreport autocleanup temp directory (options.tempAutoCleanupDirectory)
77
- * ensuring that the directory always exists
78
- *
79
- * @public
80
- */
81
- async writeTempFile (filenameFn, content, opts) {
82
- if (this.options.tempAutoCleanupDirectory == null) {
83
- throw new Error('Can not use writeTempFile when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
84
- }
85
-
86
- return tempFilesHandler.writeTempFile(this.options.tempAutoCleanupDirectory, filenameFn, content, opts)
87
- }
88
-
89
- /**
90
- * Reads a file as stream from the jsreport autocleanup temp directory (options.tempAutoCleanupDirectory)
91
- *
92
- * @public
93
- */
94
- async readTempFileStream (filename, opts) {
95
- if (this.options.tempAutoCleanupDirectory == null) {
96
- throw new Error('Can not use readTempFileStream when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
97
- }
98
-
99
- return tempFilesHandler.readTempFileStream(this.options.tempAutoCleanupDirectory, filename, opts)
100
- }
101
-
102
- /**
103
- * Creates a file as stream into the jsreport autocleanup temp directory (options.tempAutoCleanupDirectory)
104
- * ensuring that the directory always exists
105
- *
106
- * @public
107
- */
108
- async writeTempFileStream (filenameFn, opts) {
109
- if (this.options.tempAutoCleanupDirectory == null) {
110
- throw new Error('Can not use writeTempFileStream when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
111
- }
112
-
113
- return tempFilesHandler.writeTempFileStream(this.options.tempAutoCleanupDirectory, filenameFn, opts)
114
- }
115
-
116
- async init () {
117
- this.templates = Templates(this)
118
- this.folders = Folders(this)
119
- this.encryption = encryption(this)
120
- }
121
- }
122
-
123
- module.exports = Reporter
1
+ const EventEmitter = require('events')
2
+ const createListenerCollection = require('./listenerCollection')
3
+ const Request = require('./request')
4
+ const Templates = require('./templates')
5
+ const Folders = require('./folders')
6
+ const createOrExtendError = require('./createError')
7
+ const tempFilesHandler = require('./tempFilesHandler')
8
+ const encryption = require('./encryption')
9
+
10
+ class Reporter extends EventEmitter {
11
+ constructor (options) {
12
+ super()
13
+
14
+ this.options = options || {}
15
+ this.Request = Request
16
+
17
+ // since `reporter` instance will be used for other extensions,
18
+ // it will quickly reach the limit of `10` listeners,
19
+ // we increase the limit to Infinity for now,
20
+ // later we should probably design
21
+ // a way to detect possible memory leaks from extensions
22
+ this.setMaxListeners(Infinity)
23
+
24
+ const coreVersion = require('../../package.json').version
25
+
26
+ this.version = coreVersion
27
+ this.coreVersion = coreVersion
28
+
29
+ this.initializeListeners = this.createListenerCollection('initialize')
30
+ this.afterRenderListeners = this.createListenerCollection('afterRender')
31
+ this.renderErrorListeners = this.createListenerCollection('renderError')
32
+ this.beforeRenderListeners = this.createListenerCollection('beforeRender')
33
+ this.closeListeners = this.createListenerCollection('close')
34
+ }
35
+
36
+ createListenerCollection (name) {
37
+ return createListenerCollection(name)
38
+ }
39
+
40
+ /**
41
+ * Creates a custom error or extends an existing one
42
+ *
43
+ * @public
44
+ */
45
+ createError (message, options = {}) {
46
+ return createOrExtendError(message, options)
47
+ }
48
+
49
+ /**
50
+ * Ensures that the jsreport auto-cleanup temp directory (options.tempAutoCleanupDirectory) exists by doing a mkdir call
51
+ *
52
+ * @public
53
+ */
54
+ async ensureTempDirectoryExists () {
55
+ if (this.options.tempAutoCleanupDirectory == null) {
56
+ throw new Error('Can not use ensureTempDirectoryExists when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
57
+ }
58
+
59
+ return tempFilesHandler.ensureTempDirectoryExists(this.options.tempAutoCleanupDirectory)
60
+ }
61
+
62
+ /**
63
+ * Reads a file from the jsreport auto-cleanup temp directory (options.tempAutoCleanupDirectory)
64
+ *
65
+ * @public
66
+ */
67
+ async readTempFile (filename, opts) {
68
+ if (this.options.tempAutoCleanupDirectory == null) {
69
+ throw new Error('Can not use readTempFile when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
70
+ }
71
+
72
+ return tempFilesHandler.readTempFile(this.options.tempAutoCleanupDirectory, filename, opts)
73
+ }
74
+
75
+ /**
76
+ * Creates a file into the jsreport auto-cleanup temp directory (options.tempAutoCleanupDirectory)
77
+ * ensuring that the directory always exists
78
+ *
79
+ * @public
80
+ */
81
+ async writeTempFile (filenameFn, content, opts) {
82
+ if (this.options.tempAutoCleanupDirectory == null) {
83
+ throw new Error('Can not use writeTempFile when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
84
+ }
85
+
86
+ return tempFilesHandler.writeTempFile(this.options.tempAutoCleanupDirectory, filenameFn, content, opts)
87
+ }
88
+
89
+ /**
90
+ * Reads a file as stream from the jsreport auto-cleanup temp directory (options.tempAutoCleanupDirectory)
91
+ *
92
+ * @public
93
+ */
94
+ async readTempFileStream (filename, opts) {
95
+ if (this.options.tempAutoCleanupDirectory == null) {
96
+ throw new Error('Can not use readTempFileStream when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
97
+ }
98
+
99
+ return tempFilesHandler.readTempFileStream(this.options.tempAutoCleanupDirectory, filename, opts)
100
+ }
101
+
102
+ /**
103
+ * Creates a file as stream into the jsreport auto-cleanup temp directory (options.tempAutoCleanupDirectory)
104
+ * ensuring that the directory always exists
105
+ *
106
+ * @public
107
+ */
108
+ async writeTempFileStream (filenameFn, opts) {
109
+ if (this.options.tempAutoCleanupDirectory == null) {
110
+ throw new Error('Can not use writeTempFileStream when tempAutoCleanupDirectory option is not initialized, make sure to initialize jsreport first using jsreport.init()')
111
+ }
112
+
113
+ return tempFilesHandler.writeTempFileStream(this.options.tempAutoCleanupDirectory, filenameFn, opts)
114
+ }
115
+
116
+ async init () {
117
+ this.templates = Templates(this)
118
+ this.folders = Folders(this)
119
+ this.encryption = encryption(this)
120
+ }
121
+ }
122
+
123
+ module.exports = Reporter
@@ -1,64 +1,64 @@
1
- const extend = require('node.extend.without.arrays')
2
- const omit = require('lodash.omit')
3
-
4
- module.exports = (obj, parent) => {
5
- if (parent && !parent.__isJsreportRequest__) {
6
- throw new Error('Invalid parent request passed')
7
- }
8
-
9
- const request = Object.create({}, {
10
- __isJsreportRequest__: {
11
- value: true,
12
- writable: false,
13
- configurable: false,
14
- enumerable: false
15
- }
16
- })
17
-
18
- request.template = extend(true, {}, obj.template)
19
-
20
- if (parent) {
21
- request.context = Object.assign({}, request.context, omit(parent.context, ['id', 'logs', 'systemHelpers']))
22
- request.context.isChildRequest = true
23
- request.options = Object.assign({}, request.options, parent.options)
24
-
25
- if (parent.data) {
26
- const dataInput = normalizeJSONData(parent.data)
27
- request.data = Object.assign(Array.isArray(dataInput) ? [] : {}, dataInput)
28
- }
29
- }
30
-
31
- request.options = extend(true, {}, request.options, obj.options)
32
- request.context = extend(true, {}, request.context, obj.context)
33
- request.context.shared = extend(true, {}, request.context.shared)
34
-
35
- if (obj.data) {
36
- const dataInput = normalizeJSONData(obj.data)
37
- request.data = Object.assign(Array.isArray(dataInput) ? [] : {}, request.data, dataInput)
38
-
39
- // don't override value if it was already set by caller
40
- if (obj.context == null || obj.context.originalInputDataIsEmpty == null) {
41
- request.context.originalInputDataIsEmpty = false
42
- }
43
- } else if (!parent) {
44
- // don't override value if it was already set by caller
45
- if (obj.context == null || obj.context.originalInputDataIsEmpty == null) {
46
- request.context.originalInputDataIsEmpty = true
47
- }
48
- }
49
-
50
- // initialize data if it is empty
51
- if (!request.data) {
52
- request.data = {}
53
- }
54
-
55
- return request
56
- }
57
-
58
- function normalizeJSONData (data) {
59
- if (typeof data === 'string') {
60
- return JSON.parse(data)
61
- }
62
-
63
- return data
64
- }
1
+ const extend = require('node.extend.without.arrays')
2
+ const omit = require('lodash.omit')
3
+
4
+ module.exports = (obj, parent) => {
5
+ if (parent && !parent.__isJsreportRequest__) {
6
+ throw new Error('Invalid parent request passed')
7
+ }
8
+
9
+ const request = Object.create({}, {
10
+ __isJsreportRequest__: {
11
+ value: true,
12
+ writable: false,
13
+ configurable: false,
14
+ enumerable: false
15
+ }
16
+ })
17
+
18
+ request.template = extend(true, {}, obj.template)
19
+
20
+ if (parent) {
21
+ request.context = Object.assign({}, request.context, omit(parent.context, ['id', 'logs', 'systemHelpers']))
22
+ request.context.isChildRequest = true
23
+ request.options = Object.assign({}, request.options, parent.options)
24
+
25
+ if (parent.data) {
26
+ const dataInput = normalizeJSONData(parent.data)
27
+ request.data = Object.assign(Array.isArray(dataInput) ? [] : {}, dataInput)
28
+ }
29
+ }
30
+
31
+ request.options = extend(true, {}, request.options, obj.options)
32
+ request.context = extend(true, {}, request.context, obj.context)
33
+ request.context.shared = extend(true, {}, request.context.shared)
34
+
35
+ if (obj.data) {
36
+ const dataInput = normalizeJSONData(obj.data)
37
+ request.data = Object.assign(Array.isArray(dataInput) ? [] : {}, request.data, dataInput)
38
+
39
+ // don't override value if it was already set by caller
40
+ if (obj.context == null || obj.context.originalInputDataIsEmpty == null) {
41
+ request.context.originalInputDataIsEmpty = false
42
+ }
43
+ } else if (!parent) {
44
+ // don't override value if it was already set by caller
45
+ if (obj.context == null || obj.context.originalInputDataIsEmpty == null) {
46
+ request.context.originalInputDataIsEmpty = true
47
+ }
48
+ }
49
+
50
+ // initialize data if it is empty
51
+ if (!request.data) {
52
+ request.data = {}
53
+ }
54
+
55
+ return request
56
+ }
57
+
58
+ function normalizeJSONData (data) {
59
+ if (typeof data === 'string') {
60
+ return JSON.parse(data)
61
+ }
62
+
63
+ return data
64
+ }
@@ -1,81 +1,81 @@
1
- const path = require('path')
2
- const fs = require('fs')
3
- const fsAsync = require('fs/promises')
4
- const { v4: uuidv4 } = require('uuid')
5
-
6
- module.exports.ensureTempDirectoryExists = async function (tempDirectory) {
7
- await fsAsync.mkdir(tempDirectory, {
8
- recursive: true
9
- })
10
-
11
- return {
12
- directoryPath: tempDirectory
13
- }
14
- }
15
-
16
- module.exports.readTempFile = async function readTempFile (tempDirectory, filename, opts = {}) {
17
- const pathToFile = path.join(tempDirectory, filename)
18
-
19
- const content = await fsAsync.readFile(pathToFile, opts)
20
-
21
- return {
22
- pathToFile,
23
- filename,
24
- content
25
- }
26
- }
27
-
28
- module.exports.readTempFileStream = async function readTempFileStream (tempDirectory, filename, opts = {}) {
29
- const pathToFile = path.join(tempDirectory, filename)
30
-
31
- return new Promise((resolve) => {
32
- const stream = fs.createReadStream(pathToFile, opts)
33
-
34
- resolve({
35
- pathToFile,
36
- filename,
37
- stream
38
- })
39
- })
40
- }
41
-
42
- module.exports.writeTempFile = async function writeTempFile (tempDirectory, filenameFn, content, opts = {}) {
43
- return writeFile(tempDirectory, filenameFn, content, opts)
44
- }
45
-
46
- module.exports.writeTempFileStream = async function writeTempFileStream (tempDirectory, filenameFn, opts = {}) {
47
- return writeFile(tempDirectory, filenameFn, undefined, opts, true)
48
- }
49
-
50
- async function writeFile (tempDirectory, filenameFn, content, opts, asStream = false) {
51
- const filename = filenameFn(uuidv4())
52
-
53
- if (filename == null || filename === '') {
54
- throw new Error('No valid filename was returned from filenameFn')
55
- }
56
-
57
- const pathToFile = path.join(tempDirectory, filename)
58
-
59
- await fsAsync.mkdir(tempDirectory, {
60
- recursive: true
61
- })
62
-
63
- if (asStream === true) {
64
- return new Promise((resolve) => {
65
- const stream = fs.createWriteStream(pathToFile, opts)
66
-
67
- resolve({
68
- pathToFile,
69
- filename,
70
- stream
71
- })
72
- })
73
- } else {
74
- await fsAsync.writeFile(pathToFile, content, opts)
75
-
76
- return {
77
- pathToFile,
78
- filename
79
- }
80
- }
81
- }
1
+ const path = require('path')
2
+ const fs = require('fs')
3
+ const fsAsync = require('fs/promises')
4
+ const { v4: uuidv4 } = require('uuid')
5
+
6
+ module.exports.ensureTempDirectoryExists = async function (tempDirectory) {
7
+ await fsAsync.mkdir(tempDirectory, {
8
+ recursive: true
9
+ })
10
+
11
+ return {
12
+ directoryPath: tempDirectory
13
+ }
14
+ }
15
+
16
+ module.exports.readTempFile = async function readTempFile (tempDirectory, filename, opts = {}) {
17
+ const pathToFile = path.join(tempDirectory, filename)
18
+
19
+ const content = await fsAsync.readFile(pathToFile, opts)
20
+
21
+ return {
22
+ pathToFile,
23
+ filename,
24
+ content
25
+ }
26
+ }
27
+
28
+ module.exports.readTempFileStream = async function readTempFileStream (tempDirectory, filename, opts = {}) {
29
+ const pathToFile = path.join(tempDirectory, filename)
30
+
31
+ return new Promise((resolve) => {
32
+ const stream = fs.createReadStream(pathToFile, opts)
33
+
34
+ resolve({
35
+ pathToFile,
36
+ filename,
37
+ stream
38
+ })
39
+ })
40
+ }
41
+
42
+ module.exports.writeTempFile = async function writeTempFile (tempDirectory, filenameFn, content, opts = {}) {
43
+ return writeFile(tempDirectory, filenameFn, content, opts)
44
+ }
45
+
46
+ module.exports.writeTempFileStream = async function writeTempFileStream (tempDirectory, filenameFn, opts = {}) {
47
+ return writeFile(tempDirectory, filenameFn, undefined, opts, true)
48
+ }
49
+
50
+ async function writeFile (tempDirectory, filenameFn, content, opts, asStream = false) {
51
+ const filename = filenameFn(uuidv4())
52
+
53
+ if (filename == null || filename === '') {
54
+ throw new Error('No valid filename was returned from filenameFn')
55
+ }
56
+
57
+ const pathToFile = path.join(tempDirectory, filename)
58
+
59
+ await fsAsync.mkdir(tempDirectory, {
60
+ recursive: true
61
+ })
62
+
63
+ if (asStream === true) {
64
+ return new Promise((resolve) => {
65
+ const stream = fs.createWriteStream(pathToFile, opts)
66
+
67
+ resolve({
68
+ pathToFile,
69
+ filename,
70
+ stream
71
+ })
72
+ })
73
+ } else {
74
+ await fsAsync.writeFile(pathToFile, content, opts)
75
+
76
+ return {
77
+ pathToFile,
78
+ filename
79
+ }
80
+ }
81
+ }