@pi-r/gcp 0.9.3 → 0.9.5

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
@@ -125,6 +125,10 @@ const asFieldPath = (params) => Array.isArray(params) && params.every(item => ty
125
125
  const getFirebasePackageName = (credential) => credential.apiKey && credential.authDomain ? 'firebase' : 'firebase-admin';
126
126
  const isErrorConflict = (err) => (err instanceof Error) && err.code === 409;
127
127
  const hasGoogleAuth = (credential) => (0, types_1.isString)(credential.keyFilename || credential.keyFile || process.env.GOOGLE_APPLICATION_CREDENTIALS) || (0, types_1.isObject)(credential.credentials) || !!credential.authClient;
128
+ const isSpanner = (data) => data.product === "spanner" || !data.product && !!(data.name && data.database && (data.query || data.table));
129
+ const isBigtable = (data) => data.product === "bigtable" || !data.product && !!(data.name && data.table && !data.database);
130
+ 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));
131
+ const isDatastore = (data) => data.product === "datastore" || !data.product && !!(data.keys || data.kind || data.query && !data.table && !data.id);
128
132
  function isFirebaseApp(credential, store, admin) {
129
133
  return !!(credential.apiKey && credential.authDomain && (store || credential.databaseURL) || credential.product === "firebase" && process.env.GOOGLE_APPLICATION_CREDENTIALS) && (!admin || !credential.admin);
130
134
  }
@@ -161,20 +165,19 @@ function createDatabaseClient(credential, data) {
161
165
  }
162
166
  getProjectId(credential, true);
163
167
  if (data) {
164
- const { product, name, table, query, database } = data;
165
- if (product === "spanner" || !product && name && database && (query || table)) {
168
+ if (isSpanner(data)) {
166
169
  const { Spanner } = require(packageName = '@google-cloud/spanner');
167
170
  return new Spanner(credential);
168
171
  }
169
- if (product === "bigquery" || !product && (!name && table && database || (0, types_1.isString)(query))) {
170
- const { BigQuery } = require(packageName = '@google-cloud/bigquery');
171
- return new BigQuery(credential);
172
- }
173
- if (product === "bigtable" || !product && name && table && !database) {
172
+ if (isBigtable(data)) {
174
173
  const { Bigtable } = require(packageName = '@google-cloud/bigtable');
175
174
  return new Bigtable(credential);
176
175
  }
177
- if (product === "datastore" || !product && (data.keys || data.kind || query && !table && !data.id)) {
176
+ if (isBigQuery(data)) {
177
+ const { BigQuery } = require(packageName = '@google-cloud/bigquery');
178
+ return new BigQuery(credential);
179
+ }
180
+ if (isDatastore(data)) {
178
181
  const { Datastore } = require(packageName = '@google-cloud/datastore');
179
182
  return new Datastore(credential);
180
183
  }
@@ -514,7 +517,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
514
517
  rows = [group && (0, types_1.isObject)(val) && (0, types_1.isObject)(val[group[0]]) ? val[group[0]] : val];
515
518
  }
516
519
  }
517
- else if (product === "spanner" || !product && name && database && (query || table)) {
520
+ else if (isSpanner(item)) {
518
521
  const columns = (0, types_1.isPlainObject)(query) && query.columns || item.columns;
519
522
  if (!(query || table && columns)) {
520
523
  closeClient();
@@ -577,7 +580,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
577
580
  [rows] = await db.run(request);
578
581
  }
579
582
  }
580
- else if (product === "bigtable" || !product && name && table && !database) {
583
+ else if (isBigtable(item)) {
581
584
  if (!name || !table) {
582
585
  closeClient();
583
586
  throw (0, util_1.formatError)(item, !name ? "Missing database name" : "Missing database table");
@@ -623,7 +626,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
623
626
  });
624
627
  }
625
628
  }
626
- else if (product === "bigquery" || !product && (!name && database && table || (0, types_1.isString)(query) || (0, types_1.isString)(item.options?.query))) {
629
+ else if (isBigQuery(item)) {
627
630
  const { params, options = {} } = item;
628
631
  if ((0, types_1.isString)(query)) {
629
632
  options.query = query;
@@ -665,7 +668,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
665
668
  [rows] = await instance.query(options);
666
669
  }
667
670
  }
668
- else if (product === "datastore" || !product && (item.keys || item.kind || query && !table && !id)) {
671
+ else if (isDatastore(item)) {
669
672
  const { keys, kind, options } = item;
670
673
  if (!keys && !kind && !Array.isArray(query)) {
671
674
  closeClient();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/gcp",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "Google (GCP) cloud functions for E-mc.",
5
5
  "main": "client/index.js",
6
6
  "publishConfig": {
@@ -19,9 +19,9 @@
19
19
  "license": "MIT",
20
20
  "homepage": "https://github.com/anpham6/pi-r#readme",
21
21
  "dependencies": {
22
- "@e-mc/cloud": "^0.11.4",
23
- "@e-mc/module": "^0.11.4",
24
- "@e-mc/types": "^0.11.4",
22
+ "@e-mc/cloud": "^0.11.17",
23
+ "@e-mc/module": "^0.11.17",
24
+ "@e-mc/types": "^0.11.17",
25
25
  "@google-cloud/firestore": "^7.11.0",
26
26
  "@google-cloud/storage": "^7.15.2"
27
27
  }