@jsreport/jsreport-core 3.12.0 → 4.0.1
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 +11 -0
- package/lib/main/optionsSchema.js +263 -271
- package/lib/main/reporter.js +8 -16
- package/lib/main/schemaValidator.js +1 -1
- package/lib/main/settings.js +14 -8
- package/lib/main/store/memoryStoreProvider.js +104 -99
- package/lib/worker/render/executeEngine.js +23 -1
- package/lib/worker/reporter.js +45 -0
- package/lib/worker/sandbox/createSandbox.js +56 -98
- package/lib/worker/sandbox/isolatedRequire.js +1 -21
- package/lib/worker/sandbox/propertiesSandbox.js +2 -2
- package/lib/worker/sandbox/runInSandbox.js +20 -7
- package/package.json +7 -7
- package/test/extensions/validExtensions/listeners/main.js +62 -51
- package/test/extensions/validExtensions/listeners/worker.js +81 -74
- package/test/store/common.js +55 -0
- package/lib/main/migration/resourcesToAssets.js +0 -230
- package/lib/main/migration/xlsxTemplatesToAssets.js +0 -128
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
const Request = require('../../shared/request')
|
|
2
|
-
|
|
3
|
-
module.exports = async (reporter) => {
|
|
4
|
-
if (
|
|
5
|
-
reporter.options.migrateXlsxTemplatesToAssets === false ||
|
|
6
|
-
reporter.documentStore.collection('xlsxTemplates') == null ||
|
|
7
|
-
reporter.documentStore.collection('assets') == null
|
|
8
|
-
) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const migrated = await reporter.settings.findValue('core-migrated-xlsxTemplates')
|
|
13
|
-
|
|
14
|
-
if (migrated) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const req = Request({})
|
|
19
|
-
await reporter.documentStore.beginTransaction(req)
|
|
20
|
-
|
|
21
|
-
try {
|
|
22
|
-
const xlsxTemplateIds = await reporter.documentStore.collection('xlsxTemplates').find({}, { _id: 1 }, req)
|
|
23
|
-
|
|
24
|
-
if (xlsxTemplateIds.length !== 0) {
|
|
25
|
-
reporter.logger.debug('Running migration "xlsxTemplatesToAssets"')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const xlsxTemplateToAssetMap = new Map()
|
|
29
|
-
|
|
30
|
-
for (const xlsxTemplateId of xlsxTemplateIds) {
|
|
31
|
-
const xlsxTemplate = await reporter.documentStore.collection('xlsxTemplates').findOne({ _id: xlsxTemplateId._id }, req)
|
|
32
|
-
|
|
33
|
-
if (!xlsxTemplateToAssetMap.has(xlsxTemplate.shortid)) {
|
|
34
|
-
let newAsset
|
|
35
|
-
let tryCount = 0
|
|
36
|
-
|
|
37
|
-
while (newAsset == null) {
|
|
38
|
-
try {
|
|
39
|
-
const assetName = `${'_'.repeat(tryCount) + xlsxTemplate.name}.xlsx`
|
|
40
|
-
|
|
41
|
-
const assetProps = {
|
|
42
|
-
name: assetName,
|
|
43
|
-
content: xlsxTemplate.contentRaw,
|
|
44
|
-
folder: xlsxTemplate.folder || null
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (xlsxTemplate.readPermissions != null) {
|
|
48
|
-
assetProps.readPermissions = xlsxTemplate.readPermissions
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
if (xlsxTemplate.editPermissions != null) {
|
|
52
|
-
assetProps.editPermissions = xlsxTemplate.editPermissions
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
newAsset = await reporter.documentStore.collection('assets').insert(assetProps, req)
|
|
56
|
-
} catch (insertError) {
|
|
57
|
-
tryCount++
|
|
58
|
-
|
|
59
|
-
if (insertError.code === 'DUPLICATED_ENTITY') {
|
|
60
|
-
continue
|
|
61
|
-
} else {
|
|
62
|
-
throw insertError
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
xlsxTemplateToAssetMap.set(xlsxTemplate.shortid, newAsset)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const templateIds = await reporter.documentStore.collection('templates').find({}, { _id: 1 }, req)
|
|
72
|
-
|
|
73
|
-
for (const templateId of templateIds) {
|
|
74
|
-
const template = await reporter.documentStore.collection('templates').findOne({ _id: templateId._id }, req)
|
|
75
|
-
let continueUpdate = false
|
|
76
|
-
|
|
77
|
-
// handle jsreport-xlsx migration
|
|
78
|
-
if (template.xlsxTemplate != null) {
|
|
79
|
-
continueUpdate = true
|
|
80
|
-
|
|
81
|
-
const xlsxTemplateRef = template.xlsxTemplate
|
|
82
|
-
|
|
83
|
-
template.xlsxTemplate = null
|
|
84
|
-
|
|
85
|
-
if (xlsxTemplateRef.shortid != null && xlsxTemplateToAssetMap.has(xlsxTemplateRef.shortid)) {
|
|
86
|
-
template.xlsx = template.xlsx || {}
|
|
87
|
-
template.xlsx.templateAssetShortid = xlsxTemplateToAssetMap.get(xlsxTemplateRef.shortid).shortid
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// handle jsreport-html-to-xlsx migration
|
|
92
|
-
if (template.baseXlsxTemplate != null) {
|
|
93
|
-
continueUpdate = true
|
|
94
|
-
|
|
95
|
-
const baseXlsxTemplateRef = template.baseXlsxTemplate
|
|
96
|
-
|
|
97
|
-
template.baseXlsxTemplate = null
|
|
98
|
-
|
|
99
|
-
if (baseXlsxTemplateRef.shortid != null && xlsxTemplateToAssetMap.has(baseXlsxTemplateRef.shortid)) {
|
|
100
|
-
template.htmlToXlsx = template.htmlToXlsx || {}
|
|
101
|
-
template.htmlToXlsx.templateAssetShortid = xlsxTemplateToAssetMap.get(baseXlsxTemplateRef.shortid).shortid
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (continueUpdate) {
|
|
106
|
-
await reporter.documentStore.collection('templates').update({ _id: template._id }, { $set: template }, req)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
for (const xlsxTemplateId of xlsxTemplateIds) {
|
|
111
|
-
await reporter.documentStore.collection('xlsxTemplates').remove({ _id: xlsxTemplateId._id }, req)
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (xlsxTemplateIds.length !== 0) {
|
|
115
|
-
reporter.logger.debug('Migration "xlsxTemplatesToAssets" finished')
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await reporter.documentStore.commitTransaction(req)
|
|
119
|
-
|
|
120
|
-
await reporter.settings.addOrSet('core-migrated-xlsxTemplates', true)
|
|
121
|
-
} catch (migrationErr) {
|
|
122
|
-
await reporter.documentStore.rollbackTransaction(req)
|
|
123
|
-
|
|
124
|
-
migrationErr.message = `Migration "xlsxTemplatesToAssets" failed: ${migrationErr.message}`
|
|
125
|
-
|
|
126
|
-
throw migrationErr
|
|
127
|
-
}
|
|
128
|
-
}
|