@furystack/utils 4.0.0 → 4.0.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/esm/debounce.js +19 -0
- package/esm/debounce.js.map +1 -0
- package/esm/deep-merge.js +29 -0
- package/esm/deep-merge.js.map +1 -0
- package/esm/disposable.js +56 -0
- package/esm/disposable.js.map +1 -0
- package/esm/index.js +11 -0
- package/esm/index.js.map +1 -0
- package/esm/observable-value.js +109 -0
- package/esm/observable-value.js.map +1 -0
- package/esm/path-helper.js +66 -0
- package/esm/path-helper.js.map +1 -0
- package/esm/sleep-async.js +8 -0
- package/esm/sleep-async.js.map +1 -0
- package/esm/sort-by.js +15 -0
- package/esm/sort-by.js.map +1 -0
- package/esm/trace.js +127 -0
- package/esm/trace.js.map +1 -0
- package/esm/tuple.js +7 -0
- package/esm/tuple.js.map +1 -0
- package/esm/value-observer.js +40 -0
- package/esm/value-observer.js.map +1 -0
- package/package.json +2 -2
package/esm/debounce.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param method The method that should be debounced
|
|
3
|
+
* @param debounceMs The timeout in millisecs
|
|
4
|
+
* @returns a method that wraps the original one with an async debounce
|
|
5
|
+
*/
|
|
6
|
+
export const debounce = (method, debounceMs = 250) => {
|
|
7
|
+
let timeout;
|
|
8
|
+
return ((...args) => {
|
|
9
|
+
if (timeout) {
|
|
10
|
+
clearTimeout(timeout);
|
|
11
|
+
}
|
|
12
|
+
timeout = setTimeout(() => {
|
|
13
|
+
method(...args);
|
|
14
|
+
timeout ?? clearTimeout(timeout);
|
|
15
|
+
timeout = undefined;
|
|
16
|
+
}, debounceMs);
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=debounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.js","sourceRoot":"","sources":["../src/debounce.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAoC,MAAoC,EAAE,UAAU,GAAG,GAAG,EAAE,EAAE;IACpH,IAAI,OAAkD,CAAA;IACtD,OAAO,CAAC,CAAC,GAAG,IAAW,EAAE,EAAE;QACzB,IAAI,OAAO,EAAE;YACX,YAAY,CAAC,OAAO,CAAC,CAAA;SACtB;QACD,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;YACxB,MAAM,CAAC,GAAG,IAAI,CAAC,CAAA;YACf,OAAO,IAAI,YAAY,CAAC,OAAO,CAAC,CAAA;YAChC,OAAO,GAAG,SAAS,CAAA;QACrB,CAAC,EAAE,UAAU,CAAC,CAAA;IAChB,CAAC,CAAiC,CAAA;AACpC,CAAC,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deep merge two objects.
|
|
3
|
+
* @param target The source object to be merged
|
|
4
|
+
* @param sources The source objects
|
|
5
|
+
* @returns A new instance with the merged values
|
|
6
|
+
*/
|
|
7
|
+
export const deepMerge = (target, ...sources) => {
|
|
8
|
+
if (!sources.length) {
|
|
9
|
+
return target;
|
|
10
|
+
}
|
|
11
|
+
const merged = { ...target };
|
|
12
|
+
for (const source of sources) {
|
|
13
|
+
if (!source) {
|
|
14
|
+
continue;
|
|
15
|
+
}
|
|
16
|
+
const keys = Object.keys(source);
|
|
17
|
+
for (const key of keys) {
|
|
18
|
+
if (!(source[key] instanceof Array) && typeof source[key] === 'object' && typeof target[key] === 'object') {
|
|
19
|
+
merged[key] = deepMerge(target[key], source[key]);
|
|
20
|
+
}
|
|
21
|
+
else if (source[key] !== undefined) {
|
|
22
|
+
;
|
|
23
|
+
merged[key] = source[key];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return merged;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=deep-merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deep-merge.js","sourceRoot":"","sources":["../src/deep-merge.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAI,MAAS,EAAE,GAAG,OAA0C,EAAE,EAAE;IACvF,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;QACnB,OAAO,MAAM,CAAA;KACd;IACD,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,EAAE,CAAA;IAC5B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,IAAI,CAAC,MAAM,EAAE;YACX,SAAQ;SACT;QACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAmB,CAAA;QAClD,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE;YACtB,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,YAAY,KAAK,CAAC,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,IAAI,OAAO,MAAM,CAAC,GAAG,CAAC,KAAK,QAAQ,EAAE;gBACzG,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;aAClD;iBAAM,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,EAAE;gBACpC,CAAC;gBAAC,MAAM,CAAC,GAAG,CAAS,GAAG,MAAM,CAAC,GAAG,CAAC,CAAA;aACpC;SACF;KACF;IACD,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* You can implement *IDisposable* resources and use them with a *using()* or *usingAsync()* syntax.
|
|
4
|
+
*
|
|
5
|
+
* Usage example:
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* class Resource implements IDisposable{
|
|
9
|
+
* dispose(){
|
|
10
|
+
* // cleanup logics
|
|
11
|
+
* }
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* using(new Resource(), (resource)=>{
|
|
16
|
+
* // do something with the resource
|
|
17
|
+
* })
|
|
18
|
+
*
|
|
19
|
+
* usingAsync(new Resource(), async (resource)=>{
|
|
20
|
+
* // do something with the resource, allows awaiting promises
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
/** */
|
|
25
|
+
/**
|
|
26
|
+
* Method that accepts an IDisposable resource that will be disposed after the callback
|
|
27
|
+
* @param resource The resource that is used in the callback and will be disposed afterwards
|
|
28
|
+
* @param callback The callback that will be executed synchrounously before the resource will be disposed
|
|
29
|
+
* @returns the value that will be returned by the callback method
|
|
30
|
+
*/
|
|
31
|
+
export const using = (resource, callback) => {
|
|
32
|
+
try {
|
|
33
|
+
return callback(resource);
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
resource.dispose();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Method that accepts an IDisposable resource that will be disposed after the callback
|
|
41
|
+
* @param resource The resource that is used in the callback and will be disposed afterwards
|
|
42
|
+
* @param callback The callback that will be executed asynchrounously before the resource will be disposed
|
|
43
|
+
* @returns A promise that will be resolved with a return value after the resource is disposed
|
|
44
|
+
*/
|
|
45
|
+
export const usingAsync = async (resource, callback) => {
|
|
46
|
+
try {
|
|
47
|
+
return await callback(resource);
|
|
48
|
+
}
|
|
49
|
+
finally {
|
|
50
|
+
const disposeResult = resource.dispose();
|
|
51
|
+
if (disposeResult instanceof Promise) {
|
|
52
|
+
await disposeResult;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=disposable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disposable.js","sourceRoot":"","sources":["../src/disposable.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM;AAaN;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAiC,QAAW,EAAE,QAA4B,EAAE,EAAE;IACjG,IAAI;QACF,OAAO,QAAQ,CAAC,QAAQ,CAAC,CAAA;KAC1B;YAAS;QACR,QAAQ,CAAC,OAAO,EAAE,CAAA;KACnB;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,QAAW,EACX,QAAqC,EACrC,EAAE;IACF,IAAI;QACF,OAAO,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAA;KAChC;YAAS;QACR,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAA;QACxC,IAAI,aAAa,YAAY,OAAO,EAAE;YACpC,MAAM,aAAa,CAAA;SACpB;KACF;AACH,CAAC,CAAA"}
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from './disposable';
|
|
2
|
+
export * from './deep-merge';
|
|
3
|
+
export * from './debounce';
|
|
4
|
+
export * from './observable-value';
|
|
5
|
+
export * from './value-observer';
|
|
6
|
+
export * from './path-helper';
|
|
7
|
+
export * from './sleep-async';
|
|
8
|
+
export * from './sort-by';
|
|
9
|
+
export * from './trace';
|
|
10
|
+
export * from './tuple';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { ValueObserver } from './value-observer';
|
|
2
|
+
/**
|
|
3
|
+
* Error thrown when you try to retrieve or set an observable value that is already disposed.
|
|
4
|
+
*/
|
|
5
|
+
export class ObservableAlreadyDisposedError extends Error {
|
|
6
|
+
constructor() {
|
|
7
|
+
super('Observable already disposed');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Defines an ObservableValue value object.
|
|
12
|
+
*
|
|
13
|
+
* You can set and get its value with it's *setValue()* and *getValue()* methods and you can subscribe to value changes with *subscribe()*
|
|
14
|
+
*
|
|
15
|
+
* Usage example:
|
|
16
|
+
* ```ts
|
|
17
|
+
* const observableValue = new ObservableValue<number>(0);
|
|
18
|
+
* const observer = observableValue.subscribe((newValue) => {
|
|
19
|
+
* console.log("Value changed:", newValue);
|
|
20
|
+
* });
|
|
21
|
+
* // To update the value
|
|
22
|
+
* observableValue.setValue(Math.random());
|
|
23
|
+
* // if you want to dispose a single observer
|
|
24
|
+
* observer.dispose();
|
|
25
|
+
* // if you want to dispose the whole observableValue with all of its observers:
|
|
26
|
+
* observableValue.dispose();
|
|
27
|
+
* ```
|
|
28
|
+
* @param T Generic argument to indicate the value type
|
|
29
|
+
*/
|
|
30
|
+
export class ObservableValue {
|
|
31
|
+
get isDisposed() {
|
|
32
|
+
return this._isDisposed;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Disposes the ObservableValue object, removes all observers
|
|
36
|
+
*/
|
|
37
|
+
dispose() {
|
|
38
|
+
this.observers.clear();
|
|
39
|
+
this._isDisposed = true;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Subscribes to a value changes
|
|
43
|
+
* @param callback The callback method that will be called on each change
|
|
44
|
+
* @param getLast Will call the callback with the last known value right after subscription
|
|
45
|
+
* @returns The ValueObserver instance
|
|
46
|
+
*/
|
|
47
|
+
subscribe(callback, getLast = false) {
|
|
48
|
+
if (this._isDisposed) {
|
|
49
|
+
throw new ObservableAlreadyDisposedError();
|
|
50
|
+
}
|
|
51
|
+
const observer = new ValueObserver(this, callback);
|
|
52
|
+
this.observers.add(observer);
|
|
53
|
+
if (getLast) {
|
|
54
|
+
callback(this.currentValue);
|
|
55
|
+
}
|
|
56
|
+
return observer;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The observer will unsubscribe from the Observable
|
|
60
|
+
* @param observer The ValueObserver instance
|
|
61
|
+
* @returns if unsubscribing was successfull
|
|
62
|
+
*/
|
|
63
|
+
unsubscribe(observer) {
|
|
64
|
+
return this.observers.delete(observer);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets the current Value
|
|
68
|
+
* @returns The current value
|
|
69
|
+
*/
|
|
70
|
+
getValue() {
|
|
71
|
+
if (this._isDisposed) {
|
|
72
|
+
throw new ObservableAlreadyDisposedError();
|
|
73
|
+
}
|
|
74
|
+
return this.currentValue;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Sets a new value and notifies the observers.
|
|
78
|
+
* @param newValue The new value to be set
|
|
79
|
+
*/
|
|
80
|
+
setValue(newValue) {
|
|
81
|
+
if (this._isDisposed) {
|
|
82
|
+
throw new ObservableAlreadyDisposedError();
|
|
83
|
+
}
|
|
84
|
+
if (this.currentValue !== newValue) {
|
|
85
|
+
this.currentValue = newValue;
|
|
86
|
+
for (const subscription of this.observers) {
|
|
87
|
+
subscription.callback(newValue);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Gets the observers
|
|
93
|
+
* @returns The subscribed observers
|
|
94
|
+
*/
|
|
95
|
+
getObservers() {
|
|
96
|
+
return [...this.observers];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* @param initialValue Optional initial value
|
|
100
|
+
*/
|
|
101
|
+
constructor(initialValue) {
|
|
102
|
+
this._isDisposed = false;
|
|
103
|
+
this.observers = new Set();
|
|
104
|
+
if (initialValue !== undefined) {
|
|
105
|
+
this.currentValue = initialValue;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=observable-value.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observable-value.js","sourceRoot":"","sources":["../src/observable-value.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACvD;QACE,KAAK,CAAC,6BAA6B,CAAC,CAAA;IACtC,CAAC;CACF;AAOD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,eAAe;IAC1B,IAAW,UAAU;QACnB,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAID;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAA;QACtB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAA;IACzB,CAAC;IAID;;;;;OAKG;IACI,SAAS,CAAC,QAAgC,EAAE,OAAO,GAAG,KAAK;QAChE,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,IAAI,8BAA8B,EAAE,CAAA;SAC3C;QACD,MAAM,QAAQ,GAAG,IAAI,aAAa,CAAI,IAAI,EAAE,QAAQ,CAAC,CAAA;QACrD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;QAC5B,IAAI,OAAO,EAAE;YACX,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;SAC5B;QACD,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED;;;;OAIG;IACI,WAAW,CAAC,QAA0B;QAC3C,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACxC,CAAC;IAED;;;OAGG;IACI,QAAQ;QACb,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,IAAI,8BAA8B,EAAE,CAAA;SAC3C;QACD,OAAO,IAAI,CAAC,YAAY,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACI,QAAQ,CAAC,QAAW;QACzB,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,MAAM,IAAI,8BAA8B,EAAE,CAAA;SAC3C;QACD,IAAI,IAAI,CAAC,YAAY,KAAK,QAAQ,EAAE;YAClC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAA;YAC5B,KAAK,MAAM,YAAY,IAAI,IAAI,CAAC,SAAS,EAAE;gBACzC,YAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;aAChC;SACF;IACH,CAAC;IAED;;;OAGG;IACI,YAAY;QACjB,OAAO,CAAC,GAAG,IAAI,CAAC,SAAS,CAAoC,CAAA;IAC/D,CAAC;IAED;;OAEG;IACH,YAAY,YAAgB;QA7EpB,gBAAW,GAAG,KAAK,CAAA;QASnB,cAAS,GAA0B,IAAI,GAAG,EAAE,CAAA;QAqElD,IAAI,YAAY,KAAK,SAAS,EAAE;YAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;SACjC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper class for path-related functions and methods
|
|
3
|
+
*
|
|
4
|
+
* The class contains general helper methods for joining, splitting, modifying and validating paths.
|
|
5
|
+
*/
|
|
6
|
+
export class PathHelper {
|
|
7
|
+
/**
|
|
8
|
+
* Trims the slash characters from the beginning and from the end of the path to avoid duplicated slashes
|
|
9
|
+
* @param {string} path The source path that should be trimmed
|
|
10
|
+
* @returns the trimmed path
|
|
11
|
+
*/
|
|
12
|
+
static trimSlashes(path) {
|
|
13
|
+
while (path.endsWith('/')) {
|
|
14
|
+
path = path.substring(0, path.length - 1);
|
|
15
|
+
}
|
|
16
|
+
while (path.startsWith('/')) {
|
|
17
|
+
path = path.substring(1, path.length);
|
|
18
|
+
}
|
|
19
|
+
return path;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Splits a full path into path segments,
|
|
23
|
+
* e.g.: /Root/Example/stuff
|
|
24
|
+
* @param path The path to be splitted
|
|
25
|
+
* @returns {string[]} the segments for the path
|
|
26
|
+
*/
|
|
27
|
+
static getSegments(path) {
|
|
28
|
+
return path.split('/').filter((segment) => segment && segment.length);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Method that allows to join paths without multiple or missing slashes
|
|
32
|
+
* @param args The list of the paths to join
|
|
33
|
+
* @returns the joined path string
|
|
34
|
+
*/
|
|
35
|
+
static joinPaths(...args) {
|
|
36
|
+
return args.map(this.trimSlashes).join('/');
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if the ancestorPath is really the ancestor of the descendantPath
|
|
40
|
+
* @param {string} ancestorPath the ancestor path
|
|
41
|
+
* @param {string} descendantPath the descendant path
|
|
42
|
+
* @returns {boolean} if the provided path is the ancestor of the descendant
|
|
43
|
+
*/
|
|
44
|
+
static isAncestorOf(ancestorPath, descendantPath) {
|
|
45
|
+
return descendantPath.indexOf(`${this.joinPaths(ancestorPath)}/`) === 0;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Returns the parent path from a specified path.
|
|
49
|
+
* e.g. "/Root/Example/Content" will return "/Root/Example"
|
|
50
|
+
*
|
|
51
|
+
* "Root" will always return "Root"
|
|
52
|
+
* @param path The content path
|
|
53
|
+
* @returns the parent path
|
|
54
|
+
*/
|
|
55
|
+
static getParentPath(path) {
|
|
56
|
+
const segments = this.getSegments(path);
|
|
57
|
+
if (segments.length > 1) {
|
|
58
|
+
segments.pop();
|
|
59
|
+
}
|
|
60
|
+
return segments.join('/');
|
|
61
|
+
}
|
|
62
|
+
static normalize(path) {
|
|
63
|
+
return this.getSegments(path).join('/');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=path-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-helper.js","sourceRoot":"","sources":["../src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CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IAC3B,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,IAAY;QAClC,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACzC,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a simple promise that will be resolved within a discrete timeout
|
|
3
|
+
* @param timeout The timeout in millisecs
|
|
4
|
+
*/
|
|
5
|
+
export const sleepAsync = (timeout = 250) => new Promise((resolve) => setTimeout(() => {
|
|
6
|
+
resolve();
|
|
7
|
+
}, timeout));
|
|
8
|
+
//# sourceMappingURL=sleep-async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sleep-async.js","sourceRoot":"","sources":["../src/sleep-async.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAO,GAAG,GAAG,EAAE,EAAE,CAC1C,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAC5B,UAAU,CAAC,GAAG,EAAE;IACd,OAAO,EAAE,CAAA;AACX,CAAC,EAAE,OAAO,CAAC,CACZ,CAAA"}
|
package/esm/sort-by.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export const compareBy = (entity1, entity2, field, direction) => {
|
|
2
|
+
const a = direction === 'asc' ? entity1 : entity2;
|
|
3
|
+
const b = direction === 'asc' ? entity2 : entity1;
|
|
4
|
+
if (a[field] < b[field]) {
|
|
5
|
+
return -1;
|
|
6
|
+
}
|
|
7
|
+
if (a[field] > b[field]) {
|
|
8
|
+
return 1;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
};
|
|
12
|
+
Array.prototype.sortBy = function (key, direction = 'asc') {
|
|
13
|
+
return this.sort((a, b) => compareBy(a, b, key, direction));
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=sort-by.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sort-by.js","sourceRoot":"","sources":["../src/sort-by.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,SAAS,GAAG,CAAuB,OAAU,EAAE,OAAU,EAAE,KAAQ,EAAE,SAAyB,EAAE,EAAE;IAC7G,MAAM,CAAC,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IACjD,MAAM,CAAC,GAAG,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAA;IACjD,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,CAAC,CAAC,CAAA;KACV;IACD,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE;QACvB,OAAO,CAAC,CAAA;KACT;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,UAAU,GAAG,EAAE,SAAS,GAAG,KAAK;IACvD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC,CAAA;AAC7D,CAAC,CAAA"}
|
package/esm/trace.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { ObservableValue } from './observable-value';
|
|
2
|
+
/**
|
|
3
|
+
* Helper class that can be used to trace method calls programmatically
|
|
4
|
+
*
|
|
5
|
+
* Usage example:
|
|
6
|
+
* ```ts
|
|
7
|
+
* const methodTracer: IDisposable = Trace.method({
|
|
8
|
+
* object: myObjectInstance, // You can define an object constructor for static methods as well
|
|
9
|
+
* method: myObjectInstance.method, // The method to be tracked
|
|
10
|
+
* isAsync: true, // if you set to async, method finished will be *await*-ed
|
|
11
|
+
* onCalled: (traceData) => {
|
|
12
|
+
* console.log("Method called:", traceData)
|
|
13
|
+
* },
|
|
14
|
+
* onFinished: (traceData) => {
|
|
15
|
+
* console.log("Method call finished:", traceData)
|
|
16
|
+
* },
|
|
17
|
+
* onError: (traceData) => {
|
|
18
|
+
* console.log("Method throwed an error:", traceData)
|
|
19
|
+
* }
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
class Trace {
|
|
24
|
+
static getMethodTrace(object, method) {
|
|
25
|
+
const objectTrace = this.objectTraces.get(object);
|
|
26
|
+
return objectTrace.methodMappings.get(method.name);
|
|
27
|
+
}
|
|
28
|
+
static traceStart(methodTrace, args) {
|
|
29
|
+
const startDateTime = new Date();
|
|
30
|
+
const traceValue = {
|
|
31
|
+
methodArguments: args,
|
|
32
|
+
startDateTime,
|
|
33
|
+
};
|
|
34
|
+
methodTrace.callObservable.setValue(traceValue);
|
|
35
|
+
return traceValue;
|
|
36
|
+
}
|
|
37
|
+
static traceFinished(methodTrace, args, callTrace, returned) {
|
|
38
|
+
const finishedTrace = {
|
|
39
|
+
methodArguments: args,
|
|
40
|
+
startDateTime: callTrace.startDateTime,
|
|
41
|
+
finishedDateTime: new Date(),
|
|
42
|
+
returned,
|
|
43
|
+
};
|
|
44
|
+
methodTrace.finishedObservable.setValue(finishedTrace);
|
|
45
|
+
}
|
|
46
|
+
static traceError(methodTrace, args, callTrace, error) {
|
|
47
|
+
const errorTrace = {
|
|
48
|
+
methodArguments: args,
|
|
49
|
+
startDateTime: callTrace.startDateTime,
|
|
50
|
+
errorDateTime: new Date(),
|
|
51
|
+
error,
|
|
52
|
+
};
|
|
53
|
+
methodTrace.errorObservable.setValue(errorTrace);
|
|
54
|
+
return errorTrace;
|
|
55
|
+
}
|
|
56
|
+
static callMethod(object, method, args) {
|
|
57
|
+
const methodTrace = this.getMethodTrace(object, method);
|
|
58
|
+
const start = this.traceStart(methodTrace, args);
|
|
59
|
+
try {
|
|
60
|
+
const returned = methodTrace.originalMethod.call(object, ...args);
|
|
61
|
+
this.traceFinished(methodTrace, args, start, returned);
|
|
62
|
+
return returned;
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
this.traceError(methodTrace, args, start, error);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static async callMethodAsync(object, method, args) {
|
|
70
|
+
const methodTrace = this.getMethodTrace(object, method);
|
|
71
|
+
const start = this.traceStart(methodTrace, args);
|
|
72
|
+
try {
|
|
73
|
+
const returned = await methodTrace.originalMethod.call(object, ...args);
|
|
74
|
+
this.traceFinished(methodTrace, args, start, returned);
|
|
75
|
+
return returned;
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
this.traceError(methodTrace, args, start, error);
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates an observer that will be observe method calls, finishes and errors
|
|
84
|
+
* @param options The options object for the trace
|
|
85
|
+
* @returns the trace object that can be disposed after usage
|
|
86
|
+
*/
|
|
87
|
+
static method(options) {
|
|
88
|
+
// add object mapping
|
|
89
|
+
if (!this.objectTraces.has(options.object)) {
|
|
90
|
+
this.objectTraces.set(options.object, {
|
|
91
|
+
methodMappings: new Map(),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
// setup override if needed
|
|
95
|
+
if (!options.method.isTraced) {
|
|
96
|
+
const overriddenMethod = options.isAsync
|
|
97
|
+
? (...args) => this.callMethodAsync(options.object, options.method, args)
|
|
98
|
+
: (...args) => this.callMethod(options.object, options.method, args);
|
|
99
|
+
Object.defineProperty(overriddenMethod, 'name', { value: options.method.name });
|
|
100
|
+
Object.defineProperty(overriddenMethod, 'isTraced', { value: options.method.name });
|
|
101
|
+
options.object[options.method.name] = overriddenMethod;
|
|
102
|
+
}
|
|
103
|
+
const objectTrace = this.objectTraces.get(options.object);
|
|
104
|
+
// add method mapping if needed
|
|
105
|
+
if (!objectTrace.methodMappings.has(options.method.name)) {
|
|
106
|
+
objectTrace.methodMappings.set(options.method.name, {
|
|
107
|
+
originalMethod: options.method,
|
|
108
|
+
callObservable: new ObservableValue(),
|
|
109
|
+
finishedObservable: new ObservableValue(),
|
|
110
|
+
errorObservable: new ObservableValue(),
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const methodTrace = objectTrace.methodMappings.get(options.method.name);
|
|
114
|
+
const callbacks = [
|
|
115
|
+
options.onCalled && methodTrace.callObservable.subscribe(options.onCalled),
|
|
116
|
+
options.onFinished && methodTrace.finishedObservable.subscribe(options.onFinished),
|
|
117
|
+
options.onError && methodTrace.errorObservable.subscribe(options.onError),
|
|
118
|
+
];
|
|
119
|
+
// Subscribe and return the observer
|
|
120
|
+
return {
|
|
121
|
+
dispose: () => callbacks.forEach((c) => c && c.dispose()),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
Trace.objectTraces = new Map();
|
|
126
|
+
export { Trace };
|
|
127
|
+
//# sourceMappingURL=trace.js.map
|
package/esm/trace.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../src/trace.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AA2FpD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAa,KAAK;IAGR,MAAM,CAAC,cAAc,CAC3B,MAAc,EACd,MAAoC;QAEpC,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAuB,CAAA;QACvE,OAAO,WAAW,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAA0C,CAAA;IAC7F,CAAC;IAEO,MAAM,CAAC,UAAU,CACvB,WAA6C,EAC7C,IAAa;QAEb,MAAM,aAAa,GAAG,IAAI,IAAI,EAAE,CAAA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OAAO,CAAC,UAAU,IAAI,WAAW,CAAC,kBAAkB,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC;YAClF,OAAO,CAAC,OAAO,IAAI,WAAW,CAAC,eAAe,CAAC,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC;SAC1E,CAAA;QAED,oCAAoC;QACpC,OAAO;YACL,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;SAC1D,CAAA;IACH,CAAC;;AAxIc,kBAAY,GAA6B,IAAI,GAAG,EAAE,CAAA;SADtD,KAAK"}
|
package/esm/tuple.js
ADDED
package/esm/tuple.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tuple.js","sourceRoot":"","sources":["../src/tuple.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAqB,GAAG,IAAO,EAAE,EAAE,CAAC,IAAI,CAAA"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines a generic ValueObserver instance
|
|
3
|
+
*
|
|
4
|
+
* A ValueObserver is created whenever you subscribe for an *ObservableValue* changes.
|
|
5
|
+
*
|
|
6
|
+
* Usage example:
|
|
7
|
+
* ```ts
|
|
8
|
+
*
|
|
9
|
+
* const observableValue = new ObservableValue<number>(0);
|
|
10
|
+
* const observer = observableValue.subscribe((newValue) => {
|
|
11
|
+
* console.log("Value changed:", newValue);
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* // To update the value
|
|
15
|
+
* observableValue.setValue(Math.random());
|
|
16
|
+
* // if you want to dispose a single observer
|
|
17
|
+
* observer.dispose();
|
|
18
|
+
* // if you want to dispose the whole observableValue with all of its observers:
|
|
19
|
+
* observableValue.dispose();
|
|
20
|
+
* ```
|
|
21
|
+
* @param T This type parameter is the value type to observe
|
|
22
|
+
*/
|
|
23
|
+
export class ValueObserver {
|
|
24
|
+
/**
|
|
25
|
+
* Disposes the ValueObserver instance. Unsubscribes from the observable
|
|
26
|
+
*/
|
|
27
|
+
dispose() {
|
|
28
|
+
this.observable.unsubscribe(this);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @constructs ValueObserver<T> the ValueObserver instance
|
|
32
|
+
* @param observable The related Observable object
|
|
33
|
+
* @param callback The callback that will be fired on change
|
|
34
|
+
*/
|
|
35
|
+
constructor(observable, callback) {
|
|
36
|
+
this.observable = observable;
|
|
37
|
+
this.callback = callback;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=value-observer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"value-observer.js","sourceRoot":"","sources":["../src/value-observer.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,OAAO,aAAa;IACxB;;OAEG;IACI,OAAO;QACZ,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;IAED;;;;OAIG;IACH,YAA4B,UAA8B,EAAS,QAAgC;QAAvE,eAAU,GAAV,UAAU,CAAoB;QAAS,aAAQ,GAAR,QAAQ,CAAwB;IAAG,CAAC;CACxG"}
|
package/package.json
CHANGED