cloud-bucket 0.3.12 → 0.3.16
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/dist/bucket.js +3 -3
- package/dist/driver-aws.js +5 -5
- package/dist/index.js +4 -4
- package/package.json +14 -14
- package/src/driver-aws.ts +6 -6
- package/src/driver-gcp.ts +2 -2
- package/CHANGELOG.md +0 -24
package/dist/bucket.js
CHANGED
|
@@ -135,7 +135,7 @@ class BucketImpl {
|
|
|
135
135
|
const remotePath = this.driver.getPath(cf);
|
|
136
136
|
const localFilePath = (isLocalPathDir) ? getDestPath(baseDir, remotePath, localPath) : localPath;
|
|
137
137
|
const localPathDir = Path.dirname(localFilePath);
|
|
138
|
-
await fs_extra_plus_1.mkdirp(localPathDir);
|
|
138
|
+
await (0, fs_extra_plus_1.mkdirp)(localPathDir);
|
|
139
139
|
if (this.log) {
|
|
140
140
|
process.stdout.write(`Downloading ${this.type}://${this.name}/${remotePath} to ${localFilePath}`);
|
|
141
141
|
}
|
|
@@ -167,7 +167,7 @@ class BucketImpl {
|
|
|
167
167
|
}
|
|
168
168
|
const isLocalGlob = localPath.includes('*');
|
|
169
169
|
const { baseDir } = parsePrefixOrGlob(localPath);
|
|
170
|
-
const localFiles = await fs_extra_plus_1.glob(localPath);
|
|
170
|
+
const localFiles = await (0, fs_extra_plus_1.glob)(localPath);
|
|
171
171
|
for (const localPath of localFiles) {
|
|
172
172
|
// if we have an localFileExpression (globs), then, we build the fullDestPath relative to the baseDir of the glob (last / before the first *)
|
|
173
173
|
const fullDestPath = (isLocalGlob) ? getDestPath(baseDir, localPath, remotePath) : buildFullDestPath(localPath, remotePath);
|
|
@@ -275,7 +275,7 @@ function buildFullDestPath(localPath, destPath) {
|
|
|
275
275
|
}
|
|
276
276
|
exports.buildFullDestPath = buildFullDestPath;
|
|
277
277
|
function getContentType(path) {
|
|
278
|
-
let ct = mime_types_1.lookup(path);
|
|
278
|
+
let ct = (0, mime_types_1.lookup)(path);
|
|
279
279
|
let contentType = (ct) ? ct : undefined;
|
|
280
280
|
return contentType;
|
|
281
281
|
}
|
package/dist/driver-aws.js
CHANGED
|
@@ -101,12 +101,12 @@ class S3Driver {
|
|
|
101
101
|
listParams.MaxKeys = limit;
|
|
102
102
|
}
|
|
103
103
|
if (marker != null) {
|
|
104
|
-
listParams.
|
|
104
|
+
listParams.ContinuationToken = marker;
|
|
105
105
|
}
|
|
106
106
|
const params = { ...this.baseParams, ...listParams };
|
|
107
107
|
// perform the s3 list request
|
|
108
108
|
try {
|
|
109
|
-
const awsResult = await this.s3.
|
|
109
|
+
const awsResult = await this.s3.listObjectsV2(params).promise();
|
|
110
110
|
const awsFiles = awsResult.Contents;
|
|
111
111
|
// if glob, filter again the result
|
|
112
112
|
let files = (!glob) ? awsFiles : awsFiles.filter(af => micromatch.isMatch(af.Key, glob));
|
|
@@ -118,7 +118,7 @@ class S3Driver {
|
|
|
118
118
|
dirs = prefixes;
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
const nextMarker = awsResult.
|
|
121
|
+
const nextMarker = awsResult.NextContinuationToken;
|
|
122
122
|
return { files, dirs, nextMarker };
|
|
123
123
|
}
|
|
124
124
|
catch (ex) {
|
|
@@ -141,7 +141,7 @@ class S3Driver {
|
|
|
141
141
|
const remotePath = rawFile.Key;
|
|
142
142
|
const params = { ...this.baseParams, ...{ Key: remotePath } };
|
|
143
143
|
const remoteReadStream = this.s3.getObject(params).createReadStream();
|
|
144
|
-
const localWriteStream = fs_extra_plus_1.createWriteStream(localPath);
|
|
144
|
+
const localWriteStream = (0, fs_extra_plus_1.createWriteStream)(localPath);
|
|
145
145
|
const writePromise = new Promise((resolve, reject) => {
|
|
146
146
|
localWriteStream.once('close', () => {
|
|
147
147
|
resolve();
|
|
@@ -154,7 +154,7 @@ class S3Driver {
|
|
|
154
154
|
await writePromise;
|
|
155
155
|
}
|
|
156
156
|
async uploadCloudFile(localPath, remoteFilePath, contentType) {
|
|
157
|
-
const readable = fs_extra_plus_1.createReadStream(localPath);
|
|
157
|
+
const readable = (0, fs_extra_plus_1.createReadStream)(localPath);
|
|
158
158
|
const awsResult = await this.s3.putObject({ ...this.baseParams, ...{ Key: remoteFilePath, Body: readable, ContentType: contentType } }).promise();
|
|
159
159
|
// TODO: probably check the awsResult that match remoteFilePath
|
|
160
160
|
return { Key: remoteFilePath };
|
package/dist/index.js
CHANGED
|
@@ -16,19 +16,19 @@ async function getBucket(options) {
|
|
|
16
16
|
const log = (_a = options.log) !== null && _a !== void 0 ? _a : false; // by default, false.
|
|
17
17
|
// if has .project_id, assume GcpBucket
|
|
18
18
|
const driver = await getDriver(options);
|
|
19
|
-
const bucket = bucket_1.newBucket({ driver, log });
|
|
19
|
+
const bucket = (0, bucket_1.newBucket)({ driver, log });
|
|
20
20
|
return bucket;
|
|
21
21
|
}
|
|
22
22
|
exports.getBucket = getBucket;
|
|
23
23
|
async function getDriver(driverCfg) {
|
|
24
24
|
if (isGsDriverCfg(driverCfg)) {
|
|
25
|
-
return driver_gcp_1.getGsDriver(driverCfg);
|
|
25
|
+
return (0, driver_gcp_1.getGsDriver)(driverCfg);
|
|
26
26
|
}
|
|
27
27
|
else if (isMinioDriverCfg(driverCfg)) { // IMPORTANT MUST be before S3Driver, because same access_key...
|
|
28
|
-
return driver_minio_1.getMinioDriver(driverCfg);
|
|
28
|
+
return (0, driver_minio_1.getMinioDriver)(driverCfg);
|
|
29
29
|
}
|
|
30
30
|
else if (isS3DriverCfg(driverCfg)) {
|
|
31
|
-
return driver_aws_1.getS3Driver(driverCfg);
|
|
31
|
+
return (0, driver_aws_1.getS3Driver)(driverCfg);
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
34
|
throw new Error(`bucket config does not seem to be valid (only support Gcp and Aws for now)`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cloud-bucket",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.16",
|
|
4
4
|
"description": "Simple multi cloud (Google Storage and AWS S3) bucket API",
|
|
5
5
|
"author": "Jeremy Chone <jeremy.chone@gmail.com>",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -12,21 +12,21 @@
|
|
|
12
12
|
"node": ">=14"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@google-cloud/storage": "^5.
|
|
16
|
-
"@types/micromatch": "^4.0.
|
|
17
|
-
"@types/mime-types": "^2.1.
|
|
18
|
-
"aws-sdk": "^2.
|
|
19
|
-
"fs-extra-plus": "^0.5.
|
|
20
|
-
"micromatch": "^4.0.
|
|
21
|
-
"mime-types": "^2.1.
|
|
15
|
+
"@google-cloud/storage": "^5.16.0",
|
|
16
|
+
"@types/micromatch": "^4.0.2",
|
|
17
|
+
"@types/mime-types": "^2.1.1",
|
|
18
|
+
"aws-sdk": "^2.1037.0",
|
|
19
|
+
"fs-extra-plus": "^0.5.23",
|
|
20
|
+
"micromatch": "^4.0.4",
|
|
21
|
+
"mime-types": "^2.1.34"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/js-yaml": "^4.0.
|
|
25
|
-
"@types/mocha": "^
|
|
26
|
-
"js-yaml": "^4.
|
|
27
|
-
"mocha": "^
|
|
28
|
-
"ts-node": "^
|
|
29
|
-
"typescript": "^4.
|
|
24
|
+
"@types/js-yaml": "^4.0.5",
|
|
25
|
+
"@types/mocha": "^9.0.0",
|
|
26
|
+
"js-yaml": "^4.1.0",
|
|
27
|
+
"mocha": "^9.1.3",
|
|
28
|
+
"ts-node": "^10.4.0",
|
|
29
|
+
"typescript": "^4.5.2"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
32
32
|
"test": "TS_NODE_FILES=true ./node_modules/.bin/mocha",
|
package/src/driver-aws.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Credentials, S3 } from 'aws-sdk';
|
|
2
|
-
import {
|
|
2
|
+
import { ListObjectsV2Request } from 'aws-sdk/clients/s3';
|
|
3
3
|
import { createReadStream, createWriteStream } from 'fs-extra-plus';
|
|
4
4
|
import { PassThrough, Readable, Writable } from "stream";
|
|
5
5
|
import { Driver, ListCloudFilesOptions, ListCloudFilesResult } from "./driver";
|
|
@@ -99,7 +99,7 @@ export class S3Driver implements Driver<AwsFile> {
|
|
|
99
99
|
|
|
100
100
|
const awsFile: AwsFile = { Key, Size, LastModified, ETag, ContentType };
|
|
101
101
|
return awsFile;
|
|
102
|
-
} catch (ex) {
|
|
102
|
+
} catch (ex: any) {
|
|
103
103
|
// if NotFound, return false
|
|
104
104
|
if (ex.code === 'NotFound') {
|
|
105
105
|
return null;
|
|
@@ -117,7 +117,7 @@ export class S3Driver implements Driver<AwsFile> {
|
|
|
117
117
|
const { prefix, glob, directory, limit, marker } = opts;
|
|
118
118
|
|
|
119
119
|
// build the list params
|
|
120
|
-
let listParams: Partial<
|
|
120
|
+
let listParams: Partial<ListObjectsV2Request> = {};
|
|
121
121
|
if (prefix) {
|
|
122
122
|
listParams.Prefix = prefix;
|
|
123
123
|
}
|
|
@@ -128,13 +128,13 @@ export class S3Driver implements Driver<AwsFile> {
|
|
|
128
128
|
listParams.MaxKeys = limit;
|
|
129
129
|
}
|
|
130
130
|
if (marker != null) {
|
|
131
|
-
listParams.
|
|
131
|
+
listParams.ContinuationToken = marker;
|
|
132
132
|
}
|
|
133
133
|
const params = { ...this.baseParams, ...listParams };
|
|
134
134
|
|
|
135
135
|
// perform the s3 list request
|
|
136
136
|
try {
|
|
137
|
-
const awsResult = await this.s3.
|
|
137
|
+
const awsResult = await this.s3.listObjectsV2(params).promise();
|
|
138
138
|
const awsFiles = awsResult.Contents as AwsFile[];
|
|
139
139
|
// if glob, filter again the result
|
|
140
140
|
let files: AwsFile[] = (!glob) ? awsFiles : awsFiles.filter(af => micromatch.isMatch(af.Key!, glob));
|
|
@@ -147,7 +147,7 @@ export class S3Driver implements Driver<AwsFile> {
|
|
|
147
147
|
dirs = prefixes;
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
|
-
const nextMarker = awsResult.
|
|
150
|
+
const nextMarker = awsResult.NextContinuationToken;
|
|
151
151
|
|
|
152
152
|
return { files, dirs, nextMarker };
|
|
153
153
|
} catch (ex) {
|
package/src/driver-gcp.ts
CHANGED
|
@@ -68,7 +68,7 @@ class GcpDriver implements Driver<GoogleFile> {
|
|
|
68
68
|
const googleFile = this.googleBucket.file(path);
|
|
69
69
|
try {
|
|
70
70
|
return (await googleFile.get())[0];
|
|
71
|
-
} catch (ex) {
|
|
71
|
+
} catch (ex: any) {
|
|
72
72
|
// not found return null, as per getFile design.
|
|
73
73
|
if (ex.code === 404) {
|
|
74
74
|
return null;
|
|
@@ -143,7 +143,7 @@ class GcpDriver implements Driver<GoogleFile> {
|
|
|
143
143
|
if (googleFile) {
|
|
144
144
|
try {
|
|
145
145
|
await googleFile.delete();
|
|
146
|
-
} catch (ex) {
|
|
146
|
+
} catch (ex: any) {
|
|
147
147
|
// if not found, just return false.
|
|
148
148
|
if (ex.code === 404) {
|
|
149
149
|
process.stdout.write(` - Skipped (object not found)\n`);
|
package/CHANGELOG.md
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
> Legend: `!` change; `+` enhancement; `-` fix; `.` minor
|
|
2
|
-
|
|
3
|
-
> Note: Minor updates with dependency only update are not recorded here (but still tagged)
|
|
4
|
-
|
|
5
|
-
### [v0.3.5](https://github.com/BriteSnow/node-cloud-bucket/compare/v0.3.3...v0.3.5) July 19, 2020
|
|
6
|
-
|
|
7
|
-
- `+` minio - Added support for minio (for dev/mock only for now)
|
|
8
|
-
|
|
9
|
-
### [v0.3.3](https://github.com/BriteSnow/node-cloud-bucket/compare/v0.3.2...v0.3.3) June 12, 2020
|
|
10
|
-
|
|
11
|
-
- `+` stream - add content type support for createStream
|
|
12
|
-
|
|
13
|
-
### [v0.3.2](https://github.com/BriteSnow/node-cloud-bucket/compare/v0.3.0...v0.3.2) June 9, 2020
|
|
14
|
-
|
|
15
|
-
- `!` log - removed console.log by default, added .log: boolean
|
|
16
|
-
|
|
17
|
-
### [v0.3.0](https://github.com/BriteSnow/node-cloud-bucket/compare/v0.2.16...v0.3.0) May 21, 2020
|
|
18
|
-
|
|
19
|
-
- `!` Rename `bucket.list` to `bucket.listFiles` and change the `bucket.list` to return `ListResult` (allow full pagination and other metadata information)
|
|
20
|
-
|
|
21
|
-
### [v0.2.16](https://github.com/BriteSnow/node-cloud-bucket/compare/v0.2.15...v0.2.16) Apr 16 2020
|
|
22
|
-
|
|
23
|
-
- s3 upload - move to stream to upload to s3
|
|
24
|
-
- refactoring to driver pattern
|