lean-s3 0.1.6 → 0.2.1

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/src/KeyCache.js DELETED
@@ -1,36 +0,0 @@
1
- import * as sign from "./sign.js";
2
-
3
- /**@typedef {import("./AmzDate.js").AmzDate} AmzDate */
4
-
5
- export default class KeyCache {
6
- /** @type {number} */
7
- #lastNumericDay = -1;
8
- /** @type {Map<string, Buffer>} */
9
- #keys = new Map();
10
-
11
- /**
12
- * @param {AmzDate} date
13
- * @param {string} region
14
- * @param {string} accessKeyId
15
- * @param {string} secretAccessKey
16
- * @returns {Buffer}
17
- */
18
- computeIfAbsent(date, region, accessKeyId, secretAccessKey) {
19
- if (date.numericDayStart !== this.#lastNumericDay) {
20
- this.#keys.clear();
21
- this.#lastNumericDay = date.numericDayStart;
22
- // TODO: Add mechanism to clear the cache after some time
23
- }
24
-
25
- // using accessKeyId to prevent keeping the secretAccessKey somewhere
26
- const cacheKey = `${date.date}:${region}:${accessKeyId}`;
27
- const key = this.#keys.get(cacheKey);
28
- if (key) {
29
- return key;
30
- }
31
-
32
- const newKey = sign.deriveSigningKey(date.date, region, secretAccessKey);
33
- this.#keys.set(cacheKey, newKey);
34
- return newKey;
35
- }
36
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * @typedef {import("./index.js").StorageClass} StorageClass
3
- * @typedef {import("./index.js").ChecksumAlgorithm} ChecksumAlgorithm
4
- * @typedef {import("./index.js").ChecksumType} ChecksumType
5
- */
6
-
7
- /**
8
- * @internal Normally, we'd use an interface for that, but having a class with pre-defined fields makes it easier for V8 top optimize hidden classes.
9
- */
10
- export default class S3BucketEntry {
11
- /**
12
- * @readonly
13
- * @type {string}
14
- */
15
- key;
16
- /**
17
- * @readonly
18
- * @type {number}
19
- */
20
- size;
21
- /**
22
- * @readonly
23
- * @type {Date}
24
- */
25
- lastModified;
26
- /**
27
- * @readonly
28
- * @type {string}
29
- */
30
- etag;
31
- /**
32
- * @readonly
33
- * @type {StorageClass}
34
- */
35
- storageClass;
36
- /**
37
- * @readonly
38
- * @type {ChecksumAlgorithm | undefined}
39
- */
40
- checksumAlgorithm;
41
- /**
42
- * @readonly
43
- * @type {ChecksumType | undefined}
44
- */
45
- checksumType;
46
-
47
- /**
48
- * @param {string} key
49
- * @param {number} size
50
- * @param {Date} lastModified
51
- * @param {string} etag
52
- * @param {StorageClass} storageClass
53
- * @param {ChecksumAlgorithm | undefined} checksumAlgorithm
54
- * @param {ChecksumType | undefined} checksumType
55
- */
56
- constructor(
57
- key,
58
- size,
59
- lastModified,
60
- etag,
61
- storageClass,
62
- checksumAlgorithm,
63
- checksumType,
64
- ) {
65
- this.key = key;
66
- this.size = size;
67
- this.lastModified = lastModified;
68
- this.etag = etag;
69
- this.storageClass = storageClass;
70
- this.checksumAlgorithm = checksumAlgorithm;
71
- this.checksumType = checksumType;
72
- }
73
-
74
- /**
75
- * @internal
76
- * @param {any} source
77
- * @returns {S3BucketEntry}
78
- */
79
- static parse(source) {
80
- // TODO: check values and throw exceptions
81
- return new S3BucketEntry(
82
- source.Key,
83
- source.Size,
84
- new Date(source.LastModified),
85
- source.ETag,
86
- source.StorageClass,
87
- source.ChecksumAlgorithm,
88
- source.ChecksumType,
89
- );
90
- }
91
- }