@certik/skynet 0.14.0 → 0.15.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.
@@ -0,0 +1,5 @@
1
+ {
2
+ "conventionalCommits.scopes": [
3
+ "lib-skynet"
4
+ ]
5
+ }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.15.0
4
+
5
+ - BREAKING: only start one S3 client globally
6
+ - Fixed: Properly throw error if S3 client encounters them
7
+
3
8
  ## 0.14.0
4
9
 
5
10
  - BREAKING: only start one DynamoDB client globally
package/bun.lockb CHANGED
Binary file
package/examples/api.js CHANGED
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "main": "index.js",
package/s3.js CHANGED
@@ -6,11 +6,17 @@ import {
6
6
  DeleteObjectCommand,
7
7
  ListObjectsV2Command,
8
8
  NotFound,
9
+ NoSuchKey,
9
10
  } from "@aws-sdk/client-s3";
10
11
  import { getAWSSDKConfig } from "./env.js";
11
12
 
12
- function getS3() {
13
- return new S3Client(getAWSSDKConfig());
13
+ let _s3Client;
14
+
15
+ function getS3(forceNew = false) {
16
+ if (!_s3Client || forceNew) {
17
+ _s3Client = new S3Client(getAWSSDKConfig());
18
+ }
19
+ return _s3Client;
14
20
  }
15
21
 
16
22
  async function readFile(bucketName, key, verbose = false) {
@@ -21,12 +27,16 @@ async function readFile(bucketName, key, verbose = false) {
21
27
  try {
22
28
  const result = await s3.send(new GetObjectCommand(params));
23
29
  return result.Body.transformToString();
24
- } catch (noSuchKeyErr) {
25
- if (verbose) {
26
- console.log("no such bucket or key", bucketName, key);
30
+ } catch (error) {
31
+ if (error instanceof NoSuchKey) {
32
+ if (verbose) {
33
+ console.log("no such bucket or key", bucketName, key);
34
+ }
35
+ // do nothing
36
+ return null;
27
37
  }
28
- // do nothing
29
- return null;
38
+
39
+ throw error;
30
40
  }
31
41
  }
32
42
 
@@ -93,10 +103,16 @@ async function deleteFile(bucketName, key, verbose = false) {
93
103
 
94
104
  try {
95
105
  await s3.send(new DeleteObjectCommand(params));
96
- } catch (noSuchKeyErr) {
97
- if (verbose) {
98
- console.log("no such bucket or key", bucketName, key);
106
+ } catch (error) {
107
+ if (error instanceof NoSuchKey) {
108
+ if (verbose) {
109
+ console.log("no such bucket or key", bucketName, key);
110
+ }
111
+ // do nothing
112
+ return null;
99
113
  }
114
+
115
+ throw error;
100
116
  }
101
117
  }
102
118