@icp-sdk/core 5.1.0 → 5.2.0-beta.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/lib/cjs/agent/agent/http/index.d.ts +17 -0
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +43 -20
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +18 -1
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +42 -5
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/index.d.ts +1 -0
- package/lib/cjs/agent/index.d.ts.map +1 -1
- package/lib/cjs/agent/index.js.map +1 -1
- package/lib/cjs/agent/utils/createExpirableStore.d.ts +23 -0
- package/lib/cjs/agent/utils/createExpirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/createExpirableStore.js +18 -0
- package/lib/cjs/agent/utils/createExpirableStore.js.map +1 -0
- package/lib/cjs/agent/utils/expirableStore.d.ts +39 -0
- package/lib/cjs/agent/utils/expirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/expirableStore.js +14 -0
- package/lib/cjs/agent/utils/expirableStore.js.map +1 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.d.ts +14 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.js +46 -0
- package/lib/cjs/agent/utils/inMemoryExpirableStore.js.map +1 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.d.ts +28 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.d.ts.map +1 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.js +139 -0
- package/lib/cjs/agent/utils/indexedDBExpirableStore.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +17 -0
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +44 -21
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +18 -1
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +39 -4
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/index.d.ts +1 -0
- package/lib/esm/agent/index.d.ts.map +1 -1
- package/lib/esm/agent/index.js.map +1 -1
- package/lib/esm/agent/utils/createExpirableStore.d.ts +23 -0
- package/lib/esm/agent/utils/createExpirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/createExpirableStore.js +15 -0
- package/lib/esm/agent/utils/createExpirableStore.js.map +1 -0
- package/lib/esm/agent/utils/expirableStore.d.ts +39 -0
- package/lib/esm/agent/utils/expirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/expirableStore.js +11 -0
- package/lib/esm/agent/utils/expirableStore.js.map +1 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.d.ts +14 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.js +42 -0
- package/lib/esm/agent/utils/inMemoryExpirableStore.js.map +1 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.d.ts +28 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.d.ts.map +1 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.js +135 -0
- package/lib/esm/agent/utils/indexedDBExpirableStore.js.map +1 -0
- package/package.json +2 -1
- package/src/agent/agent/http/index.ts +48 -17
- package/src/agent/errors.ts +45 -4
- package/src/agent/index.ts +1 -0
- package/src/agent/utils/createExpirableStore.ts +31 -0
- package/src/agent/utils/expirableStore.ts +47 -0
- package/src/agent/utils/inMemoryExpirableStore.ts +49 -0
- package/src/agent/utils/indexedDBExpirableStore.ts +191 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts +0 -80
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +0 -1
- package/lib/cjs/agent/utils/expirableMap.js +0 -148
- package/lib/cjs/agent/utils/expirableMap.js.map +0 -1
- package/lib/esm/agent/utils/expirableMap.d.ts +0 -80
- package/lib/esm/agent/utils/expirableMap.d.ts.map +0 -1
- package/lib/esm/agent/utils/expirableMap.js +0 -144
- package/lib/esm/agent/utils/expirableMap.js.map +0 -1
- package/src/agent/utils/expirableMap.ts +0 -163
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
var _a, _b;
|
|
2
|
-
/**
|
|
3
|
-
* A map that expires entries after a given time.
|
|
4
|
-
* Defaults to 10 minutes.
|
|
5
|
-
*/
|
|
6
|
-
export class ExpirableMap {
|
|
7
|
-
static { _a = Symbol.iterator, _b = Symbol.toStringTag; }
|
|
8
|
-
// Internals
|
|
9
|
-
#inner;
|
|
10
|
-
#expirationTime;
|
|
11
|
-
/**
|
|
12
|
-
* Create a new ExpirableMap.
|
|
13
|
-
* @param {ExpirableMapOptions<K, V>} options - options for the map.
|
|
14
|
-
* @param {Iterable<[K, V]>} options.source - an optional source of entries to initialize the map with.
|
|
15
|
-
* @param {number} options.expirationTime - the time in milliseconds after which entries will expire.
|
|
16
|
-
*/
|
|
17
|
-
constructor(options = {}) {
|
|
18
|
-
this[_a] = this.entries.bind(this);
|
|
19
|
-
this[_b] = 'ExpirableMap';
|
|
20
|
-
const { source = [], expirationTime = 10 * 60 * 1000 } = options;
|
|
21
|
-
const currentTime = Date.now();
|
|
22
|
-
this.#inner = new Map([...source].map(([key, value]) => [key, { value, timestamp: currentTime }]));
|
|
23
|
-
this.#expirationTime = expirationTime;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Prune removes all expired entries.
|
|
27
|
-
*/
|
|
28
|
-
prune() {
|
|
29
|
-
const currentTime = Date.now();
|
|
30
|
-
for (const [key, entry] of this.#inner.entries()) {
|
|
31
|
-
if (currentTime - entry.timestamp > this.#expirationTime) {
|
|
32
|
-
this.#inner.delete(key);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return this;
|
|
36
|
-
}
|
|
37
|
-
// Implementing the Map interface
|
|
38
|
-
/**
|
|
39
|
-
* Set the value for the given key. Prunes expired entries.
|
|
40
|
-
* @param key for the entry
|
|
41
|
-
* @param value of the entry
|
|
42
|
-
* @returns this
|
|
43
|
-
*/
|
|
44
|
-
set(key, value) {
|
|
45
|
-
this.prune();
|
|
46
|
-
const entry = {
|
|
47
|
-
value,
|
|
48
|
-
timestamp: Date.now(),
|
|
49
|
-
};
|
|
50
|
-
this.#inner.set(key, entry);
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Get the value associated with the key, if it exists and has not expired.
|
|
55
|
-
* @param key K
|
|
56
|
-
* @returns the value associated with the key, or undefined if the key is not present or has expired.
|
|
57
|
-
*/
|
|
58
|
-
get(key) {
|
|
59
|
-
const entry = this.#inner.get(key);
|
|
60
|
-
if (entry === undefined) {
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
63
|
-
if (Date.now() - entry.timestamp > this.#expirationTime) {
|
|
64
|
-
this.#inner.delete(key);
|
|
65
|
-
return undefined;
|
|
66
|
-
}
|
|
67
|
-
return entry.value;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Clear all entries.
|
|
71
|
-
*/
|
|
72
|
-
clear() {
|
|
73
|
-
this.#inner.clear();
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Entries returns the entries of the map, without the expiration time.
|
|
77
|
-
* @returns an iterator over the entries of the map.
|
|
78
|
-
*/
|
|
79
|
-
entries() {
|
|
80
|
-
const iterator = this.#inner.entries();
|
|
81
|
-
const generator = function* () {
|
|
82
|
-
for (const [key, value] of iterator) {
|
|
83
|
-
yield [key, value.value];
|
|
84
|
-
}
|
|
85
|
-
return undefined;
|
|
86
|
-
};
|
|
87
|
-
return generator();
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Values returns the values of the map, without the expiration time.
|
|
91
|
-
* @returns an iterator over the values of the map.
|
|
92
|
-
*/
|
|
93
|
-
values() {
|
|
94
|
-
const iterator = this.#inner.values();
|
|
95
|
-
const generator = function* () {
|
|
96
|
-
for (const value of iterator) {
|
|
97
|
-
yield value.value;
|
|
98
|
-
}
|
|
99
|
-
return undefined;
|
|
100
|
-
};
|
|
101
|
-
return generator();
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Keys returns the keys of the map
|
|
105
|
-
* @returns an iterator over the keys of the map.
|
|
106
|
-
*/
|
|
107
|
-
keys() {
|
|
108
|
-
return this.#inner.keys();
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* forEach calls the callbackfn on each entry of the map.
|
|
112
|
-
* @param callbackfn to call on each entry
|
|
113
|
-
* @param thisArg to use as this when calling the callbackfn
|
|
114
|
-
*/
|
|
115
|
-
forEach(callbackfn, thisArg) {
|
|
116
|
-
for (const [key, value] of this.#inner.entries()) {
|
|
117
|
-
callbackfn.call(thisArg, value.value, key, this);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* has returns true if the key exists and has not expired.
|
|
122
|
-
* @param key K
|
|
123
|
-
* @returns true if the key exists and has not expired.
|
|
124
|
-
*/
|
|
125
|
-
has(key) {
|
|
126
|
-
return this.#inner.has(key);
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* delete the entry for the given key.
|
|
130
|
-
* @param key K
|
|
131
|
-
* @returns true if the key existed and has been deleted.
|
|
132
|
-
*/
|
|
133
|
-
delete(key) {
|
|
134
|
-
return this.#inner.delete(key);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* get size of the map.
|
|
138
|
-
* @returns the size of the map.
|
|
139
|
-
*/
|
|
140
|
-
get size() {
|
|
141
|
-
return this.#inner.size;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
//# sourceMappingURL=expirableMap.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"expirableMap.js","s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KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;gBAC7B,MAAM,KAAK,CAAC,KAAK,CAAC;YACpB,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC;QACF,OAAO,SAAS,EAAE,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,UAAsD,EAAE,OAA4B;QAC1F,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;YACjD,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACnD,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAM;QACR,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAM;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;CACF"}
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
export interface ExpirableMapOptions<K, V> {
|
|
2
|
-
source?: Iterable<[K, V]>;
|
|
3
|
-
expirationTime?: number;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A map that expires entries after a given time.
|
|
8
|
-
* Defaults to 10 minutes.
|
|
9
|
-
*/
|
|
10
|
-
export class ExpirableMap<K, V> implements Map<K, V> {
|
|
11
|
-
// Internals
|
|
12
|
-
#inner: Map<K, { value: V; timestamp: number }>;
|
|
13
|
-
#expirationTime: number;
|
|
14
|
-
|
|
15
|
-
[Symbol.iterator]: () => MapIterator<[K, V]> = this.entries.bind(this);
|
|
16
|
-
[Symbol.toStringTag] = 'ExpirableMap';
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Create a new ExpirableMap.
|
|
20
|
-
* @param {ExpirableMapOptions<K, V>} options - options for the map.
|
|
21
|
-
* @param {Iterable<[K, V]>} options.source - an optional source of entries to initialize the map with.
|
|
22
|
-
* @param {number} options.expirationTime - the time in milliseconds after which entries will expire.
|
|
23
|
-
*/
|
|
24
|
-
constructor(options: ExpirableMapOptions<K, V> = {}) {
|
|
25
|
-
const { source = [], expirationTime = 10 * 60 * 1000 } = options;
|
|
26
|
-
const currentTime = Date.now();
|
|
27
|
-
this.#inner = new Map(
|
|
28
|
-
[...source].map(([key, value]) => [key, { value, timestamp: currentTime }]),
|
|
29
|
-
);
|
|
30
|
-
this.#expirationTime = expirationTime;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Prune removes all expired entries.
|
|
35
|
-
*/
|
|
36
|
-
prune() {
|
|
37
|
-
const currentTime = Date.now();
|
|
38
|
-
for (const [key, entry] of this.#inner.entries()) {
|
|
39
|
-
if (currentTime - entry.timestamp > this.#expirationTime) {
|
|
40
|
-
this.#inner.delete(key);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return this;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Implementing the Map interface
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Set the value for the given key. Prunes expired entries.
|
|
50
|
-
* @param key for the entry
|
|
51
|
-
* @param value of the entry
|
|
52
|
-
* @returns this
|
|
53
|
-
*/
|
|
54
|
-
set(key: K, value: V) {
|
|
55
|
-
this.prune();
|
|
56
|
-
const entry = {
|
|
57
|
-
value,
|
|
58
|
-
timestamp: Date.now(),
|
|
59
|
-
};
|
|
60
|
-
this.#inner.set(key, entry);
|
|
61
|
-
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Get the value associated with the key, if it exists and has not expired.
|
|
67
|
-
* @param key K
|
|
68
|
-
* @returns the value associated with the key, or undefined if the key is not present or has expired.
|
|
69
|
-
*/
|
|
70
|
-
get(key: K) {
|
|
71
|
-
const entry = this.#inner.get(key);
|
|
72
|
-
if (entry === undefined) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
if (Date.now() - entry.timestamp > this.#expirationTime) {
|
|
76
|
-
this.#inner.delete(key);
|
|
77
|
-
return undefined;
|
|
78
|
-
}
|
|
79
|
-
return entry.value;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Clear all entries.
|
|
84
|
-
*/
|
|
85
|
-
clear() {
|
|
86
|
-
this.#inner.clear();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Entries returns the entries of the map, without the expiration time.
|
|
91
|
-
* @returns an iterator over the entries of the map.
|
|
92
|
-
*/
|
|
93
|
-
entries(): MapIterator<[K, V]> {
|
|
94
|
-
const iterator = this.#inner.entries();
|
|
95
|
-
const generator = function* () {
|
|
96
|
-
for (const [key, value] of iterator) {
|
|
97
|
-
yield [key, value.value] as [K, V];
|
|
98
|
-
}
|
|
99
|
-
return undefined;
|
|
100
|
-
};
|
|
101
|
-
return generator();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Values returns the values of the map, without the expiration time.
|
|
106
|
-
* @returns an iterator over the values of the map.
|
|
107
|
-
*/
|
|
108
|
-
values(): MapIterator<V> {
|
|
109
|
-
const iterator = this.#inner.values();
|
|
110
|
-
const generator = function* () {
|
|
111
|
-
for (const value of iterator) {
|
|
112
|
-
yield value.value;
|
|
113
|
-
}
|
|
114
|
-
return undefined;
|
|
115
|
-
};
|
|
116
|
-
return generator();
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Keys returns the keys of the map
|
|
121
|
-
* @returns an iterator over the keys of the map.
|
|
122
|
-
*/
|
|
123
|
-
keys(): MapIterator<K> {
|
|
124
|
-
return this.#inner.keys();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* forEach calls the callbackfn on each entry of the map.
|
|
129
|
-
* @param callbackfn to call on each entry
|
|
130
|
-
* @param thisArg to use as this when calling the callbackfn
|
|
131
|
-
*/
|
|
132
|
-
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void, thisArg?: ExpirableMap<K, V>) {
|
|
133
|
-
for (const [key, value] of this.#inner.entries()) {
|
|
134
|
-
callbackfn.call(thisArg, value.value, key, this);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* has returns true if the key exists and has not expired.
|
|
140
|
-
* @param key K
|
|
141
|
-
* @returns true if the key exists and has not expired.
|
|
142
|
-
*/
|
|
143
|
-
has(key: K): boolean {
|
|
144
|
-
return this.#inner.has(key);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* delete the entry for the given key.
|
|
149
|
-
* @param key K
|
|
150
|
-
* @returns true if the key existed and has been deleted.
|
|
151
|
-
*/
|
|
152
|
-
delete(key: K) {
|
|
153
|
-
return this.#inner.delete(key);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* get size of the map.
|
|
158
|
-
* @returns the size of the map.
|
|
159
|
-
*/
|
|
160
|
-
get size() {
|
|
161
|
-
return this.#inner.size;
|
|
162
|
-
}
|
|
163
|
-
}
|