@pi-r/azure 0.8.3 → 0.9.0
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 +22 -12
- package/download/index.js +3 -5
- package/package.json +8 -9
- package/types/index.d.ts +1 -0
- package/upload/index.js +6 -8
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
|
@@ -9,15 +9,16 @@ exports.createBucketV2 = createBucketV2;
|
|
|
9
9
|
exports.setBucketWebsite = setBucketWebsite;
|
|
10
10
|
exports.deleteObjects = deleteObjects;
|
|
11
11
|
exports.deleteObjectsV2 = deleteObjectsV2;
|
|
12
|
+
exports.deleteObjectsV3 = deleteObjectsV3;
|
|
12
13
|
exports.executeQuery = executeQuery;
|
|
13
14
|
exports.executeBatchQuery = executeBatchQuery;
|
|
14
|
-
const path = require("path");
|
|
15
|
+
const path = require("node:path");
|
|
15
16
|
const storage = require("@azure/storage-blob");
|
|
16
17
|
const cosmos = require("@azure/cosmos");
|
|
17
18
|
const identity = require("@azure/identity");
|
|
18
19
|
const Cloud = require("@e-mc/cloud");
|
|
19
|
-
const util_1 = require("@e-mc/cloud/util");
|
|
20
20
|
const types_1 = require("@e-mc/types");
|
|
21
|
+
const util_1 = require("@e-mc/cloud/util");
|
|
21
22
|
function validateStorage(credential) {
|
|
22
23
|
const env = process.env;
|
|
23
24
|
if (credential.accountName && (credential.accountKey || credential.accountSas) || credential.connectionString || credential.sharedAccessSignature || env.AZURE_TENANT_ID && env.AZURE_CLIENT_ID && env.AZURE_CLIENT_SECRET) {
|
|
@@ -143,25 +144,34 @@ async function setBucketWebsite(credential, bucket, options, service = 'azure')
|
|
|
143
144
|
return false;
|
|
144
145
|
});
|
|
145
146
|
}
|
|
146
|
-
async function deleteObjects(credential,
|
|
147
|
-
return deleteObjectsV2.call(this, credential,
|
|
147
|
+
async function deleteObjects(credential, bucket, service, sdk, recursive = true) {
|
|
148
|
+
return deleteObjectsV2.call(this, credential, bucket, recursive, service);
|
|
149
|
+
}
|
|
150
|
+
async function deleteObjectsV2(credential, bucket, recursive = true, service) {
|
|
151
|
+
return deleteObjectsV3.call(this, credential, bucket, { recursive }, service);
|
|
148
152
|
}
|
|
149
|
-
async function
|
|
153
|
+
async function deleteObjectsV3(credential, bucket, options = {}, service = 'azure') {
|
|
150
154
|
const containerClient = createStorageClient.call(this, credential).getContainerClient(bucket);
|
|
151
155
|
if (await containerClient.exists().catch(() => false)) {
|
|
152
156
|
try {
|
|
157
|
+
options = { ...options };
|
|
158
|
+
let recursive = true;
|
|
159
|
+
if ('recursive' in options) {
|
|
160
|
+
recursive = options.recursive;
|
|
161
|
+
delete options.recursive;
|
|
162
|
+
}
|
|
163
|
+
options.includeUncommitedBlobs ??= true;
|
|
153
164
|
const tasks = [];
|
|
154
165
|
let fileCount = 0;
|
|
155
|
-
for await (const blob of containerClient.listBlobsFlat(
|
|
156
|
-
if (
|
|
157
|
-
|
|
166
|
+
for await (const blob of containerClient.listBlobsFlat(options)) {
|
|
167
|
+
if (recursive || !blob.name.includes('/')) {
|
|
168
|
+
tasks.push(containerClient.deleteBlob(blob.name, { versionId: blob.versionId }).catch(() => {
|
|
169
|
+
--fileCount;
|
|
170
|
+
}));
|
|
158
171
|
}
|
|
159
|
-
tasks.push(containerClient.deleteBlob(blob.name, { versionId: blob.versionId }).catch(() => {
|
|
160
|
-
--fileCount;
|
|
161
|
-
}));
|
|
162
172
|
}
|
|
163
173
|
fileCount = tasks.length;
|
|
164
|
-
|
|
174
|
+
await this.allSettled(tasks, ["Unable to delete blob", bucket], 64).then(() => {
|
|
165
175
|
this.formatMessage(64, service, ['Container emptied' + (recursive ? ' (recursive)' : ''), bucket], fileCount + ' files', { ...Cloud.LOG_CLOUD_COMMAND });
|
|
166
176
|
});
|
|
167
177
|
}
|
package/download/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
const
|
|
3
|
-
const path = require("path");
|
|
2
|
+
const path = require("node:path");
|
|
4
3
|
const Cloud = require("@e-mc/cloud");
|
|
4
|
+
const types_1 = require("@e-mc/types");
|
|
5
5
|
const client_1 = require("@pi-r/azure");
|
|
6
6
|
function download(credential, service = 'azure') {
|
|
7
7
|
const blobServiceClient = client_1.createStorageClient.call(this, credential);
|
|
@@ -46,9 +46,7 @@ function download(credential, service = 'azure') {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
})
|
|
49
|
-
.catch(
|
|
50
|
-
downloadResponse(err);
|
|
51
|
-
});
|
|
49
|
+
.catch(downloadResponse);
|
|
52
50
|
};
|
|
53
51
|
}
|
|
54
52
|
module.exports = download;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/azure",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Azure cloud functions for E-mc.",
|
|
5
5
|
"main": "client/index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -13,18 +13,17 @@
|
|
|
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
|
-
"@azure/cosmos": "^4.
|
|
27
|
-
"@azure/identity": "
|
|
28
|
-
"@azure/storage-blob": "^12.
|
|
22
|
+
"@e-mc/cloud": "^0.11.0",
|
|
23
|
+
"@e-mc/module": "^0.11.0",
|
|
24
|
+
"@e-mc/types": "^0.11.0",
|
|
25
|
+
"@azure/cosmos": "^4.2.0",
|
|
26
|
+
"@azure/identity": "*",
|
|
27
|
+
"@azure/storage-blob": "^12.26.0"
|
|
29
28
|
}
|
|
30
29
|
}
|
package/types/index.d.ts
CHANGED
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/azure");
|
|
9
9
|
const BUCKET_SESSION = new Set();
|
|
10
10
|
const BUCKET_RESPONSE = {};
|
|
@@ -60,15 +60,13 @@ function upload(credential, service = 'azure') {
|
|
|
60
60
|
const { expiresOn, startsOn, permissions } = retentionPolicy[0].accessPolicy;
|
|
61
61
|
this.formatMessage(64, service, ["Bucket configured" + ' (retention policy)', bucket], expiresOn ? expiresOn.toLocaleString() + ' (expires)' : startsOn ? startsOn.toLocaleString() + ' (starts)' : permissions, { ...Cloud.LOG_CLOUD_COMMAND });
|
|
62
62
|
})
|
|
63
|
-
.catch(
|
|
64
|
-
addLog(err);
|
|
65
|
-
});
|
|
63
|
+
.catch(addLog);
|
|
66
64
|
}
|
|
67
65
|
if (!overwrite) {
|
|
68
66
|
try {
|
|
69
67
|
const current = filename;
|
|
70
68
|
const next = (0, util_1.generateFilename)(filename);
|
|
71
|
-
let i = 0, exists;
|
|
69
|
+
let i = 0, exists = false;
|
|
72
70
|
do {
|
|
73
71
|
if (i > 0) {
|
|
74
72
|
[filename, exists] = next(i);
|