assertron 10.0.0 → 11.0.0
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/cjs/assert-order/AssertOrder.js +99 -176
- package/cjs/assert-order/AssertOrder.js.map +1 -1
- package/cjs/assert-order/InvalidOrder.js +16 -34
- package/cjs/assert-order/InvalidOrder.js.map +1 -1
- package/cjs/assert-order/StateMachine.js +66 -122
- package/cjs/assert-order/StateMachine.js.map +1 -1
- package/cjs/assertron/assertron.js +12 -12
- package/cjs/assertron/assertron.js.map +1 -1
- package/cjs/assertron/falsy.js +2 -2
- package/cjs/assertron/falsy.js.map +1 -1
- package/cjs/assertron/pathEqual.js +3 -3
- package/cjs/assertron/pathEqual.js.map +1 -1
- package/cjs/assertron/rejects.js +3 -3
- package/cjs/assertron/rejects.js.map +1 -1
- package/cjs/assertron/repeat.js +4 -4
- package/cjs/assertron/repeat.js.map +1 -1
- package/cjs/assertron/resolves.js +3 -3
- package/cjs/assertron/resolves.js.map +1 -1
- package/cjs/assertron/satisfies.js +4 -4
- package/cjs/assertron/satisfies.js.map +1 -1
- package/cjs/assertron/throws.js +9 -9
- package/cjs/assertron/throws.js.map +1 -1
- package/cjs/assertron/truthy.js +2 -2
- package/cjs/assertron/truthy.js.map +1 -1
- package/cjs/errors.js +12 -32
- package/cjs/errors.js.map +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/package.json +1 -0
- package/cjs/utils/index.js +2 -2
- package/cjs/utils/index.js.map +1 -1
- package/cjs/utils/notEqualMessage.js +1 -1
- package/cjs/utils/notEqualMessage.js.map +1 -1
- package/cjs/utils/notSatisfiedMessage.js +6 -15
- package/cjs/utils/notSatisfiedMessage.js.map +1 -1
- package/cjs/utils/notThrownMessage.js +2 -2
- package/cjs/utils/notThrownMessage.js.map +1 -1
- package/cjs/utils/promiseMessages.js +5 -5
- package/cjs/utils/promiseMessages.js.map +1 -1
- package/cjs/utils/unexpectedErrorMessage.js +4 -4
- package/cjs/utils/unexpectedErrorMessage.js.map +1 -1
- package/package.json +14 -12
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AssertOrder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const InvalidOrder_js_1 = require("./InvalidOrder.js");
|
|
5
|
+
const StateMachine_js_1 = require("./StateMachine.js");
|
|
6
6
|
// order.atLeast(step, count) // expected to be executed at least `count` times
|
|
7
7
|
// order.atMost(step, count) // exected to be executed at most `count` times
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
class AssertOrder {
|
|
9
|
+
constructor(plan) {
|
|
10
10
|
Object.defineProperty(this, "state", {
|
|
11
11
|
enumerable: true,
|
|
12
12
|
configurable: true,
|
|
@@ -15,205 +15,128 @@ var AssertOrder = /** @class */ (function () {
|
|
|
15
15
|
});
|
|
16
16
|
this.state = new StateMachine_js_1.StateMachine(plan);
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
enumerable: false,
|
|
26
|
-
configurable: true
|
|
27
|
-
});
|
|
18
|
+
/**
|
|
19
|
+
* Gets the current expecting step.
|
|
20
|
+
*/
|
|
21
|
+
get currentStep() {
|
|
22
|
+
return this.state.step;
|
|
23
|
+
}
|
|
28
24
|
/**
|
|
29
25
|
* Asserts the current step is `step`.
|
|
30
26
|
* @param step expected step.
|
|
31
27
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
writable: true,
|
|
36
|
-
value: function (step) {
|
|
37
|
-
this.assert('is', step);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
28
|
+
is(step) {
|
|
29
|
+
this.assert('is', step);
|
|
30
|
+
}
|
|
40
31
|
/**
|
|
41
32
|
* Asserts the current step is not `step`.
|
|
42
33
|
* @param step not expected step.
|
|
43
34
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
writable: true,
|
|
48
|
-
value: function (step) {
|
|
49
|
-
if (this.state.isValid(step)) {
|
|
50
|
-
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not });
|
|
51
|
-
}
|
|
35
|
+
not(step) {
|
|
36
|
+
if (this.state.isValid(step)) {
|
|
37
|
+
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'not', [step], { ssf: this.not });
|
|
52
38
|
}
|
|
53
|
-
}
|
|
39
|
+
}
|
|
54
40
|
/**
|
|
55
41
|
* Reset to specified step.
|
|
56
42
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
writable: true,
|
|
61
|
-
value: function (step) {
|
|
62
|
-
this.state.jump(step);
|
|
63
|
-
}
|
|
64
|
-
});
|
|
43
|
+
jump(step) {
|
|
44
|
+
this.state.jump(step);
|
|
45
|
+
}
|
|
65
46
|
/**
|
|
66
47
|
* Move to next step.
|
|
67
48
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
writable: true,
|
|
72
|
-
value: function () {
|
|
73
|
-
this.state.move();
|
|
74
|
-
}
|
|
75
|
-
});
|
|
49
|
+
move() {
|
|
50
|
+
this.state.move();
|
|
51
|
+
}
|
|
76
52
|
/**
|
|
77
53
|
* Asserts the specified step will run once.
|
|
78
54
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
55
|
+
once(step) {
|
|
56
|
+
this.assert('once', step);
|
|
57
|
+
this.state.move();
|
|
58
|
+
}
|
|
59
|
+
on(step, assert) {
|
|
60
|
+
this.state.on(step, () => {
|
|
61
|
+
assert(step);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
atLeastOnce(step) {
|
|
65
|
+
const nextStep = step + 1;
|
|
66
|
+
if (this.state.step === step) {
|
|
85
67
|
this.state.move();
|
|
68
|
+
return this.state.moveSubStep();
|
|
86
69
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
enumerable: false,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: function (step, assert) {
|
|
93
|
-
this.state.on(step, function () {
|
|
94
|
-
assert(step);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
Object.defineProperty(AssertOrder.prototype, "atLeastOnce", {
|
|
99
|
-
enumerable: false,
|
|
100
|
-
configurable: true,
|
|
101
|
-
writable: true,
|
|
102
|
-
value: function (step) {
|
|
103
|
-
var nextStep = step + 1;
|
|
104
|
-
if (this.state.step === step) {
|
|
105
|
-
this.state.move();
|
|
106
|
-
return this.state.moveSubStep();
|
|
107
|
-
}
|
|
108
|
-
else if (this.state.step === nextStep && this.state.subStep > 0) {
|
|
109
|
-
return this.state.moveSubStep();
|
|
110
|
-
}
|
|
111
|
-
else
|
|
112
|
-
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce });
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
Object.defineProperty(AssertOrder.prototype, "any", {
|
|
116
|
-
enumerable: false,
|
|
117
|
-
configurable: true,
|
|
118
|
-
writable: true,
|
|
119
|
-
value: function (steps) {
|
|
120
|
-
var index = steps.indexOf(this.state.step);
|
|
121
|
-
if (index === -1)
|
|
122
|
-
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any });
|
|
123
|
-
this.state.move();
|
|
124
|
-
return steps[index];
|
|
70
|
+
else if (this.state.step === nextStep && this.state.subStep > 0) {
|
|
71
|
+
return this.state.moveSubStep();
|
|
125
72
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
});
|
|
151
|
-
if (!hasPass)
|
|
152
|
-
throw firstError;
|
|
73
|
+
else
|
|
74
|
+
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'atLeastOnce', [step], { ssf: this.atLeastOnce });
|
|
75
|
+
}
|
|
76
|
+
any(steps) {
|
|
77
|
+
const index = steps.indexOf(this.state.step);
|
|
78
|
+
if (index === -1)
|
|
79
|
+
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'any', [steps], { ssf: this.any });
|
|
80
|
+
this.state.move();
|
|
81
|
+
return steps[index];
|
|
82
|
+
}
|
|
83
|
+
onAny(steps, ...asserts) {
|
|
84
|
+
steps.forEach(step => {
|
|
85
|
+
this.state.on(step, () => {
|
|
86
|
+
let firstError;
|
|
87
|
+
let hasPass = false;
|
|
88
|
+
asserts.forEach(assert => {
|
|
89
|
+
try {
|
|
90
|
+
assert(step);
|
|
91
|
+
hasPass = true;
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
if (!firstError)
|
|
95
|
+
firstError = err;
|
|
96
|
+
}
|
|
153
97
|
});
|
|
98
|
+
if (!hasPass)
|
|
99
|
+
throw firstError;
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
end(timeout) {
|
|
105
|
+
if (timeout) {
|
|
106
|
+
return new Promise(r => {
|
|
107
|
+
setTimeout(r, timeout);
|
|
108
|
+
}).then(() => {
|
|
109
|
+
return this.end();
|
|
154
110
|
});
|
|
155
|
-
return;
|
|
156
111
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
configurable: true,
|
|
161
|
-
writable: true,
|
|
162
|
-
value: function (timeout) {
|
|
163
|
-
var _this = this;
|
|
164
|
-
if (timeout) {
|
|
165
|
-
return new Promise(function (r) {
|
|
166
|
-
setTimeout(r, timeout);
|
|
167
|
-
}).then(function () {
|
|
168
|
-
return _this.end();
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
if (!this.state.isMaxStepDefined()) {
|
|
172
|
-
this.state.stopAccepting();
|
|
173
|
-
return this.state.getTimeTaken();
|
|
174
|
-
}
|
|
175
|
-
if (this.state.isAccepting()) {
|
|
176
|
-
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'end', [], { ssf: this.end });
|
|
177
|
-
}
|
|
112
|
+
if (!this.state.isMaxStepDefined()) {
|
|
113
|
+
this.state.stopAccepting();
|
|
114
|
+
return this.state.getTimeTaken();
|
|
178
115
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
enumerable: false,
|
|
182
|
-
configurable: true,
|
|
183
|
-
writable: true,
|
|
184
|
-
value: function (step, times) {
|
|
185
|
-
if (this.state.isNotValid(step))
|
|
186
|
-
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly });
|
|
187
|
-
if (this.state.maxSubStep === undefined) {
|
|
188
|
-
this.state.maxSubStep = times;
|
|
189
|
-
this.state.minSubStep = times;
|
|
190
|
-
}
|
|
191
|
-
return this.state.moveSubStep();
|
|
116
|
+
if (this.state.isAccepting()) {
|
|
117
|
+
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'end', [], { ssf: this.end });
|
|
192
118
|
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
if (callback)
|
|
201
|
-
this.on(step, callback);
|
|
202
|
-
else
|
|
203
|
-
return new Promise(function (a) { _this.on(step, a); });
|
|
119
|
+
}
|
|
120
|
+
exactly(step, times) {
|
|
121
|
+
if (this.state.isNotValid(step))
|
|
122
|
+
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), 'exactly', [step, times], { ssf: this.exactly });
|
|
123
|
+
if (this.state.maxSubStep === undefined) {
|
|
124
|
+
this.state.maxSubStep = times;
|
|
125
|
+
this.state.minSubStep = times;
|
|
204
126
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
127
|
+
return this.state.moveSubStep();
|
|
128
|
+
}
|
|
129
|
+
wait(step, callback) {
|
|
130
|
+
if (callback)
|
|
131
|
+
this.on(step, callback);
|
|
132
|
+
else
|
|
133
|
+
return new Promise(a => { this.on(step, a); });
|
|
134
|
+
}
|
|
135
|
+
assert(method, step) {
|
|
136
|
+
if (this.state.isNotValid(step)) {
|
|
137
|
+
throw new InvalidOrder_js_1.InvalidOrder(this.state.get(), method, [step], { ssf: this[method] });
|
|
214
138
|
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
}());
|
|
139
|
+
}
|
|
140
|
+
}
|
|
218
141
|
exports.AssertOrder = AssertOrder;
|
|
219
142
|
//# sourceMappingURL=AssertOrder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssertOrder.js","sourceRoot":"","sources":["../../ts/assert-order/AssertOrder.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"AssertOrder.js","sourceRoot":"","sources":["../../ts/assert-order/AssertOrder.ts"],"names":[],"mappings":";;;AAAA,uDAAgD;AAChD,uDAAgD;AAEhD,+EAA+E;AAC/E,4EAA4E;AAE5E,MAAa,WAAW;IAStB,YAAY,IAAa;QADzB;;;;;WAA2B;QAEzB,IAAI,CAAC,KAAK,GAAG,IAAI,8BAAY,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAVD;;OAEG;IACH,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAA;IACxB,CAAC;IAOD;;;OAGG;IACH,EAAE,CA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AQ;YACV,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAA;;YAEvB,OAAO,IAAI,OAAO,CAAM,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA,CAAC,CAAC,CAAC,CAAA;IACtD,CAAC;IACO,MAAM,CAAC,MAAc,EAAE,IAAY;QACzC,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE;YAC/B,MAAM,IAAI,8BAAY,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,EAAG,IAAY,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;SACzF;IACH,CAAC;CACF;AAhJD,kCAgJC"}
|
|
@@ -1,68 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.InvalidOrder = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Object.defineProperty(_this, "state", {
|
|
4
|
+
const errors_js_1 = require("../errors.js");
|
|
5
|
+
class InvalidOrder extends errors_js_1.AssertionError {
|
|
6
|
+
constructor(state, method, args, options) {
|
|
7
|
+
super(method === 'end' ? getEndMessage(state) : getExpectingMessage(state, method, args), options);
|
|
8
|
+
Object.defineProperty(this, "state", {
|
|
25
9
|
enumerable: true,
|
|
26
10
|
configurable: true,
|
|
27
11
|
writable: true,
|
|
28
12
|
value: state
|
|
29
13
|
});
|
|
30
|
-
Object.defineProperty(
|
|
14
|
+
Object.defineProperty(this, "method", {
|
|
31
15
|
enumerable: true,
|
|
32
16
|
configurable: true,
|
|
33
17
|
writable: true,
|
|
34
18
|
value: method
|
|
35
19
|
});
|
|
36
|
-
Object.defineProperty(
|
|
20
|
+
Object.defineProperty(this, "args", {
|
|
37
21
|
enumerable: true,
|
|
38
22
|
configurable: true,
|
|
39
23
|
writable: true,
|
|
40
24
|
value: args
|
|
41
25
|
});
|
|
42
|
-
return _this;
|
|
43
26
|
}
|
|
44
|
-
|
|
45
|
-
}(errors_js_1.AssertionError));
|
|
27
|
+
}
|
|
46
28
|
exports.InvalidOrder = InvalidOrder;
|
|
47
29
|
function getEndMessage(state) {
|
|
48
|
-
return
|
|
30
|
+
return `Planned for ${state.maxStep} step but expecting step ${state.step} when 'end()' is called`;
|
|
49
31
|
}
|
|
50
32
|
function getExpectingMessage(state, method, args) {
|
|
51
|
-
return
|
|
33
|
+
return `Expecting ${getExpectingCalls(state)}, but received '${method}(${getMethodArgs(args)})'`;
|
|
52
34
|
}
|
|
53
35
|
function getExpectingCalls(state) {
|
|
54
|
-
|
|
36
|
+
let message;
|
|
55
37
|
if (state.subStep === 0) {
|
|
56
|
-
|
|
57
|
-
message = methods.map(
|
|
38
|
+
const methods = ['is', 'once', 'any'];
|
|
39
|
+
message = methods.map(m => `'${m}(${['any'].indexOf(m) === -1 ? state.step : `[${state.step}]`})'`).join(', ');
|
|
58
40
|
}
|
|
59
41
|
else {
|
|
60
|
-
|
|
61
|
-
message = methods.map(
|
|
42
|
+
const methods = ['exactly'];
|
|
43
|
+
message = methods.map(m => `'${m}(${state.step}, ${state.maxSubStep})'`).join(', ');
|
|
62
44
|
}
|
|
63
45
|
return message;
|
|
64
46
|
}
|
|
65
47
|
function getMethodArgs(args) {
|
|
66
|
-
return args.map(
|
|
48
|
+
return args.map(a => Array.isArray(a) ? `[${a.join(', ')}]` : a).join(', ');
|
|
67
49
|
}
|
|
68
50
|
//# sourceMappingURL=InvalidOrder.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InvalidOrder.js","sourceRoot":"","sources":["../../ts/assert-order/InvalidOrder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"InvalidOrder.js","sourceRoot":"","sources":["../../ts/assert-order/InvalidOrder.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAG7C,MAAa,YAAa,SAAQ,0BAAc;IAC9C,YAAmB,KAAY,EAAS,MAAc,EAAS,IAAW,EAAE,OAA+B;QACzG,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,CAAA;;;;;mBADjF;;;;;;mBAAqB;;;;;;mBAAuB;;IAE/D,CAAC;CACF;AAJD,oCAIC;AAED,SAAS,aAAa,CAAC,KAAY;IACjC,OAAO,eAAe,KAAK,CAAC,OAAO,4BAA4B,KAAK,CAAC,IAAI,yBAAyB,CAAA;AACpG,CAAC;AAED,SAAS,mBAAmB,CAAC,KAAY,EAAE,MAAc,EAAE,IAAW;IACpE,OAAO,aAAa,iBAAiB,CAAC,KAAK,CAAC,mBAAmB,MAAM,IAAI,aAAa,CAAC,IAAI,CAAC,IAAI,CAAA;AAClG,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAY;IACrC,IAAI,OAAe,CAAA;IACnB,IAAI,KAAK,CAAC,OAAO,KAAK,CAAC,EAAE;QACvB,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAA;QACrC,OAAO,GAAG,OAAO,CAAC,GAAG,CACnB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,IAAI,GAAG,IAAI,CAC7E,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KACb;SACI;QACH,MAAM,OAAO,GAAG,CAAC,SAAS,CAAC,CAAA;QAC3B,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;KACpF;IACD,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,SAAS,aAAa,CAAC,IAAW;IAChC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAC7E,CAAC"}
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StateMachine = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const perf_hooks_1 = require("perf_hooks");
|
|
5
|
+
let timeTracker;
|
|
6
6
|
// istanbul ignore else
|
|
7
7
|
if (process && typeof process.hrtime === 'function') {
|
|
8
|
-
|
|
8
|
+
let tick;
|
|
9
9
|
timeTracker = {
|
|
10
|
-
start
|
|
11
|
-
taken
|
|
12
|
-
|
|
10
|
+
start() { tick = process.hrtime(); },
|
|
11
|
+
taken() {
|
|
12
|
+
const [second, nanoSecond] = process.hrtime(tick);
|
|
13
13
|
return second * 1000 + nanoSecond / 1e6;
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
else if (perf_hooks_1.performance && typeof perf_hooks_1.performance.now === 'function') {
|
|
18
|
-
|
|
18
|
+
let tick;
|
|
19
19
|
timeTracker = {
|
|
20
|
-
start
|
|
21
|
-
taken
|
|
20
|
+
start() { tick = perf_hooks_1.performance.now(); },
|
|
21
|
+
taken() { return perf_hooks_1.performance.now() - tick; }
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
|
|
25
|
+
let tick;
|
|
26
26
|
timeTracker = {
|
|
27
|
-
start
|
|
28
|
-
taken
|
|
27
|
+
start() { tick = new Date().valueOf(); },
|
|
28
|
+
taken() { return new Date().valueOf() - tick; }
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
class StateMachine {
|
|
32
|
+
constructor(maxStep) {
|
|
33
33
|
Object.defineProperty(this, "listeners", {
|
|
34
34
|
enumerable: true,
|
|
35
35
|
configurable: true,
|
|
@@ -69,114 +69,58 @@ var StateMachine = /** @class */ (function () {
|
|
|
69
69
|
this.maxStep = maxStep;
|
|
70
70
|
timeTracker.start();
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
enumerable: false,
|
|
84
|
-
configurable: true,
|
|
85
|
-
writable: true,
|
|
86
|
-
value: function () {
|
|
87
|
-
var listeners = this.listeners[this.step];
|
|
88
|
-
this.step = this.step + 1;
|
|
89
|
-
this.subStep = 0;
|
|
90
|
-
if (listeners) {
|
|
91
|
-
listeners.forEach(function (l) { return l(); });
|
|
92
|
-
}
|
|
93
|
-
return this.step;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
Object.defineProperty(StateMachine.prototype, "moveSubStep", {
|
|
97
|
-
enumerable: false,
|
|
98
|
-
configurable: true,
|
|
99
|
-
writable: true,
|
|
100
|
-
value: function () {
|
|
101
|
-
var subStep = ++this.subStep;
|
|
102
|
-
if (this.maxSubStep === this.subStep)
|
|
103
|
-
this.move();
|
|
104
|
-
return subStep;
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
Object.defineProperty(StateMachine.prototype, "get", {
|
|
108
|
-
enumerable: false,
|
|
109
|
-
configurable: true,
|
|
110
|
-
writable: true,
|
|
111
|
-
value: function () {
|
|
112
|
-
var _a = this, step = _a.step, subStep = _a.subStep, maxStep = _a.maxStep, minSubStep = _a.minSubStep, maxSubStep = _a.maxSubStep;
|
|
113
|
-
return {
|
|
114
|
-
step: step,
|
|
115
|
-
maxStep: maxStep,
|
|
116
|
-
subStep: subStep,
|
|
117
|
-
minSubStep: minSubStep,
|
|
118
|
-
maxSubStep: maxSubStep
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
Object.defineProperty(StateMachine.prototype, "on", {
|
|
123
|
-
enumerable: false,
|
|
124
|
-
configurable: true,
|
|
125
|
-
writable: true,
|
|
126
|
-
value: function (step, listener) {
|
|
127
|
-
this.listeners[step] = [listener];
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
Object.defineProperty(StateMachine.prototype, "isNotValid", {
|
|
131
|
-
enumerable: false,
|
|
132
|
-
configurable: true,
|
|
133
|
-
writable: true,
|
|
134
|
-
value: function (step) {
|
|
135
|
-
return step !== this.step || (this.maxStep !== undefined && this.maxStep < step);
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
Object.defineProperty(StateMachine.prototype, "isValid", {
|
|
139
|
-
enumerable: false,
|
|
140
|
-
configurable: true,
|
|
141
|
-
writable: true,
|
|
142
|
-
value: function (step) {
|
|
143
|
-
return step === this.step;
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
Object.defineProperty(StateMachine.prototype, "isMaxStepDefined", {
|
|
147
|
-
enumerable: false,
|
|
148
|
-
configurable: true,
|
|
149
|
-
writable: true,
|
|
150
|
-
value: function () {
|
|
151
|
-
return this.maxStep !== undefined;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
Object.defineProperty(StateMachine.prototype, "stopAccepting", {
|
|
155
|
-
enumerable: false,
|
|
156
|
-
configurable: true,
|
|
157
|
-
writable: true,
|
|
158
|
-
value: function () {
|
|
159
|
-
this.maxStep = this.step - 1;
|
|
160
|
-
}
|
|
161
|
-
});
|
|
162
|
-
Object.defineProperty(StateMachine.prototype, "isAccepting", {
|
|
163
|
-
enumerable: false,
|
|
164
|
-
configurable: true,
|
|
165
|
-
writable: true,
|
|
166
|
-
value: function () {
|
|
167
|
-
// istanbul ignore next
|
|
168
|
-
return this.maxStep ? this.maxStep >= this.step : true;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
Object.defineProperty(StateMachine.prototype, "getTimeTaken", {
|
|
172
|
-
enumerable: false,
|
|
173
|
-
configurable: true,
|
|
174
|
-
writable: true,
|
|
175
|
-
value: function () {
|
|
176
|
-
return timeTracker.taken();
|
|
72
|
+
jump(step) {
|
|
73
|
+
this.step = step;
|
|
74
|
+
this.subStep = 0;
|
|
75
|
+
return this.step;
|
|
76
|
+
}
|
|
77
|
+
move() {
|
|
78
|
+
const listeners = this.listeners[this.step];
|
|
79
|
+
this.step = this.step + 1;
|
|
80
|
+
this.subStep = 0;
|
|
81
|
+
if (listeners) {
|
|
82
|
+
listeners.forEach(l => l());
|
|
177
83
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
84
|
+
return this.step;
|
|
85
|
+
}
|
|
86
|
+
moveSubStep() {
|
|
87
|
+
const subStep = ++this.subStep;
|
|
88
|
+
if (this.maxSubStep === this.subStep)
|
|
89
|
+
this.move();
|
|
90
|
+
return subStep;
|
|
91
|
+
}
|
|
92
|
+
get() {
|
|
93
|
+
const { step, subStep, maxStep, minSubStep, maxSubStep } = this;
|
|
94
|
+
return {
|
|
95
|
+
step,
|
|
96
|
+
maxStep,
|
|
97
|
+
subStep,
|
|
98
|
+
minSubStep,
|
|
99
|
+
maxSubStep
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
on(step, listener) {
|
|
103
|
+
this.listeners[step] = [listener];
|
|
104
|
+
}
|
|
105
|
+
isNotValid(step) {
|
|
106
|
+
return step !== this.step || (this.maxStep !== undefined && this.maxStep < step);
|
|
107
|
+
}
|
|
108
|
+
isValid(step) {
|
|
109
|
+
return step === this.step;
|
|
110
|
+
}
|
|
111
|
+
isMaxStepDefined() {
|
|
112
|
+
return this.maxStep !== undefined;
|
|
113
|
+
}
|
|
114
|
+
stopAccepting() {
|
|
115
|
+
this.maxStep = this.step - 1;
|
|
116
|
+
}
|
|
117
|
+
isAccepting() {
|
|
118
|
+
// istanbul ignore next
|
|
119
|
+
return this.maxStep ? this.maxStep >= this.step : true;
|
|
120
|
+
}
|
|
121
|
+
getTimeTaken() {
|
|
122
|
+
return timeTracker.taken();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
181
125
|
exports.StateMachine = StateMachine;
|
|
182
126
|
//# sourceMappingURL=StateMachine.js.map
|