@factorearth/recordmiddleware-dataaccesslayer 6.4.0 → 6.4.1-s3methods.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/dist/aws-services.d.ts +2 -0
- package/dist/aws-services.js +37 -5
- package/dist/aws-services.js.map +1 -1
- package/package.json +2 -2
package/dist/aws-services.d.ts
CHANGED
|
@@ -15,3 +15,5 @@ export declare function getDocClient(config?: DynamoDBClientConfig): DynamoDBDoc
|
|
|
15
15
|
* @returns The reference to the S3Client object
|
|
16
16
|
*/
|
|
17
17
|
export declare function getS3Client(config?: S3ClientConfig): S3Client;
|
|
18
|
+
export declare function checkS3ObjectExists(bucketName: string, key: string, config?: S3ClientConfig): Promise<boolean>;
|
|
19
|
+
export declare function deleteS3Object(bucketName: string, key: string, config?: S3ClientConfig): Promise<boolean>;
|
package/dist/aws-services.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
2
|
-
import { S3Client } from "@aws-sdk/client-s3";
|
|
2
|
+
import { S3Client, HeadObjectCommand, DeleteObjectCommand } from "@aws-sdk/client-s3";
|
|
3
3
|
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
|
|
4
4
|
let dynamoDbDocClient;
|
|
5
|
-
let
|
|
5
|
+
let s3BucketClient;
|
|
6
6
|
/**
|
|
7
7
|
* Returns a reference to the existing dynamoDBDocClient, creating it if it hasn't been already with the provided config
|
|
8
8
|
* @author Eric Webb <ewebb@factorearth.com>
|
|
@@ -23,9 +23,41 @@ export function getDocClient(config) {
|
|
|
23
23
|
* @returns The reference to the S3Client object
|
|
24
24
|
*/
|
|
25
25
|
export function getS3Client(config) {
|
|
26
|
-
if (!
|
|
27
|
-
|
|
26
|
+
if (!s3BucketClient) {
|
|
27
|
+
s3BucketClient = config ? new S3Client(config) : new S3Client();
|
|
28
|
+
}
|
|
29
|
+
return s3BucketClient;
|
|
30
|
+
}
|
|
31
|
+
export async function checkS3ObjectExists(bucketName, key, config) {
|
|
32
|
+
try {
|
|
33
|
+
const s3Client = getS3Client(config);
|
|
34
|
+
const command = new HeadObjectCommand({
|
|
35
|
+
Bucket: bucketName,
|
|
36
|
+
Key: key,
|
|
37
|
+
});
|
|
38
|
+
await s3Client.send(command);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error.name === "NotFound" || error.$metadata?.httpStatusCode === 404) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export async function deleteS3Object(bucketName, key, config) {
|
|
49
|
+
try {
|
|
50
|
+
const s3Client = getS3Client(config);
|
|
51
|
+
const command = new DeleteObjectCommand({
|
|
52
|
+
Bucket: bucketName,
|
|
53
|
+
Key: key,
|
|
54
|
+
});
|
|
55
|
+
await s3Client.send(command);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.error(`Failed to delete S3 object ${key}:`, error);
|
|
60
|
+
return false;
|
|
28
61
|
}
|
|
29
|
-
return s3Client;
|
|
30
62
|
}
|
|
31
63
|
//# sourceMappingURL=aws-services.js.map
|
package/dist/aws-services.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws-services.js","sourceRoot":"","sources":["../lib/aws-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAkB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"aws-services.js","sourceRoot":"","sources":["../lib/aws-services.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwB,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAkB,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;A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ChB,CAAC;AACL,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,UAAkB,EAAE,GAAW,EAAE,MAAuB;IACzF,IAAI,CAAC;QACD,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;QACrC,MAAM,OAAO,GAAG,IAAI,mBAAmB,CAAC;YACpC,MAAM,EAAE,UAAU;YAClB,GAAG,EAAE,GAAG;SACX,CAAC,CAAC;QAEH,MAAM,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,8BAA8B,GAAG,GAAG,EAAE,KAAK,CAAC,CAAC;QAC3D,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorearth/recordmiddleware-dataaccesslayer",
|
|
3
|
-
"version": "6.4.0",
|
|
3
|
+
"version": "6.4.1-s3methods.0",
|
|
4
4
|
"description": "A module for accessing dynamdb efficiently",
|
|
5
5
|
"author": "madtrx <marlin.makori@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/FactorEarth/RecordMiddleware#readme",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"access": "public",
|
|
34
34
|
"registry": "https://registry.npmjs.org/"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "1763d1dcad86ebd1c534f5176810cfb817629c9d"
|
|
37
37
|
}
|