@pittica/google-business-intelligence-helpers 1.7.1 → 1.9.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/dist/contents/storage.js +27 -0
- package/dist/index.js +5 -1
- package/dist/naming/date.js +13 -1
- package/dist/naming/file.js +1 -1
- package/package.json +1 -1
package/dist/contents/storage.js
CHANGED
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
const {
|
|
16
16
|
getFiles
|
|
17
17
|
} = require("@pittica/google-cloud-storage-helpers");
|
|
18
|
+
const {
|
|
19
|
+
format
|
|
20
|
+
} = require("date-and-time");
|
|
18
21
|
const {
|
|
19
22
|
getSchemaKeys
|
|
20
23
|
} = require("./schema");
|
|
@@ -50,6 +53,30 @@ exports.mapStorageResponse = (response, schemas = "") => {
|
|
|
50
53
|
return Object.values(files).flat(1).map(file => splitName(file));
|
|
51
54
|
};
|
|
52
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Maps the given response and returns grouped and ordered object to import.
|
|
58
|
+
*
|
|
59
|
+
* @param {Array} response Google Cloud Storage response.
|
|
60
|
+
* @param {string} schemas Schema files folder path.
|
|
61
|
+
* @param {string} dateFormat Format string.
|
|
62
|
+
* @returns {object} Bucket files.
|
|
63
|
+
*/
|
|
64
|
+
exports.extractStorageResponse = (response, schemas = "", dateFormat = "YYYY-MM-DD") => {
|
|
65
|
+
const days = {};
|
|
66
|
+
const files = this.mapStorageResponse(response, schemas);
|
|
67
|
+
files.forEach(file => {
|
|
68
|
+
const date = format(file.date, dateFormat);
|
|
69
|
+
if (typeof days[date] === "undefined") {
|
|
70
|
+
days[date] = [];
|
|
71
|
+
}
|
|
72
|
+
days[date].push(file);
|
|
73
|
+
});
|
|
74
|
+
return Object.values(Object.keys(days).sort().reduce((obj, key) => {
|
|
75
|
+
obj[key] = days[key];
|
|
76
|
+
return obj;
|
|
77
|
+
}, {})).flat();
|
|
78
|
+
};
|
|
79
|
+
|
|
53
80
|
/**
|
|
54
81
|
* Ritrieves a safe name of a file in the given folder in the given bucket.
|
|
55
82
|
*
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ const {
|
|
|
23
23
|
} = require("./contents/sql");
|
|
24
24
|
const {
|
|
25
25
|
mapStorageResponse,
|
|
26
|
+
extractStorageResponse,
|
|
26
27
|
getSafeFilename,
|
|
27
28
|
getSafeFilenameFromBucket
|
|
28
29
|
} = require("./contents/storage");
|
|
@@ -32,7 +33,8 @@ const {
|
|
|
32
33
|
} = require("./naming/dataset");
|
|
33
34
|
const {
|
|
34
35
|
partsToDate,
|
|
35
|
-
stringToDate
|
|
36
|
+
stringToDate,
|
|
37
|
+
getNow
|
|
36
38
|
} = require("./naming/date");
|
|
37
39
|
const {
|
|
38
40
|
isDataCsv
|
|
@@ -58,12 +60,14 @@ exports.getSchemaKeys = getSchemaKeys;
|
|
|
58
60
|
exports.hasSchema = hasSchema;
|
|
59
61
|
exports.getSqlFilePath = getSqlFilePath;
|
|
60
62
|
exports.mapStorageResponse = mapStorageResponse;
|
|
63
|
+
exports.extractStorageResponse = extractStorageResponse;
|
|
61
64
|
exports.getSafeFilename = getSafeFilename;
|
|
62
65
|
exports.getSafeFilenameFromBucket = getSafeFilenameFromBucket;
|
|
63
66
|
exports.getTemporaryTableName = getTemporaryTableName;
|
|
64
67
|
exports.getTemporaryTableSuffix = getTemporaryTableSuffix;
|
|
65
68
|
exports.partsToDate = partsToDate;
|
|
66
69
|
exports.stringToDate = stringToDate;
|
|
70
|
+
exports.getNow = getNow;
|
|
67
71
|
exports.isDataCsv = isDataCsv;
|
|
68
72
|
exports.getFilenameVersion = getFilenameVersion;
|
|
69
73
|
exports.incrementFilenameVersion = incrementFilenameVersion;
|
package/dist/naming/date.js
CHANGED
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
// See the License for the specific language governing permissions and
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
|
|
15
|
+
const {
|
|
16
|
+
format
|
|
17
|
+
} = require("date-and-time");
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* Converts the file name parts to a date object.
|
|
17
21
|
*
|
|
@@ -32,4 +36,12 @@ exports.stringToDate = date => {
|
|
|
32
36
|
return this.partsToDate(split);
|
|
33
37
|
}
|
|
34
38
|
return null;
|
|
35
|
-
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Gets the current date in the given format.
|
|
43
|
+
*
|
|
44
|
+
* @param {string} dateFormat Format string.
|
|
45
|
+
* @returns {string} The current date in the given format.
|
|
46
|
+
*/
|
|
47
|
+
exports.getNow = (dateFormat = "YYYY-MM-DD") => format(new Date(), dateFormat);
|
package/dist/naming/file.js
CHANGED
|
@@ -78,7 +78,7 @@ exports.mergeFilename = (date, name, extension, version = 0) => `${format(date,
|
|
|
78
78
|
*
|
|
79
79
|
* @param {object} filedata Data to merge.
|
|
80
80
|
* @param {boolean} increment A value indicating whether the file version needs to be increased.
|
|
81
|
-
* @returns The merged given filename data.
|
|
81
|
+
* @returns {string} The merged given filename data.
|
|
82
82
|
*/
|
|
83
83
|
exports.mergeFiledata = ({
|
|
84
84
|
date,
|
package/package.json
CHANGED