presidium 0.25.1 → 0.26.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/S3.js +8 -2
- package/S3Bucket.js +4 -0
- package/S3Bucket.test.js +2 -0
- package/internal/pathWalk.js +29 -21
- package/internal/pathWalk.test.js +20 -11
- package/package.json +2 -1
package/S3.js
CHANGED
|
@@ -346,14 +346,20 @@ S3.prototype.getObject = function s3GetObject(bucketname, key, options) {
|
|
|
346
346
|
}).promise()
|
|
347
347
|
}
|
|
348
348
|
|
|
349
|
-
S3.prototype.
|
|
349
|
+
S3.prototype.headObject = async function headObject(
|
|
350
350
|
bucketname, key, options = {},
|
|
351
351
|
) {
|
|
352
|
-
|
|
352
|
+
return this.s3.headObject({
|
|
353
353
|
Bucket: bucketname,
|
|
354
354
|
Key: key,
|
|
355
355
|
...options,
|
|
356
356
|
}).promise()
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
S3.prototype.getObjectStream = async function s3GetObject(
|
|
360
|
+
bucketname, key, options = {},
|
|
361
|
+
) {
|
|
362
|
+
const headRes = await this.headObject(bucketname, key, options)
|
|
357
363
|
|
|
358
364
|
const rs = this.s3.getObject({
|
|
359
365
|
Bucket: bucketname,
|
package/S3Bucket.js
CHANGED
|
@@ -304,6 +304,10 @@ S3Bucket.prototype.getObject = async function getObject(key, options) {
|
|
|
304
304
|
return this.s3.getObject(this.name, key, options)
|
|
305
305
|
}
|
|
306
306
|
|
|
307
|
+
S3Bucket.prototype.headObject = async function headObject(key, options) {
|
|
308
|
+
return this.s3.headObject(this.name, key, options)
|
|
309
|
+
}
|
|
310
|
+
|
|
307
311
|
S3Bucket.prototype.getObjectStream = async function getObjectStream(
|
|
308
312
|
key, options,
|
|
309
313
|
) {
|
package/S3Bucket.test.js
CHANGED
|
@@ -69,6 +69,8 @@ const test = new Test('S3Bucket', S3Bucket)
|
|
|
69
69
|
{
|
|
70
70
|
const key = 'buffer2'
|
|
71
71
|
await testBucket.upload(key, Buffer.from('buffer'))
|
|
72
|
+
const headRes = await testBucket.headObject(key)
|
|
73
|
+
assert.equal(headRes.ContentLength, 6)
|
|
72
74
|
const res = await testBucket.getObjectStream(key)
|
|
73
75
|
assert.equal(res.headers.ContentLength, 6)
|
|
74
76
|
}
|
package/internal/pathWalk.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require('rubico/global')
|
|
2
2
|
const fs = require('fs/promises')
|
|
3
|
+
const { minimatch } = require('minimatch')
|
|
3
4
|
const pathResolve = require('./pathResolve')
|
|
4
5
|
const isArray = require('./isArray')
|
|
5
6
|
|
|
@@ -20,29 +21,36 @@ const isArray = require('./isArray')
|
|
|
20
21
|
* }) // -> Promise<paths Array<string>>
|
|
21
22
|
* ```
|
|
22
23
|
*/
|
|
23
|
-
const pathWalk = function (path, options) {
|
|
24
|
-
const ignore =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
curry.arity(2, fs.readdir, __, { withFileTypes: true }),
|
|
29
|
-
() => []),
|
|
24
|
+
const pathWalk = async function (path, options = {}) {
|
|
25
|
+
const { ignore = [] } = options
|
|
26
|
+
const absPath = pathResolve(path)
|
|
27
|
+
const dirents = await fs.readdir(absPath, { withFileTypes: true })
|
|
28
|
+
const result = []
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
30
|
+
for (const dirent of dirents) {
|
|
31
|
+
const dirName = dirent.name
|
|
32
|
+
const dirPath = pathResolve(path, dirName)
|
|
33
|
+
let shouldIgnore = false
|
|
34
|
+
for (const pattern of ignore) {
|
|
35
|
+
if (minimatch(dirPath, pattern) || minimatch(dirName, pattern)) {
|
|
36
|
+
shouldIgnore = true
|
|
37
|
+
break
|
|
39
38
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (shouldIgnore) {
|
|
42
|
+
continue
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (dirent.isDirectory()) {
|
|
46
|
+
const subPaths = await pathWalk(dirPath, options)
|
|
47
|
+
result.push(...subPaths)
|
|
48
|
+
} else {
|
|
49
|
+
result.push(dirPath)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return result
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
module.exports = pathWalk
|
|
@@ -3,14 +3,23 @@ const Test = require('thunk-test')
|
|
|
3
3
|
const pathWalk = require('./pathWalk')
|
|
4
4
|
const pathResolve = require('./pathResolve')
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
.
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const test = Test('pathWalk', pathWalk)
|
|
7
|
+
|
|
8
|
+
.case(__dirname, function (paths) {
|
|
9
|
+
assert(paths.length > 0)
|
|
10
|
+
this.allInternalPaths = paths
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
.case(__dirname, { ignore: ['pathWalk.js'] }, function (paths) {
|
|
14
|
+
assert.equal(paths.length, this.allInternalPaths.length - 1)
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
.case(__dirname, { ignore: [pathResolve(__dirname, 'pathWalk.js')] }, function (paths) {
|
|
18
|
+
assert.equal(paths.length, this.allInternalPaths.length - 1)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
if (process.argv[1] == __filename) {
|
|
22
|
+
test()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = test
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "presidium",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "A library for creating web services",
|
|
5
5
|
"author": "Richard Tong",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"aws-sdk": "^2.1123.0",
|
|
34
34
|
"bcrypt": "^5.1.0",
|
|
35
35
|
"ioredis": "^4.19.0",
|
|
36
|
+
"minimatch": "^9.0.3",
|
|
36
37
|
"mongodb": "^3.6.3",
|
|
37
38
|
"node-fetch": "^2.6.1",
|
|
38
39
|
"rubico": "latest",
|