@pi-r/gcp 0.7.4 → 0.7.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.
- package/LICENSE +6 -6
- package/client/index.js +15 -12
- package/package.json +4 -4
package/LICENSE
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
Copyright 2024 An Pham
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
1
|
+
Copyright 2024 An Pham
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
7
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/client/index.js
CHANGED
|
@@ -106,6 +106,10 @@ const asFieldPath = (params) => Array.isArray(params) && params.every(item => ty
|
|
|
106
106
|
const getFirebasePackageName = (credential) => credential.apiKey && credential.authDomain ? 'firebase' : 'firebase-admin';
|
|
107
107
|
const isErrorConflict = (err) => (err instanceof Error) && err.code === 409;
|
|
108
108
|
const hasGoogleAuth = (credential) => (0, types_1.isString)(credential.keyFilename || credential.keyFile || process.env.GOOGLE_APPLICATION_CREDENTIALS) || (0, types_1.isObject)(credential.credentials) || !!credential.authClient;
|
|
109
|
+
const isSpanner = (data) => data.product === "spanner" || !data.product && !!(data.name && data.database && (data.query || data.table));
|
|
110
|
+
const isBigtable = (data) => data.product === "bigtable" || !data.product && !!(data.name && data.table && !data.database);
|
|
111
|
+
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));
|
|
112
|
+
const isDatastore = (data) => data.product === "datastore" || !data.product && !!(data.keys || data.kind || data.query && !data.table && !data.id);
|
|
109
113
|
function isFirebaseApp(credential, store, admin) {
|
|
110
114
|
return !!(credential.apiKey && credential.authDomain && (store || credential.databaseURL) || credential.product === "firebase" && process.env.GOOGLE_APPLICATION_CREDENTIALS) && (!admin || !credential.admin);
|
|
111
115
|
}
|
|
@@ -146,20 +150,19 @@ function createDatabaseClient(credential, data) {
|
|
|
146
150
|
}
|
|
147
151
|
getProjectId(credential, true);
|
|
148
152
|
if (data) {
|
|
149
|
-
|
|
150
|
-
if (product === "spanner" || !product && name && database && (query || table)) {
|
|
153
|
+
if (isSpanner(data)) {
|
|
151
154
|
const { Spanner } = require(packageName = '@google-cloud/spanner');
|
|
152
155
|
return new Spanner(credential);
|
|
153
156
|
}
|
|
154
|
-
if (
|
|
155
|
-
const { BigQuery } = require(packageName = '@google-cloud/bigquery');
|
|
156
|
-
return new BigQuery(credential);
|
|
157
|
-
}
|
|
158
|
-
if (product === "bigtable" || !product && name && table && !database) {
|
|
157
|
+
if (isBigtable(data)) {
|
|
159
158
|
const { Bigtable } = require(packageName = '@google-cloud/bigtable');
|
|
160
159
|
return new Bigtable(credential);
|
|
161
160
|
}
|
|
162
|
-
if (
|
|
161
|
+
if (isBigQuery(data)) {
|
|
162
|
+
const { BigQuery } = require(packageName = '@google-cloud/bigquery');
|
|
163
|
+
return new BigQuery(credential);
|
|
164
|
+
}
|
|
165
|
+
if (isDatastore(data)) {
|
|
163
166
|
const { Datastore } = require(packageName = '@google-cloud/datastore');
|
|
164
167
|
return new Datastore(credential);
|
|
165
168
|
}
|
|
@@ -502,7 +505,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
502
505
|
rows = [group && (0, types_1.isObject)(val) && (0, types_1.isObject)(val[group[0]]) ? val[group[0]] : val];
|
|
503
506
|
}
|
|
504
507
|
}
|
|
505
|
-
else if (
|
|
508
|
+
else if (isSpanner(item)) {
|
|
506
509
|
const columns = (0, types_1.isPlainObject)(query) && query.columns || item.columns;
|
|
507
510
|
if (!(query || table && columns)) {
|
|
508
511
|
closeClient();
|
|
@@ -563,7 +566,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
563
566
|
[rows] = await db.run(request);
|
|
564
567
|
}
|
|
565
568
|
}
|
|
566
|
-
else if (
|
|
569
|
+
else if (isBigtable(item)) {
|
|
567
570
|
if (!name || !table) {
|
|
568
571
|
closeClient();
|
|
569
572
|
throw (0, util_1.formatError)(item, !name ? "Missing database name" : "Missing database table");
|
|
@@ -607,7 +610,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
607
610
|
});
|
|
608
611
|
}
|
|
609
612
|
}
|
|
610
|
-
else if (
|
|
613
|
+
else if (isBigQuery(item)) {
|
|
611
614
|
const { params, options = {} } = item;
|
|
612
615
|
if ((0, types_1.isString)(query)) {
|
|
613
616
|
options.query = query;
|
|
@@ -646,7 +649,7 @@ async function executeBatchQuery(credential, batch, sessionKey) {
|
|
|
646
649
|
}
|
|
647
650
|
[rows] = await job.getQueryResults();
|
|
648
651
|
}
|
|
649
|
-
else if (
|
|
652
|
+
else if (isDatastore(item)) {
|
|
650
653
|
const { keys, kind, options } = item;
|
|
651
654
|
if (!keys && !kind && !Array.isArray(query)) {
|
|
652
655
|
closeClient();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.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.9.
|
|
24
|
-
"@e-mc/module": "^0.9.
|
|
25
|
-
"@e-mc/types": "^0.9.
|
|
23
|
+
"@e-mc/cloud": "^0.9.28",
|
|
24
|
+
"@e-mc/module": "^0.9.28",
|
|
25
|
+
"@e-mc/types": "^0.9.28",
|
|
26
26
|
"@google-cloud/firestore": "^7.10.0",
|
|
27
27
|
"@google-cloud/storage": "^7.13.0"
|
|
28
28
|
}
|