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