@jsreport/jsreport-core 3.1.2-test.2 → 3.4.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/LICENSE +166 -166
- package/README.md +310 -298
- package/index.js +29 -29
- package/lib/main/blobStorage/blobStorage.js +53 -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 +254 -244
- package/lib/main/migration/resourcesToAssets.js +230 -230
- package/lib/main/migration/xlsxTemplatesToAssets.js +128 -128
- package/lib/main/monitoring.js +92 -91
- package/lib/main/optionsLoad.js +231 -237
- package/lib/main/optionsSchema.js +237 -237
- package/lib/main/profiler.js +13 -1
- package/lib/main/reporter.js +589 -579
- package/lib/main/request.js +21 -0
- 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 +232 -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 +162 -158
- package/lib/worker/render/render.js +202 -205
- package/lib/worker/render/resolveReferences.js +60 -60
- package/lib/worker/reporter.js +197 -191
- package/lib/worker/sandbox/runInSandbox.js +64 -12
- package/lib/worker/sandbox/safeSandbox.js +829 -828
- package/lib/worker/templates.js +80 -78
- package/lib/worker/workerHandler.js +55 -54
- package/package.json +91 -92
- package/test/blobStorage/common.js +25 -21
- package/test/store/common.js +1449 -1449
package/lib/worker/templates.js
CHANGED
|
@@ -1,78 +1,80 @@
|
|
|
1
|
-
const extend = require('node.extend.without.arrays')
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
!req.template.
|
|
10
|
-
!req.template.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
req
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
req.template.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
currentFolder =
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
const extend = require('node.extend.without.arrays')
|
|
2
|
+
const omit = require('lodash.omit')
|
|
3
|
+
|
|
4
|
+
module.exports = (reporter) => {
|
|
5
|
+
reporter.addRequestContextMetaConfig('currentFolderPath', { sandboxReadOnly: true })
|
|
6
|
+
|
|
7
|
+
reporter.beforeRenderListeners.add('templates', async (req, res) => {
|
|
8
|
+
if (
|
|
9
|
+
!req.template._id &&
|
|
10
|
+
!req.template.shortid &&
|
|
11
|
+
!req.template.name
|
|
12
|
+
) {
|
|
13
|
+
if (req.template.content == null) {
|
|
14
|
+
throw reporter.createError('Template must contains _id, name, shortid or content attribute', {
|
|
15
|
+
weak: true,
|
|
16
|
+
statusCode: 400
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
reporter.logger.info(
|
|
21
|
+
`Rendering anonymous template { recipe: ${req.template.recipe}, engine: ${req.template.engine} }`,
|
|
22
|
+
req
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
return
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const template = req.context.resolvedTemplate
|
|
29
|
+
|
|
30
|
+
if (!template && !req.template.content) {
|
|
31
|
+
throw reporter.createError(`Unable to find specified template or user does not have permissions to read it: ${
|
|
32
|
+
(req.template._id || req.template.shortid || req.template.name)
|
|
33
|
+
}`, {
|
|
34
|
+
weak: true,
|
|
35
|
+
statusCode: 404
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// store a copy to prevent side-effects, we ignore name from the req.template because it can be path "/path/to/template"
|
|
40
|
+
// and we want that req.template.name be always the real template name
|
|
41
|
+
req.template = template ? extend(true, {}, template, omit(req.template, ['name'])) : req.template
|
|
42
|
+
req.template.content = req.template.content || ''
|
|
43
|
+
|
|
44
|
+
reporter.logger.info(
|
|
45
|
+
`Rendering template { name: ${req.template.name}, recipe: ${req.template.recipe}, engine: ${req.template.engine}, preview: ${(req.options.preview || false)} }`,
|
|
46
|
+
req
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if (!req.options.reportName && req.template.name) {
|
|
50
|
+
res.meta.reportName = req.template.name
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
req.context.currentFolderPath = await resolveCurrentPath(reporter, req)
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function resolveCurrentPath (reporter, req) {
|
|
58
|
+
if (!req.template) {
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const pathFragments = []
|
|
63
|
+
let currentFolder = req.template.folder
|
|
64
|
+
|
|
65
|
+
if (currentFolder) {
|
|
66
|
+
currentFolder = await reporter.documentStore.collection('folders').findOne({ shortid: currentFolder.shortid }, req)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
while (currentFolder) {
|
|
70
|
+
pathFragments.push(currentFolder.name)
|
|
71
|
+
|
|
72
|
+
if (!currentFolder.folder) {
|
|
73
|
+
currentFolder = null
|
|
74
|
+
} else {
|
|
75
|
+
currentFolder = await reporter.documentStore.collection('folders').findOne({ shortid: currentFolder.folder.shortid }, req)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return '/' + pathFragments.reverse().join('/')
|
|
80
|
+
}
|
|
@@ -1,54 +1,55 @@
|
|
|
1
|
-
const WorkerReporter = require('./reporter')
|
|
2
|
-
const omit = require('lodash.omit')
|
|
3
|
-
|
|
4
|
-
module.exports = (userInitData, { executeMain, convertUint8ArrayToBuffer }) => {
|
|
5
|
-
const reporter = new WorkerReporter(userInitData, async (actionName, data, req) => {
|
|
6
|
-
const actionRes = await executeMain({
|
|
7
|
-
actionName,
|
|
8
|
-
data
|
|
9
|
-
})
|
|
10
|
-
convertUint8ArrayToBuffer(actionRes)
|
|
11
|
-
return actionRes
|
|
12
|
-
})
|
|
13
|
-
let parsedReq
|
|
14
|
-
return {
|
|
15
|
-
init: () => {
|
|
16
|
-
return reporter.init()
|
|
17
|
-
},
|
|
18
|
-
|
|
19
|
-
close: () => {
|
|
20
|
-
return reporter.close()
|
|
21
|
-
},
|
|
22
|
-
|
|
23
|
-
execute: ({ actionName, data, req }) => {
|
|
24
|
-
// we need to convert back arrays to buffer because transfer to/from thread converts buffers to array
|
|
25
|
-
convertUint8ArrayToBuffer(data)
|
|
26
|
-
convertUint8ArrayToBuffer(req)
|
|
27
|
-
|
|
28
|
-
if (actionName === 'parse') {
|
|
29
|
-
try {
|
|
30
|
-
parsedReq = {
|
|
31
|
-
...JSON.parse(req.rawContent),
|
|
32
|
-
context: req.context
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
e.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}
|
|
1
|
+
const WorkerReporter = require('./reporter')
|
|
2
|
+
const omit = require('lodash.omit')
|
|
3
|
+
|
|
4
|
+
module.exports = (userInitData, { executeMain, convertUint8ArrayToBuffer }) => {
|
|
5
|
+
const reporter = new WorkerReporter(userInitData, async (actionName, data, req) => {
|
|
6
|
+
const actionRes = await executeMain({
|
|
7
|
+
actionName,
|
|
8
|
+
data
|
|
9
|
+
})
|
|
10
|
+
convertUint8ArrayToBuffer(actionRes)
|
|
11
|
+
return actionRes
|
|
12
|
+
})
|
|
13
|
+
let parsedReq
|
|
14
|
+
return {
|
|
15
|
+
init: () => {
|
|
16
|
+
return reporter.init()
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
close: () => {
|
|
20
|
+
return reporter.close()
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
execute: ({ actionName, data, req }) => {
|
|
24
|
+
// we need to convert back arrays to buffer because transfer to/from thread converts buffers to array
|
|
25
|
+
convertUint8ArrayToBuffer(data)
|
|
26
|
+
convertUint8ArrayToBuffer(req)
|
|
27
|
+
|
|
28
|
+
if (actionName === 'parse') {
|
|
29
|
+
try {
|
|
30
|
+
parsedReq = {
|
|
31
|
+
...JSON.parse(req.rawContent),
|
|
32
|
+
context: req.context
|
|
33
|
+
}
|
|
34
|
+
parsedReq.context.parsedInWorker = true
|
|
35
|
+
|
|
36
|
+
return omit(parsedReq, 'data')
|
|
37
|
+
} catch (e) {
|
|
38
|
+
e.message = 'Invalid request json: ' + e.message
|
|
39
|
+
e.weak = true
|
|
40
|
+
throw e
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (parsedReq) {
|
|
45
|
+
if (parsedReq.context.rootId === req.context.rootId) {
|
|
46
|
+
req.data = parsedReq.data
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
parsedReq = null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return reporter.executeWorkerAction(actionName, data, req)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,92 +1,91 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@jsreport/jsreport-core",
|
|
3
|
-
"version": "3.1
|
|
4
|
-
"description": "javascript based business reporting",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"report",
|
|
7
|
-
"business",
|
|
8
|
-
"javascript"
|
|
9
|
-
],
|
|
10
|
-
"homepage": "https://github.com/jsreport/jsreport/tree/master/packages/jsreport-core",
|
|
11
|
-
"repository": {
|
|
12
|
-
"type": "git",
|
|
13
|
-
"url": "git+ssh://git@github.com/jsreport/jsreport.git"
|
|
14
|
-
},
|
|
15
|
-
"license": "LGPL",
|
|
16
|
-
"author": {
|
|
17
|
-
"name": "Jan Blaha",
|
|
18
|
-
"email": "jan.blaha@hotmail.com"
|
|
19
|
-
},
|
|
20
|
-
"main": "index.js",
|
|
21
|
-
"files": [
|
|
22
|
-
"lib",
|
|
23
|
-
"index.js",
|
|
24
|
-
"test/store/common.js",
|
|
25
|
-
"test/blobStorage/common.js"
|
|
26
|
-
],
|
|
27
|
-
"scripts": {
|
|
28
|
-
"test": "mocha --timeout 5000 --recursive test --exit && standard",
|
|
29
|
-
"test:watch": "mocha --watch --recursive test"
|
|
30
|
-
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@babel/code-frame": "7.12.13",
|
|
33
|
-
"@babel/parser": "7.14.4",
|
|
34
|
-
"@babel/traverse": "7.12.9",
|
|
35
|
-
"@jsreport/advanced-workers": "1.
|
|
36
|
-
"@jsreport/mingo": "2.4.1",
|
|
37
|
-
"ajv": "6.12.6",
|
|
38
|
-
"app-root-path": "2.0.1",
|
|
39
|
-
"async-replace": "1.0.1",
|
|
40
|
-
"camelcase": "5.0.0",
|
|
41
|
-
"debug": "4.3.2",
|
|
42
|
-
"decamelize": "2.0.0",
|
|
43
|
-
"deepmerge": "2.1.0",
|
|
44
|
-
"diff": "3.5.0",
|
|
45
|
-
"diff-match-patch": "1.0.5",
|
|
46
|
-
"enhanced-resolve": "5.8.3",
|
|
47
|
-
"has-own-deep": "1.1.0",
|
|
48
|
-
"isbinaryfile": "4.0.0",
|
|
49
|
-
"listener-collection": "1.2.0",
|
|
50
|
-
"lodash.get": "4.4.2",
|
|
51
|
-
"lodash.groupby": "4.6.0",
|
|
52
|
-
"lodash.omit": "4.5.0",
|
|
53
|
-
"lodash.set": "4.3.2",
|
|
54
|
-
"lru-cache": "4.1.1",
|
|
55
|
-
"ms": "2.1.3",
|
|
56
|
-
"nanoid": "3.
|
|
57
|
-
"nconf": "0.
|
|
58
|
-
"node.extend.without.arrays": "1.1.6",
|
|
59
|
-
"reap2": "1.0.1",
|
|
60
|
-
"semver": "7.3.5",
|
|
61
|
-
"serializator": "1.0.2",
|
|
62
|
-
"stack-trace": "0.0.10",
|
|
63
|
-
"triple-beam": "1.3.0",
|
|
64
|
-
"unset-value": "1.0.0",
|
|
65
|
-
"uuid": "8.3.2",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"winston": "
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@jsreport/jsreport-core",
|
|
3
|
+
"version": "3.4.1",
|
|
4
|
+
"description": "javascript based business reporting",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"report",
|
|
7
|
+
"business",
|
|
8
|
+
"javascript"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://github.com/jsreport/jsreport/tree/master/packages/jsreport-core",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+ssh://git@github.com/jsreport/jsreport.git"
|
|
14
|
+
},
|
|
15
|
+
"license": "LGPL",
|
|
16
|
+
"author": {
|
|
17
|
+
"name": "Jan Blaha",
|
|
18
|
+
"email": "jan.blaha@hotmail.com"
|
|
19
|
+
},
|
|
20
|
+
"main": "index.js",
|
|
21
|
+
"files": [
|
|
22
|
+
"lib",
|
|
23
|
+
"index.js",
|
|
24
|
+
"test/store/common.js",
|
|
25
|
+
"test/blobStorage/common.js"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "mocha --timeout 5000 --recursive test --exit && standard",
|
|
29
|
+
"test:watch": "mocha --watch --recursive test"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@babel/code-frame": "7.12.13",
|
|
33
|
+
"@babel/parser": "7.14.4",
|
|
34
|
+
"@babel/traverse": "7.12.9",
|
|
35
|
+
"@jsreport/advanced-workers": "1.2.0",
|
|
36
|
+
"@jsreport/mingo": "2.4.1",
|
|
37
|
+
"ajv": "6.12.6",
|
|
38
|
+
"app-root-path": "2.0.1",
|
|
39
|
+
"async-replace": "1.0.1",
|
|
40
|
+
"camelcase": "5.0.0",
|
|
41
|
+
"debug": "4.3.2",
|
|
42
|
+
"decamelize": "2.0.0",
|
|
43
|
+
"deepmerge": "2.1.0",
|
|
44
|
+
"diff": "3.5.0",
|
|
45
|
+
"diff-match-patch": "1.0.5",
|
|
46
|
+
"enhanced-resolve": "5.8.3",
|
|
47
|
+
"has-own-deep": "1.1.0",
|
|
48
|
+
"isbinaryfile": "4.0.0",
|
|
49
|
+
"listener-collection": "1.2.0",
|
|
50
|
+
"lodash.get": "4.4.2",
|
|
51
|
+
"lodash.groupby": "4.6.0",
|
|
52
|
+
"lodash.omit": "4.5.0",
|
|
53
|
+
"lodash.set": "4.3.2",
|
|
54
|
+
"lru-cache": "4.1.1",
|
|
55
|
+
"ms": "2.1.3",
|
|
56
|
+
"nanoid": "3.2.0",
|
|
57
|
+
"nconf": "0.11.3",
|
|
58
|
+
"node.extend.without.arrays": "1.1.6",
|
|
59
|
+
"reap2": "1.0.1",
|
|
60
|
+
"semver": "7.3.5",
|
|
61
|
+
"serializator": "1.0.2",
|
|
62
|
+
"stack-trace": "0.0.10",
|
|
63
|
+
"triple-beam": "1.3.0",
|
|
64
|
+
"unset-value": "1.0.0",
|
|
65
|
+
"uuid": "8.3.2",
|
|
66
|
+
"vm2": "3.9.5",
|
|
67
|
+
"winston": "3.3.3",
|
|
68
|
+
"winston-transport": "4.4.0"
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"mocha": "8.2.1",
|
|
72
|
+
"should": "13.2.3",
|
|
73
|
+
"standard": "16.0.4",
|
|
74
|
+
"std-mocks": "1.0.1",
|
|
75
|
+
"winston-loggly-bulk": "3.2.1"
|
|
76
|
+
},
|
|
77
|
+
"engines": {
|
|
78
|
+
"node": ">=16.11"
|
|
79
|
+
},
|
|
80
|
+
"maintainers": [
|
|
81
|
+
{
|
|
82
|
+
"name": "pofider",
|
|
83
|
+
"email": "jan.blaha@hotmail.com"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
"standard": {
|
|
87
|
+
"env": {
|
|
88
|
+
"mocha": true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
module.exports = (storage) => {
|
|
2
|
-
it('write and read', async () => {
|
|
3
|
-
await storage().write('foo', Buffer.from('hula'))
|
|
4
|
-
|
|
5
|
-
const content = await storage().read('foo')
|
|
6
|
-
content.toString().should.be.eql('hula')
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
it('write remove read should fail', async () => {
|
|
10
|
-
await storage().write('foo', Buffer.from('hula'))
|
|
11
|
-
await storage().remove('foo')
|
|
12
|
-
|
|
13
|
-
return storage().read('foo').should.be.rejected()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
it('should work with folders and paths', async () => {
|
|
17
|
-
await storage().write('foldera/folderb/myblob.txt', Buffer.from('hula'))
|
|
18
|
-
const buf = await storage().read('foldera/folderb/myblob.txt')
|
|
19
|
-
buf.toString().should.be.eql('hula')
|
|
20
|
-
})
|
|
21
|
-
|
|
1
|
+
module.exports = (storage) => {
|
|
2
|
+
it('write and read', async () => {
|
|
3
|
+
await storage().write('foo', Buffer.from('hula'))
|
|
4
|
+
|
|
5
|
+
const content = await storage().read('foo')
|
|
6
|
+
content.toString().should.be.eql('hula')
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
it('write remove read should fail', async () => {
|
|
10
|
+
await storage().write('foo', Buffer.from('hula'))
|
|
11
|
+
await storage().remove('foo')
|
|
12
|
+
|
|
13
|
+
return storage().read('foo').should.be.rejected()
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('should work with folders and paths', async () => {
|
|
17
|
+
await storage().write('foldera/folderb/myblob.txt', Buffer.from('hula'))
|
|
18
|
+
const buf = await storage().read('foldera/folderb/myblob.txt')
|
|
19
|
+
buf.toString().should.be.eql('hula')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('remove shouldnt fail for missing blob', async () => {
|
|
23
|
+
await storage().remove('foo')
|
|
24
|
+
})
|
|
25
|
+
}
|