@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.
- package/client/index.js +85 -87
- 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
|
|
929
|
-
if (
|
|
930
|
-
|
|
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
|
-
|
|
939
|
-
|
|
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
|
-
|
|
953
|
-
|
|
954
|
-
|
|
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
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
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(
|
|
966
|
+
targets.push(col);
|
|
972
967
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
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
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
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.
|
|
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.
|
|
23
|
-
"@e-mc/module": "^0.12.
|
|
24
|
-
"@e-mc/types": "^0.12.
|
|
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.
|
|
26
|
+
"@google-cloud/storage": "^7.17.1"
|
|
27
27
|
}
|
|
28
28
|
}
|