@cellaware/utils 8.6.0 → 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.
@@ -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
- export declare function storageBlobDelete(containerClientId: string, blobId: string): Promise<void>;
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>;
@@ -21,28 +21,31 @@ export async function storageContainerCreate(containerClientId) {
21
21
  console.log(`STORAGE: CONTAINER create error: ${err.message}`);
22
22
  }
23
23
  }
24
+ /**
25
+ * Stringifies `data` and uploads to blob storage.
26
+ *
27
+ * **Important:** `data` must not be a string.
28
+ */
24
29
  export async function storageBlobUpload(containerClientId, blobId, data) {
25
- try {
26
- const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.STORAGE_CONNECTION_STRING ?? '');
27
- const containerClient = blobServiceClient.getContainerClient(containerClientId);
28
- const blockBlobClient = containerClient.getBlockBlobClient(blobId);
29
- await blockBlobClient.upload(data, data.length);
30
- }
31
- catch (err) {
32
- console.log(`STORAGE: BLOB upload error: ${err.message}`);
30
+ if (typeof data === 'string') {
31
+ throw new Error('STORAGE: Input `data` cannot be a string');
33
32
  }
34
- }
35
- export async function storageBlobDelete(containerClientId, blobId) {
36
33
  try {
37
34
  const blobServiceClient = BlobServiceClient.fromConnectionString(process.env.STORAGE_CONNECTION_STRING ?? '');
38
35
  const containerClient = blobServiceClient.getContainerClient(containerClientId);
39
36
  const blockBlobClient = containerClient.getBlockBlobClient(blobId);
40
- await blockBlobClient.delete();
37
+ const str = JSON.stringify(data);
38
+ await blockBlobClient.upload(str, str.length);
41
39
  }
42
40
  catch (err) {
43
- console.log(`STORAGE: BLOB delete error: ${err.message}`);
41
+ console.log(`STORAGE: BLOB upload error: ${err.message}`);
44
42
  }
45
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
+ */
46
49
  export async function storageBlobDownload(containerClientId, blobId) {
47
50
  if (!process.env.STORAGE_CONNECTION_STRING) {
48
51
  console.log(`STORAGE: No connection string set`);
@@ -65,3 +68,14 @@ export async function storageBlobDownload(containerClientId, blobId) {
65
68
  }
66
69
  return undefined;
67
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
+ }
package/dist/util.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare function sleep(ms: number): Promise<any>;
6
6
  export declare function reverse(str: string): string;
7
7
  export declare function base64Encode(str: string): string;
8
8
  export declare function base64Decode(str: string): string;
9
+ export declare function isArrayLike(obj: any): boolean;
9
10
  export declare function initDate(timeZone?: string): Date;
10
11
  export declare function convertDateTimeZone(date: Date, timeZone: string): Date;
11
12
  export declare function isDaylightSavingTime(timeZone?: string): boolean;
package/dist/util.js CHANGED
@@ -11,6 +11,12 @@ export function base64Encode(str) {
11
11
  export function base64Decode(str) {
12
12
  return Buffer.from(str, 'base64').toString('utf-8');
13
13
  }
14
+ export function isArrayLike(obj) {
15
+ return (Array.isArray(obj) ||
16
+ (!!obj &&
17
+ obj.hasOwnProperty("length") &&
18
+ typeof obj.length === "number"));
19
+ }
14
20
  // Dates --------------------------------------------------------------------------
15
21
  export function initDate(timeZone) {
16
22
  const date = new Date();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "8.6.0",
3
+ "version": "8.6.2",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",