@pittica/google-cloud-storage-helpers 1.0.0 → 1.1.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/README.md +1 -1
- package/dist/index.js +11 -9
- package/dist/scripts.js +1 -1
- package/dist/storage/download.js +5 -5
- package/dist/storage/file.js +1 -1
- package/dist/storage/json.js +23 -2
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ This project uses [Cloud Storage](https://cloud.google.com/storage/docs) librari
|
|
|
15
15
|
|
|
16
16
|
This project is licensed.
|
|
17
17
|
|
|
18
|
-
Copyright 2024 **Pittica S.r.l.**.
|
|
18
|
+
Copyright 2024-2025 **Pittica S.r.l.**.
|
|
19
19
|
|
|
20
20
|
- [pittica.com](https://pittica.com)
|
|
21
21
|
- [info@pittica.com](mailto:info@pittica.com)
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2024 Pittica S.r.l.
|
|
1
|
+
// Copyright 2024-2025 Pittica S.r.l.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -18,17 +18,19 @@ const {
|
|
|
18
18
|
moveFiles
|
|
19
19
|
} = require("./storage/file");
|
|
20
20
|
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
downloadBucket,
|
|
22
|
+
downloadFile,
|
|
23
|
+
downloadFolder
|
|
24
24
|
} = require("./storage/download");
|
|
25
25
|
const {
|
|
26
|
-
|
|
26
|
+
writeJson,
|
|
27
|
+
groupJson
|
|
27
28
|
} = require("./storage/json");
|
|
28
29
|
exports.copyFile = copyFile;
|
|
29
30
|
exports.deleteFile = deleteFile;
|
|
30
31
|
exports.moveFiles = moveFiles;
|
|
31
|
-
exports.
|
|
32
|
-
exports.
|
|
33
|
-
exports.
|
|
34
|
-
exports.
|
|
32
|
+
exports.writeJson = writeJson;
|
|
33
|
+
exports.groupJson = groupJson;
|
|
34
|
+
exports.downloadFile = downloadFile;
|
|
35
|
+
exports.downloadBucket = downloadBucket;
|
|
36
|
+
exports.downloadFolder = downloadFolder;
|
package/dist/scripts.js
CHANGED
package/dist/storage/download.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2024 Pittica S.r.l.
|
|
1
|
+
// Copyright 2024-2025 Pittica S.r.l.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -26,13 +26,13 @@ const fs = require("fs");
|
|
|
26
26
|
* @param {string} bucket Bucket name.
|
|
27
27
|
* @param {string} destination Destination path.
|
|
28
28
|
*/
|
|
29
|
-
exports.
|
|
29
|
+
exports.downloadBucket = async (bucket, destination = __dirname) => {
|
|
30
30
|
const storage = new Storage();
|
|
31
31
|
const source = storage.bucket(bucket);
|
|
32
32
|
const [files] = await source.getFiles();
|
|
33
33
|
files.forEach(({
|
|
34
34
|
name
|
|
35
|
-
}) => this.
|
|
35
|
+
}) => this.downloadFile(name, source, destination));
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
/**
|
|
@@ -42,7 +42,7 @@ exports.bucket = async (bucket, destination = __dirname) => {
|
|
|
42
42
|
* @param {Bucket} bucket Google Cloud Storage bucket object.
|
|
43
43
|
* @param {string} directory Destination directory.
|
|
44
44
|
*/
|
|
45
|
-
exports.
|
|
45
|
+
exports.downloadFile = async (file, bucket, directory = __dirname) => {
|
|
46
46
|
const destination = path.join(directory, file);
|
|
47
47
|
const folder = path.dirname(destination);
|
|
48
48
|
if (!fs.existsSync(folder)) {
|
|
@@ -62,7 +62,7 @@ exports.file = async (file, bucket, directory = __dirname) => {
|
|
|
62
62
|
*
|
|
63
63
|
* @returns {Promise}
|
|
64
64
|
*/
|
|
65
|
-
exports.
|
|
65
|
+
exports.downloadFolder = (folder, bucket, directory = __dirname) => {
|
|
66
66
|
const storage = new Storage();
|
|
67
67
|
const manager = new TransferManager(storage.bucket(bucket));
|
|
68
68
|
const destination = path.join(directory, folder);
|
package/dist/storage/file.js
CHANGED
package/dist/storage/json.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright 2024 Pittica S.r.l.
|
|
1
|
+
// Copyright 2024-2025 Pittica S.r.l.
|
|
2
2
|
//
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -25,7 +25,7 @@ const log = require("@pittica/logger-helpers");
|
|
|
25
25
|
*
|
|
26
26
|
* @returns {boolean} Write action response.
|
|
27
27
|
*/
|
|
28
|
-
exports.
|
|
28
|
+
exports.writeJson = async (file, body, bucket) => {
|
|
29
29
|
const storage = new Storage();
|
|
30
30
|
const stream = storage.bucket(bucket).file(file).createWriteStream({
|
|
31
31
|
metadata: {
|
|
@@ -36,4 +36,25 @@ exports.write = async (file, body, bucket) => {
|
|
|
36
36
|
stream.on("finish", () => log.success(`"${file}" has been written.`));
|
|
37
37
|
const buffer = Buffer.from(JSON.stringify(body));
|
|
38
38
|
return stream.end(buffer);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Group files by table.
|
|
43
|
+
*
|
|
44
|
+
* @param {Array} files An array of files.
|
|
45
|
+
*/
|
|
46
|
+
exports.groupJson = files => {
|
|
47
|
+
const result = {};
|
|
48
|
+
files.forEach(file => {
|
|
49
|
+
if (file.endsWith(".json")) {
|
|
50
|
+
const group = file.split(/^(.*)\-[\d]+\.json$/gis);
|
|
51
|
+
if (group.length > 1) {
|
|
52
|
+
if (typeof result[group[1]] === "undefined") {
|
|
53
|
+
result[group[1]] = [];
|
|
54
|
+
}
|
|
55
|
+
result[group[1]].push(file);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return result;
|
|
39
60
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pittica/google-cloud-storage-helpers",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.1.0",
|
|
5
5
|
"description": "Helpers for Google Cloud Storage.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/pittica/google-cloud-storage-helpers#README.md",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@google-cloud/storage": "^7.
|
|
29
|
+
"@google-cloud/storage": "^7.15.2",
|
|
30
30
|
"@pittica/logger-helpers": "^0.9.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/cli": "^7.
|
|
33
|
+
"@babel/cli": "^7.26.4",
|
|
34
34
|
"mkdirp": "^3.0.1",
|
|
35
|
-
"prettier": "^3.
|
|
35
|
+
"prettier": "^3.5.3",
|
|
36
36
|
"rimraf": "^6.0.1",
|
|
37
37
|
"run-func": "^3.0.0"
|
|
38
38
|
}
|