@zajno/common 1.6.2 → 1.6.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/coverage/clover.xml +93 -26
- package/coverage/coverage-final.json +6 -3
- package/coverage/lcov-report/__tests__/helpers/expect.ts.html +94 -0
- package/coverage/lcov-report/__tests__/helpers/index.html +131 -0
- package/coverage/lcov-report/__tests__/helpers/main.ts.html +121 -0
- package/coverage/lcov-report/async/arrays.ts.html +199 -0
- package/coverage/lcov-report/async/index.html +19 -19
- package/coverage/lcov-report/async/timeout.ts.html +121 -19
- package/coverage/lcov-report/dates/calc.ts.html +301 -0
- package/coverage/lcov-report/dates/convert.ts.html +658 -0
- package/coverage/lcov-report/dates/datex.ts.html +211 -0
- package/coverage/lcov-report/dates/format.ts.html +403 -0
- package/coverage/lcov-report/dates/index.html +251 -0
- package/coverage/lcov-report/dates/index.ts.html +112 -0
- package/coverage/lcov-report/dates/parse.ts.html +157 -0
- package/coverage/lcov-report/dates/period.ts.html +154 -0
- package/coverage/lcov-report/dates/shift.ts.html +355 -0
- package/coverage/lcov-report/dates/types.ts.html +181 -0
- package/coverage/lcov-report/dates/yearDate.ts.html +193 -0
- package/coverage/lcov-report/fields/index.html +116 -0
- package/coverage/lcov-report/fields/update.ts.html +457 -0
- package/coverage/lcov-report/functions/disposer.ts.html +376 -0
- package/coverage/lcov-report/functions/index.html +116 -0
- package/coverage/lcov-report/functions/safeCall.ts.html +103 -0
- package/coverage/lcov-report/index.html +36 -36
- package/coverage/lcov-report/lazy/index.html +131 -0
- package/coverage/lcov-report/lazy/light.ts.html +172 -0
- package/coverage/lcov-report/lazy/promise.ts.html +241 -0
- package/coverage/lcov-report/lazy/singleton.ts.html +181 -0
- package/coverage/lcov-report/logger/batch.ts.html +112 -0
- package/coverage/lcov-report/logger/console.ts.html +241 -0
- package/coverage/lcov-report/logger/index.html +80 -20
- package/coverage/lcov-report/logger/index.ts.html +49 -49
- package/coverage/lcov-report/logger/named.ts.html +226 -0
- package/coverage/lcov-report/logger/proxy.ts.html +172 -0
- package/coverage/lcov-report/math/arrays.ts.html +907 -0
- package/coverage/lcov-report/math/calc.ts.html +292 -0
- package/coverage/lcov-report/math/distribution.ts.html +145 -0
- package/coverage/lcov-report/math/index.html +161 -0
- package/coverage/lcov-report/math/index.ts.html +166 -0
- package/coverage/lcov-report/observing/event.ts.html +358 -0
- package/coverage/lcov-report/observing/index.html +116 -0
- package/coverage/lcov-report/observing/transition.ts.html +634 -0
- package/coverage/lcov-report/queue/index.html +18 -18
- package/coverage/lcov-report/queue/tasks.ts.html +358 -0
- package/coverage/lcov-report/src/__tests__/helpers/expect.ts.html +1 -1
- package/coverage/lcov-report/src/__tests__/helpers/index.html +1 -1
- package/coverage/lcov-report/src/__tests__/helpers/main.ts.html +1 -1
- package/coverage/lcov-report/src/async/arrays.ts.html +1 -1
- package/coverage/lcov-report/src/async/index.html +1 -1
- package/coverage/lcov-report/src/async/timeout.ts.html +13 -13
- package/coverage/lcov-report/src/cache.ts.html +1 -1
- package/coverage/lcov-report/src/dates/calc.ts.html +1 -1
- package/coverage/lcov-report/src/dates/convert.ts.html +1 -1
- package/coverage/lcov-report/src/dates/datex.ts.html +1 -1
- package/coverage/lcov-report/src/dates/format.ts.html +1 -1
- package/coverage/lcov-report/src/dates/index.html +1 -1
- package/coverage/lcov-report/src/dates/index.ts.html +1 -1
- package/coverage/lcov-report/src/dates/parse.ts.html +1 -1
- package/coverage/lcov-report/src/dates/period.ts.html +1 -1
- package/coverage/lcov-report/src/dates/shift.ts.html +1 -1
- package/coverage/lcov-report/src/dates/types.ts.html +1 -1
- package/coverage/lcov-report/src/dates/yearDate.ts.html +1 -1
- package/coverage/lcov-report/src/disposer.ts.html +1 -1
- package/coverage/lcov-report/src/enumHelper.ts.html +1 -1
- package/coverage/lcov-report/src/event.ts.html +1 -1
- package/coverage/lcov-report/src/fields/index.html +1 -1
- package/coverage/lcov-report/src/fields/update.ts.html +1 -1
- package/coverage/lcov-report/src/functions.ts.html +13 -13
- package/coverage/lcov-report/src/index.html +16 -16
- package/coverage/lcov-report/src/lazy/index.html +1 -1
- package/coverage/lcov-report/src/lazy/light.ts.html +1 -1
- package/coverage/lcov-report/src/lazy/observable.ts.html +1 -1
- package/coverage/lcov-report/src/lazy/promise.ts.html +1 -1
- package/coverage/lcov-report/src/lazy/singleton.ts.html +1 -1
- package/coverage/lcov-report/src/logger/batch.ts.html +1 -1
- package/coverage/lcov-report/src/logger/console.ts.html +1 -1
- package/coverage/lcov-report/src/logger/index.html +1 -1
- package/coverage/lcov-report/src/logger/index.ts.html +1 -1
- package/coverage/lcov-report/src/logger/named.ts.html +1 -1
- package/coverage/lcov-report/src/logger/proxy.ts.html +1 -1
- package/coverage/lcov-report/src/math/arrays.ts.html +1 -1
- package/coverage/lcov-report/src/math/calc.ts.html +1 -1
- package/coverage/lcov-report/src/math/distribution.ts.html +1 -1
- package/coverage/lcov-report/src/math/index.html +1 -1
- package/coverage/lcov-report/src/math/index.ts.html +1 -1
- package/coverage/lcov-report/src/observersMap.ts.html +1 -1
- package/coverage/lcov-report/src/observingCache.ts.html +1 -1
- package/coverage/lcov-report/src/queue/index.html +24 -9
- package/coverage/lcov-report/src/queue/parallel.ts.html +1 -1
- package/coverage/lcov-report/src/queue/tasks.ts.html +358 -0
- package/coverage/lcov-report/src/tempoCache.ts.html +1 -1
- package/coverage/lcov-report/src/transitionObserver.ts.html +1 -1
- package/coverage/lcov-report/src/types/comparator.ts.html +103 -0
- package/coverage/lcov-report/src/types/getter.ts.html +127 -0
- package/coverage/lcov-report/src/types/index.html +146 -0
- package/coverage/lcov-report/src/types/index.ts.html +112 -0
- package/coverage/lcov-report/src/types.ts.html +5 -5
- package/coverage/lcov-report/src/validation/ValidationErrors.ts.html +1 -1
- package/coverage/lcov-report/src/validation/creditCard.ts.html +1 -1
- package/coverage/lcov-report/src/validation/helpers.ts.html +1 -1
- package/coverage/lcov-report/src/validation/index.html +1 -1
- package/coverage/lcov-report/src/validation/index.ts.html +1 -1
- package/coverage/lcov-report/src/validation/types.ts.html +1 -1
- package/coverage/lcov-report/src/validation/validators.ts.html +1 -1
- package/coverage/lcov-report/src/validation/wrappers.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/CommonModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/FlagModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/LoadingModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/Model.ts.html +163 -0
- package/coverage/lcov-report/src/viewModels/MultiSelectModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/NumberModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/SelectModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/TextModel.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/Validatable.ts.html +1 -1
- package/coverage/lcov-report/src/viewModels/ValueModel.ts.html +127 -0
- package/coverage/lcov-report/src/viewModels/index.html +39 -9
- package/coverage/lcov-report/src/viewModels/wrappers.ts.html +1 -1
- package/coverage/lcov-report/structures/helpers/enum.ts.html +454 -0
- package/coverage/lcov-report/structures/helpers/index.html +116 -0
- package/coverage/lcov-report/structures/index.html +116 -0
- package/coverage/lcov-report/structures/promiseCache.ts.html +628 -0
- package/coverage/lcov-report/structures/queue/index.html +131 -0
- package/coverage/lcov-report/structures/queue/parallel.ts.html +511 -0
- package/coverage/lcov-report/structures/queue/tasks.ts.html +358 -0
- package/coverage/lcov-report/structures/subscribersMap.ts.html +400 -0
- package/coverage/lcov-report/structures/subscribersPromiseCache.ts.html +562 -0
- package/coverage/lcov-report/structures/tempoCache.ts.html +139 -0
- package/coverage/lcov-report/tasks.ts.html +355 -0
- package/coverage/lcov-report/types/comparator.ts.html +103 -0
- package/coverage/lcov-report/types/getter.ts.html +127 -0
- package/coverage/lcov-report/types/index.html +146 -0
- package/coverage/lcov-report/types/index.ts.html +136 -0
- package/coverage/lcov-report/validation/ValidationErrors.ts.html +163 -0
- package/coverage/lcov-report/validation/creditCard.ts.html +160 -0
- package/coverage/lcov-report/validation/helpers.ts.html +226 -0
- package/coverage/lcov-report/validation/index.html +8 -3
- package/coverage/lcov-report/validation/index.ts.html +13 -8
- package/coverage/lcov-report/validation/types.ts.html +139 -0
- package/coverage/lcov-report/validation/validators.ts.html +250 -0
- package/coverage/lcov-report/validation/wrappers.ts.html +163 -0
- package/coverage/lcov-report/viewModels/CommonModel.ts.html +10 -5
- package/coverage/lcov-report/viewModels/LoadingModel.ts.html +11 -6
- package/coverage/lcov-report/viewModels/Model.ts.html +163 -0
- package/coverage/lcov-report/viewModels/SelectModel.ts.html +121 -116
- package/coverage/lcov-report/viewModels/TextModel.ts.html +16 -11
- package/coverage/lcov-report/viewModels/ValueModel.ts.html +127 -0
- package/coverage/lcov-report/viewModels/index.html +65 -30
- package/coverage/lcov.info +171 -30
- package/lib/queue/tasks.d.ts +17 -0
- package/lib/queue/tasks.d.ts.map +1 -0
- package/lib/queue/tasks.js +76 -0
- package/lib/queue/tasks.js.map +1 -0
- package/lib/viewModels/Model.d.ts +12 -0
- package/lib/viewModels/Model.d.ts.map +1 -0
- package/lib/viewModels/Model.js +23 -0
- package/lib/viewModels/Model.js.map +1 -0
- package/lib/viewModels/ValueModel.d.ts +2 -8
- package/lib/viewModels/ValueModel.d.ts.map +1 -1
- package/lib/viewModels/ValueModel.js +3 -16
- package/lib/viewModels/ValueModel.js.map +1 -1
- package/package.json +1 -1
- package/src/.DS_Store +0 -0
- package/src/queue/__tests__/tasks.test.ts +87 -0
- package/src/queue/tasks.ts +91 -0
- package/src/viewModels/Model.ts +26 -0
- package/src/viewModels/ValueModel.ts +3 -23
- package/src/viewModels/__tests__/common.test.ts +27 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TasksQueue = void 0;
|
|
4
|
+
class TasksQueue {
|
|
5
|
+
constructor(limit) {
|
|
6
|
+
this.limit = limit;
|
|
7
|
+
this._items = [];
|
|
8
|
+
this._running = 0;
|
|
9
|
+
this._logger = null;
|
|
10
|
+
this._runFactory = async (factory, name) => {
|
|
11
|
+
var _a;
|
|
12
|
+
this._running++;
|
|
13
|
+
try {
|
|
14
|
+
const result = await factory();
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
catch (err) {
|
|
18
|
+
(_a = this._logger) === null || _a === void 0 ? void 0 : _a.warn(`Factory "${name || factory.name || '<unknown>'}" thrown. Rethrowing...`);
|
|
19
|
+
throw err;
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
this._running--;
|
|
23
|
+
this._tryRunNext();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
this._tryRunNext = async () => {
|
|
27
|
+
if (!this._items.length || this.isFull) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const next = this._items.shift();
|
|
31
|
+
if (!next || !next.finish || !next.factory) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await next.finish(this._runFactory(next.factory));
|
|
35
|
+
};
|
|
36
|
+
if (!limit || limit < 0) {
|
|
37
|
+
throw new Error('TasksQueue: limit should be a positive number');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
get isFull() { return this._running >= this.limit; }
|
|
41
|
+
get running() { return this._running; }
|
|
42
|
+
addLogger(logger) {
|
|
43
|
+
this._logger = logger;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
enqueue(factory, name) {
|
|
47
|
+
if (typeof factory !== 'function') {
|
|
48
|
+
throw new Error('Invalid arg: factory not a function');
|
|
49
|
+
}
|
|
50
|
+
if (this.isFull) {
|
|
51
|
+
const item = {
|
|
52
|
+
factory,
|
|
53
|
+
finish: undefined,
|
|
54
|
+
name,
|
|
55
|
+
};
|
|
56
|
+
const waitPromise = new Promise((resolve, reject) => {
|
|
57
|
+
item.finish = async (res) => {
|
|
58
|
+
try {
|
|
59
|
+
const rr = await res;
|
|
60
|
+
resolve(rr);
|
|
61
|
+
return rr;
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
reject(err);
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
this._items.push(item);
|
|
70
|
+
return waitPromise;
|
|
71
|
+
}
|
|
72
|
+
return this._runFactory(factory);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.TasksQueue = TasksQueue;
|
|
76
|
+
//# sourceMappingURL=tasks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasks.js","sourceRoot":"","sources":["../../src/queue/tasks.ts"],"names":[],"mappings":";;;AAUA,MAAa,UAAU;IAMnB,YAAqB,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;QAJjB,WAAM,GAAmB,EAAE,CAAC;QACrC,aAAQ,GAAG,CAAC,CAAC;QACb,YAAO,GAAmB,IAAI,CAAC;QAiD/B,gBAAW,GAAG,KAAK,EAAE,OAAmB,EAAE,IAAa,EAAc,EAAE;;YAC3E,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,IAAI;gBACA,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAC;gBAC/B,OAAO,MAAM,CAAC;aACjB;YAAC,OAAO,GAAG,EAAE;gBACV,MAAA,IAAI,CAAC,OAAO,0CAAE,IAAI,CAAC,YAAY,IAAI,IAAI,OAAO,CAAC,IAAI,IAAI,WAAW,yBAAyB,CAAC,CAAC;gBAC7F,MAAM,GAAG,CAAC;aACb;oBAAS;gBACN,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChB,IAAI,CAAC,WAAW,EAAE,CAAC;aACtB;QACL,CAAC,CAAC;QAEM,gBAAW,GAAG,KAAK,IAAI,EAAE;YAC7B,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,EAAE;gBACpC,OAAO;aACV;YAED,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACjC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;gBACxC,OAAO;aACV;YAED,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC;QAvEE,IAAI,CAAC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE;YACrB,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;SACpE;IACL,CAAC;IAED,IAAW,MAAM,KAAK,OAAO,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,IAAW,OAAO,KAAK,OAAO,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE9C,SAAS,CAAC,MAAe;QACrB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,OAAO,CAAC,OAAmB,EAAE,IAAa;QAC7C,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE;YAC/B,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;SAC1D;QAED,IAAI,IAAI,CAAC,MAAM,EAAE;YAEb,MAAM,IAAI,GAAiB;gBACvB,OAAO;gBACP,MAAM,EAAE,SAAS;gBACjB,IAAI;aACP,CAAC;YAEF,MAAM,WAAW,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;gBACnD,IAAI,CAAC,MAAM,GAAG,KAAK,EAAE,GAAG,EAAE,EAAE;oBACxB,IAAI;wBACA,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC;wBACrB,OAAO,CAAC,EAAE,CAAC,CAAC;wBACZ,OAAO,EAAE,CAAC;qBACb;oBAAC,OAAO,GAAG,EAAE;wBACV,MAAM,CAAC,GAAG,CAAC,CAAC;wBACZ,MAAM,GAAG,CAAC;qBACb;gBACL,CAAC,CAAC;YACN,CAAC,CAAC,CAAC;YAEH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvB,OAAO,WAAW,CAAC;SACtB;QAED,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CA6BJ;AAhFD,gCAgFC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { IValueModel } from './types';
|
|
2
|
+
import { Getter } from '../types';
|
|
3
|
+
export declare class Model<T> implements IValueModel<T> {
|
|
4
|
+
private _value;
|
|
5
|
+
private readonly _defaultValue;
|
|
6
|
+
constructor(v?: Getter<T>);
|
|
7
|
+
get value(): T;
|
|
8
|
+
set value(v: T);
|
|
9
|
+
readonly setValue: (value: T) => void;
|
|
10
|
+
readonly reset: () => void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Model.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/viewModels/Model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,qBAAa,KAAK,CAAC,CAAC,CAAE,YAAW,WAAW,CAAC,CAAC,CAAC;IAC3C,OAAO,CAAC,MAAM,CAAI;IAElB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAmB;gBAErC,CAAC,GAAE,MAAM,CAAC,CAAC,CAAQ;IAK/B,IAAW,KAAK,IACI,CAAC,CADqB;IAC1C,IAAW,KAAK,CAAC,CAAC,EAAE,CAAC,EAEpB;IAED,SAAgB,QAAQ,UAAW,CAAC,UAElC;IAEF,SAAgB,KAAK,aAEnB;CACL"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Model = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
5
|
+
class Model {
|
|
6
|
+
constructor(v = null) {
|
|
7
|
+
this._defaultValue = null;
|
|
8
|
+
this.setValue = (value) => {
|
|
9
|
+
this._value = value;
|
|
10
|
+
};
|
|
11
|
+
this.reset = () => {
|
|
12
|
+
this.setValue(types_1.Getter.getValue(this._defaultValue));
|
|
13
|
+
};
|
|
14
|
+
this._value = types_1.Getter.getValue(v) || null;
|
|
15
|
+
this._defaultValue = v;
|
|
16
|
+
}
|
|
17
|
+
get value() { return this._value; }
|
|
18
|
+
set value(v) {
|
|
19
|
+
this.setValue(v);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.Model = Model;
|
|
23
|
+
//# sourceMappingURL=Model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Model.js","sourceRoot":"","sources":["../../src/viewModels/Model.ts"],"names":[],"mappings":";;;AACA,oCAAkC;AAElC,MAAa,KAAK;IAKd,YAAY,IAAe,IAAI;QAFd,kBAAa,GAAc,IAAI,CAAC;QAYjC,aAAQ,GAAG,CAAC,KAAQ,EAAE,EAAE;YACpC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC;QAEc,UAAK,GAAG,GAAG,EAAE;YACzB,IAAI,CAAC,QAAQ,CAAC,cAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QACvD,CAAC,CAAC;QAfE,IAAI,CAAC,MAAM,GAAG,cAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;QACzC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;IAC3B,CAAC;IAED,IAAW,KAAK,KAAK,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAC1C,IAAW,KAAK,CAAC,CAAI;QACjB,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;CASJ;AAtBD,sBAsBC"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { Getter } from '../types';
|
|
2
|
-
import {
|
|
3
|
-
export declare class ValueModel<T>
|
|
4
|
-
private _value;
|
|
5
|
-
private _defaultValue;
|
|
2
|
+
import { Model } from './Model';
|
|
3
|
+
export declare class ValueModel<T> extends Model<T> {
|
|
6
4
|
constructor(v?: Getter<T>, useRefObservable?: boolean);
|
|
7
|
-
get value(): T;
|
|
8
|
-
set value(v: T);
|
|
9
|
-
readonly setValue: (value: T) => void;
|
|
10
|
-
reset: () => void;
|
|
11
5
|
}
|
|
12
6
|
//# sourceMappingURL=ValueModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueModel.d.ts","sourceRoot":"","sources":["../../src/viewModels/ValueModel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ValueModel.d.ts","sourceRoot":"","sources":["../../src/viewModels/ValueModel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,qBAAa,UAAU,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,CAAC;gBAC3B,CAAC,GAAE,MAAM,CAAC,CAAC,CAAQ,EAAE,gBAAgB,UAAO;CAQ3D"}
|
|
@@ -2,28 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ValueModel = void 0;
|
|
4
4
|
const mobx_1 = require("mobx");
|
|
5
|
-
const
|
|
6
|
-
class ValueModel {
|
|
5
|
+
const Model_1 = require("./Model");
|
|
6
|
+
class ValueModel extends Model_1.Model {
|
|
7
7
|
constructor(v = null, useRefObservable = true) {
|
|
8
|
-
|
|
9
|
-
// action
|
|
10
|
-
this.setValue = (value) => {
|
|
11
|
-
this._value = value;
|
|
12
|
-
};
|
|
13
|
-
this.reset = () => {
|
|
14
|
-
this._value = types_1.Getter.getValue(this._defaultValue);
|
|
15
|
-
};
|
|
16
|
-
this._value = types_1.Getter.getValue(v) || null;
|
|
17
|
-
this._defaultValue = v;
|
|
8
|
+
super(v);
|
|
18
9
|
(0, mobx_1.makeObservable)(this, {
|
|
19
10
|
_value: useRefObservable ? mobx_1.observable.ref : mobx_1.observable,
|
|
20
11
|
setValue: mobx_1.action,
|
|
21
12
|
});
|
|
22
13
|
}
|
|
23
|
-
get value() { return this._value; }
|
|
24
|
-
set value(v) {
|
|
25
|
-
this.setValue(v);
|
|
26
|
-
}
|
|
27
14
|
}
|
|
28
15
|
exports.ValueModel = ValueModel;
|
|
29
16
|
//# sourceMappingURL=ValueModel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ValueModel.js","sourceRoot":"","sources":["../../src/viewModels/ValueModel.ts"],"names":[],"mappings":";;;AAAA,+BAA0D;
|
|
1
|
+
{"version":3,"file":"ValueModel.js","sourceRoot":"","sources":["../../src/viewModels/ValueModel.ts"],"names":[],"mappings":";;;AAAA,+BAA0D;AAE1D,mCAAgC;AAEhC,MAAa,UAAc,SAAQ,aAAQ;IACvC,YAAY,IAAe,IAAI,EAAE,gBAAgB,GAAG,IAAI;QACpD,KAAK,CAAC,CAAC,CAAC,CAAC;QAET,IAAA,qBAAc,EAA0B,IAAI,EAAE;YAC1C,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,iBAAU,CAAC,GAAG,CAAC,CAAC,CAAC,iBAAU;YACtD,QAAQ,EAAE,aAAM;SACnB,CAAC,CAAC;IACP,CAAC;CACJ;AATD,gCASC"}
|
package/package.json
CHANGED
package/src/.DS_Store
CHANGED
|
Binary file
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { TasksQueue } from '../tasks';
|
|
2
|
+
import { setTimeoutAsync } from '../../async/timeout';
|
|
3
|
+
import { safeCall } from '../../functions';
|
|
4
|
+
import 'jest-extended';
|
|
5
|
+
|
|
6
|
+
describe('TasksQueue', () => {
|
|
7
|
+
|
|
8
|
+
const createFactory = <T>(res: T, cb?: () => void) => {
|
|
9
|
+
return async () => {
|
|
10
|
+
await setTimeoutAsync(50);
|
|
11
|
+
safeCall(cb);
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
it('correctly initializes', async () => {
|
|
17
|
+
const fnZero = async () => {
|
|
18
|
+
return new TasksQueue(0);
|
|
19
|
+
};
|
|
20
|
+
const fnNegative = async () => {
|
|
21
|
+
return new TasksQueue(-12);
|
|
22
|
+
};
|
|
23
|
+
const fnPositive = async () => {
|
|
24
|
+
return new TasksQueue(12);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
await expect(fnZero()).rejects.toThrow();
|
|
28
|
+
await expect(fnNegative()).rejects.toThrow();
|
|
29
|
+
await expect(fnPositive()).resolves.not.toBeNull();
|
|
30
|
+
|
|
31
|
+
const failEnqueue = async () => {
|
|
32
|
+
const q = new TasksQueue<number>(123);
|
|
33
|
+
q.enqueue(null as any);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
await expect(failEnqueue()).rejects.toThrow();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('runs without limit', async () => {
|
|
40
|
+
const queue = new TasksQueue(5);
|
|
41
|
+
|
|
42
|
+
expect(queue.isFull).toBeFalsy();
|
|
43
|
+
expect(queue.running).toBe(0);
|
|
44
|
+
|
|
45
|
+
const val1 = 123;
|
|
46
|
+
|
|
47
|
+
const res1 = queue.enqueue(createFactory(val1));
|
|
48
|
+
|
|
49
|
+
expect(queue.isFull).toBeFalsy();
|
|
50
|
+
expect(queue.running).toBe(1);
|
|
51
|
+
|
|
52
|
+
await expect(res1).resolves.toBe(val1);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('runs with limit 1', async () => {
|
|
56
|
+
const queue = new TasksQueue(1);
|
|
57
|
+
|
|
58
|
+
const val1 = 123;
|
|
59
|
+
const cb1 = jest.fn();
|
|
60
|
+
const res1 = queue.enqueue(createFactory(val1, cb1));
|
|
61
|
+
|
|
62
|
+
const val2 = 321;
|
|
63
|
+
const cb2 = jest.fn();
|
|
64
|
+
const res2 = queue.enqueue(createFactory(val2, cb2));
|
|
65
|
+
|
|
66
|
+
const val3 = 111;
|
|
67
|
+
const cb3 = jest.fn();
|
|
68
|
+
const res3 = queue.enqueue(createFactory(val3, cb3));
|
|
69
|
+
|
|
70
|
+
expect(queue.isFull).toBeTruthy();
|
|
71
|
+
expect(queue.running).toBe(1);
|
|
72
|
+
|
|
73
|
+
await expect(res1).resolves.toBe(val1);
|
|
74
|
+
expect(queue.running).toBe(1);
|
|
75
|
+
|
|
76
|
+
await expect(res2).resolves.toBe(val2);
|
|
77
|
+
|
|
78
|
+
expect(queue.running).toBe(1);
|
|
79
|
+
await expect(res3).resolves.toBe(val3);
|
|
80
|
+
|
|
81
|
+
expect(queue.running).toBe(0);
|
|
82
|
+
|
|
83
|
+
expect(cb1).toHaveBeenCalledBefore(cb2);
|
|
84
|
+
expect(cb2).toHaveBeenCalledBefore(cb3);
|
|
85
|
+
expect(cb3).toHaveBeenCalled();
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ILogger } from '../logger';
|
|
2
|
+
|
|
3
|
+
type Factory<T> = () => Promise<T>;
|
|
4
|
+
|
|
5
|
+
type QueueItem<T> = {
|
|
6
|
+
factory: Factory<T>;
|
|
7
|
+
finish?: (res: Promise<T>) => Promise<T>;
|
|
8
|
+
name?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class TasksQueue<T> {
|
|
12
|
+
|
|
13
|
+
private readonly _items: QueueItem<T>[] = [];
|
|
14
|
+
private _running = 0;
|
|
15
|
+
private _logger: ILogger | null = null;
|
|
16
|
+
|
|
17
|
+
constructor(readonly limit: number) {
|
|
18
|
+
if (!limit || limit < 0) {
|
|
19
|
+
throw new Error('TasksQueue: limit should be a positive number');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public get isFull() { return this._running >= this.limit; }
|
|
24
|
+
public get running() { return this._running; }
|
|
25
|
+
|
|
26
|
+
addLogger(logger: ILogger) {
|
|
27
|
+
this._logger = logger;
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public enqueue(factory: Factory<T>, name?: string): Promise<T> {
|
|
32
|
+
if (typeof factory !== 'function') {
|
|
33
|
+
throw new Error('Invalid arg: factory not a function');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (this.isFull) {
|
|
37
|
+
|
|
38
|
+
const item: QueueItem<T> = {
|
|
39
|
+
factory,
|
|
40
|
+
finish: undefined,
|
|
41
|
+
name,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const waitPromise = new Promise<T>((resolve, reject) => {
|
|
45
|
+
item.finish = async (res) => {
|
|
46
|
+
try {
|
|
47
|
+
const rr = await res;
|
|
48
|
+
resolve(rr);
|
|
49
|
+
return rr;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
reject(err);
|
|
52
|
+
throw err;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this._items.push(item);
|
|
58
|
+
return waitPromise;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return this._runFactory(factory);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
private _runFactory = async (factory: Factory<T>, name?: string): Promise<T> => {
|
|
65
|
+
this._running++;
|
|
66
|
+
try {
|
|
67
|
+
const result = await factory();
|
|
68
|
+
return result;
|
|
69
|
+
} catch (err) {
|
|
70
|
+
this._logger?.warn(`Factory "${name || factory.name || '<unknown>'}" thrown. Rethrowing...`);
|
|
71
|
+
throw err;
|
|
72
|
+
} finally {
|
|
73
|
+
this._running--;
|
|
74
|
+
this._tryRunNext();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
private _tryRunNext = async () => {
|
|
79
|
+
if (!this._items.length || this.isFull) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const next = this._items.shift();
|
|
84
|
+
if (!next || !next.finish || !next.factory) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
await next.finish(this._runFactory(next.factory));
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { IValueModel } from './types';
|
|
2
|
+
import { Getter } from '../types';
|
|
3
|
+
|
|
4
|
+
export class Model<T> implements IValueModel<T> {
|
|
5
|
+
private _value: T;
|
|
6
|
+
|
|
7
|
+
private readonly _defaultValue: Getter<T> = null;
|
|
8
|
+
|
|
9
|
+
constructor(v: Getter<T> = null) {
|
|
10
|
+
this._value = Getter.getValue(v) || null;
|
|
11
|
+
this._defaultValue = v;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public get value() { return this._value; }
|
|
15
|
+
public set value(v: T) {
|
|
16
|
+
this.setValue(v);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public readonly setValue = (value: T) => {
|
|
20
|
+
this._value = value;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
public readonly reset = () => {
|
|
24
|
+
this.setValue(Getter.getValue(this._defaultValue));
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -1,34 +1,14 @@
|
|
|
1
1
|
import { action, makeObservable, observable } from 'mobx';
|
|
2
2
|
import { Getter } from '../types';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export class ValueModel<T> implements IValueModel<T> {
|
|
6
|
-
// observable[.ref]
|
|
7
|
-
private _value: T;
|
|
8
|
-
|
|
9
|
-
private _defaultValue: Getter<T> = null;
|
|
3
|
+
import { Model } from './Model';
|
|
10
4
|
|
|
5
|
+
export class ValueModel<T> extends Model<T> {
|
|
11
6
|
constructor(v: Getter<T> = null, useRefObservable = true) {
|
|
12
|
-
|
|
13
|
-
this._defaultValue = v;
|
|
7
|
+
super(v);
|
|
14
8
|
|
|
15
9
|
makeObservable<ValueModel<T>, '_value'>(this, {
|
|
16
10
|
_value: useRefObservable ? observable.ref : observable,
|
|
17
11
|
setValue: action,
|
|
18
12
|
});
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
public get value() { return this._value; }
|
|
22
|
-
public set value(v: T) {
|
|
23
|
-
this.setValue(v);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// action
|
|
27
|
-
public readonly setValue = (value: T) => {
|
|
28
|
-
this._value = value;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
reset = () => {
|
|
32
|
-
this._value = Getter.getValue(this._defaultValue);
|
|
33
|
-
};
|
|
34
14
|
}
|
|
@@ -4,13 +4,15 @@ import { LoadingModel } from '../LoadingModel';
|
|
|
4
4
|
import { setTimeoutAsync } from '../../async/timeout';
|
|
5
5
|
import { SelectString } from '../SelectModel';
|
|
6
6
|
import { TextInputVM } from '../TextModel';
|
|
7
|
+
import { ValueModel } from '../ValueModel';
|
|
8
|
+
import { reaction } from 'mobx';
|
|
7
9
|
|
|
8
10
|
describe('CommonModel', () => {
|
|
9
11
|
const NotEmptyError = 'should be not empty';
|
|
10
12
|
|
|
11
13
|
it('works', async () => {
|
|
12
14
|
|
|
13
|
-
let m: CommonModel<string[]
|
|
15
|
+
let m: CommonModel<string[]> = null;
|
|
14
16
|
|
|
15
17
|
const fn = async () => {
|
|
16
18
|
m = new CommonModel<string[]>(() => [], true)
|
|
@@ -103,5 +105,29 @@ describe('Others', () => {
|
|
|
103
105
|
return new TextInputVM();
|
|
104
106
|
})()).resolves.not.toThrow();
|
|
105
107
|
|
|
108
|
+
await expect((async () => {
|
|
109
|
+
return new ValueModel();
|
|
110
|
+
})()).resolves.not.toThrow();
|
|
111
|
+
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('ValueModel', () => {
|
|
115
|
+
it('observable', () => {
|
|
116
|
+
|
|
117
|
+
const vm = new ValueModel(123);
|
|
118
|
+
|
|
119
|
+
const sub = jest.fn();
|
|
120
|
+
const unsub = reaction(() => vm.value, v => sub(v));
|
|
121
|
+
|
|
122
|
+
vm.value = 321;
|
|
123
|
+
expect(sub).toHaveBeenCalledWith(321);
|
|
124
|
+
|
|
125
|
+
sub.mockClear();
|
|
126
|
+
|
|
127
|
+
vm.reset();
|
|
128
|
+
expect(sub).toHaveBeenCalledWith(123);
|
|
129
|
+
|
|
130
|
+
unsub();
|
|
131
|
+
});
|
|
106
132
|
});
|
|
107
133
|
});
|