@pi-r/gcp 0.12.4 → 0.13.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.
Files changed (2) hide show
  1. package/client/index.js +12 -9
  2. package/package.json +6 -6
package/client/index.js CHANGED
@@ -530,7 +530,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
530
530
  }
531
531
  const orderBy = item.orderBy;
532
532
  if (useCache) {
533
- queryString = query + Cloud.asString(orderBy, true);
533
+ queryString = Cloud.keyForResult(query, orderBy);
534
534
  if (!update && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
535
535
  result[i] = rows;
536
536
  continue;
@@ -591,7 +591,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
591
591
  }
592
592
  const { updateType, options = {} } = item;
593
593
  if (useCache) {
594
- queryString = name + '_' + database + (table ? '_' + table + (columns ? Cloud.asString(columns, true) : '') : '') + '_' + Cloud.asString(query, true) + keyLimit(limit);
594
+ queryString = Cloud.keyForResult(name, database, table && Cloud.keyForResult(table, columns), query, keyLimit(limit));
595
595
  if (!update && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
596
596
  result[i] = rows;
597
597
  continue;
@@ -718,7 +718,10 @@ async function executeBatchQuery(credential, batch, sessionKey) {
718
718
  (options.gaxOptions ||= {}).maxResults = limit;
719
719
  }
720
720
  if (useCache) {
721
- queryString = name + '_' + table + (isString(id) ? '_' + id + (isArray(columns) ? '_' + Cloud.asString(columns, true) : '') : '') + Cloud.asString(options, true);
721
+ queryString = Cloud.keyForResult(name, table, options);
722
+ if (isString(id)) {
723
+ queryString = isArray(columns) ? Cloud.keyForResult(queryString, id, columns) : Cloud.keyForResult(queryString, id);
724
+ }
722
725
  if (!(update && id) && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
723
726
  result[i] = rows;
724
727
  continue;
@@ -730,7 +733,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
730
733
  if (update) {
731
734
  await row.save(update);
732
735
  }
733
- if (Array.isArray(columns)) {
736
+ if (isArray(columns)) {
734
737
  const [data] = await row.get(columns, options);
735
738
  rows = [getRowData(id, data)];
736
739
  }
@@ -767,7 +770,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
767
770
  options.maxResults = limit;
768
771
  }
769
772
  if (useCache) {
770
- queryString = (database ? database + '_' + (table ? table + '_' : '') : '') + Cloud.asString(options, true);
773
+ queryString = database ? Cloud.keyForResult(database, table, options) : Cloud.asString(options, true);
771
774
  if (!update && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
772
775
  result[i] = rows;
773
776
  continue;
@@ -800,7 +803,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
800
803
  throw formatError(item, "Missing database query");
801
804
  }
802
805
  if (useCache) {
803
- queryString = (keys ? Cloud.asString(keys, true) : (kind ? (name ? '_' + name : '') + '_' + Cloud.asString(kind, true) : '') + '_' + Cloud.asString(query, true) + '_' + keyLimit(limit)) + (options ? Cloud.asString(options, true) : '');
806
+ queryString = keys ? Cloud.keyForResult(keys, options) : Cloud.keyForResult(kind && Cloud.keyForResult(name, kind), query, keyLimit(limit), options);
804
807
  if (!update && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
805
808
  result[i] = rows;
806
809
  continue;
@@ -900,7 +903,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
900
903
  else if (isString(id) || Array.isArray(id)) {
901
904
  const options = Array.isArray(id) ? item.options : null;
902
905
  if (useCache) {
903
- queryString = table + '_' + id + (options ? Cloud.asString(options, true) : '');
906
+ queryString = Cloud.keyForResult(table, id, options);
904
907
  if ((!update || Array.isArray(id)) && (rows = this.getCacheResult(service, credential, queryString, cacheValue, ignoreCache))) {
905
908
  result[i] = rows;
906
909
  continue;
@@ -999,7 +1002,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
999
1002
  }
1000
1003
  else if (item.params && (options.queryVector || Array.isArray(query) && query.every(value => typeof value === 'number'))) {
1001
1004
  if (!options.queryVector) {
1002
- if (useCache && (rows = this.getCacheResult(service, credential, queryString = table + '_' + Cloud.asString(item.params, true) + '_' + Cloud.asString(query, true) + '_' + keyLimit(limit) + (options ? Cloud.asString(options, true) : ''), cacheValue, ignoreCache))) {
1005
+ if (useCache && (rows = this.getCacheResult(service, credential, queryString = Cloud.keyForResult(table, item.params, query, keyLimit(limit), options), cacheValue, ignoreCache))) {
1003
1006
  result[i] = rows;
1004
1007
  continue;
1005
1008
  }
@@ -1012,7 +1015,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
1012
1015
  rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
1013
1016
  }
1014
1017
  else if (isArray(query)) {
1015
- if (useCache && (rows = this.getCacheResult(service, credential, queryString = table + '_' + Cloud.asString(query, true) + '_' + keyLimit(limit) + '_' + (item.pipeline ? (group ? '1' : '0') + (options ? Cloud.asString(options, true) : '') : (group ? typeof id === 'number' ? `part:${id}` : ':1' : ':0') + (item.orderBy ? Cloud.asString(item.orderBy, true) : '')), cacheValue, ignoreCache))) {
1018
+ if (useCache && (rows = this.getCacheResult(service, credential, queryString = Cloud.keyForResult(table, query, keyLimit(limit), item.pipeline ? Cloud.keyForResult(group ? '1' : '0', options) : Cloud.keyForResult(group ? typeof id === 'number' ? `part:${id}` : ':1' : ':0'), item.orderBy), cacheValue, ignoreCache))) {
1016
1019
  result[i] = rows;
1017
1020
  continue;
1018
1021
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gcp",
3
- "version": "0.12.4",
3
+ "version": "0.13.0",
4
4
  "description": "Google (GCP) cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "repository": {
@@ -16,10 +16,10 @@
16
16
  "license": "MIT",
17
17
  "homepage": "https://github.com/anpham6/pi-r#readme",
18
18
  "dependencies": {
19
- "@e-mc/cloud": "^0.14.5",
20
- "@e-mc/module": "^0.14.5",
21
- "@e-mc/types": "^0.14.5",
22
- "@google-cloud/firestore": "^8.7.1",
23
- "@google-cloud/storage": "^7.21.0"
19
+ "@e-mc/cloud": "^0.14.6",
20
+ "@e-mc/module": "^0.14.6",
21
+ "@e-mc/types": "^0.14.6",
22
+ "@google-cloud/firestore": "^9.0.0",
23
+ "@google-cloud/storage": "^8.0.1"
24
24
  }
25
25
  }