@pi-r/gcp 0.3.2 → 0.5.2

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2023 Studio Trigger
1
+ Copyright 2023 Wit Studio
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
4
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @pi-r/gcp
2
2
 
3
- PEP 402 - Forever Aina
3
+ PEP 402 - Forever Vivy
4
4
 
5
5
  ## LICENSE
6
6
 
package/client/index.js CHANGED
@@ -464,7 +464,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
464
464
  }
465
465
  const { updateType, options = {} } = item;
466
466
  if (cached) {
467
- queryString = name + '_' + database + '_' + (table ? table + Module.asString(columns, true) : '') + Module.asString(query, true) + limit;
467
+ queryString = name + '_' + database + '_' + (table ? table + (columns ? Module.asString(columns, true) : '') : '') + Module.asString(query, true) + limit;
468
468
  if (!update && (rows = getCache(queryString))) {
469
469
  result[i] = rows;
470
470
  continue;
@@ -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 (!(0, types_1.isArray)(args)) {
600
- continue;
601
- }
602
- const method = args[0];
603
- switch (method) {
604
- case 'end':
605
- case 'filter':
606
- case 'groupBy':
607
- case 'hasAncestor':
608
- case 'limit':
609
- case 'offset':
610
- case 'order':
611
- case 'select':
612
- case 'start':
613
- task[method].apply(task, args.slice(1));
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));
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).collection(table);
654
653
  for (const args of query) {
655
- if (!(0, types_1.isArray)(args)) {
656
- continue;
657
- }
658
- const method = args[0];
659
- switch (method) {
660
- case 'endAt':
661
- case 'endBefore':
662
- case 'limit':
663
- case 'limitToLast':
664
- case 'offset':
665
- case 'orderBy':
666
- case 'select':
667
- case 'startAfter':
668
- case 'startAt':
669
- case 'where':
670
- case 'withConverter':
671
- db = db[method].apply(db, args.slice(1));
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));
669
+ break;
670
+ }
673
671
  }
674
672
  }
675
673
  if ((0, types_1.isArray)(orderBy)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gcp",
3
- "version": "0.3.2",
3
+ "version": "0.5.2",
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.6.1",
24
- "@e-mc/module": "^0.6.1",
25
- "@e-mc/types": "^0.6.1",
26
- "@google-cloud/firestore": "^6.8.0",
23
+ "@e-mc/cloud": "^0.7.2",
24
+ "@e-mc/module": "^0.7.2",
25
+ "@e-mc/types": "^0.7.2",
26
+ "@google-cloud/firestore": "^7.3.1",
27
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, admin.configBucket?.create || (0, client_1.createBucketRequest)(credential)));
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, service, ["Bucket configured" + ' (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", 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);