@pi-r/gcp 0.8.4 → 0.8.6

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 +15 -12
  2. package/package.json +4 -4
package/client/index.js CHANGED
@@ -124,6 +124,10 @@ const asFieldPath = (params) => Array.isArray(params) && params.every(item => ty
124
124
  const getFirebasePackageName = (credential) => credential.apiKey && credential.authDomain ? 'firebase' : 'firebase-admin';
125
125
  const isErrorConflict = (err) => (err instanceof Error) && err.code === 409;
126
126
  const hasGoogleAuth = (credential) => (0, types_1.isString)(credential.keyFilename || credential.keyFile || process.env.GOOGLE_APPLICATION_CREDENTIALS) || (0, types_1.isObject)(credential.credentials) || !!credential.authClient;
127
+ const isSpanner = (data) => data.product === "spanner" || !data.product && !!(data.name && data.database && (data.query || data.table));
128
+ const isBigtable = (data) => data.product === "bigtable" || !data.product && !!(data.name && data.table && !data.database);
129
+ const isBigQuery = (data) => data.product === "bigquery" || !data.product && !!(!data.name && data.table && data.database || (0, types_1.isString)(data.query) || (0, types_1.isString)(data.options?.query));
130
+ const isDatastore = (data) => data.product === "datastore" || !data.product && !!(data.keys || data.kind || data.query && !data.table && !data.id);
127
131
  function isFirebaseApp(credential, store, admin) {
128
132
  return !!(credential.apiKey && credential.authDomain && (store || credential.databaseURL) || credential.product === "firebase" && process.env.GOOGLE_APPLICATION_CREDENTIALS) && (!admin || !credential.admin);
129
133
  }
@@ -160,20 +164,19 @@ function createDatabaseClient(credential, data) {
160
164
  }
161
165
  getProjectId(credential, true);
162
166
  if (data) {
163
- const { product, name, table, query, database } = data;
164
- if (product === "spanner" || !product && name && database && (query || table)) {
167
+ if (isSpanner(data)) {
165
168
  const { Spanner } = require(packageName = '@google-cloud/spanner');
166
169
  return new Spanner(credential);
167
170
  }
168
- if (product === "bigquery" || !product && (!name && table && database || (0, types_1.isString)(query))) {
169
- const { BigQuery } = require(packageName = '@google-cloud/bigquery');
170
- return new BigQuery(credential);
171
- }
172
- if (product === "bigtable" || !product && name && table && !database) {
171
+ if (isBigtable(data)) {
173
172
  const { Bigtable } = require(packageName = '@google-cloud/bigtable');
174
173
  return new Bigtable(credential);
175
174
  }
176
- if (product === "datastore" || !product && (data.keys || data.kind || query && !table && !data.id)) {
175
+ if (isBigQuery(data)) {
176
+ const { BigQuery } = require(packageName = '@google-cloud/bigquery');
177
+ return new BigQuery(credential);
178
+ }
179
+ if (isDatastore(data)) {
177
180
  const { Datastore } = require(packageName = '@google-cloud/datastore');
178
181
  return new Datastore(credential);
179
182
  }
@@ -504,7 +507,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
504
507
  rows = [group && (0, types_1.isObject)(val) && (0, types_1.isObject)(val[group[0]]) ? val[group[0]] : val];
505
508
  }
506
509
  }
507
- else if (product === "spanner" || !product && name && database && (query || table)) {
510
+ else if (isSpanner(item)) {
508
511
  const columns = (0, types_1.isPlainObject)(query) && query.columns || item.columns;
509
512
  if (!(query || table && columns)) {
510
513
  closeClient();
@@ -567,7 +570,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
567
570
  [rows] = await db.run(request);
568
571
  }
569
572
  }
570
- else if (product === "bigtable" || !product && name && table && !database) {
573
+ else if (isBigtable(item)) {
571
574
  if (!name || !table) {
572
575
  closeClient();
573
576
  throw (0, util_1.formatError)(item, !name ? "Missing database name" : "Missing database table");
@@ -613,7 +616,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
613
616
  });
614
617
  }
615
618
  }
616
- else if (product === "bigquery" || !product && (!name && database && table || (0, types_1.isString)(query) || (0, types_1.isString)(item.options?.query))) {
619
+ else if (isBigQuery(item)) {
617
620
  const { params, options = {} } = item;
618
621
  if ((0, types_1.isString)(query)) {
619
622
  options.query = query;
@@ -655,7 +658,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
655
658
  [rows] = await instance.query(options);
656
659
  }
657
660
  }
658
- else if (product === "datastore" || !product && (item.keys || item.kind || query && !table && !id)) {
661
+ else if (isDatastore(item)) {
659
662
  const { keys, kind, options } = item;
660
663
  if (!keys && !kind && !Array.isArray(query)) {
661
664
  closeClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gcp",
3
- "version": "0.8.4",
3
+ "version": "0.8.6",
4
4
  "description": "Google (GCP) cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -20,9 +20,9 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/cloud": "^0.10.9",
24
- "@e-mc/module": "^0.10.9",
25
- "@e-mc/types": "^0.10.9",
23
+ "@e-mc/cloud": "^0.10.21",
24
+ "@e-mc/module": "^0.10.21",
25
+ "@e-mc/types": "^0.10.21",
26
26
  "@google-cloud/firestore": "^7.10.0",
27
27
  "@google-cloud/storage": "^7.13.0"
28
28
  }