@pi-r/gcp 0.10.2 → 0.10.4

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 +85 -87
  2. package/package.json +5 -5
package/client/index.js CHANGED
@@ -925,107 +925,105 @@ async function executeBatchQuery(credential, batch, sessionKey) {
925
925
  }
926
926
  else {
927
927
  const options = item.options || {};
928
- if (options.vectorField || item.params || Array.isArray(query)) {
929
- if (options.vectorField) {
930
- if (Array.isArray(query)) {
931
- options.queryVector ||= firestore_1.FieldValue.vector(query);
932
- }
933
- if (limit > 0) {
934
- options.limit = limit;
935
- }
936
- rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
928
+ if (options.vectorField) {
929
+ if (Array.isArray(query)) {
930
+ options.queryVector ||= firestore_1.FieldValue.vector(query);
937
931
  }
938
- else if (item.params && (options.queryVector || Array.isArray(query) && query.every(value => typeof value === 'number'))) {
939
- if (!options.queryVector) {
940
- if (useCache && (rows = this.getCacheResult(service, credential, queryString = table + '_' + Cloud.asString(item.params, true) + '_' + Cloud.asString(query, true) + (options ? Cloud.asString(options, true) : '') + keyLimit(limit), cacheValue, ignoreCache))) {
941
- result[i] = rows;
942
- continue;
943
- }
944
- options.queryVector = firestore_1.FieldValue.vector(query);
945
- }
946
- options.vectorField = asFieldPath(item.params);
947
- if (limit > 0) {
948
- options.limit = limit;
949
- }
950
- rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
932
+ if (limit > 0) {
933
+ options.limit = limit;
951
934
  }
952
- else {
953
- const orderBy = item.orderBy;
954
- if (useCache && (rows = this.getCacheResult(service, credential, queryString = table + '_' + Cloud.asString(query, true) + '_' + Cloud.asString(orderBy, true) + `_${group ? '1' : '0'}_${typeof id === 'number' ? '1' : '0'}` + keyLimit(limit), cacheValue, ignoreCache))) {
935
+ rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
936
+ }
937
+ else if (item.params && (options.queryVector || Array.isArray(query) && query.every(value => typeof value === 'number'))) {
938
+ if (!options.queryVector) {
939
+ if (useCache && (rows = this.getCacheResult(service, credential, queryString = table + '_' + Cloud.asString(item.params, true) + '_' + Cloud.asString(query, true) + (options ? Cloud.asString(options, true) : '') + keyLimit(limit), cacheValue, ignoreCache))) {
955
940
  result[i] = rows;
956
941
  continue;
957
942
  }
958
- const targets = [];
959
- if (group) {
960
- const col = db.collectionGroup(table);
961
- if (typeof id === 'number') {
962
- for await (const partition of col.getPartitions(id)) {
963
- targets.push(partition.toQuery());
964
- }
965
- }
966
- else {
967
- targets.push(col);
943
+ options.queryVector = firestore_1.FieldValue.vector(query);
944
+ }
945
+ options.vectorField = asFieldPath(item.params);
946
+ if (limit > 0) {
947
+ options.limit = limit;
948
+ }
949
+ rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
950
+ }
951
+ else if ((0, types_1.isArray)(query)) {
952
+ const orderBy = item.orderBy;
953
+ if (useCache && (rows = this.getCacheResult(service, credential, queryString = table + '_' + Cloud.asString(query, true) + '_' + Cloud.asString(orderBy, true) + `_${group ? `1${typeof id === 'number' ? `:${id}` : ''}` : '0'}` + keyLimit(limit), cacheValue, ignoreCache))) {
954
+ result[i] = rows;
955
+ continue;
956
+ }
957
+ const targets = [];
958
+ if (group) {
959
+ const col = db.collectionGroup(table);
960
+ if (typeof id === 'number') {
961
+ for await (const partition of col.getPartitions(id)) {
962
+ targets.push(partition.toQuery());
968
963
  }
969
964
  }
970
965
  else {
971
- targets.push(db.collection(table));
966
+ targets.push(col);
972
967
  }
973
- rows = [];
974
- for (let target of targets) {
975
- for (const args of query) {
976
- if ((0, types_1.isArray)(args)) {
977
- const method = args[0];
978
- const params = args.slice(1);
979
- switch (method) {
980
- case 'whereAnd':
981
- case 'whereOr':
982
- if (!params.every(p => (0, types_1.isArray)(p))) {
983
- throw (0, types_1.errorMessage)(method, 'Conditionals are not in array format', Cloud.asString(params));
984
- }
985
- target = target.where(firestore_1.Filter[method === 'whereAnd' ? 'and' : 'or'](...params.map((p) => firestore_1.Filter.where(p[0], p[1], p[2]))));
986
- break;
987
- case 'findNearest':
988
- params[0] = asFieldPath(params[0]);
989
- target = target.findNearest.apply(target, params).query;
990
- break;
991
- case 'where':
992
- case 'orderBy':
993
- params[0] = asFieldPath(params[0]);
994
- target = target[method].apply(target, params);
995
- case 'select':
996
- params.forEach((field, index) => {
997
- params[index] = asFieldPath(field);
998
- });
999
- target = target.select.apply(target, params);
1000
- break;
1001
- case 'endAt':
1002
- case 'endBefore':
1003
- case 'limit':
1004
- case 'limitToLast':
1005
- case 'offset':
1006
- case 'startAfter':
1007
- case 'startAt':
1008
- case 'withConverter':
1009
- target = target[method].apply(target, params);
1010
- break;
1011
- }
968
+ }
969
+ else {
970
+ targets.push(db.collection(table));
971
+ }
972
+ rows = [];
973
+ for (let target of targets) {
974
+ for (const args of query) {
975
+ if ((0, types_1.isArray)(args)) {
976
+ const method = args[0];
977
+ const params = args.slice(1);
978
+ switch (method) {
979
+ case 'whereAnd':
980
+ case 'whereOr':
981
+ if (!params.every(p => (0, types_1.isArray)(p))) {
982
+ throw (0, types_1.errorMessage)(method, 'Conditionals are not in array format', Cloud.asString(params));
983
+ }
984
+ target = target.where(firestore_1.Filter[method === 'whereAnd' ? 'and' : 'or'](...params.map((p) => firestore_1.Filter.where(p[0], p[1], p[2]))));
985
+ break;
986
+ case 'findNearest':
987
+ params[0] = asFieldPath(params[0]);
988
+ target = target.findNearest.apply(target, params).query;
989
+ break;
990
+ case 'where':
991
+ case 'orderBy':
992
+ params[0] = asFieldPath(params[0]);
993
+ target = target[method].apply(target, params);
994
+ case 'select':
995
+ params.forEach((field, index) => {
996
+ params[index] = asFieldPath(field);
997
+ });
998
+ target = target.select.apply(target, params);
999
+ break;
1000
+ case 'endAt':
1001
+ case 'endBefore':
1002
+ case 'limit':
1003
+ case 'limitToLast':
1004
+ case 'offset':
1005
+ case 'startAfter':
1006
+ case 'startAt':
1007
+ case 'withConverter':
1008
+ target = target[method].apply(target, params);
1009
+ break;
1012
1010
  }
1013
1011
  }
1014
- if (Array.isArray(orderBy)) {
1015
- for (const order of orderBy) {
1016
- if ((0, types_1.isArray)(order)) {
1017
- target = target.orderBy(asFieldPath(order[0]), order[1]);
1018
- }
1019
- else if ((0, types_1.isString)(order)) {
1020
- target = target.orderBy(order);
1021
- }
1012
+ }
1013
+ if (Array.isArray(orderBy)) {
1014
+ for (const order of orderBy) {
1015
+ if ((0, types_1.isArray)(order)) {
1016
+ target = target.orderBy(asFieldPath(order[0]), order[1]);
1017
+ }
1018
+ else if ((0, types_1.isString)(order)) {
1019
+ target = target.orderBy(order);
1022
1020
  }
1023
1021
  }
1024
- if (limit > 0) {
1025
- target = target.limit(limit);
1026
- }
1027
- rows = rows.concat((await target.get()).docs.map(doc => doc.data()));
1028
1022
  }
1023
+ if (limit > 0) {
1024
+ target = target.limit(limit);
1025
+ }
1026
+ rows = rows.concat((await target.get()).docs.map(doc => doc.data()));
1029
1027
  }
1030
1028
  }
1031
1029
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gcp",
3
- "version": "0.10.2",
3
+ "version": "0.10.4",
4
4
  "description": "Google (GCP) cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -19,10 +19,10 @@
19
19
  "license": "MIT",
20
20
  "homepage": "https://github.com/anpham6/pi-r#readme",
21
21
  "dependencies": {
22
- "@e-mc/cloud": "^0.12.5",
23
- "@e-mc/module": "^0.12.5",
24
- "@e-mc/types": "^0.12.5",
22
+ "@e-mc/cloud": "^0.12.16",
23
+ "@e-mc/module": "^0.12.16",
24
+ "@e-mc/types": "^0.12.16",
25
25
  "@google-cloud/firestore": "^7.11.3",
26
- "@google-cloud/storage": "^7.16.0"
26
+ "@google-cloud/storage": "^7.17.1"
27
27
  }
28
28
  }