ts-ag 1.0.24 → 1.0.26
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/s3/object.d.ts +10 -0
- package/dist/s3/object.d.ts.map +1 -1
- package/dist/s3/object.js +26 -1
- package/package.json +6 -6
- package/src/s3/object.ts +28 -1
package/dist/s3/object.d.ts
CHANGED
|
@@ -14,4 +14,14 @@ export declare const getObject: (bucketName: string, key: string) => ResultAsync
|
|
|
14
14
|
* Convenience function to get an object from S3 and return it as a string.
|
|
15
15
|
*/
|
|
16
16
|
export declare function getObjectString(bucketName: string, key: string): ResultAsync<string, typeof error_s3_get>;
|
|
17
|
+
/**
|
|
18
|
+
* Checks if an object exists in an s3 bucket by retrieving the HEAD data
|
|
19
|
+
*
|
|
20
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
21
|
+
* @param {string} key - The key of the object to retrieve.
|
|
22
|
+
* @returns {Promise<Buffer>} A promise that resolves to a boolean.
|
|
23
|
+
*/
|
|
24
|
+
export declare const objectExists: (bucketName: string, key: string) => ResultAsync<boolean, {
|
|
25
|
+
type: "s3_get";
|
|
26
|
+
}>;
|
|
17
27
|
//# sourceMappingURL=object.d.ts.map
|
package/dist/s3/object.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/s3/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;;EAiBrB,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,YAAY,CAAC,CAEzG"}
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../src/s3/object.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;;EAiBrB,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,WAAW,CAAC,MAAM,EAAE,OAAO,YAAY,CAAC,CAEzG;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY;;EAkBxB,CAAC"}
|
package/dist/s3/object.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetObjectCommand } from '@aws-sdk/client-s3';
|
|
1
|
+
import { HeadObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
2
2
|
import { ResultAsync } from 'neverthrow';
|
|
3
3
|
import { getS3 } from './client.js';
|
|
4
4
|
import { error_s3_get } from './errors.js';
|
|
@@ -30,3 +30,28 @@ export const getObject = ResultAsync.fromThrowable(async (bucketName, key) => {
|
|
|
30
30
|
export function getObjectString(bucketName, key) {
|
|
31
31
|
return getObject(bucketName, key).map((buffer) => buffer.toString('utf-8'));
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if an object exists in an s3 bucket by retrieving the HEAD data
|
|
35
|
+
*
|
|
36
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
37
|
+
* @param {string} key - The key of the object to retrieve.
|
|
38
|
+
* @returns {Promise<Buffer>} A promise that resolves to a boolean.
|
|
39
|
+
*/
|
|
40
|
+
export const objectExists = ResultAsync.fromThrowable(async (bucketName, key) => {
|
|
41
|
+
const s3 = getS3();
|
|
42
|
+
try {
|
|
43
|
+
const cmd = new HeadObjectCommand({ Bucket: bucketName, Key: key });
|
|
44
|
+
const res = await s3.send(cmd);
|
|
45
|
+
return res.$metadata.httpStatusCode === 200;
|
|
46
|
+
}
|
|
47
|
+
catch (e) {
|
|
48
|
+
if (e.$metadata.httpStatusCode === 404) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
throw e;
|
|
53
|
+
}
|
|
54
|
+
}, (e) => {
|
|
55
|
+
console.error(`Error getting object head from S3: ${e}`);
|
|
56
|
+
return error_s3_get;
|
|
57
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ag",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.26",
|
|
4
4
|
"description": "Useful TS stuff",
|
|
5
5
|
"bugs": "https://github.com/ageorgeh/ts-ag/issues",
|
|
6
6
|
"author": "Alexander Hornung",
|
|
@@ -42,9 +42,9 @@
|
|
|
42
42
|
"tsc:watch": "concurrently \" npx tsc -w \" \" npx ts-alias -w \""
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@aws-sdk/client-cognito-identity-provider": "3.
|
|
46
|
-
"@aws-sdk/client-s3": "3.
|
|
47
|
-
"@aws-sdk/s3-request-presigner": "3.
|
|
45
|
+
"@aws-sdk/client-cognito-identity-provider": "3.1001.0",
|
|
46
|
+
"@aws-sdk/client-s3": "3.1001.0",
|
|
47
|
+
"@aws-sdk/s3-request-presigner": "3.1001.0",
|
|
48
48
|
"@ungap/structured-clone": "1.3.0",
|
|
49
49
|
"chalk": "5.6.2",
|
|
50
50
|
"chokidar": "5.0.0",
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"@types/hast": "3.0.4",
|
|
72
72
|
"@types/node": "^24.11.0",
|
|
73
73
|
"@types/ungap__structured-clone": "1.2.0",
|
|
74
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
74
|
+
"@typescript/native-preview": "7.0.0-dev.20260303.1",
|
|
75
75
|
"concurrently": "^9.2.1",
|
|
76
76
|
"globals": "^17.4.0",
|
|
77
77
|
"husky": "^9.1.7",
|
|
78
78
|
"jiti": "2.6.1",
|
|
79
|
-
"lint-staged": "^16.3.
|
|
79
|
+
"lint-staged": "^16.3.2",
|
|
80
80
|
"oxlint": "^1.51.0",
|
|
81
81
|
"semantic-release": "^25.0.3",
|
|
82
82
|
"typescript": "^5.9.3",
|
package/src/s3/object.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GetObjectCommand } from '@aws-sdk/client-s3';
|
|
1
|
+
import { HeadObjectCommand, GetObjectCommand } from '@aws-sdk/client-s3';
|
|
2
2
|
import { ResultAsync } from 'neverthrow';
|
|
3
3
|
|
|
4
4
|
import { getS3 } from './client.js';
|
|
@@ -36,3 +36,30 @@ export const getObject = ResultAsync.fromThrowable(
|
|
|
36
36
|
export function getObjectString(bucketName: string, key: string): ResultAsync<string, typeof error_s3_get> {
|
|
37
37
|
return getObject(bucketName, key).map((buffer) => buffer.toString('utf-8'));
|
|
38
38
|
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an object exists in an s3 bucket by retrieving the HEAD data
|
|
42
|
+
*
|
|
43
|
+
* @param {string} bucketName - The name of the S3 bucket.
|
|
44
|
+
* @param {string} key - The key of the object to retrieve.
|
|
45
|
+
* @returns {Promise<Buffer>} A promise that resolves to a boolean.
|
|
46
|
+
*/
|
|
47
|
+
export const objectExists = ResultAsync.fromThrowable(
|
|
48
|
+
async (bucketName: string, key: string) => {
|
|
49
|
+
const s3 = getS3();
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const cmd = new HeadObjectCommand({ Bucket: bucketName, Key: key });
|
|
53
|
+
const res = await s3.send(cmd);
|
|
54
|
+
return res.$metadata.httpStatusCode === 200;
|
|
55
|
+
} catch (e) {
|
|
56
|
+
if ((e as any).$metadata.httpStatusCode === 404) {
|
|
57
|
+
return false;
|
|
58
|
+
} else throw e;
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
(e) => {
|
|
62
|
+
console.error(`Error getting object head from S3: ${e}`);
|
|
63
|
+
return error_s3_get;
|
|
64
|
+
}
|
|
65
|
+
);
|