@aws-sdk/endpoint-cache 3.873.0 → 3.953.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-cjs/index.js +50 -131
- package/package.json +3 -2
package/dist-cjs/index.js
CHANGED
|
@@ -1,140 +1,59 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
30
2
|
|
|
31
|
-
|
|
32
|
-
var index_exports = {};
|
|
33
|
-
__export(index_exports, {
|
|
34
|
-
EndpointCache: () => EndpointCache
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var LRUCache = require('mnemonist/lru-cache');
|
|
37
4
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
__name(this, "EndpointCache");
|
|
43
|
-
}
|
|
44
|
-
cache;
|
|
45
|
-
constructor(capacity) {
|
|
46
|
-
this.cache = new import_lru_cache.default(capacity);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Returns an un-expired endpoint for the given key.
|
|
50
|
-
*
|
|
51
|
-
* @param endpointsWithExpiry
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
getEndpoint(key) {
|
|
55
|
-
const endpointsWithExpiry = this.get(key);
|
|
56
|
-
if (!endpointsWithExpiry || endpointsWithExpiry.length === 0) {
|
|
57
|
-
return void 0;
|
|
5
|
+
class EndpointCache {
|
|
6
|
+
cache;
|
|
7
|
+
constructor(capacity) {
|
|
8
|
+
this.cache = new LRUCache(capacity);
|
|
58
9
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @returns
|
|
67
|
-
*/
|
|
68
|
-
get(key) {
|
|
69
|
-
if (!this.has(key)) {
|
|
70
|
-
return;
|
|
10
|
+
getEndpoint(key) {
|
|
11
|
+
const endpointsWithExpiry = this.get(key);
|
|
12
|
+
if (!endpointsWithExpiry || endpointsWithExpiry.length === 0) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const endpoints = endpointsWithExpiry.map((endpoint) => endpoint.Address);
|
|
16
|
+
return endpoints[Math.floor(Math.random() * endpoints.length)];
|
|
71
17
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
18
|
+
get(key) {
|
|
19
|
+
if (!this.has(key)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const value = this.cache.get(key);
|
|
23
|
+
if (!value) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
const endpointsWithExpiry = value.filter((endpoint) => now < endpoint.Expires);
|
|
28
|
+
if (endpointsWithExpiry.length === 0) {
|
|
29
|
+
this.delete(key);
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return endpointsWithExpiry;
|
|
75
33
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
34
|
+
set(key, endpoints) {
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
this.cache.set(key, endpoints.map(({ Address, CachePeriodInMinutes }) => ({
|
|
37
|
+
Address,
|
|
38
|
+
Expires: now + CachePeriodInMinutes * 60 * 1000,
|
|
39
|
+
})));
|
|
81
40
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Stores the endpoints passed for the key in cache.
|
|
86
|
-
* If not defined, uses empty string for the Address in endpoint.
|
|
87
|
-
* If not defined, uses one minute for CachePeriodInMinutes in endpoint.
|
|
88
|
-
* Stores milliseconds elapsed since the UNIX epoch in Expires param based
|
|
89
|
-
* on value provided in CachePeriodInMinutes.
|
|
90
|
-
*
|
|
91
|
-
* @param key
|
|
92
|
-
* @param endpoints
|
|
93
|
-
*/
|
|
94
|
-
set(key, endpoints) {
|
|
95
|
-
const now = Date.now();
|
|
96
|
-
this.cache.set(
|
|
97
|
-
key,
|
|
98
|
-
endpoints.map(({ Address, CachePeriodInMinutes }) => ({
|
|
99
|
-
Address,
|
|
100
|
-
Expires: now + CachePeriodInMinutes * 60 * 1e3
|
|
101
|
-
}))
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Deletes the value for the given key in the cache.
|
|
106
|
-
*
|
|
107
|
-
* @param {string} key
|
|
108
|
-
*/
|
|
109
|
-
delete(key) {
|
|
110
|
-
this.cache.set(key, []);
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Checks whether the key exists in cache.
|
|
114
|
-
*
|
|
115
|
-
* @param {string} key
|
|
116
|
-
* @returns {boolean}
|
|
117
|
-
*/
|
|
118
|
-
has(key) {
|
|
119
|
-
if (!this.cache.has(key)) {
|
|
120
|
-
return false;
|
|
41
|
+
delete(key) {
|
|
42
|
+
this.cache.set(key, []);
|
|
121
43
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
44
|
+
has(key) {
|
|
45
|
+
if (!this.cache.has(key)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
const endpoints = this.cache.peek(key);
|
|
49
|
+
if (!endpoints) {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return endpoints.length > 0;
|
|
125
53
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
*/
|
|
131
|
-
clear() {
|
|
132
|
-
this.cache.clear();
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
-
|
|
137
|
-
0 && (module.exports = {
|
|
138
|
-
EndpointCache
|
|
139
|
-
});
|
|
54
|
+
clear() {
|
|
55
|
+
this.cache.clear();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
140
58
|
|
|
59
|
+
exports.EndpointCache = EndpointCache;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/endpoint-cache",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.953.0",
|
|
4
4
|
"scripts": {
|
|
5
|
-
"build": "concurrently 'yarn:build:
|
|
5
|
+
"build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline endpoint-cache",
|
|
7
7
|
"build:es": "tsc -p tsconfig.es.json",
|
|
8
8
|
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"test": "yarn g:vitest run",
|
|
13
13
|
"test:watch": "yarn g:vitest watch"
|
|
14
14
|
},
|
|
15
|
+
"sideEffects": false,
|
|
15
16
|
"author": {
|
|
16
17
|
"name": "AWS SDK for JavaScript Team",
|
|
17
18
|
"url": "https://aws.amazon.com/javascript/"
|