@pittica/google-business-intelligence-csv 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/dist/config.js +2 -1
- package/dist/helpers/storage.js +40 -0
- package/dist/scripts/bulk.js +4 -1
- package/dist/scripts/day.js +4 -1
- package/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Sorts the given files.
|
|
17
|
+
*
|
|
18
|
+
* @param {Array} files An array of file data.
|
|
19
|
+
* @returns The sorted files.
|
|
20
|
+
*/
|
|
21
|
+
exports.sort = files => files.sort((a, b) => {
|
|
22
|
+
const first = config.order.indexOf(a.name);
|
|
23
|
+
const second = config.order.indexOf(b.name);
|
|
24
|
+
if (first < second) {
|
|
25
|
+
return -1;
|
|
26
|
+
} else if (first > second) {
|
|
27
|
+
return 1;
|
|
28
|
+
}
|
|
29
|
+
if (a.date < b.date) {
|
|
30
|
+
return -1;
|
|
31
|
+
} else if (a.date > b.date) {
|
|
32
|
+
return 1;
|
|
33
|
+
}
|
|
34
|
+
if (a.version < a.version) {
|
|
35
|
+
return -1;
|
|
36
|
+
} else if (b.version > b.version) {
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
});
|
package/dist/scripts/bulk.js
CHANGED
|
@@ -24,6 +24,9 @@ const {
|
|
|
24
24
|
getNow
|
|
25
25
|
} = require("@pittica/google-business-intelligence-helpers");
|
|
26
26
|
const log = require("@pittica/logger-helpers");
|
|
27
|
+
const {
|
|
28
|
+
sort
|
|
29
|
+
} = require("../helpers/storage");
|
|
27
30
|
const {
|
|
28
31
|
process
|
|
29
32
|
} = require("./day");
|
|
@@ -45,6 +48,6 @@ exports.bulk = async (source, temporary, destination) => {
|
|
|
45
48
|
storage.bucket(source).getFiles().then(response => {
|
|
46
49
|
log.info(`Starting bulk import...`);
|
|
47
50
|
const files = extractStorageResponse(response, config.files.sql);
|
|
48
|
-
process(dataset, bucketSource, bucketTemporary, bucketDestination, files, now);
|
|
51
|
+
process(dataset, bucketSource, bucketTemporary, bucketDestination, sort(files), now);
|
|
49
52
|
}).catch(logErrors);
|
|
50
53
|
};
|
package/dist/scripts/day.js
CHANGED
|
@@ -39,6 +39,9 @@ const log = require("@pittica/logger-helpers");
|
|
|
39
39
|
const {
|
|
40
40
|
getJobMetadata
|
|
41
41
|
} = require("../helpers/bigquery");
|
|
42
|
+
const {
|
|
43
|
+
sort
|
|
44
|
+
} = require("../helpers/storage");
|
|
42
45
|
|
|
43
46
|
/**
|
|
44
47
|
* Processes all CSV files in given buckets bucket for the given date.
|
|
@@ -72,7 +75,7 @@ exports.run = async (day, now, source, temporary, destination) => {
|
|
|
72
75
|
const bucketSource = await storage.bucket(source);
|
|
73
76
|
const bucketTemporary = await storage.bucket(temporary);
|
|
74
77
|
const bucketDestination = await storage.bucket(destination);
|
|
75
|
-
getFiles(storage, source, `${day}-`).then(response => this.process(dataset, bucketSource, bucketTemporary, bucketDestination, mapStorageResponse(response, config.files.sql), now));
|
|
78
|
+
getFiles(storage, source, `${day}-`).then(response => this.process(dataset, bucketSource, bucketTemporary, bucketDestination, sort(mapStorageResponse(response, config.files.sql)), now));
|
|
76
79
|
};
|
|
77
80
|
|
|
78
81
|
/**
|
package/package.json
CHANGED