@pi-r/gcp 0.3.0 → 0.5.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/client/index.js +33 -34
- package/package.json +6 -6
- package/upload/index.js +11 -2
package/client/index.js
CHANGED
|
@@ -596,22 +596,21 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
596
596
|
else {
|
|
597
597
|
const task = db.createQuery(item.kind);
|
|
598
598
|
for (const args of query) {
|
|
599
|
-
if (
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
break;
|
|
599
|
+
if ((0, types_1.isArray)(args)) {
|
|
600
|
+
const method = args[0];
|
|
601
|
+
switch (method) {
|
|
602
|
+
case 'end':
|
|
603
|
+
case 'filter':
|
|
604
|
+
case 'groupBy':
|
|
605
|
+
case 'hasAncestor':
|
|
606
|
+
case 'limit':
|
|
607
|
+
case 'offset':
|
|
608
|
+
case 'order':
|
|
609
|
+
case 'select':
|
|
610
|
+
case 'start':
|
|
611
|
+
task[method].apply(task, args.slice(1)); // eslint-disable-line prefer-spread
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
615
614
|
}
|
|
616
615
|
}
|
|
617
616
|
if (limit > 0) {
|
|
@@ -652,24 +651,23 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
652
651
|
}
|
|
653
652
|
let db = createClient(item, 3 /* DB.FIRESTORE */).collection(table);
|
|
654
653
|
for (const args of query) {
|
|
655
|
-
if (
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
break;
|
|
654
|
+
if ((0, types_1.isArray)(args)) {
|
|
655
|
+
const method = args[0];
|
|
656
|
+
switch (method) {
|
|
657
|
+
case 'endAt':
|
|
658
|
+
case 'endBefore':
|
|
659
|
+
case 'limit':
|
|
660
|
+
case 'limitToLast':
|
|
661
|
+
case 'offset':
|
|
662
|
+
case 'orderBy':
|
|
663
|
+
case 'select':
|
|
664
|
+
case 'startAfter':
|
|
665
|
+
case 'startAt':
|
|
666
|
+
case 'where':
|
|
667
|
+
case 'withConverter':
|
|
668
|
+
db = db[method].apply(db, args.slice(1)); // eslint-disable-line prefer-spread
|
|
669
|
+
break;
|
|
670
|
+
}
|
|
673
671
|
}
|
|
674
672
|
}
|
|
675
673
|
if ((0, types_1.isArray)(orderBy)) {
|
|
@@ -801,6 +799,7 @@ function createBucketRequest(credential) {
|
|
|
801
799
|
case 'cors':
|
|
802
800
|
case 'customPlacementConfig':
|
|
803
801
|
case 'dra':
|
|
802
|
+
case 'enableObjectRetention':
|
|
804
803
|
case 'location':
|
|
805
804
|
case 'multiRegional':
|
|
806
805
|
case 'nearline':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.
|
|
24
|
-
"@e-mc/module": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"@google-cloud/firestore": "^
|
|
27
|
-
"@google-cloud/storage": "^7.
|
|
23
|
+
"@e-mc/cloud": "^0.7.0",
|
|
24
|
+
"@e-mc/module": "^0.7.0",
|
|
25
|
+
"@e-mc/types": "^0.7.0",
|
|
26
|
+
"@google-cloud/firestore": "^7.1.0",
|
|
27
|
+
"@google-cloud/storage": "^7.7.0"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/upload/index.js
CHANGED
|
@@ -27,6 +27,7 @@ function upload(credential, service = 'gcp') {
|
|
|
27
27
|
}
|
|
28
28
|
callback(err, url);
|
|
29
29
|
};
|
|
30
|
+
const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
|
|
30
31
|
if (firebase) {
|
|
31
32
|
const { ref, listAll } = require('@firebase/storage');
|
|
32
33
|
bucketClient = ref(storage, bucket);
|
|
@@ -41,9 +42,10 @@ function upload(credential, service = 'gcp') {
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
45
|
+
const configBucket = admin.configBucket;
|
|
44
46
|
if (!BUCKET_SESSION.has(bucket)) {
|
|
45
47
|
const bucketAcl = admin.publicRead ? 'publicRead' : admin.acl;
|
|
46
|
-
const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl,
|
|
48
|
+
const response = BUCKET_RESPONSE[_a = bucketKey = getBucketKey(credential, bucket, bucketAcl)] || (BUCKET_RESPONSE[_a] = client_1.createBucketV2.call(this, credential, bucket, bucketAcl, configBucket?.create || (0, client_1.createBucketRequest)(credential)));
|
|
47
49
|
if (!await response) {
|
|
48
50
|
uploadResponse(null);
|
|
49
51
|
return;
|
|
@@ -51,6 +53,14 @@ function upload(credential, service = 'gcp') {
|
|
|
51
53
|
BUCKET_SESSION.add(bucket);
|
|
52
54
|
}
|
|
53
55
|
bucketClient = storage.bucket(bucket);
|
|
56
|
+
const retentionPolicy = configBucket?.retentionPolicy;
|
|
57
|
+
if (typeof retentionPolicy === 'number') {
|
|
58
|
+
bucketClient.setRetentionPeriod(retentionPolicy)
|
|
59
|
+
.then(([response]) => {
|
|
60
|
+
this.formatMessage(64 /* LOG_TYPE.CLOUD */, service, ["Bucket configured" /* VAL_CLOUD.CONFIGURE_BUCKET */ + ' (retention policy)', bucket], response.retentionPolicy?.effectiveTime, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
61
|
+
})
|
|
62
|
+
.catch(err => addLog(err));
|
|
63
|
+
}
|
|
54
64
|
}
|
|
55
65
|
if (!overwrite && (!listFiles || listFiles.length)) {
|
|
56
66
|
const current = filename;
|
|
@@ -79,7 +89,6 @@ function upload(credential, service = 'gcp') {
|
|
|
79
89
|
const Body = [data.buffer];
|
|
80
90
|
const ContentType = [contentType];
|
|
81
91
|
const getURL = (value) => endpoint ? Module.joinPath(endpoint, value) : Module.joinPath("https://storage.googleapis.com" /* STRINGS.BASE_URL */, bucket, value);
|
|
82
|
-
const addLog = (err) => err instanceof Error && this.addLog(this.statusType.WARN, err.message, service + ': ' + bucket);
|
|
83
92
|
if (fileGroup) {
|
|
84
93
|
for (const [content, ext, localFile] of fileGroup) {
|
|
85
94
|
Key.push(ext === '.map' && localFile ? path.basename(localFile) : filename + ext);
|