@cellaware/utils 8.6.1 → 8.6.2
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/dist/azure/storage.d.ts +11 -1
- package/dist/azure/storage.js +26 -20
- package/package.json +1 -1
package/dist/azure/storage.d.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
export declare function storageContainerCreate(containerClientId: string): Promise<void>;
|
|
2
|
+
/**
|
|
3
|
+
* Stringifies `data` and uploads to blob storage.
|
|
4
|
+
*
|
|
5
|
+
* **Important:** `data` must not be a string.
|
|
6
|
+
*/
|
|
2
7
|
export declare function storageBlobUpload(containerClientId: string, blobId: string, data: any): Promise<void>;
|
|
3
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Parses string data downloaded from blob storage and returns JSON object/JSON array.
|
|
10
|
+
*
|
|
11
|
+
* **Important:** will return `undefined` if any issues or blob does not exist.
|
|
12
|
+
*/
|
|
4
13
|
export declare function storageBlobDownload(containerClientId: string, blobId: string): Promise<any>;
|
|
14
|
+
export declare function storageBlobDelete(containerClientId: string, blobId: string): Promise<void>;
|
package/dist/azure/storage.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { BlobServiceClient } from '@azure/storage-blob';
|
|
2
|
-
import { isArrayLike } from '../util.js';
|
|
3
2
|
function streamToBuffer(stream) {
|
|
4
3
|
return new Promise((resolve, reject) => {
|
|
5
4
|
const chunks = [];
|
|
@@ -22,35 +21,31 @@ export async function storageContainerCreate(containerClientId) {
|
|
|
22
21
|
console.log(`STORAGE: CONTAINER create error: ${err.message}`);
|
|
23
22
|
}
|
|
24
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Stringifies `data` and uploads to blob storage.
|
|
26
|
+
*
|
|
27
|
+
* **Important:** `data` must not be a string.
|
|
28
|
+
*/
|
|
25
29
|
export async function storageBlobUpload(containerClientId, blobId, data) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const containerClient = blobServiceClient.getContainerClient(containerClientId);
|
|
29
|
-
const blockBlobClient = containerClient.getBlockBlobClient(blobId);
|
|
30
|
-
let len = 0;
|
|
31
|
-
if (isArrayLike(data)) {
|
|
32
|
-
len = data.length;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
len = JSON.stringify(data).length;
|
|
36
|
-
}
|
|
37
|
-
await blockBlobClient.upload(data, len);
|
|
30
|
+
if (typeof data === 'string') {
|
|
31
|
+
throw new Error('STORAGE: Input `data` cannot be a string');
|
|
38
32
|
}
|
|
39
|
-
catch (err) {
|
|
40
|
-
console.log(`STORAGE: BLOB upload error: ${err.message}`);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
export async function storageBlobDelete(containerClientId, blobId) {
|
|
44
33
|
try {
|
|
45
34
|
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.STORAGE_CONNECTION_STRING ?? '');
|
|
46
35
|
const containerClient = blobServiceClient.getContainerClient(containerClientId);
|
|
47
36
|
const blockBlobClient = containerClient.getBlockBlobClient(blobId);
|
|
48
|
-
|
|
37
|
+
const str = JSON.stringify(data);
|
|
38
|
+
await blockBlobClient.upload(str, str.length);
|
|
49
39
|
}
|
|
50
40
|
catch (err) {
|
|
51
|
-
console.log(`STORAGE: BLOB
|
|
41
|
+
console.log(`STORAGE: BLOB upload error: ${err.message}`);
|
|
52
42
|
}
|
|
53
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Parses string data downloaded from blob storage and returns JSON object/JSON array.
|
|
46
|
+
*
|
|
47
|
+
* **Important:** will return `undefined` if any issues or blob does not exist.
|
|
48
|
+
*/
|
|
54
49
|
export async function storageBlobDownload(containerClientId, blobId) {
|
|
55
50
|
if (!process.env.STORAGE_CONNECTION_STRING) {
|
|
56
51
|
console.log(`STORAGE: No connection string set`);
|
|
@@ -73,3 +68,14 @@ export async function storageBlobDownload(containerClientId, blobId) {
|
|
|
73
68
|
}
|
|
74
69
|
return undefined;
|
|
75
70
|
}
|
|
71
|
+
export async function storageBlobDelete(containerClientId, blobId) {
|
|
72
|
+
try {
|
|
73
|
+
const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.STORAGE_CONNECTION_STRING ?? '');
|
|
74
|
+
const containerClient = blobServiceClient.getContainerClient(containerClientId);
|
|
75
|
+
const blockBlobClient = containerClient.getBlockBlobClient(blobId);
|
|
76
|
+
await blockBlobClient.delete();
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
console.log(`STORAGE: BLOB delete error: ${err.message}`);
|
|
80
|
+
}
|
|
81
|
+
}
|