jikan0 0.0.1 → 0.0.2
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/README.md +1 -1
- package/adapters/README.md +1 -0
- package/adapters/package.json +12 -0
- package/adapters/src/index.d.ts +1 -0
- package/adapters/src/index.js +6 -0
- package/adapters/src/index.js.map +1 -0
- package/adapters/src/lib/statefulSimulation.d.ts +32 -0
- package/adapters/src/lib/statefulSimulation.js +130 -0
- package/adapters/src/lib/statefulSimulation.js.map +1 -0
- package/fsm/README.md +3 -0
- package/fsm/package.json +12 -0
- package/fsm/src/index.d.ts +1 -0
- package/fsm/src/index.js +5 -0
- package/fsm/src/index.js.map +1 -0
- package/fsm/src/lib/fsm.d.ts +26 -0
- package/fsm/src/lib/fsm.js +106 -0
- package/fsm/src/lib/fsm.js.map +1 -0
- package/package.json +1 -1
- package/src/index.d.ts +2 -2
- package/src/index.js +2 -2
- package/src/index.js.map +1 -1
- package/test-utils/README.md +11 -0
- package/test-utils/package.json +11 -0
- package/test-utils/src/index.d.ts +1 -0
- package/test-utils/src/index.js +5 -0
- package/test-utils/src/index.js.map +1 -0
- package/test-utils/src/lib/testUtils.d.ts +4 -0
- package/test-utils/src/lib/testUtils.js +32 -0
- package/test-utils/src/lib/testUtils.js.map +1 -0
- package/utils/README.md +11 -0
- package/utils/package.json +10 -0
- package/utils/src/index.d.ts +1 -0
- package/utils/src/index.js +5 -0
- package/utils/src/index.js.map +1 -0
- package/utils/src/lib/utils.d.ts +6 -0
- package/utils/src/lib/utils.js +29 -0
- package/utils/src/lib/utils.js.map +1 -0
package/README.md
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
stateful adapters for fsm; to be a main convenient OO interface for lib users
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { StatefulSimulation } from './lib/statefulSimulation';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StatefulSimulation = void 0;
|
|
4
|
+
var statefulSimulation_1 = require("./lib/statefulSimulation");
|
|
5
|
+
Object.defineProperty(exports, "StatefulSimulation", { enumerable: true, get: function () { return statefulSimulation_1.StatefulSimulation; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../adapters/src/index.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAArD,wHAAA,kBAAkB,OAAA"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { QueueItem, State } from "../../../fsm/src";
|
|
2
|
+
export declare const StatefulSimulation: {
|
|
3
|
+
new <QueueItemType extends string = string>(queue: QueueItem<QueueItemType>[], opts?: {
|
|
4
|
+
leniency?: number | undefined;
|
|
5
|
+
onChange?: ((next: QueueItem | null) => void) | undefined;
|
|
6
|
+
stopOnEmpty?: boolean | undefined;
|
|
7
|
+
}): {
|
|
8
|
+
"__#1@#state": State<QueueItemType>;
|
|
9
|
+
"__#1@#setState": (state1: State<QueueItemType>) => void;
|
|
10
|
+
readonly "__#1@#state0": State<QueueItemType>;
|
|
11
|
+
"__#1@#intervalHandle": ReturnType<typeof setInterval> | null;
|
|
12
|
+
readonly leniency: number;
|
|
13
|
+
readonly stopOnEmpty: boolean;
|
|
14
|
+
isRunning: () => boolean;
|
|
15
|
+
"__#1@#changeListeners": Map<number, (next: QueueItem | null) => void>;
|
|
16
|
+
"__#1@#nextListenerId": number;
|
|
17
|
+
onChange: (f: (next: QueueItem | null) => void, opts?: {
|
|
18
|
+
withCurrent: boolean;
|
|
19
|
+
}) => (() => void);
|
|
20
|
+
"__#1@#reportQueueItem": (next: QueueItem<QueueItemType> | null) => void;
|
|
21
|
+
"__#1@#tick": (step: number) => QueueItem<QueueItemType>[];
|
|
22
|
+
push: (queueItems: QueueItem<QueueItemType>[]) => void;
|
|
23
|
+
restart: () => void;
|
|
24
|
+
reset: () => void;
|
|
25
|
+
pause: () => void;
|
|
26
|
+
start: () => void;
|
|
27
|
+
stop: () => void;
|
|
28
|
+
isEmpty: () => boolean;
|
|
29
|
+
length: () => number;
|
|
30
|
+
current: () => QueueItem<QueueItemType> | null;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _state, _setState, _state0, _intervalHandle, _changeListeners, _nextListenerId, _reportQueueItem, _tick, _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.StatefulSimulation = void 0;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const fsm_1 = require("../../../fsm/src");
|
|
7
|
+
const utils_1 = require("@jikan0/utils");
|
|
8
|
+
const DEFAULT_OPTS = { leniency: 100 /*ms*/, stopOnEmpty: true };
|
|
9
|
+
const SUSPICIOUSLY_TOO_MANY_LISTENERS = 100;
|
|
10
|
+
const SUSPICIOUSLY_TOO_MANY_LISTENERS_MSG = (n) => `Suspiciously many listeners: ${n}. Please check that you clean up listener functions calling the cleanup function returned from onChange`;
|
|
11
|
+
let isSuspiciouslyTooManyListenersReported = false;
|
|
12
|
+
const checkTooManyListeners = (n) => {
|
|
13
|
+
if (n >= SUSPICIOUSLY_TOO_MANY_LISTENERS &&
|
|
14
|
+
!isSuspiciouslyTooManyListenersReported) {
|
|
15
|
+
console.warn(SUSPICIOUSLY_TOO_MANY_LISTENERS_MSG(n));
|
|
16
|
+
isSuspiciouslyTooManyListenersReported = true;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
const areQueueItemsEqual = (a, b) => {
|
|
20
|
+
if (a === null && b === null)
|
|
21
|
+
return true;
|
|
22
|
+
if (a === null || b === null)
|
|
23
|
+
return false;
|
|
24
|
+
return (0, fsm_1.eqQueueItem)(b)(a);
|
|
25
|
+
};
|
|
26
|
+
exports.StatefulSimulation = (_a = class {
|
|
27
|
+
constructor(queue, opts = DEFAULT_OPTS) {
|
|
28
|
+
// set only thru #setState
|
|
29
|
+
_state.set(this, (0, fsm_1.empty)());
|
|
30
|
+
_setState.set(this, (state1) => {
|
|
31
|
+
const queueItem = (0, fsm_1.current)(tslib_1.__classPrivateFieldGet(this, _state, "f"));
|
|
32
|
+
const nextQueueItem = (0, fsm_1.current)(state1);
|
|
33
|
+
tslib_1.__classPrivateFieldSet(this, _state, state1, "f");
|
|
34
|
+
if (!areQueueItemsEqual(queueItem, nextQueueItem)) {
|
|
35
|
+
tslib_1.__classPrivateFieldGet(this, _reportQueueItem, "f").call(this, nextQueueItem);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
_state0.set(this, void 0);
|
|
39
|
+
_intervalHandle.set(this, null);
|
|
40
|
+
this.isRunning = () => tslib_1.__classPrivateFieldGet(this, _intervalHandle, "f") !== null;
|
|
41
|
+
_changeListeners.set(this, new Map());
|
|
42
|
+
_nextListenerId.set(this, 1);
|
|
43
|
+
this.onChange = (f, opts = {
|
|
44
|
+
withCurrent: true,
|
|
45
|
+
}) => {
|
|
46
|
+
if (opts.withCurrent)
|
|
47
|
+
f(this.current());
|
|
48
|
+
const listenerId = tslib_1.__classPrivateFieldGet(this, _nextListenerId, "f");
|
|
49
|
+
tslib_1.__classPrivateFieldGet(this, _changeListeners, "f").set(listenerId, f);
|
|
50
|
+
tslib_1.__classPrivateFieldSet(this, _nextListenerId, listenerId + 1, "f");
|
|
51
|
+
checkTooManyListeners(tslib_1.__classPrivateFieldGet(this, _changeListeners, "f").size);
|
|
52
|
+
return () => {
|
|
53
|
+
tslib_1.__classPrivateFieldGet(this, _changeListeners, "f").delete(listenerId);
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
_reportQueueItem.set(this, (next) => {
|
|
57
|
+
// called before #state change; TODO don't depend on execution order as much
|
|
58
|
+
tslib_1.__classPrivateFieldGet(this, _changeListeners, "f").forEach((f) => f(next));
|
|
59
|
+
});
|
|
60
|
+
_tick.set(this, (step) => {
|
|
61
|
+
const [state1, queueItems] = (0, fsm_1.tick)(step)(tslib_1.__classPrivateFieldGet(this, _state, "f"));
|
|
62
|
+
tslib_1.__classPrivateFieldGet(this, _setState, "f").call(this, state1);
|
|
63
|
+
return queueItems;
|
|
64
|
+
});
|
|
65
|
+
this.push = (queueItems) => {
|
|
66
|
+
tslib_1.__classPrivateFieldGet(this, _setState, "f").call(this, (0, fsm_1.push)(queueItems)(tslib_1.__classPrivateFieldGet(this, _state, "f")));
|
|
67
|
+
};
|
|
68
|
+
this.restart = () => {
|
|
69
|
+
tslib_1.__classPrivateFieldGet(this, _setState, "f").call(this, (0, fsm_1.restart)(tslib_1.__classPrivateFieldGet(this, _state, "f")));
|
|
70
|
+
};
|
|
71
|
+
this.reset = () => {
|
|
72
|
+
tslib_1.__classPrivateFieldGet(this, _setState, "f").call(this, tslib_1.__classPrivateFieldGet(this, _state0, "f"));
|
|
73
|
+
};
|
|
74
|
+
this.pause = () => {
|
|
75
|
+
if (!this.isRunning())
|
|
76
|
+
return;
|
|
77
|
+
clearInterval((0, utils_1.assertExists)(tslib_1.__classPrivateFieldGet(this, _intervalHandle, "f")));
|
|
78
|
+
tslib_1.__classPrivateFieldSet(this, _intervalHandle, null, "f");
|
|
79
|
+
};
|
|
80
|
+
this.start = () => {
|
|
81
|
+
if (this.isRunning())
|
|
82
|
+
return;
|
|
83
|
+
let lastMs = Date.now();
|
|
84
|
+
tslib_1.__classPrivateFieldSet(this, _intervalHandle, setInterval(() => {
|
|
85
|
+
const now = Date.now();
|
|
86
|
+
const delta = now - lastMs;
|
|
87
|
+
lastMs = now;
|
|
88
|
+
tslib_1.__classPrivateFieldGet(this, _tick, "f").call(this, delta);
|
|
89
|
+
if (this.isEmpty() && this.stopOnEmpty) {
|
|
90
|
+
this.stop();
|
|
91
|
+
}
|
|
92
|
+
}, this.leniency), "f");
|
|
93
|
+
};
|
|
94
|
+
this.stop = () => {
|
|
95
|
+
this.pause();
|
|
96
|
+
this.reset();
|
|
97
|
+
};
|
|
98
|
+
this.isEmpty = () => {
|
|
99
|
+
return (0, fsm_1.isEmpty)(tslib_1.__classPrivateFieldGet(this, _state, "f"));
|
|
100
|
+
};
|
|
101
|
+
this.length = () => {
|
|
102
|
+
return tslib_1.__classPrivateFieldGet(this, _state, "f").queue.length;
|
|
103
|
+
};
|
|
104
|
+
this.current = () => {
|
|
105
|
+
return (0, fsm_1.current)(tslib_1.__classPrivateFieldGet(this, _state, "f"));
|
|
106
|
+
};
|
|
107
|
+
const opts_ = Object.assign(Object.assign({}, DEFAULT_OPTS), opts);
|
|
108
|
+
if (opts_.leniency <= 0)
|
|
109
|
+
throw new Error('leniency must be positive');
|
|
110
|
+
this.push(queue);
|
|
111
|
+
tslib_1.__classPrivateFieldSet(this, _state0, tslib_1.__classPrivateFieldGet(this, _state, "f"), "f");
|
|
112
|
+
this.leniency = opts_.leniency;
|
|
113
|
+
this.stopOnEmpty = opts_.stopOnEmpty;
|
|
114
|
+
// nb! not cleanable, should be fine as it exists together with the object lifetime and semantics seem to match the Constructor assumptions
|
|
115
|
+
if (opts_.onChange)
|
|
116
|
+
this.onChange(opts_.onChange, {
|
|
117
|
+
withCurrent: true,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
_state = new WeakMap(),
|
|
122
|
+
_setState = new WeakMap(),
|
|
123
|
+
_state0 = new WeakMap(),
|
|
124
|
+
_intervalHandle = new WeakMap(),
|
|
125
|
+
_changeListeners = new WeakMap(),
|
|
126
|
+
_nextListenerId = new WeakMap(),
|
|
127
|
+
_reportQueueItem = new WeakMap(),
|
|
128
|
+
_tick = new WeakMap(),
|
|
129
|
+
_a);
|
|
130
|
+
//# sourceMappingURL=statefulSimulation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statefulSimulation.js","sourceRoot":"","sources":["../../../../adapters/src/lib/statefulSimulation.ts"],"names":[],"mappings":";;;;;AAAA,qCAUqB;AACrB,yCAA6C;AAE7C,MAA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CAAC,MAAA,CAAC;YACpB,CAAC,CAAC;YACF,SAAI,GAAG,GAAG,EAAE;gBACV,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,IAAI,CAAC,KAAK,EAAE,CAAC;YACf,CAAC,CAAC;YACF,YAAO,GAAG,GAAG,EAAE;gBACb,OAAO,IAAA,aAAO,EAAC,+BAAA,IAAI,cAAO,CAAC,CAAC;YAC9B,CAAC,CAAC;YACF,WAAM,GAAG,GAAG,EAAE;gBACZ,OAAO,+BAAA,IAAI,cAAO,CAAC,KAAK,CAAC,MAAM,CAAC;YAClC,CAAC,CAAC;YACF,YAAO,GAAG,GAAG,EAAE;gBACb,OAAO,IAAA,aAAO,EAAC,+BAAA,IAAI,cAAO,CAAC,CAAC;YAC9B,CAAC,CAAC;YAhFA,MAAM,KAAK,mCAAQ,YAAY,GAAK,IAAI,CAAE,CAAC;YAC3C,IAAI,KAAK,CAAC,QAAQ,IAAI,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;YACtE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACjB,+BAAA,IAAI,WAAW,+BAAA,IAAI,cAAO,MAAA,CAAC;YAC3B,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;YACrC,2IAA2I;YAC3I,IAAI,KAAK,CAAC,QAAQ;gBAChB,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,QAAQ,EAAE;oBAC5B,WAAW,EAAE,IAAI;iBAClB,CAAC,CAAC;QACP,CAAC;KAsEF;;;;;;;;;QAAC"}
|
package/fsm/README.md
ADDED
package/fsm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/fsm';
|
package/fsm/src/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../fsm/src/index.ts"],"names":[],"mappings":";;;AAAA,oDAA0B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const showPrintDuration0QueueItemError: (queueItem: QueueItem<string>) => string;
|
|
2
|
+
export type QueueItem<Kind extends string = string> = {
|
|
3
|
+
kind: Kind;
|
|
4
|
+
duration: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const eqQueueItem: <Kind extends string>(b: QueueItem<Kind>) => (a: QueueItem<Kind>) => boolean;
|
|
7
|
+
type Queue<Kind extends string = string> = readonly QueueItem<Kind>[];
|
|
8
|
+
export type EmptyState = {
|
|
9
|
+
duration: 0;
|
|
10
|
+
queue: readonly [];
|
|
11
|
+
};
|
|
12
|
+
export type NonEmptyState<Kind extends string> = {
|
|
13
|
+
duration: number;
|
|
14
|
+
queue: readonly [QueueItem<Kind>, ...Queue<Kind>];
|
|
15
|
+
};
|
|
16
|
+
export type State<Kind extends string = string> = NonEmptyState<Kind> | EmptyState;
|
|
17
|
+
export declare const empty: <Kind extends string>() => State<Kind>;
|
|
18
|
+
export declare const isEmpty: <Kind extends string>(state: State<Kind>) => state is EmptyState;
|
|
19
|
+
export declare const restart: <Kind extends string>(state: State<Kind>) => State<Kind>;
|
|
20
|
+
export declare const reset: <Kind extends string>(_state: State<Kind>) => State<Kind>;
|
|
21
|
+
export declare const push: <Kind_ extends string>(qx_: Queue<Kind_>) => <Kind extends string>(state: State<Kind_ extends Kind ? Kind : never>) => State<Kind_ | Kind>;
|
|
22
|
+
export declare const pop: <Kind extends string>(state: State<Kind>) => [State<Kind>, QueueItem<Kind> | null];
|
|
23
|
+
export declare const currentNE: <Kind extends string>(state: NonEmptyState<Kind>) => QueueItem<Kind>;
|
|
24
|
+
export declare const current: <Kind extends string>(state: State<Kind>) => QueueItem<Kind> | null;
|
|
25
|
+
export declare const tick: (step: number) => <Kind extends string>(state: State<Kind>) => [State<Kind>, QueueItem<Kind>[]];
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tick = exports.current = exports.currentNE = exports.pop = exports.push = exports.reset = exports.restart = exports.isEmpty = exports.empty = exports.eqQueueItem = exports.showPrintDuration0QueueItemError = void 0;
|
|
4
|
+
const utils_1 = require("@jikan0/utils");
|
|
5
|
+
let duration0QueueItemErrorShown = false;
|
|
6
|
+
const printDuration0QueueItemError = (queueItem) => {
|
|
7
|
+
if (!duration0QueueItemErrorShown) {
|
|
8
|
+
duration0QueueItemErrorShown = true;
|
|
9
|
+
console.warn((0, exports.showPrintDuration0QueueItemError)(queueItem));
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const showPrintDuration0QueueItemError = (queueItem) => `duration <= 0 queue item provided: ${showQueueItem(queueItem)}; this is not an error, but it is not recommended; the item will be ignored`;
|
|
13
|
+
exports.showPrintDuration0QueueItemError = showPrintDuration0QueueItemError;
|
|
14
|
+
const showQueueItem = (queueItem) => `${queueItem.kind}(${queueItem.duration})`;
|
|
15
|
+
// not entirely reliable (same kind+duration don't mean same item in general) but good enough for our purposes
|
|
16
|
+
const eqQueueItem = (b) => (a) => a.kind === b.kind && a.duration === b.duration;
|
|
17
|
+
exports.eqQueueItem = eqQueueItem;
|
|
18
|
+
const empty_ = {
|
|
19
|
+
duration: 0,
|
|
20
|
+
queue: Object.freeze([]),
|
|
21
|
+
};
|
|
22
|
+
const empty = () => empty_;
|
|
23
|
+
exports.empty = empty;
|
|
24
|
+
const isEmpty = (state) => state.queue.length === 0 && (0, utils_1.assertTrue)(/*defensive*/ state.duration === 0);
|
|
25
|
+
exports.isEmpty = isEmpty;
|
|
26
|
+
const restart = (state) => !(0, utils_1.isRNEA)(state.queue) /*nothing to restart*/
|
|
27
|
+
? state
|
|
28
|
+
: {
|
|
29
|
+
queue: state.queue,
|
|
30
|
+
duration: (0, utils_1.lastNEA)(state.queue).duration,
|
|
31
|
+
};
|
|
32
|
+
exports.restart = restart;
|
|
33
|
+
const reset = (_state) => (0, exports.empty)();
|
|
34
|
+
exports.reset = reset;
|
|
35
|
+
const push = (qx_) => (state) => {
|
|
36
|
+
const qx = Object.freeze(
|
|
37
|
+
/*just to cast to RA*/ qx_
|
|
38
|
+
.filter((x) => {
|
|
39
|
+
if (x.duration > 0)
|
|
40
|
+
return true;
|
|
41
|
+
printDuration0QueueItemError(x);
|
|
42
|
+
return false;
|
|
43
|
+
})
|
|
44
|
+
.reverse());
|
|
45
|
+
if (!(0, utils_1.isRNEA)(qx))
|
|
46
|
+
return state; // noop
|
|
47
|
+
return Object.freeze({
|
|
48
|
+
duration: state.duration &&
|
|
49
|
+
(0, utils_1.assertTrue)(
|
|
50
|
+
/*defensive; duration 0 means queue is []*/ (0, utils_1.isRNEA)(state.queue))
|
|
51
|
+
? state.duration
|
|
52
|
+
: (0, utils_1.lastNEA)(qx).duration,
|
|
53
|
+
queue: (0, utils_1.assertRNEA)(Object.freeze([...qx, ...state.queue])),
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
exports.push = push;
|
|
57
|
+
const popQueue = (queue) => [
|
|
58
|
+
Object.freeze(queue.slice(0, -1)),
|
|
59
|
+
(0, utils_1.last)(queue),
|
|
60
|
+
];
|
|
61
|
+
const pop = (state) => {
|
|
62
|
+
const [queue, queueItem] = popQueue(state.queue);
|
|
63
|
+
if (!(0, utils_1.isRNEA)(queue))
|
|
64
|
+
return [(0, exports.empty)(), queueItem];
|
|
65
|
+
return [
|
|
66
|
+
Object.freeze({
|
|
67
|
+
duration: (0, utils_1.lastNEA)(queue).duration,
|
|
68
|
+
queue,
|
|
69
|
+
}),
|
|
70
|
+
queueItem,
|
|
71
|
+
];
|
|
72
|
+
};
|
|
73
|
+
exports.pop = pop;
|
|
74
|
+
const currentNE = (state) => (Object.assign(Object.assign({}, (0, utils_1.lastNEA)(state.queue)), {
|
|
75
|
+
// users are interested in current left duration, not the programmed one
|
|
76
|
+
duration: state.duration }));
|
|
77
|
+
exports.currentNE = currentNE;
|
|
78
|
+
const current = (state) => ((0, exports.isEmpty)(state) ? null : (0, exports.currentNE)(state));
|
|
79
|
+
exports.current = current;
|
|
80
|
+
const tick = (step /*no check, because 0s and negatives are all right, theoretically*/) => (state) => {
|
|
81
|
+
const tick_ = (step, state, acc) => {
|
|
82
|
+
if (step === 0)
|
|
83
|
+
return [state, acc]; // noop
|
|
84
|
+
if ((0, exports.isEmpty)(state))
|
|
85
|
+
return [state, acc]; // noop
|
|
86
|
+
const duration = state.duration - step;
|
|
87
|
+
return duration <= 0 /*handle overshoots*/
|
|
88
|
+
? (() => {
|
|
89
|
+
const [state1, queueItem] = (0, exports.pop)(state);
|
|
90
|
+
if (queueItem !== null)
|
|
91
|
+
acc.push(queueItem);
|
|
92
|
+
return tick_(-duration, state1, acc);
|
|
93
|
+
})()
|
|
94
|
+
: [
|
|
95
|
+
Object.freeze({
|
|
96
|
+
queue: state.queue,
|
|
97
|
+
/*normal case*/
|
|
98
|
+
duration,
|
|
99
|
+
}),
|
|
100
|
+
acc,
|
|
101
|
+
];
|
|
102
|
+
};
|
|
103
|
+
return tick_(step, state, []);
|
|
104
|
+
};
|
|
105
|
+
exports.tick = tick;
|
|
106
|
+
//# sourceMappingURL=fsm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fsm.js","sourceRoot":"","sources":["../../../../fsm/src/lib/fsm.ts"],"names":[],"mappings":";;;AAAA,yCAA8E;AAE9E,IAAI,4BAA4B,GAAG,KAAK,CAAC;AACzC,MAAM,4BAA4B,GAAG,CAAC,SAA4B,EAAE,EAAE;IACpE,IAAI,CAAC,4BAA4B,EAAE;QACjC,4BAA4B,GAAG,IAAI,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,IAAA,wCAAgC,EAAC,SAAS,CAAC,CAAC,CAAC;KAC3D;AACH,CAAC,CAAC;AAEK,MAAM,gCAAgC,GAAG,CAC9C,SAA4B,EACpB,EAAE,CACV,sCAAsC,aAAa,CACjD,SAAS,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G,EAAC,KAAK,CAAC,CAAC;gBACvC,IAAI,SAAS,KAAK,IAAI;oBAAE,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBAC5C,OAAO,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;YACvC,CAAC,CAAC,EAAE;YACN,CAAC,CAAC;gBACE,MAAM,CAAC,MAAM,CAAC;oBACZ,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,eAAe;oBACf,QAAQ;iBACT,CAAC;gBACF,GAAG;aACJ,CAAC;IACR,CAAC,CAAC;IAEF,OAAO,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC,CAAC;AAhCS,QAAA,IAAI,QAgCb"}
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { empty, State, QueueItem, isEmpty, current, currentNE, tick, push, pop, restart, reset, } from
|
|
2
|
-
export { StatefulSimulation as Timer } from
|
|
1
|
+
export { empty, State, QueueItem, isEmpty, current, currentNE, tick, push, pop, restart, reset, } from "../fsm/src";
|
|
2
|
+
export { StatefulSimulation as Timer } from "../adapters/src";
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Timer = exports.reset = exports.restart = exports.pop = exports.push = exports.tick = exports.currentNE = exports.current = exports.isEmpty = exports.empty = void 0;
|
|
4
|
-
var fsm_1 = require("
|
|
4
|
+
var fsm_1 = require("../fsm/src");
|
|
5
5
|
Object.defineProperty(exports, "empty", { enumerable: true, get: function () { return fsm_1.empty; } });
|
|
6
6
|
Object.defineProperty(exports, "isEmpty", { enumerable: true, get: function () { return fsm_1.isEmpty; } });
|
|
7
7
|
Object.defineProperty(exports, "current", { enumerable: true, get: function () { return fsm_1.current; } });
|
|
@@ -11,6 +11,6 @@ Object.defineProperty(exports, "push", { enumerable: true, get: function () { re
|
|
|
11
11
|
Object.defineProperty(exports, "pop", { enumerable: true, get: function () { return fsm_1.pop; } });
|
|
12
12
|
Object.defineProperty(exports, "restart", { enumerable: true, get: function () { return fsm_1.restart; } });
|
|
13
13
|
Object.defineProperty(exports, "reset", { enumerable: true, get: function () { return fsm_1.reset; } });
|
|
14
|
-
var adapters_1 = require("
|
|
14
|
+
var adapters_1 = require("../adapters/src");
|
|
15
15
|
Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return adapters_1.StatefulSimulation; } });
|
|
16
16
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../facade/src/index.ts"],"names":[],"mappings":";;;AAAA,mCAYqB;AAXnB,4FAAA,KAAK,OAAA;AAGL,8FAAA,OAAO,OAAA;AACP,8FAAA,OAAO,OAAA;AACP,gGAAA,SAAS,OAAA;AACT,2FAAA,IAAI,OAAA;AACJ,2FAAA,IAAI,OAAA;AACJ,0FAAA,GAAG,OAAA;AACH,8FAAA,OAAO,OAAA;AACP,4FAAA,KAAK,OAAA;AAGP,6CAA+D;AAAtD,iGAAA,kBAAkB,OAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/testUtils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../test-utils/src/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BASIC_EXERCISE_PROGRAM = void 0;
|
|
4
|
+
exports.BASIC_EXERCISE_PROGRAM = (() => {
|
|
5
|
+
const ROUND_TYPES = ['warmup', 'exercise', 'rest', 'cooldown'];
|
|
6
|
+
const ONE_MINUTE = 60 * 1000;
|
|
7
|
+
const TOTAL_ROUNDS = 10;
|
|
8
|
+
const WARMUP_DURATION = 5 * ONE_MINUTE;
|
|
9
|
+
const EXERCISE_DURATION = 3 * ONE_MINUTE;
|
|
10
|
+
// noinspection PointlessArithmeticExpressionJS
|
|
11
|
+
const REST_DURATION = 1 * ONE_MINUTE;
|
|
12
|
+
const COOLDOWN_DURATION = 5 * ONE_MINUTE;
|
|
13
|
+
const DURATIONS = {
|
|
14
|
+
warmup: WARMUP_DURATION,
|
|
15
|
+
exercise: EXERCISE_DURATION,
|
|
16
|
+
rest: REST_DURATION,
|
|
17
|
+
cooldown: COOLDOWN_DURATION,
|
|
18
|
+
};
|
|
19
|
+
return [...Array(TOTAL_ROUNDS + 2 /*warmup/cooldown*/).keys()]
|
|
20
|
+
.map((i) => i === 0
|
|
21
|
+
? 'warmup'
|
|
22
|
+
: i === TOTAL_ROUNDS + 1
|
|
23
|
+
? 'cooldown'
|
|
24
|
+
: i % 2 === 1
|
|
25
|
+
? 'exercise'
|
|
26
|
+
: 'rest')
|
|
27
|
+
.map((kind) => ({
|
|
28
|
+
kind,
|
|
29
|
+
duration: DURATIONS[kind],
|
|
30
|
+
}));
|
|
31
|
+
})();
|
|
32
|
+
//# sourceMappingURL=testUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../../../../test-utils/src/lib/testUtils.ts"],"names":[],"mappings":";;;AAAa,QAAA,sBAAsB,GAAG,CAAC,GAAG,EAAE;IAC1C,MAAM,WAAW,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,CAAU,CAAC;IAExE,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,CAAC;IAC7B,MAAM,YAAY,GAAG,EAAE,CAAC;IACxB,MAAM,eAAe,GAAG,CAAC,GAAG,UAAU,CAAC;IACvC,MAAM,iBAAiB,GAAG,CAAC,GAAG,UAAU,CAAC;IACzC,+CAA+C;IAC/C,MAAM,aAAa,GAAG,CAAC,GAAG,UAAU,CAAC;IACrC,MAAM,iBAAiB,GAAG,CAAC,GAAG,UAAU,CAAC;IACzC,MAAM,SAAS,GAEX;QACF,MAAM,EAAE,eAAe;QACvB,QAAQ,EAAE,iBAAiB;QAC3B,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,iBAAiB;KAC5B,CAAC;IACF,OAAO,CAAC,GAAG,KAAK,CAAC,YAAY,GAAG,CAAC,CAAC,mBAAmB,CAAC,CAAC,IAAI,EAAE,CAAC;SAC3D,GAAG,CACF,CAAC,CAAC,EAAa,EAAE,CACf,CAAC,KAAK,CAAC;QACL,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,CAAC,KAAK,YAAY,GAAG,CAAC;YACxB,CAAC,CAAC,UAAU;YACZ,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC;gBACb,CAAC,CAAC,UAAU;gBACZ,CAAC,CAAC,MAAM,CACb;SACA,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACd,IAAI;QACJ,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC;KAC1B,CAAC,CAAC,CAAC;AACR,CAAC,CAAC,EAAE,CAAC"}
|
package/utils/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './lib/utils';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../utils/src/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const isRNEA: <T>(a: readonly T[]) => a is readonly [T, ...T[]];
|
|
2
|
+
export declare const assertRNEA: <T>(a: readonly T[]) => readonly [T, ...T[]];
|
|
3
|
+
export declare const last: <T>(a: readonly T[] | T[]) => T | null;
|
|
4
|
+
export declare const lastNEA: <T>(a: readonly [T, ...T[]]) => T;
|
|
5
|
+
export declare const assertTrue: (b: boolean) => true;
|
|
6
|
+
export declare const assertExists: <T>(x: T | null | undefined) => T;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertExists = exports.assertTrue = exports.lastNEA = exports.last = exports.assertRNEA = exports.isRNEA = void 0;
|
|
4
|
+
// RNEA is read only non-empty array
|
|
5
|
+
const isRNEA = (a) => a.length > 0;
|
|
6
|
+
exports.isRNEA = isRNEA;
|
|
7
|
+
const assertRNEA = (a) => {
|
|
8
|
+
if (!(0, exports.isRNEA)(a))
|
|
9
|
+
throw new Error('panic! assertion RNEA failed');
|
|
10
|
+
return a;
|
|
11
|
+
};
|
|
12
|
+
exports.assertRNEA = assertRNEA;
|
|
13
|
+
const last = (a) => (0, exports.isRNEA)(a) ? a[a.length - 1] : null;
|
|
14
|
+
exports.last = last;
|
|
15
|
+
const lastNEA = (a) => a[a.length - 1];
|
|
16
|
+
exports.lastNEA = lastNEA;
|
|
17
|
+
const assertTrue = (b) => {
|
|
18
|
+
if (!b)
|
|
19
|
+
throw new Error('panic! assertion true failed');
|
|
20
|
+
return true;
|
|
21
|
+
};
|
|
22
|
+
exports.assertTrue = assertTrue;
|
|
23
|
+
const assertExists = (x) => {
|
|
24
|
+
if (x === null || x === undefined)
|
|
25
|
+
throw new Error('panic! assertion exists failed');
|
|
26
|
+
return x;
|
|
27
|
+
};
|
|
28
|
+
exports.assertExists = assertExists;
|
|
29
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../utils/src/lib/utils.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AAC7B,MAAM,MAAM,GAAG,CAAI,CAAe,EAA6B,EAAE,CACtE,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AADF,QAAA,MAAM,UACJ;AACR,MAAM,UAAU,GAAG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