@pittica/google-business-intelligence-helpers 1.1.0 → 1.3.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.
@@ -0,0 +1,43 @@
1
+ // Copyright 2024-2025 Pittica S.r.l.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ const {
16
+ getSchemaKeys
17
+ } = require("./schema");
18
+ const {
19
+ splitName
20
+ } = require("../naming/split");
21
+
22
+ /**
23
+ * Maps Google Cloud Storage response.
24
+ *
25
+ * @param {Array} response Google Cloud Storage response.
26
+ * @param {string} schemas Schema files folder path.
27
+ * @returns {object} Mapped response.
28
+ */
29
+ exports.mapStorageResponse = (response, schemas) => {
30
+ const files = {};
31
+ getSchemaKeys(schemas).map(key => files[key] = []);
32
+ response.flat(3).forEach(({
33
+ id
34
+ }) => {
35
+ if (id) {
36
+ const filename = splitName(id);
37
+ if (typeof files[filename.name] !== "undefined") {
38
+ files[filename.name].push(id);
39
+ }
40
+ }
41
+ });
42
+ return Object.values(files).flat(1).map(file => splitName(file));
43
+ };
package/dist/index.js CHANGED
@@ -21,6 +21,9 @@ const {
21
21
  const {
22
22
  getSqlFilePath
23
23
  } = require("./contents/sql");
24
+ const {
25
+ mapStorageResponse
26
+ } = require("./contents/storage");
24
27
  const {
25
28
  getTemporaryTableName,
26
29
  getTemporaryTableSuffix
@@ -31,6 +34,7 @@ const {
31
34
  } = require("./naming/date");
32
35
  const {
33
36
  getFilenameVersion,
37
+ incrementFilenameVersion,
34
38
  getJsonStorageName,
35
39
  createFilename,
36
40
  mergeFilename
@@ -47,11 +51,13 @@ exports.getSchema = getSchema;
47
51
  exports.getSchemaKeys = getSchemaKeys;
48
52
  exports.hasSchema = hasSchema;
49
53
  exports.getSqlFilePath = getSqlFilePath;
54
+ exports.mapStorageResponse = mapStorageResponse;
50
55
  exports.getTemporaryTableName = getTemporaryTableName;
51
56
  exports.getTemporaryTableSuffix = getTemporaryTableSuffix;
52
57
  exports.partsToDate = partsToDate;
53
58
  exports.stringToDate = stringToDate;
54
59
  exports.getFilenameVersion = getFilenameVersion;
60
+ exports.incrementFilenameVersion = incrementFilenameVersion;
55
61
  exports.getJsonStorageName = getJsonStorageName;
56
62
  exports.createFilename = createFilename;
57
63
  exports.mergeFilename = mergeFilename;
@@ -29,6 +29,17 @@ exports.getFilenameVersion = name => {
29
29
  return isNaN(version) ? 0 : version;
30
30
  };
31
31
 
32
+ /**
33
+ * Increments the version of a filename in the given filedata.
34
+ *
35
+ * @param {object} filedata File data.
36
+ * @returns {number} The given file data.
37
+ */
38
+ exports.incrementFilenameVersion = filedata => {
39
+ filedata.version = typeof filedata.version !== "undefined" ? filedata.version + 1 : 1;
40
+ return filedata;
41
+ };
42
+
32
43
  /**
33
44
  * Gets the name of a JSON storage file.
34
45
  *
@@ -41,7 +52,7 @@ exports.getJsonStorageName = (date, file) => `${format(date, "YYYY-MM-DD")}/${fo
41
52
  /**
42
53
  * Generates a filename from the givend data.
43
54
  *
44
- * @param {object} filedata File date.
55
+ * @param {object} filedata File data.
45
56
  * @returns {string} A filename from the givend data.
46
57
  */
47
58
  exports.createFilename = filedata => `${format(filedata.date, "YYYY-MM-DD")}-${filedata.fullname}.${filedata.extension}`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pittica/google-business-intelligence-helpers",
3
3
  "private": false,
4
- "version": "1.1.0",
4
+ "version": "1.3.0",
5
5
  "description": "Helpers for business intelligence for Google Cloud.",
6
6
  "main": "dist/index.js",
7
7
  "scripts": {