@alterior/common 3.15.0 → 3.16.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/dist/cache.d.ts +2 -2
- package/dist/cache.d.ts.map +1 -1
- package/dist/cache.js +2 -1
- package/dist/cache.js.map +1 -1
- package/dist/cache.test.js.map +1 -1
- package/dist/clone.d.ts +5 -2
- package/dist/clone.d.ts.map +1 -1
- package/dist/clone.js +4 -6
- package/dist/clone.js.map +1 -1
- package/dist/colors.d.ts +2 -56
- package/dist/colors.d.ts.map +1 -1
- package/dist/colors.js +3 -8
- package/dist/colors.js.map +1 -1
- package/dist/console.d.ts +0 -8
- package/dist/console.d.ts.map +1 -1
- package/dist/console.js.map +1 -1
- package/dist/constructor.d.ts.map +1 -1
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +1 -1
- package/dist/decorators.js.map +1 -1
- package/dist/errors.d.ts +8 -6
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/lazy-promise.d.ts +1 -1
- package/dist/lazy-promise.d.ts.map +1 -1
- package/dist/lazy-promise.js.map +1 -1
- package/dist/locks.d.ts +3 -3
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js.map +1 -1
- package/dist/object-entries-typed.d.ts +3 -0
- package/dist/object-entries-typed.d.ts.map +1 -0
- package/dist/object-entries-typed.js +11 -0
- package/dist/object-entries-typed.js.map +1 -0
- package/dist/presentation.d.ts +1 -1
- package/dist/presentation.d.ts.map +1 -1
- package/dist/presentation.js +1 -0
- package/dist/presentation.js.map +1 -1
- package/dist/presentation.test.js.map +1 -1
- package/dist/serializer.d.ts +5 -0
- package/dist/serializer.d.ts.map +1 -1
- package/dist/serializer.js +7 -11
- package/dist/serializer.js.map +1 -1
- package/dist/timeout.js.map +1 -1
- package/dist/zones.d.ts +1 -1
- package/dist/zones.d.ts.map +1 -1
- package/dist/zones.js +5 -2
- package/dist/zones.js.map +1 -1
- package/dist.esm/cache.d.ts +2 -2
- package/dist.esm/cache.d.ts.map +1 -1
- package/dist.esm/cache.js +2 -1
- package/dist.esm/cache.js.map +1 -1
- package/dist.esm/cache.test.js.map +1 -1
- package/dist.esm/clone.d.ts +5 -2
- package/dist.esm/clone.d.ts.map +1 -1
- package/dist.esm/clone.js +4 -6
- package/dist.esm/clone.js.map +1 -1
- package/dist.esm/colors.d.ts +2 -56
- package/dist.esm/colors.d.ts.map +1 -1
- package/dist.esm/colors.js +3 -8
- package/dist.esm/colors.js.map +1 -1
- package/dist.esm/console.d.ts +0 -8
- package/dist.esm/console.d.ts.map +1 -1
- package/dist.esm/console.js.map +1 -1
- package/dist.esm/constructor.d.ts.map +1 -1
- package/dist.esm/decorators.d.ts.map +1 -1
- package/dist.esm/decorators.js +1 -1
- package/dist.esm/decorators.js.map +1 -1
- package/dist.esm/errors.d.ts +8 -6
- package/dist.esm/errors.d.ts.map +1 -1
- package/dist.esm/errors.js.map +1 -1
- package/dist.esm/lazy-promise.d.ts +1 -1
- package/dist.esm/lazy-promise.d.ts.map +1 -1
- package/dist.esm/lazy-promise.js.map +1 -1
- package/dist.esm/locks.d.ts +3 -3
- package/dist.esm/locks.d.ts.map +1 -1
- package/dist.esm/locks.js.map +1 -1
- package/dist.esm/object-entries-typed.d.ts +3 -0
- package/dist.esm/object-entries-typed.d.ts.map +1 -0
- package/dist.esm/object-entries-typed.js +7 -0
- package/dist.esm/object-entries-typed.js.map +1 -0
- package/dist.esm/presentation.d.ts +1 -1
- package/dist.esm/presentation.d.ts.map +1 -1
- package/dist.esm/presentation.js +1 -0
- package/dist.esm/presentation.js.map +1 -1
- package/dist.esm/presentation.test.js.map +1 -1
- package/dist.esm/serializer.d.ts +5 -0
- package/dist.esm/serializer.d.ts.map +1 -1
- package/dist.esm/serializer.js +7 -11
- package/dist.esm/serializer.js.map +1 -1
- package/dist.esm/timeout.js.map +1 -1
- package/dist.esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist.esm/zones.d.ts +1 -1
- package/dist.esm/zones.d.ts.map +1 -1
- package/dist.esm/zones.js +5 -2
- package/dist.esm/zones.js.map +1 -1
- package/package.json +2 -2
- package/src/cache.test.ts +2 -2
- package/src/cache.ts +25 -24
- package/src/clone.ts +20 -9
- package/src/colors.ts +16 -19
- package/src/console.ts +8 -17
- package/src/constructor.ts +1 -1
- package/src/decorators.ts +1 -1
- package/src/errors.ts +30 -30
- package/src/lazy-promise.ts +4 -4
- package/src/locks.ts +3 -3
- package/src/object-entries-typed.ts +7 -0
- package/src/presentation.test.ts +9 -9
- package/src/presentation.ts +30 -30
- package/src/serializer.ts +17 -6
- package/src/timeout.ts +1 -1
- package/src/zones.ts +23 -23
- package/tsconfig.tsbuildinfo +1 -1
package/dist.esm/serializer.js
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
* Prepare an object for serialization by removing any fields which are undefined
|
|
3
|
-
* or functions and return the result. The operation is recursive across all subobjects.
|
|
4
|
-
* The original object is not modified.
|
|
5
|
-
*
|
|
6
|
-
* @param data
|
|
7
|
-
*/
|
|
1
|
+
import { objectEntriesTyped } from "./object-entries-typed";
|
|
8
2
|
export function prepareForSerialization(data) {
|
|
9
3
|
if (data === undefined || data === null)
|
|
10
|
-
return
|
|
11
|
-
if (data
|
|
12
|
-
data = data
|
|
4
|
+
return data;
|
|
5
|
+
if (data.toJSON)
|
|
6
|
+
data = data.toJSON();
|
|
7
|
+
if (data === undefined || data === null)
|
|
8
|
+
return data;
|
|
13
9
|
if (typeof data !== 'object')
|
|
14
10
|
return data;
|
|
15
|
-
return
|
|
11
|
+
return objectEntriesTyped(data)
|
|
16
12
|
.filter(x => x[1] !== undefined)
|
|
17
13
|
.filter(x => typeof x[1] !== 'function')
|
|
18
14
|
.map(x => [x[0], prepareForSerialization(x[1])])
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAe5D,MAAM,UAAU,uBAAuB,CAAI,IAA2B;IAClE,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QACnC,OAAO,IAAI,CAAC;IAEhB,IAAK,IAAY,CAAC,MAAM;QACpB,IAAI,GAAI,IAAY,CAAC,MAAM,EAAE,CAAC;IAElC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QACnC,OAAO,IAAI,CAAC;IAEhB,IAAI,OAAO,IAAI,KAAK,QAAQ;QACxB,OAAO,IAAI,CAAC;IAEhB,OAAO,kBAAkB,CAAC,IAAI,CAAC;SACtB,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC;SAC/B,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC;SACvC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAU,CAAC;SACxD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,EAAK,EAAE,CAAC,CAClD;AACL,CAAC"}
|
package/dist.esm/timeout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../src/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB,CAAC;IACxC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC5C,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAa;IACrC,IAAI,
|
|
1
|
+
{"version":3,"file":"timeout.js","sourceRoot":"","sources":["../src/timeout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG7C;;;GAGG;AACH,MAAM,UAAU,OAAO,CAAC,OAAgB,CAAC;IACxC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC5C,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAa;IACrC,IAAI,QAAa,CAAC;IAClB,OAAO,WAAW,CAAC;QAClB,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC,QAAQ,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9D,IAAI,EAAE,GAAG,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC;KACnC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/base64.test.ts","../src/base64.ts","../src/cache.test.ts","../src/cache.ts","../src/check-native-async.ts","../src/clone.test.ts","../src/clone.ts","../src/coalesce.test.ts","../src/coalesce.ts","../src/colors.ts","../src/console.ts","../src/constructor.ts","../src/decorators.ts","../src/environment.ts","../src/errors.test.ts","../src/errors.ts","../src/get-param-names.ts","../src/index.ts","../src/is-constructor.test.ts","../src/is-constructor.ts","../src/lazy-promise.ts","../src/lazy-subject.ts","../src/locks.test.ts","../src/locks.ts","../src/padding.ts","../src/presentation.test.ts","../src/presentation.ts","../src/serializer.ts","../src/test.ts","../src/time.ts","../src/timeout.ts","../src/zones.ts"],"version":"5.9.3"}
|
|
1
|
+
{"root":["../src/base64.test.ts","../src/base64.ts","../src/cache.test.ts","../src/cache.ts","../src/check-native-async.ts","../src/clone.test.ts","../src/clone.ts","../src/coalesce.test.ts","../src/coalesce.ts","../src/colors.ts","../src/console.ts","../src/constructor.ts","../src/decorators.ts","../src/environment.ts","../src/errors.test.ts","../src/errors.ts","../src/get-param-names.ts","../src/index.ts","../src/is-constructor.test.ts","../src/is-constructor.ts","../src/lazy-promise.ts","../src/lazy-subject.ts","../src/locks.test.ts","../src/locks.ts","../src/object-entries-typed.ts","../src/padding.ts","../src/presentation.test.ts","../src/presentation.ts","../src/serializer.ts","../src/test.ts","../src/time.ts","../src/timeout.ts","../src/zones.ts"],"version":"5.9.3"}
|
package/dist.esm/zones.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export declare class AsyncZone {
|
|
|
38
38
|
get onStable(): Observable<void>;
|
|
39
39
|
get onError(): Observable<Error>;
|
|
40
40
|
checkStable(): void;
|
|
41
|
-
runOutside(runnable:
|
|
41
|
+
runOutside(runnable: Function): void;
|
|
42
42
|
invoke(callback: () => void): void;
|
|
43
43
|
private innerInvoke;
|
|
44
44
|
onEnter(): void;
|
package/dist.esm/zones.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zones.d.ts","sourceRoot":"","sources":["../src/zones.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,SAAS;gBACC,IAAI,
|
|
1
|
+
{"version":3,"file":"zones.d.ts","sourceRoot":"","sources":["../src/zones.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAW,MAAM,MAAM,CAAC;AAE3C;;;;GAIG;AACH,qBAAa,SAAS;gBACC,IAAI,EAAE,MAAM,EAAE,UAAU,GAAE,GAAQ;IAiDrD,OAAO,CAAC,2BAA2B,CAAc;IACjD,OAAO,CAAC,2BAA2B,CAAc;IAEjD,OAAO,CAAC,QAAQ,CAAO;IACvB,OAAO,CAAC,QAAQ,CAAa;IAC7B,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,QAAQ,CAAwC;IACxD,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,iBAAiB,CAAsC;IAC/D,OAAO,CAAC,SAAS,CAAsC;WAEzC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAW5D;;;;;;OAMG;IACH,IAAW,IAAI,IAAI,GAAG,CAErB;IAED,IAAW,gBAAgB,IAAI,UAAU,CAAC,IAAI,CAAC,CAE9C;IAED,IAAW,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC,CAEtC;IAED,IAAW,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAEtC;IAEM,WAAW;IAuBX,UAAU,CAAC,QAAQ,EAAE,QAAQ;IAI7B,MAAM,CAAC,QAAQ,EAAE,MAAM,IAAI;IAIlC,OAAO,CAAC,WAAW;IASZ,OAAO;IAIP,OAAO;CAGjB"}
|
package/dist.esm/zones.js
CHANGED
|
@@ -18,7 +18,10 @@ export class AsyncZone {
|
|
|
18
18
|
this._zonesWithPendingMicrotasks = [];
|
|
19
19
|
this._zonesWithPendingMacrotasks = [];
|
|
20
20
|
this._nesting = 0;
|
|
21
|
+
this._hasPendingMicrotasks = false;
|
|
22
|
+
this._hasPendingMacrotasks = false;
|
|
21
23
|
this._onError = new Subject();
|
|
24
|
+
this._isStable = false;
|
|
22
25
|
this._onMicrotaskEmpty = new Subject();
|
|
23
26
|
this._onStable = new Subject();
|
|
24
27
|
let self = this;
|
|
@@ -97,13 +100,13 @@ export class AsyncZone {
|
|
|
97
100
|
return;
|
|
98
101
|
try {
|
|
99
102
|
this._nesting++;
|
|
100
|
-
this._onMicrotaskEmpty.next(
|
|
103
|
+
this._onMicrotaskEmpty.next();
|
|
101
104
|
}
|
|
102
105
|
finally {
|
|
103
106
|
this._nesting--;
|
|
104
107
|
if (!this._hasPendingMicrotasks) {
|
|
105
108
|
try {
|
|
106
|
-
this.runOutside(() => this._onStable.next(
|
|
109
|
+
this.runOutside(() => this._onStable.next());
|
|
107
110
|
}
|
|
108
111
|
finally {
|
|
109
112
|
this._isStable = true;
|
package/dist.esm/zones.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zones.js","sourceRoot":"","sources":["../src/zones.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;AAEH,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAE3C;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAClB,YAAmB,
|
|
1
|
+
{"version":3,"file":"zones.js","sourceRoot":"","sources":["../src/zones.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;AAEH,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAE3C;;;;GAIG;AACH,MAAM,OAAO,SAAS;IAClB,YAAmB,IAAY,EAAE,aAAkB,EAAE;QAiD7C,gCAA2B,GAAW,EAAE,CAAC;QACzC,gCAA2B,GAAW,EAAE,CAAC;QAGzC,aAAQ,GAAW,CAAC,CAAC;QACrB,0BAAqB,GAAG,KAAK,CAAC;QAC9B,0BAAqB,GAAG,KAAK,CAAC;QAE9B,aAAQ,GAAmB,IAAI,OAAO,EAAS,CAAC;QAChD,cAAS,GAAG,KAAK,CAAC;QAClB,sBAAiB,GAAkB,IAAI,OAAO,EAAQ,CAAC;QACvD,cAAS,GAAkB,IAAI,OAAO,EAAQ,CAAC;QA3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;QAC9B,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,CAAC;IAEO,WAAW,CAAC,QAAoB;QACpC,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,CAAC;YACD,OAAO,QAAQ,EAAE,CAAC;QACtB,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;IACL,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;IACvB,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC;IACvB,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alterior/common",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.16.1",
|
|
4
4
|
"description": "Useful utilities for Typescript apps",
|
|
5
5
|
"author": "The Alterior Project (https://github.com/alterior-mvc)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
},
|
|
46
46
|
"gitHead": "87f31ea4078faaca53b45573c6a0013cdb40dd07",
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@types/node": "^20.19.
|
|
48
|
+
"@types/node": "^20.19.41"
|
|
49
49
|
}
|
|
50
50
|
}
|
package/src/cache.test.ts
CHANGED
|
@@ -32,7 +32,7 @@ describe('Cache', () => {
|
|
|
32
32
|
expect(value2).to.equal('bar');
|
|
33
33
|
});
|
|
34
34
|
it('caches null correctly', async () => {
|
|
35
|
-
let cache = new Cache<string>(1000, 1000);
|
|
35
|
+
let cache = new Cache<string | null>(1000, 1000);
|
|
36
36
|
let value1 = await cache.fetch('foo', async () => null, { timeToLive: 1000 });
|
|
37
37
|
let value2 = await cache.fetch('foo', async () => 'bar');
|
|
38
38
|
|
|
@@ -40,7 +40,7 @@ describe('Cache', () => {
|
|
|
40
40
|
expect(value2).to.be.null;
|
|
41
41
|
});
|
|
42
42
|
it('caches undefined correctly', async () => {
|
|
43
|
-
let cache = new Cache<string>(1000, 1000);
|
|
43
|
+
let cache = new Cache<string | undefined>(1000, 1000);
|
|
44
44
|
let value1 = await cache.fetch('foo', async () => undefined, { timeToLive: 1000 });
|
|
45
45
|
let value2 = await cache.fetch('foo', async () => 'bar');
|
|
46
46
|
|
package/src/cache.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { deepClone } from "./clone";
|
|
2
2
|
|
|
3
3
|
interface CacheEntry<T> {
|
|
4
|
-
key
|
|
5
|
-
time
|
|
6
|
-
expiresAt
|
|
7
|
-
lastFetched
|
|
8
|
-
value
|
|
4
|
+
key: string;
|
|
5
|
+
time: number;
|
|
6
|
+
expiresAt: number;
|
|
7
|
+
lastFetched: number;
|
|
8
|
+
value: T;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
interface CacheMap<T> {
|
|
12
|
-
[s
|
|
12
|
+
[s: string]: CacheEntry<T>;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
interface CacheFetcher<T> {
|
|
@@ -20,7 +20,7 @@ interface FetchOptions {
|
|
|
20
20
|
/**
|
|
21
21
|
* The time to live to set for a fulfilled item
|
|
22
22
|
*/
|
|
23
|
-
timeToLive
|
|
23
|
+
timeToLive?: number;
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* What kind of cache miss strategy should be used here.
|
|
@@ -30,7 +30,7 @@ interface FetchOptions {
|
|
|
30
30
|
* If the cache misses due to an expired value, return the expired (stale) value
|
|
31
31
|
* and call the fetcher to update the value in the background.
|
|
32
32
|
*/
|
|
33
|
-
missStrategy
|
|
33
|
+
missStrategy?: "fulfill" | "stale-revalidate";
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/**
|
|
@@ -42,10 +42,10 @@ export class Cache<T> {
|
|
|
42
42
|
* @param timeToLive Time a cached item should live before expiring, in milliseconds
|
|
43
43
|
* @param maxItems Amount of items that can be held in the cache maximum.
|
|
44
44
|
*/
|
|
45
|
-
public constructor(private timeToLive
|
|
45
|
+
public constructor(private timeToLive: number, private maxItems: number) {
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
private entries
|
|
48
|
+
private entries: CacheMap<T> = {};
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Cache cleanup routine run whenever a value is stored in the cache
|
|
@@ -67,14 +67,15 @@ export class Cache<T> {
|
|
|
67
67
|
|
|
68
68
|
while (itemCount > this.maxItems) {
|
|
69
69
|
let entry = this.getOldestEntry();
|
|
70
|
-
|
|
70
|
+
if (entry)
|
|
71
|
+
delete this.entries[entry.key];
|
|
71
72
|
--itemCount;
|
|
72
73
|
}
|
|
73
74
|
}, 100);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
public getOldestEntry() {
|
|
77
|
-
let selectedEntry
|
|
78
|
+
let selectedEntry: CacheEntry<T> | null = null;
|
|
78
79
|
for (let key in this.entries) {
|
|
79
80
|
let entry = this.entries[key];
|
|
80
81
|
|
|
@@ -94,15 +95,15 @@ export class Cache<T> {
|
|
|
94
95
|
* @param value The value to cache
|
|
95
96
|
* @param timeToLive How long the value should remain valid for before revalidation
|
|
96
97
|
*/
|
|
97
|
-
public insertItem(key
|
|
98
|
+
public insertItem(key: string, value: T, timeToLive?: number) {
|
|
98
99
|
if (timeToLive === undefined)
|
|
99
100
|
timeToLive = this.timeToLive;
|
|
100
101
|
|
|
101
102
|
// Compute the value
|
|
102
103
|
let now = new Date().getTime();
|
|
103
|
-
let entry = this.entries[key] = {
|
|
104
|
+
let entry = this.entries[key] = {
|
|
104
105
|
key,
|
|
105
|
-
time: now,
|
|
106
|
+
time: now,
|
|
106
107
|
expiresAt: now + timeToLive,
|
|
107
108
|
lastFetched: now,
|
|
108
109
|
value: deepClone(value)
|
|
@@ -119,7 +120,7 @@ export class Cache<T> {
|
|
|
119
120
|
*
|
|
120
121
|
* @param key The key to get
|
|
121
122
|
*/
|
|
122
|
-
public get(key
|
|
123
|
+
public get(key: string): T | undefined {
|
|
123
124
|
let entry = this.entries[key];
|
|
124
125
|
return entry ? deepClone(entry.value) : undefined;
|
|
125
126
|
}
|
|
@@ -128,7 +129,7 @@ export class Cache<T> {
|
|
|
128
129
|
* Get the cache entry for the given key.
|
|
129
130
|
* @param key The key to get
|
|
130
131
|
*/
|
|
131
|
-
public getEntry(key
|
|
132
|
+
public getEntry(key: string): CacheEntry<T> {
|
|
132
133
|
return this.entries[key];
|
|
133
134
|
}
|
|
134
135
|
|
|
@@ -147,32 +148,32 @@ export class Cache<T> {
|
|
|
147
148
|
* @param fetcher A function to define the value of the key if a cache miss occurs
|
|
148
149
|
* @param options Options for doing the caching.
|
|
149
150
|
*/
|
|
150
|
-
public async fetch(key
|
|
151
|
+
public async fetch(key: string, fetcher?: CacheFetcher<T>, options: FetchOptions = {}): Promise<T> {
|
|
151
152
|
let existingFetch = this.outstandingFetches.get(key);
|
|
152
153
|
if (existingFetch)
|
|
153
154
|
return await existingFetch;
|
|
154
155
|
|
|
155
|
-
let entry
|
|
156
|
+
let entry: CacheEntry<T> | undefined;
|
|
156
157
|
let now = Date.now();
|
|
157
158
|
let stale = true;
|
|
158
|
-
|
|
159
|
+
|
|
159
160
|
if (key in this.entries) {
|
|
160
161
|
entry = this.entries[key];
|
|
161
162
|
stale = entry.expiresAt < now;
|
|
162
163
|
}
|
|
163
|
-
|
|
164
|
+
|
|
164
165
|
if (!options.missStrategy)
|
|
165
166
|
options.missStrategy = 'fulfill';
|
|
166
|
-
|
|
167
|
+
|
|
167
168
|
if (options.missStrategy === 'fulfill')
|
|
168
169
|
entry = stale ? undefined : entry;
|
|
169
170
|
|
|
170
|
-
let fetchOperation
|
|
171
|
+
let fetchOperation: Promise<any> | undefined;
|
|
171
172
|
|
|
172
173
|
if (stale && fetcher) {
|
|
173
174
|
fetchOperation = new Promise(async (resolve, reject) => {
|
|
174
175
|
// Fetch!
|
|
175
|
-
let value
|
|
176
|
+
let value: T;
|
|
176
177
|
try {
|
|
177
178
|
value = await fetcher();
|
|
178
179
|
|
package/src/clone.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
2
|
* Perform a shallow clone of the object, producing one that has the
|
|
4
3
|
* same constructor chain and prototype as the passed object.
|
|
@@ -27,13 +26,20 @@ export function clone<T = any>(obj : T): T {
|
|
|
27
26
|
*
|
|
28
27
|
* @param o
|
|
29
28
|
*/
|
|
30
|
-
export function deepClone(o) {
|
|
29
|
+
export function deepClone<T>(o: T): T {
|
|
30
|
+
if (typeof structuredClone === 'function')
|
|
31
|
+
return structuredClone(o);
|
|
31
32
|
return deepCloneWithMemoization(o, new WeakMap());
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
function deepCloneWithMemoization(o, memo : WeakMap<any, any>)
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
function deepCloneWithMemoization<T>(o: T, memo : WeakMap<any, any>): T;
|
|
36
|
+
function deepCloneWithMemoization<T>(o: T | null, memo : WeakMap<any, any>): T | null;
|
|
37
|
+
function deepCloneWithMemoization<T>(o: T | undefined, memo : WeakMap<any, any>): T | undefined;
|
|
38
|
+
function deepCloneWithMemoization<T>(o: T | null | undefined, memo : WeakMap<any, any>): T | null | undefined;
|
|
39
|
+
function deepCloneWithMemoization<T>(o: T | null | undefined, memo : WeakMap<any, any>): T | null | undefined {
|
|
40
|
+
if (o === null || o === undefined || typeof o !== 'object')
|
|
41
|
+
return o;
|
|
42
|
+
|
|
37
43
|
if (!Array.isArray(o) && typeof o !== 'object')
|
|
38
44
|
return o;
|
|
39
45
|
|
|
@@ -46,17 +52,22 @@ function deepCloneWithMemoization(o, memo : WeakMap<any, any>) {
|
|
|
46
52
|
memo.set(o, output);
|
|
47
53
|
|
|
48
54
|
for (key in o) {
|
|
49
|
-
v = o[key];
|
|
50
|
-
output[key] = (typeof v === 'object') ? deepCloneWithMemoization(v, memo) : v;
|
|
55
|
+
v = (o as any)[key];
|
|
56
|
+
(output as any)[key] = (typeof v === 'object') ? deepCloneWithMemoization(v, memo) : v;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
return output;
|
|
59
|
+
return output as T;
|
|
54
60
|
}
|
|
61
|
+
|
|
55
62
|
/**
|
|
56
63
|
* Clone the value by serializing it to JSON and back.
|
|
57
64
|
* @param obj
|
|
58
65
|
*/
|
|
59
|
-
export function cloneBySerialization(obj)
|
|
66
|
+
export function cloneBySerialization<T>(obj: T): T;
|
|
67
|
+
export function cloneBySerialization<T>(obj: T | null): T | null;
|
|
68
|
+
export function cloneBySerialization<T>(obj: T | undefined): T | undefined;
|
|
69
|
+
export function cloneBySerialization<T>(obj: T | null | undefined): T | null | undefined;
|
|
70
|
+
export function cloneBySerialization<T>(obj: T | null | undefined): T | null | undefined {
|
|
60
71
|
if (obj === undefined || obj === null || typeof obj !== 'object')
|
|
61
72
|
return obj;
|
|
62
73
|
|
package/src/colors.ts
CHANGED
|
@@ -20,9 +20,11 @@
|
|
|
20
20
|
* THE SOFTWARE.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
import { objectEntriesTyped, objectKeysTyped } from "./object-entries-typed";
|
|
24
|
+
|
|
25
|
+
export const CONSOLE_COLORS: Record<string, [number, number]> = {
|
|
24
26
|
reset: [0, 0],
|
|
25
|
-
|
|
27
|
+
|
|
26
28
|
bold: [1, 22],
|
|
27
29
|
dim: [2, 22],
|
|
28
30
|
italic: [3, 23],
|
|
@@ -30,7 +32,7 @@ export const CONSOLE_COLORS = {
|
|
|
30
32
|
inverse: [7, 27],
|
|
31
33
|
hidden: [8, 28],
|
|
32
34
|
strikethrough: [9, 29],
|
|
33
|
-
|
|
35
|
+
|
|
34
36
|
black: [30, 39],
|
|
35
37
|
red: [31, 39],
|
|
36
38
|
green: [32, 39],
|
|
@@ -41,7 +43,7 @@ export const CONSOLE_COLORS = {
|
|
|
41
43
|
white: [37, 39],
|
|
42
44
|
gray: [90, 39],
|
|
43
45
|
grey: [90, 39],
|
|
44
|
-
|
|
46
|
+
|
|
45
47
|
bgBlack: [40, 49],
|
|
46
48
|
bgRed: [41, 49],
|
|
47
49
|
bgGreen: [42, 49],
|
|
@@ -50,24 +52,19 @@ export const CONSOLE_COLORS = {
|
|
|
50
52
|
bgMagenta: [45, 49],
|
|
51
53
|
bgCyan: [46, 49],
|
|
52
54
|
bgWhite: [47, 49],
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export type ColorLibrary<T> = {
|
|
56
|
-
[K in keyof T] : (message : string) => string;
|
|
57
55
|
};
|
|
58
56
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
Object.keys(codes).forEach(function(key) {
|
|
63
|
-
let val = codes[key];
|
|
64
|
-
let open = '\u001b[' + val[0] + 'm';
|
|
65
|
-
let close = '\u001b[' + val[1] + 'm';
|
|
66
|
-
|
|
67
|
-
library[key] = (message : string) => `${open}${message}${close}`;
|
|
68
|
-
});
|
|
57
|
+
export type ColorLibrary<T> = {
|
|
58
|
+
[K in keyof T]: (message: string) => string;
|
|
59
|
+
};
|
|
69
60
|
|
|
70
|
-
|
|
61
|
+
function objectLibrary<T extends Record<string, [number, number]>>(codes: T): ColorLibrary<T> {
|
|
62
|
+
return Object.fromEntries(
|
|
63
|
+
objectEntriesTyped(codes)
|
|
64
|
+
.map(
|
|
65
|
+
([key, [start, end]]) => [key, (message: string) => `\u001b[${start}m${message}\u001b[${end}m`]
|
|
66
|
+
)
|
|
67
|
+
) as ColorLibrary<T>;
|
|
71
68
|
}
|
|
72
69
|
|
|
73
70
|
/**
|
package/src/console.ts
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
|
|
2
|
-
export interface Console {
|
|
3
|
-
log(...args : any[]);
|
|
4
|
-
info(...args : any[]);
|
|
5
|
-
warn(...args : any[]);
|
|
6
|
-
error(...args : any[]);
|
|
7
|
-
debug(...args : any[]);
|
|
8
|
-
dir(...args : any[]);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
2
|
/**
|
|
12
3
|
* Intercept console messages emitted within the given function, allowing you to programmatically call the underlying raw console implementation (or not).
|
|
13
4
|
*
|
|
14
5
|
* @param handler
|
|
15
6
|
* @param callback
|
|
16
7
|
*/
|
|
17
|
-
export function interceptConsole(handler
|
|
18
|
-
let methods = [
|
|
8
|
+
export function interceptConsole(handler: (method: string, originalImpl: Function, console: Console, args: any[]) => void, callback: Function) {
|
|
9
|
+
let methods = ['log', 'info', 'warn', 'error', 'debug', 'dir'] as const;
|
|
10
|
+
|
|
11
|
+
let rawConsole: Console = {} as any;
|
|
12
|
+
let origConsole: Console = {} as any;
|
|
19
13
|
|
|
20
|
-
let rawConsole : Console = {} as any;
|
|
21
|
-
let origConsole = {};
|
|
22
|
-
|
|
23
14
|
for (let method of methods) {
|
|
24
15
|
origConsole[method] = console[method];
|
|
25
16
|
rawConsole[method] = (console[method] || console.log).bind(console);
|
|
26
|
-
console[method] = function() {
|
|
17
|
+
console[method] = function () {
|
|
27
18
|
handler(method, rawConsole[method], rawConsole, Array.from(arguments));
|
|
28
19
|
};
|
|
29
20
|
}
|
|
@@ -43,7 +34,7 @@ export function interceptConsole(handler : (method : string, originalImpl : Func
|
|
|
43
34
|
* @param spaces
|
|
44
35
|
* @param callback
|
|
45
36
|
*/
|
|
46
|
-
export function indentConsole(spaces
|
|
37
|
+
export function indentConsole(spaces: number, callback: Function) {
|
|
47
38
|
let indent = Array(spaces).join(' ');
|
|
48
39
|
|
|
49
40
|
return interceptConsole((method, original, console, args) => {
|
|
@@ -62,7 +53,7 @@ export function indentConsole(spaces : number, callback : Function) {
|
|
|
62
53
|
* @param formatter
|
|
63
54
|
* @param callback
|
|
64
55
|
*/
|
|
65
|
-
export function formatConsole(formatter
|
|
56
|
+
export function formatConsole(formatter: (message: string) => string, callback: Function) {
|
|
66
57
|
return interceptConsole((method, original, console, args) => {
|
|
67
58
|
if (method == 'dir') {
|
|
68
59
|
original(...args);
|
package/src/constructor.ts
CHANGED
package/src/decorators.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
3
|
export class BaseError extends Error {
|
|
4
|
-
constructor(message
|
|
4
|
+
constructor(message: string, options?: any) {
|
|
5
5
|
super(message, options);
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
static serializer
|
|
9
|
-
static setJSONSerializer(serializer
|
|
8
|
+
static serializer: (instance: any) => any;
|
|
9
|
+
static setJSONSerializer(serializer: (instance: any) => any) {
|
|
10
10
|
this.serializer = serializer;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
asJSON() {
|
|
14
14
|
if (BaseError.serializer)
|
|
15
15
|
return BaseError.serializer(this);
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
let ownKeys = Object.getOwnPropertyNames(this);
|
|
18
18
|
let repr = {
|
|
19
19
|
$type: this.constructor.name,
|
|
@@ -21,13 +21,13 @@ export class BaseError extends Error {
|
|
|
21
21
|
message: this.message,
|
|
22
22
|
stack: this['stack']
|
|
23
23
|
};
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
let includedData = ownKeys
|
|
26
26
|
.filter(x => !x.startsWith('_'))
|
|
27
|
-
.filter(x => typeof this[x] !== 'function')
|
|
28
|
-
.map(x => [x, this[x]])
|
|
29
|
-
.reduce((pv, cv) => pv[cv[0]] = cv[1], {})
|
|
30
|
-
|
|
27
|
+
.filter(x => typeof (this as any)[x] !== 'function')
|
|
28
|
+
.map(x => [x, (this as any)[x]])
|
|
29
|
+
.reduce((pv, cv) => (pv as any)[cv[0]] = cv[1], {})
|
|
30
|
+
;
|
|
31
31
|
|
|
32
32
|
return Object.assign({}, repr, includedData);
|
|
33
33
|
}
|
|
@@ -46,24 +46,24 @@ export class ApplicationError extends BaseError {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export class ArgumentError<ValueT = any> extends SystemError {
|
|
49
|
-
constructor(argumentName
|
|
49
|
+
constructor(argumentName: string, message?: string) {
|
|
50
50
|
super(message || `Invalid value for argument ${argumentName}`);
|
|
51
51
|
this._argumentName = argumentName;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
private _argumentName
|
|
55
|
-
private _value
|
|
54
|
+
private _argumentName: string;
|
|
55
|
+
private _value?: ValueT;
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* The invalid value passed for the given argument
|
|
59
59
|
*/
|
|
60
|
-
get value(): ValueT {
|
|
60
|
+
get value(): ValueT | undefined {
|
|
61
61
|
return this._value;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
withValue(value
|
|
64
|
+
withValue(value: ValueT): this & { value: ValueT } {
|
|
65
65
|
this._value = value;
|
|
66
|
-
return this;
|
|
66
|
+
return this as this & { value: ValueT };
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
/**
|
|
@@ -75,73 +75,73 @@ export class ArgumentError<ValueT = any> extends SystemError {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export class ArgumentNullError<ValueT = any> extends ArgumentError<ValueT> {
|
|
78
|
-
constructor(argumentName
|
|
78
|
+
constructor(argumentName: string, message?: string) {
|
|
79
79
|
super(argumentName, message || `Argument ${argumentName} cannot be null`);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
export class ArgumentOutOfRangeError<ValueT = any> extends ArgumentError<ValueT> {
|
|
84
|
-
constructor(argumentName
|
|
84
|
+
constructor(argumentName: string, message?: string) {
|
|
85
85
|
super(argumentName, message || `Argument ${argumentName} is out of range`);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
export class NotSupportedError extends SystemError {
|
|
90
|
-
constructor(message
|
|
90
|
+
constructor(message?: string) {
|
|
91
91
|
super(message || `The requested operation is not supported.`);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export class NotImplementedError extends SystemError {
|
|
96
|
-
constructor(message
|
|
96
|
+
constructor(message?: string) {
|
|
97
97
|
super(message || `The requested operation is not implemented.`);
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export class OperationCanceledError extends SystemError {
|
|
102
|
-
constructor(message
|
|
102
|
+
constructor(message?: string) {
|
|
103
103
|
super(message || `The requested operation is not implemented.`);
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
export class TimeoutError extends SystemError {
|
|
108
|
-
constructor(message
|
|
108
|
+
constructor(message?: string) {
|
|
109
109
|
super(message || `The operation has timed out.`);
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
export class IOError extends SystemError {
|
|
114
|
-
constructor(message
|
|
114
|
+
constructor(message?: string) {
|
|
115
115
|
super(message || `An I/O error has occurred.`);
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
export class FormatError extends SystemError {
|
|
120
|
-
constructor(message
|
|
120
|
+
constructor(message?: string) {
|
|
121
121
|
super(message || `Invalid format.`);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
export class InvalidOperationError extends SystemError {
|
|
126
|
-
constructor(message
|
|
126
|
+
constructor(message?: string) {
|
|
127
127
|
super(message || `Invalid format.`);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
export class AccessDeniedError extends SystemError {
|
|
132
|
-
constructor(message
|
|
132
|
+
constructor(message?: string) {
|
|
133
133
|
super(message || `Invalid format.`);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
export class HttpError extends Error {
|
|
138
|
-
|
|
139
|
-
public statusCode
|
|
140
|
-
public body
|
|
141
|
-
public headers
|
|
138
|
+
constructor(
|
|
139
|
+
public statusCode: number,
|
|
140
|
+
public body?: any,
|
|
141
|
+
public headers?: string[][]
|
|
142
142
|
) {
|
|
143
143
|
super(`HttpError statusCode=${statusCode} [are you sure you meant to catch this?]`);
|
|
144
144
|
this.body ??= { status: statusCode };
|
|
145
145
|
this.headers ??= [];
|
|
146
|
-
|
|
146
|
+
}
|
|
147
147
|
}
|