@pi-r/gcp 0.8.3 → 0.9.1
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 +7 -7
- package/README.md +1 -1
- package/client/index.js +18 -8
- package/download/index.js +4 -4
- package/package.json +7 -8
- package/types/index.d.ts +3 -3
- package/upload/index.js +10 -16
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
|
-
|
|
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.
|
|
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
|
+
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/README.md
CHANGED
package/client/index.js
CHANGED
|
@@ -12,18 +12,19 @@ exports.setBucketTagging = setBucketTagging;
|
|
|
12
12
|
exports.setBucketWebsite = setBucketWebsite;
|
|
13
13
|
exports.deleteObjects = deleteObjects;
|
|
14
14
|
exports.deleteObjectsV2 = deleteObjectsV2;
|
|
15
|
+
exports.deleteObjectsV3 = deleteObjectsV3;
|
|
15
16
|
exports.executeQuery = executeQuery;
|
|
16
17
|
exports.executeBatchQuery = executeBatchQuery;
|
|
17
18
|
exports.setPublicRead = setPublicRead;
|
|
18
19
|
exports.setPredefinedAcl = setPredefinedAcl;
|
|
19
20
|
exports.createBucketRequest = createBucketRequest;
|
|
20
21
|
exports.getProjectId = getProjectId;
|
|
21
|
-
const path = require("path");
|
|
22
|
+
const path = require("node:path");
|
|
22
23
|
const firestore_1 = require("@google-cloud/firestore");
|
|
23
24
|
const storage_1 = require("@google-cloud/storage");
|
|
24
25
|
const Cloud = require("@e-mc/cloud");
|
|
25
|
-
const util_1 = require("@e-mc/cloud/util");
|
|
26
26
|
const types_1 = require("@e-mc/types");
|
|
27
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
27
28
|
const FIREBASE_DB = {};
|
|
28
29
|
const FIREBASE_STORAGE = {};
|
|
29
30
|
const ADMIN_DB = {};
|
|
@@ -316,10 +317,19 @@ async function setBucketWebsite(credential, bucket, options, service = 'gcp') {
|
|
|
316
317
|
return false;
|
|
317
318
|
});
|
|
318
319
|
}
|
|
319
|
-
async function deleteObjects(credential,
|
|
320
|
-
return deleteObjectsV2.call(this, credential,
|
|
320
|
+
async function deleteObjects(credential, bucket, service, sdk, recursive = true) {
|
|
321
|
+
return deleteObjectsV2.call(this, credential, bucket, recursive, service);
|
|
321
322
|
}
|
|
322
|
-
async function deleteObjectsV2(credential, bucket, recursive = true, service
|
|
323
|
+
async function deleteObjectsV2(credential, bucket, recursive = true, service) {
|
|
324
|
+
return deleteObjectsV3.call(this, credential, bucket, { recursive }, service);
|
|
325
|
+
}
|
|
326
|
+
async function deleteObjectsV3(credential, bucket, options = {}, service = 'gcp') {
|
|
327
|
+
options = { ...options };
|
|
328
|
+
let recursive = true;
|
|
329
|
+
if ('recursive' in options) {
|
|
330
|
+
recursive = options.recursive;
|
|
331
|
+
delete options.recursive;
|
|
332
|
+
}
|
|
323
333
|
const instance = createStorageClient.call(this, credential, bucket);
|
|
324
334
|
const errors = [];
|
|
325
335
|
let promise;
|
|
@@ -350,13 +360,13 @@ async function deleteObjectsV2(credential, bucket, recursive = true, service = '
|
|
|
350
360
|
const client = instance.bucket(bucket);
|
|
351
361
|
if (await hasBucket(client)) {
|
|
352
362
|
if (recursive) {
|
|
353
|
-
return client.deleteFiles({ force: true }).then(() => {
|
|
363
|
+
return client.deleteFiles({ ...options, force: true }).then(() => {
|
|
354
364
|
this.formatMessage(64, service, "Bucket emptied" + ' (recursive)', bucket, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
355
365
|
});
|
|
356
366
|
}
|
|
357
367
|
const tasks = [];
|
|
358
368
|
try {
|
|
359
|
-
const result = await client.getFiles();
|
|
369
|
+
const result = await client.getFiles(options);
|
|
360
370
|
for (const { name } of result[0]) {
|
|
361
371
|
if (!name.includes('/')) {
|
|
362
372
|
tasks.push(client.file(name).delete({ ignoreNotFound: true }).catch((err) => {
|
|
@@ -922,7 +932,7 @@ function setPublicRead(acl, pathname, requested, service = 'gcp') {
|
|
|
922
932
|
});
|
|
923
933
|
}
|
|
924
934
|
async function setPredefinedAcl(target, value, bucket, pathname = '', metadata = {}, requested = true, service = 'gcp') {
|
|
925
|
-
let revoke;
|
|
935
|
+
let revoke = false;
|
|
926
936
|
if (metadata === true) {
|
|
927
937
|
revoke = true;
|
|
928
938
|
metadata = {};
|
package/download/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const https = require("https");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const https = require("node:https");
|
|
5
5
|
const storage_1 = require("@google-cloud/storage");
|
|
6
|
-
const types_1 = require("@e-mc/types");
|
|
7
6
|
const Cloud = require("@e-mc/cloud");
|
|
7
|
+
const types_1 = require("@e-mc/types");
|
|
8
8
|
const client_1 = require("@pi-r/gcp");
|
|
9
9
|
function download(credential, service = 'gcp') {
|
|
10
10
|
const storage = client_1.createStorageClient.call(this, credential);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/gcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Google (GCP) cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -13,17 +13,16 @@
|
|
|
13
13
|
},
|
|
14
14
|
"keywords": [
|
|
15
15
|
"squared",
|
|
16
|
-
"e-mc"
|
|
17
|
-
"squared-functions"
|
|
16
|
+
"e-mc"
|
|
18
17
|
],
|
|
19
18
|
"author": "An Pham <anpham6@gmail.com>",
|
|
20
19
|
"license": "MIT",
|
|
21
20
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
21
|
"dependencies": {
|
|
23
|
-
"@e-mc/cloud": "^0.
|
|
24
|
-
"@e-mc/module": "^0.
|
|
25
|
-
"@e-mc/types": "^0.
|
|
26
|
-
"@google-cloud/firestore": "^7.
|
|
27
|
-
"@google-cloud/storage": "^7.
|
|
22
|
+
"@e-mc/cloud": "^0.11.2",
|
|
23
|
+
"@e-mc/module": "^0.11.2",
|
|
24
|
+
"@e-mc/types": "^0.11.2",
|
|
25
|
+
"@google-cloud/firestore": "^7.11.0",
|
|
26
|
+
"@google-cloud/storage": "^7.15.0"
|
|
28
27
|
}
|
|
29
28
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -17,11 +17,11 @@ export interface GCPDatabaseQuery<T = PlainObject> extends Omit<CloudDatabase<un
|
|
|
17
17
|
service: "gcp" | "gcloud";
|
|
18
18
|
product?: "firestore" | "firebase" | "bigquery" | "bigtable" | "datastore" | "spanner";
|
|
19
19
|
database?: string;
|
|
20
|
-
id?:
|
|
20
|
+
id?: string | string[];
|
|
21
21
|
updateType?: 0 | 1 | 2 | 3;
|
|
22
22
|
columns?: string[];
|
|
23
|
-
keys?:
|
|
24
|
-
kind?:
|
|
23
|
+
keys?: DatastoreKey | DatastoreKey[];
|
|
24
|
+
kind?: string | string[];
|
|
25
25
|
orderBy?: unknown[][];
|
|
26
26
|
}
|
|
27
27
|
|
package/upload/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const stream = require("stream");
|
|
2
|
+
const path = require("node:path");
|
|
3
|
+
const fs = require("node:fs");
|
|
4
|
+
const stream = require("node:stream");
|
|
5
5
|
const Cloud = require("@e-mc/cloud");
|
|
6
|
-
const util_1 = require("@e-mc/cloud/util");
|
|
7
6
|
const types_1 = require("@e-mc/types");
|
|
7
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
8
8
|
const client_1 = require("@pi-r/gcp");
|
|
9
9
|
const BUCKET_SESSION = new Set();
|
|
10
10
|
const BUCKET_RESPONSE = {};
|
|
@@ -65,9 +65,7 @@ function upload(credential, service = 'gcp') {
|
|
|
65
65
|
.then(([response]) => {
|
|
66
66
|
commandMessage('Retention Policy', response.retentionPolicy?.effectiveTime);
|
|
67
67
|
})
|
|
68
|
-
.catch(
|
|
69
|
-
addLog(err);
|
|
70
|
-
});
|
|
68
|
+
.catch(addLog);
|
|
71
69
|
}
|
|
72
70
|
if ((0, types_1.isObject)(cors)) {
|
|
73
71
|
bucketClient.setCorsConfiguration(Array.isArray(cors) ? cors : [cors])
|
|
@@ -75,12 +73,10 @@ function upload(credential, service = 'gcp') {
|
|
|
75
73
|
const length = response.cors?.length;
|
|
76
74
|
commandMessage('CORS', length ? length + ' rules' : null);
|
|
77
75
|
})
|
|
78
|
-
.catch(
|
|
79
|
-
addLog(err);
|
|
80
|
-
});
|
|
76
|
+
.catch(addLog);
|
|
81
77
|
}
|
|
82
78
|
if ((0, types_1.isObject)(lifecycle)) {
|
|
83
|
-
let append;
|
|
79
|
+
let append = false;
|
|
84
80
|
if (Array.isArray(lifecycle)) {
|
|
85
81
|
if (lifecycle.length === 0) {
|
|
86
82
|
append = false;
|
|
@@ -98,9 +94,7 @@ function upload(credential, service = 'gcp') {
|
|
|
98
94
|
const length = response.lifecycle?.rule?.length;
|
|
99
95
|
commandMessage('Lifecycle', length ? length + ' rules' : null);
|
|
100
96
|
})
|
|
101
|
-
.catch(
|
|
102
|
-
addLog(err);
|
|
103
|
-
});
|
|
97
|
+
.catch(addLog);
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
if (flags & 4) {
|
|
@@ -113,7 +107,7 @@ function upload(credential, service = 'gcp') {
|
|
|
113
107
|
if (!overwrite && (!listFiles || listFiles.length)) {
|
|
114
108
|
const current = filename;
|
|
115
109
|
const next = (0, util_1.generateFilename)(filename);
|
|
116
|
-
let i = 0, exists;
|
|
110
|
+
let i = 0, exists = false;
|
|
117
111
|
do {
|
|
118
112
|
if (i > 0) {
|
|
119
113
|
[filename, exists] = next(i);
|
|
@@ -271,7 +265,7 @@ function upload(credential, service = 'gcp') {
|
|
|
271
265
|
else {
|
|
272
266
|
const params = { ...options };
|
|
273
267
|
const readable = publicRead || active && publicRead !== false && publicRead !== 0 && !acl;
|
|
274
|
-
let ACL, revoke, predefined;
|
|
268
|
+
let ACL, revoke = false, predefined = false;
|
|
275
269
|
if (first) {
|
|
276
270
|
params.contentType ||= ContentType[i];
|
|
277
271
|
if (readable) {
|