@alterior/common 3.9.1 → 3.13.4
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/base64.d.ts +6 -6
- package/dist/base64.js +52 -52
- package/dist/base64.js.map +1 -1
- package/dist/base64.test.d.ts +1 -1
- package/dist/cache.d.ts +84 -84
- package/dist/cache.js +148 -148
- package/dist/cache.js.map +1 -1
- package/dist/cache.test.d.ts +1 -1
- package/dist/check-native-async.d.ts +1 -1
- package/dist/check-native-async.js +27 -28
- package/dist/check-native-async.js.map +1 -1
- package/dist/clone.d.ts +23 -23
- package/dist/clone.js +59 -60
- package/dist/clone.js.map +1 -1
- package/dist/clone.test.d.ts +1 -1
- package/dist/coalesce.d.ts +5 -5
- package/dist/coalesce.js +15 -16
- package/dist/coalesce.js.map +1 -1
- package/dist/coalesce.test.d.ts +1 -1
- package/dist/colors.d.ts +62 -62
- package/dist/colors.js +66 -66
- package/dist/console.d.ts +31 -31
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js +65 -86
- package/dist/console.js.map +1 -1
- package/dist/constructor.d.ts +6 -6
- package/dist/constructor.js +2 -2
- package/dist/decorators.d.ts +1 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +6 -7
- package/dist/decorators.js.map +1 -1
- package/dist/environment.d.ts +11 -11
- package/dist/environment.d.ts.map +1 -1
- package/dist/environment.js +27 -27
- package/dist/environment.js.map +1 -1
- package/dist/errors.d.ts +66 -66
- package/dist/errors.js +133 -133
- package/dist/errors.test.d.ts +1 -1
- package/dist/get-param-names.d.ts +5 -5
- package/dist/get-param-names.js +48 -49
- package/dist/get-param-names.js.map +1 -1
- package/dist/index.d.ts +20 -20
- package/dist/index.js +23 -23
- package/dist/is-constructor.d.ts +12 -12
- package/dist/is-constructor.js +28 -29
- package/dist/is-constructor.js.map +1 -1
- package/dist/is-constructor.test.d.ts +1 -1
- package/dist/lazy-promise.d.ts +14 -14
- package/dist/lazy-promise.js +32 -32
- package/dist/lazy-promise.js.map +1 -1
- package/dist/lazy-subject.d.ts +22 -22
- package/dist/lazy-subject.js +22 -23
- package/dist/lazy-subject.js.map +1 -1
- package/dist/locks.d.ts +23 -23
- package/dist/locks.js +76 -76
- package/dist/locks.js.map +1 -1
- package/dist/locks.test.d.ts +1 -1
- package/dist/locks.test.js.map +1 -1
- package/dist/padding.d.ts +22 -22
- package/dist/padding.js +42 -43
- package/dist/padding.js.map +1 -1
- package/dist/presentation.d.ts +49 -49
- package/dist/presentation.d.ts.map +1 -1
- package/dist/presentation.js +132 -132
- package/dist/presentation.js.map +1 -1
- package/dist/presentation.test.d.ts +1 -1
- package/dist/presentation.test.js.map +1 -1
- package/dist/serializer.d.ts +8 -8
- package/dist/serializer.js +23 -24
- package/dist/serializer.js.map +1 -1
- package/dist/test.d.ts +2 -2
- package/dist/time.d.ts +9 -9
- package/dist/time.js +22 -22
- package/dist/time.js.map +1 -1
- package/dist/timeout.d.ts +13 -13
- package/dist/timeout.js +27 -28
- package/dist/timeout.js.map +1 -1
- package/dist/zones.d.ts +46 -46
- package/dist/zones.js +139 -139
- package/dist/zones.js.map +1 -1
- package/dist.esm/base64.d.ts +6 -6
- package/dist.esm/base64.js +48 -48
- package/dist.esm/base64.js.map +1 -1
- package/dist.esm/base64.test.d.ts +1 -1
- package/dist.esm/cache.d.ts +84 -84
- package/dist.esm/cache.js +144 -144
- package/dist.esm/cache.js.map +1 -1
- package/dist.esm/cache.test.d.ts +1 -1
- package/dist.esm/check-native-async.d.ts +1 -1
- package/dist.esm/check-native-async.js +24 -24
- package/dist.esm/check-native-async.js.map +1 -1
- package/dist.esm/clone.d.ts +23 -23
- package/dist.esm/clone.js +53 -53
- package/dist.esm/clone.js.map +1 -1
- package/dist.esm/clone.test.d.ts +1 -1
- package/dist.esm/coalesce.d.ts +5 -5
- package/dist.esm/coalesce.js +12 -12
- package/dist.esm/coalesce.js.map +1 -1
- package/dist.esm/coalesce.test.d.ts +1 -1
- package/dist.esm/colors.d.ts +62 -62
- package/dist.esm/colors.js +63 -63
- package/dist.esm/console.d.ts +31 -31
- package/dist.esm/console.d.ts.map +1 -1
- package/dist.esm/console.js +60 -80
- package/dist.esm/console.js.map +1 -1
- package/dist.esm/constructor.d.ts +6 -6
- package/dist.esm/constructor.js +1 -1
- package/dist.esm/decorators.d.ts +1 -1
- package/dist.esm/decorators.d.ts.map +1 -1
- package/dist.esm/decorators.js +3 -3
- package/dist.esm/environment.d.ts +11 -11
- package/dist.esm/environment.d.ts.map +1 -1
- package/dist.esm/environment.js +24 -24
- package/dist.esm/environment.js.map +1 -1
- package/dist.esm/errors.d.ts +66 -66
- package/dist.esm/errors.js +115 -115
- package/dist.esm/errors.test.d.ts +1 -1
- package/dist.esm/get-param-names.d.ts +5 -5
- package/dist.esm/get-param-names.js +45 -45
- package/dist.esm/get-param-names.js.map +1 -1
- package/dist.esm/index.d.ts +20 -20
- package/dist.esm/index.js +20 -20
- package/dist.esm/is-constructor.d.ts +12 -12
- package/dist.esm/is-constructor.js +24 -24
- package/dist.esm/is-constructor.js.map +1 -1
- package/dist.esm/is-constructor.test.d.ts +1 -1
- package/dist.esm/lazy-promise.d.ts +14 -14
- package/dist.esm/lazy-promise.js +28 -28
- package/dist.esm/lazy-promise.js.map +1 -1
- package/dist.esm/lazy-subject.d.ts +22 -22
- package/dist.esm/lazy-subject.js +19 -19
- package/dist.esm/locks.d.ts +23 -23
- package/dist.esm/locks.js +71 -71
- package/dist.esm/locks.js.map +1 -1
- package/dist.esm/locks.test.d.ts +1 -1
- package/dist.esm/locks.test.js.map +1 -1
- package/dist.esm/padding.d.ts +22 -22
- package/dist.esm/padding.js +37 -37
- package/dist.esm/presentation.d.ts +49 -49
- package/dist.esm/presentation.d.ts.map +1 -1
- package/dist.esm/presentation.js +126 -126
- package/dist.esm/presentation.js.map +1 -1
- package/dist.esm/presentation.test.d.ts +1 -1
- package/dist.esm/presentation.test.js.map +1 -1
- package/dist.esm/serializer.d.ts +8 -8
- package/dist.esm/serializer.js +20 -20
- package/dist.esm/test.d.ts +2 -2
- package/dist.esm/time.d.ts +9 -9
- package/dist.esm/time.js +19 -19
- package/dist.esm/time.js.map +1 -1
- package/dist.esm/timeout.d.ts +13 -13
- package/dist.esm/timeout.js +23 -23
- package/dist.esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist.esm/zones.d.ts +46 -46
- package/dist.esm/zones.js +135 -135
- package/dist.esm/zones.js.map +1 -1
- package/package.json +11 -8
- package/src/console.ts +2 -22
- package/src/environment.ts +2 -0
- package/tsconfig.esm.json +0 -3
- package/tsconfig.json +0 -2
- package/tsconfig.tsbuildinfo +1 -3791
package/dist.esm/cache.d.ts
CHANGED
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
interface CacheEntry<T> {
|
|
2
|
-
key: string;
|
|
3
|
-
time: number;
|
|
4
|
-
expiresAt: number;
|
|
5
|
-
lastFetched: number;
|
|
6
|
-
value: T;
|
|
7
|
-
}
|
|
8
|
-
interface CacheFetcher<T> {
|
|
9
|
-
(): Promise<T>;
|
|
10
|
-
}
|
|
11
|
-
interface FetchOptions {
|
|
12
|
-
/**
|
|
13
|
-
* The time to live to set for a fulfilled item
|
|
14
|
-
*/
|
|
15
|
-
timeToLive?: number;
|
|
16
|
-
/**
|
|
17
|
-
* What kind of cache miss strategy should be used here.
|
|
18
|
-
* - "fulfill" [default]:
|
|
19
|
-
* If the cache misses for any reason, wait until the new value is fetched and return it.
|
|
20
|
-
* - "stale-revalidate":
|
|
21
|
-
* If the cache misses due to an expired value, return the expired (stale) value
|
|
22
|
-
* and call the fetcher to update the value in the background.
|
|
23
|
-
*/
|
|
24
|
-
missStrategy?: "fulfill" | "stale-revalidate";
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Provides a generic caching mechanism useful for a number of cases
|
|
28
|
-
*/
|
|
29
|
-
export declare class Cache<T> {
|
|
30
|
-
private timeToLive;
|
|
31
|
-
private maxItems;
|
|
32
|
-
/**
|
|
33
|
-
*
|
|
34
|
-
* @param timeToLive Time a cached item should live before expiring, in milliseconds
|
|
35
|
-
* @param maxItems Amount of items that can be held in the cache maximum.
|
|
36
|
-
*/
|
|
37
|
-
constructor(timeToLive: number, maxItems: number);
|
|
38
|
-
private entries;
|
|
39
|
-
/**
|
|
40
|
-
* Cache cleanup routine run whenever a value is stored in the cache
|
|
41
|
-
*/
|
|
42
|
-
private sliceCleanup;
|
|
43
|
-
getOldestEntry(): CacheEntry<T>;
|
|
44
|
-
/**
|
|
45
|
-
* Insert the specified item into the cache under the given key,
|
|
46
|
-
* optionally specifying a custom time-to-live. If no time-to-live
|
|
47
|
-
* is specified, the class-wide default is used.
|
|
48
|
-
*
|
|
49
|
-
* @param key The key for the cache entry
|
|
50
|
-
* @param value The value to cache
|
|
51
|
-
* @param timeToLive How long the value should remain valid for before revalidation
|
|
52
|
-
*/
|
|
53
|
-
insertItem(key: string, value: T, timeToLive?: number): void;
|
|
54
|
-
private outstandingFetches;
|
|
55
|
-
/**
|
|
56
|
-
* Get the value present in the cache for the given key regardless
|
|
57
|
-
* of the cache entry's expiration status.
|
|
58
|
-
*
|
|
59
|
-
* @param key The key to get
|
|
60
|
-
*/
|
|
61
|
-
get(key: string): T;
|
|
62
|
-
/**
|
|
63
|
-
* Get the cache entry for the given key.
|
|
64
|
-
* @param key The key to get
|
|
65
|
-
*/
|
|
66
|
-
getEntry(key: string): CacheEntry<T>;
|
|
67
|
-
/**
|
|
68
|
-
* Fetch a value from the cache, calling the given function to
|
|
69
|
-
* generate the value if it is not present or it is expired.
|
|
70
|
-
* The result of the function is then cached for future calls.
|
|
71
|
-
*
|
|
72
|
-
* Use `options.missStrategy` to control the revalidation behavior. The default value ("fulfill") will
|
|
73
|
-
* wait until the fetch operation completes to return a value in the case where a cache miss occurs,
|
|
74
|
-
* even if an expired cache value is present. The "stale-revalidate" option will instead return the
|
|
75
|
-
* value found in the cache even when expired, executing the fetch operation if the value is expired
|
|
76
|
-
* and saving the resulting value back into the cache for future calls.
|
|
77
|
-
*
|
|
78
|
-
* @param key The key to fetch
|
|
79
|
-
* @param fetcher A function to define the value of the key if a cache miss occurs
|
|
80
|
-
* @param options Options for doing the caching.
|
|
81
|
-
*/
|
|
82
|
-
fetch(key: string, fetcher?: CacheFetcher<T>, options?: FetchOptions): Promise<T>;
|
|
83
|
-
}
|
|
84
|
-
export {};
|
|
1
|
+
interface CacheEntry<T> {
|
|
2
|
+
key: string;
|
|
3
|
+
time: number;
|
|
4
|
+
expiresAt: number;
|
|
5
|
+
lastFetched: number;
|
|
6
|
+
value: T;
|
|
7
|
+
}
|
|
8
|
+
interface CacheFetcher<T> {
|
|
9
|
+
(): Promise<T>;
|
|
10
|
+
}
|
|
11
|
+
interface FetchOptions {
|
|
12
|
+
/**
|
|
13
|
+
* The time to live to set for a fulfilled item
|
|
14
|
+
*/
|
|
15
|
+
timeToLive?: number;
|
|
16
|
+
/**
|
|
17
|
+
* What kind of cache miss strategy should be used here.
|
|
18
|
+
* - "fulfill" [default]:
|
|
19
|
+
* If the cache misses for any reason, wait until the new value is fetched and return it.
|
|
20
|
+
* - "stale-revalidate":
|
|
21
|
+
* If the cache misses due to an expired value, return the expired (stale) value
|
|
22
|
+
* and call the fetcher to update the value in the background.
|
|
23
|
+
*/
|
|
24
|
+
missStrategy?: "fulfill" | "stale-revalidate";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Provides a generic caching mechanism useful for a number of cases
|
|
28
|
+
*/
|
|
29
|
+
export declare class Cache<T> {
|
|
30
|
+
private timeToLive;
|
|
31
|
+
private maxItems;
|
|
32
|
+
/**
|
|
33
|
+
*
|
|
34
|
+
* @param timeToLive Time a cached item should live before expiring, in milliseconds
|
|
35
|
+
* @param maxItems Amount of items that can be held in the cache maximum.
|
|
36
|
+
*/
|
|
37
|
+
constructor(timeToLive: number, maxItems: number);
|
|
38
|
+
private entries;
|
|
39
|
+
/**
|
|
40
|
+
* Cache cleanup routine run whenever a value is stored in the cache
|
|
41
|
+
*/
|
|
42
|
+
private sliceCleanup;
|
|
43
|
+
getOldestEntry(): CacheEntry<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Insert the specified item into the cache under the given key,
|
|
46
|
+
* optionally specifying a custom time-to-live. If no time-to-live
|
|
47
|
+
* is specified, the class-wide default is used.
|
|
48
|
+
*
|
|
49
|
+
* @param key The key for the cache entry
|
|
50
|
+
* @param value The value to cache
|
|
51
|
+
* @param timeToLive How long the value should remain valid for before revalidation
|
|
52
|
+
*/
|
|
53
|
+
insertItem(key: string, value: T, timeToLive?: number): void;
|
|
54
|
+
private outstandingFetches;
|
|
55
|
+
/**
|
|
56
|
+
* Get the value present in the cache for the given key regardless
|
|
57
|
+
* of the cache entry's expiration status.
|
|
58
|
+
*
|
|
59
|
+
* @param key The key to get
|
|
60
|
+
*/
|
|
61
|
+
get(key: string): T;
|
|
62
|
+
/**
|
|
63
|
+
* Get the cache entry for the given key.
|
|
64
|
+
* @param key The key to get
|
|
65
|
+
*/
|
|
66
|
+
getEntry(key: string): CacheEntry<T>;
|
|
67
|
+
/**
|
|
68
|
+
* Fetch a value from the cache, calling the given function to
|
|
69
|
+
* generate the value if it is not present or it is expired.
|
|
70
|
+
* The result of the function is then cached for future calls.
|
|
71
|
+
*
|
|
72
|
+
* Use `options.missStrategy` to control the revalidation behavior. The default value ("fulfill") will
|
|
73
|
+
* wait until the fetch operation completes to return a value in the case where a cache miss occurs,
|
|
74
|
+
* even if an expired cache value is present. The "stale-revalidate" option will instead return the
|
|
75
|
+
* value found in the cache even when expired, executing the fetch operation if the value is expired
|
|
76
|
+
* and saving the resulting value back into the cache for future calls.
|
|
77
|
+
*
|
|
78
|
+
* @param key The key to fetch
|
|
79
|
+
* @param fetcher A function to define the value of the key if a cache miss occurs
|
|
80
|
+
* @param options Options for doing the caching.
|
|
81
|
+
*/
|
|
82
|
+
fetch(key: string, fetcher?: CacheFetcher<T>, options?: FetchOptions): Promise<T>;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
85
85
|
//# sourceMappingURL=cache.d.ts.map
|
package/dist.esm/cache.js
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { deepClone } from "./clone";
|
|
3
|
-
/**
|
|
4
|
-
* Provides a generic caching mechanism useful for a number of cases
|
|
5
|
-
*/
|
|
6
|
-
export class Cache {
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param timeToLive Time a cached item should live before expiring, in milliseconds
|
|
10
|
-
* @param maxItems Amount of items that can be held in the cache maximum.
|
|
11
|
-
*/
|
|
12
|
-
constructor(timeToLive, maxItems) {
|
|
13
|
-
this.timeToLive = timeToLive;
|
|
14
|
-
this.maxItems = maxItems;
|
|
15
|
-
this.entries = {};
|
|
16
|
-
this.outstandingFetches = new Map();
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Cache cleanup routine run whenever a value is stored in the cache
|
|
20
|
-
*/
|
|
21
|
-
sliceCleanup() {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
let keys = Object.keys(this.entries);
|
|
24
|
-
if (keys.length < this.maxItems)
|
|
25
|
-
return;
|
|
26
|
-
setTimeout(() => {
|
|
27
|
-
// Refresh the current count, and trim the
|
|
28
|
-
// cache to the right size, evicting last-fetched item
|
|
29
|
-
// first.
|
|
30
|
-
keys = Object.keys(this.entries);
|
|
31
|
-
let itemCount = keys.length;
|
|
32
|
-
while (itemCount > this.maxItems) {
|
|
33
|
-
let entry = this.getOldestEntry();
|
|
34
|
-
delete this.entries[entry.key];
|
|
35
|
-
--itemCount;
|
|
36
|
-
}
|
|
37
|
-
}, 100);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
getOldestEntry() {
|
|
41
|
-
let selectedEntry = null;
|
|
42
|
-
for (let key in this.entries) {
|
|
43
|
-
let entry = this.entries[key];
|
|
44
|
-
if (!selectedEntry || selectedEntry.time > entry.time)
|
|
45
|
-
selectedEntry = entry;
|
|
46
|
-
}
|
|
47
|
-
return selectedEntry;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Insert the specified item into the cache under the given key,
|
|
51
|
-
* optionally specifying a custom time-to-live. If no time-to-live
|
|
52
|
-
* is specified, the class-wide default is used.
|
|
53
|
-
*
|
|
54
|
-
* @param key The key for the cache entry
|
|
55
|
-
* @param value The value to cache
|
|
56
|
-
* @param timeToLive How long the value should remain valid for before revalidation
|
|
57
|
-
*/
|
|
58
|
-
insertItem(key, value, timeToLive) {
|
|
59
|
-
if (timeToLive === undefined)
|
|
60
|
-
timeToLive = this.timeToLive;
|
|
61
|
-
// Compute the value
|
|
62
|
-
let now = new Date().getTime();
|
|
63
|
-
let entry = this.entries[key] = {
|
|
64
|
-
key,
|
|
65
|
-
time: now,
|
|
66
|
-
expiresAt: now + timeToLive,
|
|
67
|
-
lastFetched: now,
|
|
68
|
-
value: deepClone(value)
|
|
69
|
-
};
|
|
70
|
-
this.sliceCleanup();
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Get the value present in the cache for the given key regardless
|
|
74
|
-
* of the cache entry's expiration status.
|
|
75
|
-
*
|
|
76
|
-
* @param key The key to get
|
|
77
|
-
*/
|
|
78
|
-
get(key) {
|
|
79
|
-
let entry = this.entries[key];
|
|
80
|
-
return entry ? deepClone(entry.value) : undefined;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Get the cache entry for the given key.
|
|
84
|
-
* @param key The key to get
|
|
85
|
-
*/
|
|
86
|
-
getEntry(key) {
|
|
87
|
-
return this.entries[key];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Fetch a value from the cache, calling the given function to
|
|
91
|
-
* generate the value if it is not present or it is expired.
|
|
92
|
-
* The result of the function is then cached for future calls.
|
|
93
|
-
*
|
|
94
|
-
* Use `options.missStrategy` to control the revalidation behavior. The default value ("fulfill") will
|
|
95
|
-
* wait until the fetch operation completes to return a value in the case where a cache miss occurs,
|
|
96
|
-
* even if an expired cache value is present. The "stale-revalidate" option will instead return the
|
|
97
|
-
* value found in the cache even when expired, executing the fetch operation if the value is expired
|
|
98
|
-
* and saving the resulting value back into the cache for future calls.
|
|
99
|
-
*
|
|
100
|
-
* @param key The key to fetch
|
|
101
|
-
* @param fetcher A function to define the value of the key if a cache miss occurs
|
|
102
|
-
* @param options Options for doing the caching.
|
|
103
|
-
*/
|
|
104
|
-
fetch(
|
|
105
|
-
return __awaiter(this,
|
|
106
|
-
let existingFetch = this.outstandingFetches.get(key);
|
|
107
|
-
if (existingFetch)
|
|
108
|
-
return yield existingFetch;
|
|
109
|
-
let entry;
|
|
110
|
-
let now = Date.now();
|
|
111
|
-
let stale = true;
|
|
112
|
-
if (key in this.entries) {
|
|
113
|
-
entry = this.entries[key];
|
|
114
|
-
stale = entry.expiresAt < now;
|
|
115
|
-
}
|
|
116
|
-
if (!options.missStrategy)
|
|
117
|
-
options.missStrategy = 'fulfill';
|
|
118
|
-
if (options.missStrategy === 'fulfill')
|
|
119
|
-
entry = stale ? undefined : entry;
|
|
120
|
-
let fetchOperation;
|
|
121
|
-
if (stale && fetcher) {
|
|
122
|
-
fetchOperation = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
// Fetch!
|
|
124
|
-
let value;
|
|
125
|
-
try {
|
|
126
|
-
value = yield fetcher();
|
|
127
|
-
if (value !== undefined)
|
|
128
|
-
this.insertItem(key, value, options.timeToLive);
|
|
129
|
-
resolve(value);
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
console.error(`Failed to fetch item ${key}:`);
|
|
133
|
-
console.error(e);
|
|
134
|
-
debugger;
|
|
135
|
-
resolve(entry ? deepClone(entry.value) : undefined);
|
|
136
|
-
}
|
|
137
|
-
}));
|
|
138
|
-
fetchOperation.finally(() => this.outstandingFetches.delete(key));
|
|
139
|
-
this.outstandingFetches.set(key, fetchOperation);
|
|
140
|
-
}
|
|
141
|
-
return entry ? deepClone(entry.value) : yield fetchOperation;
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
import { deepClone } from "./clone";
|
|
3
|
+
/**
|
|
4
|
+
* Provides a generic caching mechanism useful for a number of cases
|
|
5
|
+
*/
|
|
6
|
+
export class Cache {
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param timeToLive Time a cached item should live before expiring, in milliseconds
|
|
10
|
+
* @param maxItems Amount of items that can be held in the cache maximum.
|
|
11
|
+
*/
|
|
12
|
+
constructor(timeToLive, maxItems) {
|
|
13
|
+
this.timeToLive = timeToLive;
|
|
14
|
+
this.maxItems = maxItems;
|
|
15
|
+
this.entries = {};
|
|
16
|
+
this.outstandingFetches = new Map();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Cache cleanup routine run whenever a value is stored in the cache
|
|
20
|
+
*/
|
|
21
|
+
sliceCleanup() {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
let keys = Object.keys(this.entries);
|
|
24
|
+
if (keys.length < this.maxItems)
|
|
25
|
+
return;
|
|
26
|
+
setTimeout(() => {
|
|
27
|
+
// Refresh the current count, and trim the
|
|
28
|
+
// cache to the right size, evicting last-fetched item
|
|
29
|
+
// first.
|
|
30
|
+
keys = Object.keys(this.entries);
|
|
31
|
+
let itemCount = keys.length;
|
|
32
|
+
while (itemCount > this.maxItems) {
|
|
33
|
+
let entry = this.getOldestEntry();
|
|
34
|
+
delete this.entries[entry.key];
|
|
35
|
+
--itemCount;
|
|
36
|
+
}
|
|
37
|
+
}, 100);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
getOldestEntry() {
|
|
41
|
+
let selectedEntry = null;
|
|
42
|
+
for (let key in this.entries) {
|
|
43
|
+
let entry = this.entries[key];
|
|
44
|
+
if (!selectedEntry || selectedEntry.time > entry.time)
|
|
45
|
+
selectedEntry = entry;
|
|
46
|
+
}
|
|
47
|
+
return selectedEntry;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Insert the specified item into the cache under the given key,
|
|
51
|
+
* optionally specifying a custom time-to-live. If no time-to-live
|
|
52
|
+
* is specified, the class-wide default is used.
|
|
53
|
+
*
|
|
54
|
+
* @param key The key for the cache entry
|
|
55
|
+
* @param value The value to cache
|
|
56
|
+
* @param timeToLive How long the value should remain valid for before revalidation
|
|
57
|
+
*/
|
|
58
|
+
insertItem(key, value, timeToLive) {
|
|
59
|
+
if (timeToLive === undefined)
|
|
60
|
+
timeToLive = this.timeToLive;
|
|
61
|
+
// Compute the value
|
|
62
|
+
let now = new Date().getTime();
|
|
63
|
+
let entry = this.entries[key] = {
|
|
64
|
+
key,
|
|
65
|
+
time: now,
|
|
66
|
+
expiresAt: now + timeToLive,
|
|
67
|
+
lastFetched: now,
|
|
68
|
+
value: deepClone(value)
|
|
69
|
+
};
|
|
70
|
+
this.sliceCleanup();
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the value present in the cache for the given key regardless
|
|
74
|
+
* of the cache entry's expiration status.
|
|
75
|
+
*
|
|
76
|
+
* @param key The key to get
|
|
77
|
+
*/
|
|
78
|
+
get(key) {
|
|
79
|
+
let entry = this.entries[key];
|
|
80
|
+
return entry ? deepClone(entry.value) : undefined;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Get the cache entry for the given key.
|
|
84
|
+
* @param key The key to get
|
|
85
|
+
*/
|
|
86
|
+
getEntry(key) {
|
|
87
|
+
return this.entries[key];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Fetch a value from the cache, calling the given function to
|
|
91
|
+
* generate the value if it is not present or it is expired.
|
|
92
|
+
* The result of the function is then cached for future calls.
|
|
93
|
+
*
|
|
94
|
+
* Use `options.missStrategy` to control the revalidation behavior. The default value ("fulfill") will
|
|
95
|
+
* wait until the fetch operation completes to return a value in the case where a cache miss occurs,
|
|
96
|
+
* even if an expired cache value is present. The "stale-revalidate" option will instead return the
|
|
97
|
+
* value found in the cache even when expired, executing the fetch operation if the value is expired
|
|
98
|
+
* and saving the resulting value back into the cache for future calls.
|
|
99
|
+
*
|
|
100
|
+
* @param key The key to fetch
|
|
101
|
+
* @param fetcher A function to define the value of the key if a cache miss occurs
|
|
102
|
+
* @param options Options for doing the caching.
|
|
103
|
+
*/
|
|
104
|
+
fetch(key_1, fetcher_1) {
|
|
105
|
+
return __awaiter(this, arguments, void 0, function* (key, fetcher, options = {}) {
|
|
106
|
+
let existingFetch = this.outstandingFetches.get(key);
|
|
107
|
+
if (existingFetch)
|
|
108
|
+
return yield existingFetch;
|
|
109
|
+
let entry;
|
|
110
|
+
let now = Date.now();
|
|
111
|
+
let stale = true;
|
|
112
|
+
if (key in this.entries) {
|
|
113
|
+
entry = this.entries[key];
|
|
114
|
+
stale = entry.expiresAt < now;
|
|
115
|
+
}
|
|
116
|
+
if (!options.missStrategy)
|
|
117
|
+
options.missStrategy = 'fulfill';
|
|
118
|
+
if (options.missStrategy === 'fulfill')
|
|
119
|
+
entry = stale ? undefined : entry;
|
|
120
|
+
let fetchOperation;
|
|
121
|
+
if (stale && fetcher) {
|
|
122
|
+
fetchOperation = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
123
|
+
// Fetch!
|
|
124
|
+
let value;
|
|
125
|
+
try {
|
|
126
|
+
value = yield fetcher();
|
|
127
|
+
if (value !== undefined)
|
|
128
|
+
this.insertItem(key, value, options.timeToLive);
|
|
129
|
+
resolve(value);
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
console.error(`Failed to fetch item ${key}:`);
|
|
133
|
+
console.error(e);
|
|
134
|
+
debugger;
|
|
135
|
+
resolve(entry ? deepClone(entry.value) : undefined);
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
fetchOperation.finally(() => this.outstandingFetches.delete(key));
|
|
139
|
+
this.outstandingFetches.set(key, fetchOperation);
|
|
140
|
+
}
|
|
141
|
+
return entry ? deepClone(entry.value) : yield fetchOperation;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
145
|
//# sourceMappingURL=cache.js.map
|
package/dist.esm/cache.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAmCpC;;GAEG;AACH,MAAM,OAAO,KAAK;IACd;;;;OAIG;IACH,YAA2B,UAAmB,EAAU,QAAiB;QAA9C,eAAU,GAAV,UAAU,CAAS;QAAU,aAAQ,GAAR,QAAQ,CAAS;QAGjE,YAAO,GAAiB,EAAE,CAAC;QAkE3B,uBAAkB,GAAG,IAAI,GAAG,EAAwB,CAAC;IApE7D,CAAC;IAID;;OAEG;IACW,YAAY;;YAEtB,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ;gBAC3B,OAAO;YAEX,UAAU,CAAC,GAAG,EAAE;gBAEZ,2CAA2C;gBAC3C,sDAAsD;gBACtD,SAAS;gBAET,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACjC,IAAI,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC;gBAE5B,OAAO,SAAS,GAAG,IAAI,CAAC,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"file":"cache.js","sourceRoot":"","sources":["../src/cache.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAmCpC;;GAEG;AACH,MAAM,OAAO,KAAK;IACd;;;;OAIG;IACH,YAA2B,UAAmB,EAAU,QAAiB;QAA9C,eAAU,GAAV,UAAU,CAAS;QAAU,aAAQ,GAAR,QAAQ,CAAS;QAGjE,YA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1,2 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
2
2
|
//# sourceMappingURL=cache.test.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function disallowNativeAsync(func: Function): void;
|
|
1
|
+
export declare function disallowNativeAsync(func: Function): void;
|
|
2
2
|
//# sourceMappingURL=check-native-async.d.ts.map
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
export function disallowNativeAsync(func) {
|
|
2
|
-
if (typeof func !== 'function')
|
|
3
|
-
return;
|
|
4
|
-
if (func.constructor.name === 'AsyncFunction') {
|
|
5
|
-
console.error();
|
|
6
|
-
console.error(`----------------------------------------------------------------------------------------------------`);
|
|
7
|
-
console.error(`Detected usage of a native async function in a context where it is not allowed.`);
|
|
8
|
-
console.error(`Unfortunately, native async/await is not supported by Alterior, as it breaks Zone tracking.`);
|
|
9
|
-
console.error(`Please ensure compilerOptions.target is set to ES2016 or lower, and keep in mind that `);
|
|
10
|
-
console.error(`dependencies compiled with native async/await support may cause problems for some Alterior features.`);
|
|
11
|
-
console.error(`For more information see https://github.com/angular/angular/issues/31730`);
|
|
12
|
-
console.error();
|
|
13
|
-
console.error(`**Please support the AsyncContext proposal which will help solve this problem**`);
|
|
14
|
-
console.error(` https://github.com/tc39/proposal-async-context`);
|
|
15
|
-
console.error();
|
|
16
|
-
console.error(`Context:`);
|
|
17
|
-
console.error(` - Function name: ${func.name}`);
|
|
18
|
-
console.error(` - Function implementation:`);
|
|
19
|
-
console.error(` ${String(func).replace(/\n/g, "\n ")}`);
|
|
20
|
-
console.error(`----------------------------------------------------------------------------------------------------`);
|
|
21
|
-
console.error();
|
|
22
|
-
throw new Error(`Native async/await is not supported [${func.name}()].`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
export function disallowNativeAsync(func) {
|
|
2
|
+
if (typeof func !== 'function')
|
|
3
|
+
return;
|
|
4
|
+
if (func.constructor.name === 'AsyncFunction') {
|
|
5
|
+
console.error();
|
|
6
|
+
console.error(`----------------------------------------------------------------------------------------------------`);
|
|
7
|
+
console.error(`Detected usage of a native async function in a context where it is not allowed.`);
|
|
8
|
+
console.error(`Unfortunately, native async/await is not supported by Alterior, as it breaks Zone tracking.`);
|
|
9
|
+
console.error(`Please ensure compilerOptions.target is set to ES2016 or lower, and keep in mind that `);
|
|
10
|
+
console.error(`dependencies compiled with native async/await support may cause problems for some Alterior features.`);
|
|
11
|
+
console.error(`For more information see https://github.com/angular/angular/issues/31730`);
|
|
12
|
+
console.error();
|
|
13
|
+
console.error(`**Please support the AsyncContext proposal which will help solve this problem**`);
|
|
14
|
+
console.error(` https://github.com/tc39/proposal-async-context`);
|
|
15
|
+
console.error();
|
|
16
|
+
console.error(`Context:`);
|
|
17
|
+
console.error(` - Function name: ${func.name}`);
|
|
18
|
+
console.error(` - Function implementation:`);
|
|
19
|
+
console.error(` ${String(func).replace(/\n/g, "\n ")}`);
|
|
20
|
+
console.error(`----------------------------------------------------------------------------------------------------`);
|
|
21
|
+
console.error();
|
|
22
|
+
throw new Error(`Native async/await is not supported [${func.name}()].`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
25
|
//# sourceMappingURL=check-native-async.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-native-async.js","sourceRoot":"","sources":["../src/check-native-async.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,mBAAmB,CAAC,IAAc;IAC9C,IAAI,OAAO,IAAI,KAAK,UAAU;QAC1B,OAAO;IAEX,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,EAAE;
|
|
1
|
+
{"version":3,"file":"check-native-async.js","sourceRoot":"","sources":["../src/check-native-async.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,mBAAmB,CAAC,IAAc;IAC9C,IAAI,OAAO,IAAI,KAAK,UAAU;QAC1B,OAAO;IAEX,IAAI,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QAC5C,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,sGAAsG,CAAC,CAAC;QACtH,OAAO,CAAC,KAAK,CAAC,iFAAiF,CAAC,CAAC;QACjG,OAAO,CAAC,KAAK,CAAC,6FAA6F,CAAC,CAAC;QAC7G,OAAO,CAAC,KAAK,CAAC,wFAAwF,CAAC,CAAC;QACxG,OAAO,CAAC,KAAK,CAAC,sGAAsG,CAAC,CAAC;QACtH,OAAO,CAAC,KAAK,CAAC,0EAA0E,CAAC,CAAC;QAC1F,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,iFAAiF,CAAC,CAAC;QACjG,OAAO,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACnE,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,CAAC,KAAK,CAAC,qBAAqB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAChD,OAAO,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAC7C,OAAO,CAAC,KAAK,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAC5D,OAAO,CAAC,KAAK,CAAC,sGAAsG,CAAC,CAAC;QACtH,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,wCAAwC,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC;IAC7E,CAAC;AACL,CAAC"}
|
package/dist.esm/clone.d.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Perform a shallow clone of the object, producing one that has the
|
|
3
|
-
* same constructor chain and prototype as the passed object.
|
|
4
|
-
* @param obj
|
|
5
|
-
*/
|
|
6
|
-
export declare function shallowClone(obj: Object): any;
|
|
7
|
-
/**
|
|
8
|
-
* Perform a standard clone using serialization (see cloneBySerialization)
|
|
9
|
-
* @param obj
|
|
10
|
-
*/
|
|
11
|
-
export declare function clone<T = any>(obj: T): T;
|
|
12
|
-
/**
|
|
13
|
-
* Deeply clone the given value. If the value is an object, all subobjects
|
|
14
|
-
* are deeply cloned as well.
|
|
15
|
-
*
|
|
16
|
-
* @param o
|
|
17
|
-
*/
|
|
18
|
-
export declare function deepClone(o: any): any;
|
|
19
|
-
/**
|
|
20
|
-
* Clone the value by serializing it to JSON and back.
|
|
21
|
-
* @param obj
|
|
22
|
-
*/
|
|
23
|
-
export declare function cloneBySerialization(obj: any): any;
|
|
1
|
+
/**
|
|
2
|
+
* Perform a shallow clone of the object, producing one that has the
|
|
3
|
+
* same constructor chain and prototype as the passed object.
|
|
4
|
+
* @param obj
|
|
5
|
+
*/
|
|
6
|
+
export declare function shallowClone(obj: Object): any;
|
|
7
|
+
/**
|
|
8
|
+
* Perform a standard clone using serialization (see cloneBySerialization)
|
|
9
|
+
* @param obj
|
|
10
|
+
*/
|
|
11
|
+
export declare function clone<T = any>(obj: T): T;
|
|
12
|
+
/**
|
|
13
|
+
* Deeply clone the given value. If the value is an object, all subobjects
|
|
14
|
+
* are deeply cloned as well.
|
|
15
|
+
*
|
|
16
|
+
* @param o
|
|
17
|
+
*/
|
|
18
|
+
export declare function deepClone(o: any): any;
|
|
19
|
+
/**
|
|
20
|
+
* Clone the value by serializing it to JSON and back.
|
|
21
|
+
* @param obj
|
|
22
|
+
*/
|
|
23
|
+
export declare function cloneBySerialization(obj: any): any;
|
|
24
24
|
//# sourceMappingURL=clone.d.ts.map
|