@pi-r/gcp 0.11.0 → 0.11.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/client/index.js CHANGED
@@ -438,7 +438,7 @@ async function copyObject(credential, bucketSource, keySource, bucket, key, opti
438
438
  });
439
439
  }
440
440
  async function executeQuery(credential, data, sessionKey) {
441
- return (await executeBatchQuery.call(this, credential, [data], sessionKey))[0] || [];
441
+ return (await executeBatchQuery.call(this, credential, [data], sessionKey)).at(0) || [];
442
442
  }
443
443
  async function executeBatchQuery(credential, batch, sessionKey) {
444
444
  const length = batch.length;
@@ -815,8 +815,9 @@ async function executeBatchQuery(credential, batch, sessionKey) {
815
815
  if ((0, types_1.isPlainObject)(update)) {
816
816
  await new Promise((resolve, reject) => {
817
817
  db.runQuery(task.select('__key__'), options).then(entities => {
818
- if ((0, types_1.isArray)(entities)) {
819
- const items = entities.map((entity) => db.key(entity[db.KEY]));
818
+ const response = entities[0];
819
+ if ((0, types_1.isArray)(response)) {
820
+ const items = response.map(entity => db.key(entity[db.KEY]));
820
821
  db.save({ key: items, data: update })
821
822
  .then(() => {
822
823
  resolve();
@@ -902,7 +903,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
902
903
  return +unit;
903
904
  }
904
905
  const a = unit[0];
905
- const b = unit[unit.length - 1];
906
+ const b = unit.at(-1);
906
907
  if (a === '[' && b === ']' || a === '{' && b === '}') {
907
908
  try {
908
909
  return JSON.parse(unit.replace(/\\,/g, ','));
@@ -938,107 +939,105 @@ async function executeBatchQuery(credential, batch, sessionKey) {
938
939
  }
939
940
  else {
940
941
  const options = item.options || {};
941
- if (options.vectorField || item.params || Array.isArray(query)) {
942
- if (options.vectorField) {
943
- if (Array.isArray(query)) {
944
- options.queryVector ||= firestore_1.FieldValue.vector(query);
945
- }
946
- if (limit > 0) {
947
- options.limit = limit;
948
- }
949
- rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
942
+ if (options.vectorField) {
943
+ if (Array.isArray(query)) {
944
+ options.queryVector ||= firestore_1.FieldValue.vector(query);
950
945
  }
951
- else if (item.params && (options.queryVector || Array.isArray(query) && query.every(value => typeof value === 'number'))) {
952
- if (!options.queryVector) {
953
- 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))) {
954
- result[i] = rows;
955
- continue;
956
- }
957
- options.queryVector = firestore_1.FieldValue.vector(query);
958
- }
959
- options.vectorField = asFieldPath(item.params);
960
- if (limit > 0) {
961
- options.limit = limit;
962
- }
963
- rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
946
+ if (limit > 0) {
947
+ options.limit = limit;
964
948
  }
965
- else {
966
- const orderBy = item.orderBy;
967
- 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))) {
949
+ rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
950
+ }
951
+ else if (item.params && (options.queryVector || Array.isArray(query) && query.every(value => typeof value === 'number'))) {
952
+ if (!options.queryVector) {
953
+ 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))) {
968
954
  result[i] = rows;
969
955
  continue;
970
956
  }
971
- const targets = [];
972
- if (group) {
973
- const col = db.collectionGroup(table);
974
- if (typeof id === 'number') {
975
- for await (const partition of col.getPartitions(id)) {
976
- targets.push(partition.toQuery());
977
- }
978
- }
979
- else {
980
- targets.push(col);
957
+ options.queryVector = firestore_1.FieldValue.vector(query);
958
+ }
959
+ options.vectorField = asFieldPath(item.params);
960
+ if (limit > 0) {
961
+ options.limit = limit;
962
+ }
963
+ rows = (await db.collection(table).findNearest(options).get()).docs.map(doc => doc.data());
964
+ }
965
+ else if ((0, types_1.isArray)(query)) {
966
+ const orderBy = item.orderBy;
967
+ 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))) {
968
+ result[i] = rows;
969
+ continue;
970
+ }
971
+ const targets = [];
972
+ if (group) {
973
+ const col = db.collectionGroup(table);
974
+ if (typeof id === 'number') {
975
+ for await (const partition of col.getPartitions(id)) {
976
+ targets.push(partition.toQuery());
981
977
  }
982
978
  }
983
979
  else {
984
- targets.push(db.collection(table));
980
+ targets.push(col);
985
981
  }
986
- rows = [];
987
- for (let target of targets) {
988
- for (const args of query) {
989
- if ((0, types_1.isArray)(args)) {
990
- const method = args[0];
991
- const params = args.slice(1);
992
- switch (method) {
993
- case 'whereAnd':
994
- case 'whereOr':
995
- if (!params.every(p => (0, types_1.isArray)(p))) {
996
- throw (0, types_1.errorMessage)(method, 'Conditionals are not in array format', Cloud.asString(params));
997
- }
998
- target = target.where(firestore_1.Filter[method === 'whereAnd' ? 'and' : 'or'](...params.map((p) => firestore_1.Filter.where(p[0], p[1], p[2]))));
999
- break;
1000
- case 'findNearest':
1001
- params[0] = asFieldPath(params[0]);
1002
- target = target.findNearest.apply(target, params).query;
1003
- break;
1004
- case 'where':
1005
- case 'orderBy':
1006
- params[0] = asFieldPath(params[0]);
1007
- target = target[method].apply(target, params);
1008
- case 'select':
1009
- params.forEach((field, index) => {
1010
- params[index] = asFieldPath(field);
1011
- });
1012
- target = target.select.apply(target, params);
1013
- break;
1014
- case 'endAt':
1015
- case 'endBefore':
1016
- case 'limit':
1017
- case 'limitToLast':
1018
- case 'offset':
1019
- case 'startAfter':
1020
- case 'startAt':
1021
- case 'withConverter':
1022
- target = target[method].apply(target, params);
1023
- break;
1024
- }
982
+ }
983
+ else {
984
+ targets.push(db.collection(table));
985
+ }
986
+ rows = [];
987
+ for (let target of targets) {
988
+ for (const args of query) {
989
+ if ((0, types_1.isArray)(args)) {
990
+ const method = args[0];
991
+ const params = args.slice(1);
992
+ switch (method) {
993
+ case 'whereAnd':
994
+ case 'whereOr':
995
+ if (!params.every(p => (0, types_1.isArray)(p))) {
996
+ throw (0, types_1.errorMessage)(method, 'Conditionals are not in array format', Cloud.asString(params));
997
+ }
998
+ target = target.where(firestore_1.Filter[method === 'whereAnd' ? 'and' : 'or'](...params.map((p) => firestore_1.Filter.where(p[0], p[1], p[2]))));
999
+ break;
1000
+ case 'findNearest':
1001
+ params[0] = asFieldPath(params[0]);
1002
+ target = target.findNearest.apply(target, params).query;
1003
+ break;
1004
+ case 'where':
1005
+ case 'orderBy':
1006
+ params[0] = asFieldPath(params[0]);
1007
+ target = target[method].apply(target, params);
1008
+ case 'select':
1009
+ params.forEach((field, index) => {
1010
+ params[index] = asFieldPath(field);
1011
+ });
1012
+ target = target.select.apply(target, params);
1013
+ break;
1014
+ case 'endAt':
1015
+ case 'endBefore':
1016
+ case 'limit':
1017
+ case 'limitToLast':
1018
+ case 'offset':
1019
+ case 'startAfter':
1020
+ case 'startAt':
1021
+ case 'withConverter':
1022
+ target = target[method].apply(target, params);
1023
+ break;
1025
1024
  }
1026
1025
  }
1027
- if (Array.isArray(orderBy)) {
1028
- for (const order of orderBy) {
1029
- if ((0, types_1.isArray)(order)) {
1030
- target = target.orderBy(asFieldPath(order[0]), order[1]);
1031
- }
1032
- else if ((0, types_1.isString)(order)) {
1033
- target = target.orderBy(order);
1034
- }
1026
+ }
1027
+ if (Array.isArray(orderBy)) {
1028
+ for (const order of orderBy) {
1029
+ if ((0, types_1.isArray)(order)) {
1030
+ target = target.orderBy(asFieldPath(order[0]), order[1]);
1031
+ }
1032
+ else if ((0, types_1.isString)(order)) {
1033
+ target = target.orderBy(order);
1035
1034
  }
1036
1035
  }
1037
- if (limit > 0) {
1038
- target = target.limit(limit);
1039
- }
1040
- rows = rows.concat((await target.get()).docs.map(doc => doc.data()));
1041
1036
  }
1037
+ if (limit > 0) {
1038
+ target = target.limit(limit);
1039
+ }
1040
+ rows = rows.concat((await target.get()).docs.map(doc => doc.data()));
1042
1041
  }
1043
1042
  }
1044
1043
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gcp",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
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.13.0",
23
- "@e-mc/module": "^0.13.0",
24
- "@e-mc/types": "^0.13.0",
22
+ "@e-mc/cloud": "^0.13.9",
23
+ "@e-mc/module": "^0.13.9",
24
+ "@e-mc/types": "^0.13.9",
25
25
  "@google-cloud/firestore": "^7.11.6",
26
- "@google-cloud/storage": "^7.17.2"
26
+ "@google-cloud/storage": "^7.19.0"
27
27
  }
28
28
  }
package/types/index.d.ts CHANGED
@@ -7,7 +7,6 @@ import type { entity } from '@google-cloud/datastore/build/src/entity';
7
7
  import type { FirebaseOptions as IFirebaseOptions } from '@firebase/app';
8
8
  import type { ServiceAccount } from 'firebase-admin/app';
9
9
 
10
- // @ts-ignore
11
10
  import type { GoogleAuthOptions } from 'google-auth-library';
12
11
 
13
12
  export type GCPStorage = CloudStorage<GCPStorageCredential, "gcp | gcloud">;
@@ -22,14 +21,14 @@ export interface GCPDatabaseQuery<T = PlainObject> extends Omit<CloudDatabase<un
22
21
  id?: string | string[] | number;
23
22
  updateType?: 0 | 1 | 2 | 3;
24
23
  columns?: string[];
25
- keys?: DatastoreKey | DatastoreKey[];
24
+ keys?: ArrayOf<DatastoreKey>;
26
25
  kind?: string | string[];
27
26
  orderBy?: unknown[][];
28
27
  aggregateSpec?: AggregateSpec;
29
28
  flags?: number;
30
29
  }
31
30
 
32
- export type GCPDatabaseCredential = GoogleAuthOptions;
31
+ export interface GCPDatabaseCredential extends GoogleAuthOptions, IFirebaseOptions {}
33
32
 
34
33
  export interface FirebaseOptions extends IFirebaseOptions {
35
34
  product?: "firebase";