readiness-manager 1.1.3 → 1.2.0-rc.xf50ab1c7f
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/CHANGELOG.md +11 -1
- package/README.md +33 -17
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +10 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/error.d.ts +16 -0
- package/dist/src/error.d.ts.map +1 -0
- package/dist/src/error.js +23 -0
- package/dist/src/error.js.map +1 -0
- package/dist/src/index.d.ts +19 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +120 -0
- package/dist/src/index.js.map +1 -0
- package/dist/tests/mock.d.ts +8 -0
- package/dist/tests/mock.d.ts.map +1 -0
- package/dist/tests/mock.js +39 -0
- package/dist/tests/mock.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/jest.config.ts +8 -0
- package/package.json +16 -27
- package/project.json +16 -0
- package/src/constants.ts +11 -0
- package/src/error.ts +38 -0
- package/src/index.ts +244 -0
- package/src/spec.ts +257 -0
- package/tests/mock.ts +56 -0
- package/tsconfig.json +10 -0
- package/LICENSE +0 -8
- package/index.js +0 -1
- package/src/constants.js +0 -14
- package/src/error.js +0 -42
- package/src/index.js +0 -208
- package/src/types.d.ts +0 -40
- package/tests/mock.d.ts +0 -9
- package/tests/mock.js +0 -36
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 1.2.0 (19 January 2026)
|
|
4
|
+
|
|
5
|
+
- Migrated to platform sphinx
|
|
6
|
+
- Refactor to typescript(no breaking changes to the API)
|
|
7
|
+
- Add `debug` flag to analyze how long actions take to run.
|
|
8
|
+
|
|
9
|
+
## 1.1.4 (7 April 2022)
|
|
10
|
+
|
|
11
|
+
- Fix beacon initial execution, attempt was passed as index of the `forEach`.
|
|
12
|
+
|
|
3
13
|
## 1.1.3 (2 August 2021)
|
|
4
14
|
|
|
5
15
|
### Bug Fixes
|
|
@@ -29,4 +39,4 @@
|
|
|
29
39
|
|
|
30
40
|
### Improvements
|
|
31
41
|
|
|
32
|
-
- Adding `chain` option to manager api methods.
|
|
42
|
+
- Adding `chain` option to manager api methods.
|
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
Controlling node application readiness state.
|
|
3
2
|
|
|
4
3
|
## Motivation
|
|
@@ -24,7 +23,7 @@ ReadinessManager.register('translations', () => axios.get('https://www.translati
|
|
|
24
23
|
ReadinessManager.run();
|
|
25
24
|
|
|
26
25
|
// Will be triggered once all registered actions are successfully resolved.
|
|
27
|
-
ReadinessManager.onReady(() => console.log('App is ready!
|
|
26
|
+
ReadinessManager.onReady(() => console.log('App is ready! o/'));
|
|
28
27
|
```
|
|
29
28
|
|
|
30
29
|
This will allow you to set up an health check route, checking if you app readiness state as following:
|
|
@@ -33,10 +32,10 @@ This will allow you to set up an health check route, checking if you app readine
|
|
|
33
32
|
// routes.health.js
|
|
34
33
|
|
|
35
34
|
if (ReadinessManager.ready) {
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
res.status(200).end(`App is ready and running well`);
|
|
36
|
+
return;
|
|
38
37
|
} else {
|
|
39
|
-
|
|
38
|
+
res.status(503).end('App is not ready');
|
|
40
39
|
}
|
|
41
40
|
```
|
|
42
41
|
|
|
@@ -46,12 +45,26 @@ if (ReadinessManager.ready) {
|
|
|
46
45
|
|
|
47
46
|
Returns `true` if all the registered actions has been ran without exceptions/rejections.
|
|
48
47
|
|
|
49
|
-
### register(name: string, action: ReadyAction): void
|
|
48
|
+
### register(name: string, action: ReadyAction, debug?: boolean): void
|
|
50
49
|
|
|
51
50
|
Registers a given name and action under `ReadinessManager`, registered actions will be observed once ran in order to determine the process readiness state.
|
|
52
51
|
|
|
53
52
|
```ts
|
|
54
|
-
type ReadyAction = () => void|Promise<void>;
|
|
53
|
+
type ReadyAction = () => void | Promise<void>;
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
**Parameters:**
|
|
57
|
+
|
|
58
|
+
- `name` - Unique identifier for the action
|
|
59
|
+
- `action` - Function to execute (sync or async)
|
|
60
|
+
- `debug` - Optional flag to enable timing logs (default: `false`)
|
|
61
|
+
|
|
62
|
+
**Debug Mode:**
|
|
63
|
+
When `debug` is set to `true`, the manager will log the execution time for the action:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
ReadinessManager.register('database', () => connectToDB(), true);
|
|
67
|
+
// Logs: [ReadinessManager] Action "database" completed in 245ms
|
|
55
68
|
```
|
|
56
69
|
|
|
57
70
|
### run(): void
|
|
@@ -78,10 +91,10 @@ Registers a given callback on a specific action completion event.
|
|
|
78
91
|
|
|
79
92
|
```ts
|
|
80
93
|
interface ActionExecutionError extends Error {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
name: string;
|
|
95
|
+
stack: string;
|
|
96
|
+
attempt: number;
|
|
97
|
+
failReason: string;
|
|
85
98
|
}
|
|
86
99
|
|
|
87
100
|
type ActionRetry = () => Promise<void>;
|
|
@@ -99,7 +112,7 @@ Returns a status report for current registered actions.
|
|
|
99
112
|
|
|
100
113
|
```ts
|
|
101
114
|
type ActionsStatus = {
|
|
102
|
-
|
|
115
|
+
[status in ActionStatus]: string[];
|
|
103
116
|
};
|
|
104
117
|
|
|
105
118
|
type ActionStatus = 'not_started' | 'pending' | 'resolved' | 'rejected';
|
|
@@ -117,18 +130,21 @@ Once an error rises, the manager will trigger the error handler with both occurr
|
|
|
117
130
|
const ReadinessManager = require('readiness-manager');
|
|
118
131
|
|
|
119
132
|
let count = 0;
|
|
120
|
-
const unstableAction = () =>
|
|
133
|
+
const unstableAction = () =>
|
|
134
|
+
new Promise((resolve, reject) => {
|
|
121
135
|
count++;
|
|
122
|
-
if (counter <= 1) {
|
|
136
|
+
if (counter <= 1) {
|
|
137
|
+
return reject(new Error('Not yet'));
|
|
138
|
+
}
|
|
123
139
|
|
|
124
140
|
resolve('Ok');
|
|
125
|
-
});
|
|
141
|
+
});
|
|
126
142
|
|
|
127
143
|
ReadinessManager.register('action', unstableAction);
|
|
128
144
|
|
|
129
145
|
ReadinessManager.onError((error, retry) => {
|
|
130
|
-
|
|
131
|
-
|
|
146
|
+
console.log(error);
|
|
147
|
+
if (error.attempt <= 1) retry();
|
|
132
148
|
});
|
|
133
149
|
|
|
134
150
|
ReadinessManager.run();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,CAAC;AAK/E,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAK5C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BeaconStatus = void 0;
|
|
4
|
+
exports.BeaconStatus = {
|
|
5
|
+
NOT_STARTED: 'not_started',
|
|
6
|
+
PENDING: 'pending',
|
|
7
|
+
RESOLVED: 'resolved',
|
|
8
|
+
REJECTED: 'rejected',
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAKa,QAAA,YAAY,GAAiC;IACtD,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,UAAU;IACpB,QAAQ,EAAE,UAAU;CACd,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const ERRORS: {
|
|
2
|
+
readonly BEACON_ALREADY_EXISTS: "Beacon is already exists, please ensure to use a unique name per beacon";
|
|
3
|
+
readonly BEACON_DOES_NOT_EXISTS: "Beacon does not exists, make sure to call `register` before trying to set beacon ready hook.";
|
|
4
|
+
readonly BEACON_EXECUTION_FAILED: "Beacon execution failed";
|
|
5
|
+
};
|
|
6
|
+
export type ActionRetry = () => Promise<unknown>;
|
|
7
|
+
export type ActionErrorHandler = (error: ActionExecutionError, retry: ActionRetry) => void;
|
|
8
|
+
export declare class ActionExecutionError extends Error {
|
|
9
|
+
name: string;
|
|
10
|
+
stack: string;
|
|
11
|
+
attempt: number;
|
|
12
|
+
failReason: string;
|
|
13
|
+
constructor(name: string, attempt: number, error: Error);
|
|
14
|
+
}
|
|
15
|
+
export declare const defaultErrorHandler: ActionErrorHandler;
|
|
16
|
+
//# sourceMappingURL=error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,MAAM;;;;CAKT,CAAC;AAEX,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC;AACjD,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,oBAAoB,EAAE,KAAK,EAAE,WAAW,KAAK,IAAI,CAAC;AAK3F,qBAAa,oBAAqB,SAAQ,KAAK;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;gBAEP,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;CAS1D;AAKD,eAAO,MAAM,mBAAmB,EAAE,kBAA+D,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultErrorHandler = exports.ActionExecutionError = exports.ERRORS = void 0;
|
|
4
|
+
const obs_1 = require("@fiverr-private/obs");
|
|
5
|
+
exports.ERRORS = {
|
|
6
|
+
BEACON_ALREADY_EXISTS: 'Beacon is already exists, please ensure to use a unique name per beacon',
|
|
7
|
+
BEACON_DOES_NOT_EXISTS: 'Beacon does not exists, make sure to call `register` before trying to set beacon ready hook.',
|
|
8
|
+
BEACON_EXECUTION_FAILED: 'Beacon execution failed',
|
|
9
|
+
};
|
|
10
|
+
class ActionExecutionError extends Error {
|
|
11
|
+
constructor(name, attempt, error) {
|
|
12
|
+
super();
|
|
13
|
+
this.message = exports.ERRORS.BEACON_EXECUTION_FAILED;
|
|
14
|
+
this.name = name;
|
|
15
|
+
this.attempt = attempt;
|
|
16
|
+
this.stack = error.stack || '';
|
|
17
|
+
this.failReason = error.message;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.ActionExecutionError = ActionExecutionError;
|
|
21
|
+
const defaultErrorHandler = (beaconError) => obs_1.logger.error(beaconError);
|
|
22
|
+
exports.defaultErrorHandler = defaultErrorHandler;
|
|
23
|
+
//# sourceMappingURL=error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/error.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAIhC,QAAA,MAAM,GAAG;IAClB,qBAAqB,EAAE,yEAAyE;IAChG,sBAAsB,EAClB,8FAA8F;IAClG,uBAAuB,EAAE,yBAAyB;CAC5C,CAAC;AAQX,MAAa,oBAAqB,SAAQ,KAAK;IAM3C,YAAY,IAAY,EAAE,OAAe,EAAE,KAAY;QACnD,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,OAAO,GAAG,cAAM,CAAC,uBAAuB,CAAC;QAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,OAAO,CAAC;IACpC,CAAC;CACJ;AAfD,oDAeC;AAKM,MAAM,mBAAmB,GAAuB,CAAC,WAAW,EAAE,EAAE,CAAC,YAAM,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAArF,QAAA,mBAAmB,uBAAkE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ActionExecutionError, ActionErrorHandler } from './error';
|
|
2
|
+
export type ReadyCallback = () => void;
|
|
3
|
+
export type ReadyAction = () => unknown | Promise<unknown>;
|
|
4
|
+
export interface ActionsStatus {
|
|
5
|
+
[status: string]: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface ReadinessManager {
|
|
8
|
+
register: (name: string, action: ReadyAction, debug?: boolean) => void;
|
|
9
|
+
run: () => ReadinessManager;
|
|
10
|
+
onReady: (callback: ReadyCallback) => ReadinessManager;
|
|
11
|
+
onActionReady: (name: string, callback: ReadyCallback) => ReadinessManager;
|
|
12
|
+
onError: (errorHandler: ActionErrorHandler) => ReadinessManager;
|
|
13
|
+
status: () => ActionsStatus;
|
|
14
|
+
ready: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare const manager: ReadinessManager;
|
|
17
|
+
export default manager;
|
|
18
|
+
export { ActionExecutionError, ActionErrorHandler };
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAU,oBAAoB,EAAuB,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAGhG,MAAM,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC;AACvC,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAE3D,MAAM,WAAW,aAAa;IAC1B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC9B;AA6BD,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACvE,GAAG,EAAE,MAAM,gBAAgB,CAAC;IAC5B,OAAO,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,gBAAgB,CAAC;IACvD,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,KAAK,gBAAgB,CAAC;IAC3E,OAAO,EAAE,CAAC,YAAY,EAAE,kBAAkB,KAAK,gBAAgB,CAAC;IAChE,MAAM,EAAE,MAAM,aAAa,CAAC;IAC5B,KAAK,EAAE,OAAO,CAAC;CAClB;AAkMD,QAAA,MAAM,OAAO,EAAE,gBAA6C,CAAC;AAE7D,eAAe,OAAO,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ActionExecutionError = void 0;
|
|
4
|
+
const obs_1 = require("@fiverr-private/obs");
|
|
5
|
+
const error_1 = require("./error");
|
|
6
|
+
Object.defineProperty(exports, "ActionExecutionError", { enumerable: true, get: function () { return error_1.ActionExecutionError; } });
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
const beaconsSymbol = Symbol('beacons');
|
|
9
|
+
const callbacksSymbol = Symbol('callbacks');
|
|
10
|
+
const executeSymbol = Symbol('execute');
|
|
11
|
+
const trackBeaconUpdateSymbol = Symbol('trackBeaconUpdate');
|
|
12
|
+
const updateBeaconSymbol = Symbol('updateBeacon');
|
|
13
|
+
const errorHandlerSymbol = Symbol('errorHandler');
|
|
14
|
+
let readyState = false;
|
|
15
|
+
class ReadinessManagerImpl {
|
|
16
|
+
constructor() {
|
|
17
|
+
this[beaconsSymbol] = {};
|
|
18
|
+
this[callbacksSymbol] = [];
|
|
19
|
+
this[errorHandlerSymbol] = error_1.defaultErrorHandler;
|
|
20
|
+
this[executeSymbol] = this[executeSymbol].bind(this);
|
|
21
|
+
}
|
|
22
|
+
get ready() {
|
|
23
|
+
return readyState;
|
|
24
|
+
}
|
|
25
|
+
status() {
|
|
26
|
+
return Object.values(this[beaconsSymbol]).reduce((acc, { name, status }) => {
|
|
27
|
+
const current = acc[status] || [];
|
|
28
|
+
return Object.assign(acc, { [status]: [...current, name] });
|
|
29
|
+
}, {});
|
|
30
|
+
}
|
|
31
|
+
register(name, action, debug = false) {
|
|
32
|
+
if (this.ready) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (this[beaconsSymbol][name]) {
|
|
36
|
+
throw new Error(error_1.ERRORS.BEACON_ALREADY_EXISTS);
|
|
37
|
+
}
|
|
38
|
+
const beacon = {
|
|
39
|
+
name,
|
|
40
|
+
action,
|
|
41
|
+
callbacks: [],
|
|
42
|
+
status: constants_1.BeaconStatus.NOT_STARTED,
|
|
43
|
+
debug,
|
|
44
|
+
};
|
|
45
|
+
Object.assign(this[beaconsSymbol], { [name]: beacon });
|
|
46
|
+
}
|
|
47
|
+
run() {
|
|
48
|
+
readyState = false;
|
|
49
|
+
Object.values(this[beaconsSymbol]).forEach((beacon) => this[executeSymbol](beacon));
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
onReady(callback) {
|
|
53
|
+
if (readyState) {
|
|
54
|
+
callback();
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
this[callbacksSymbol].push(callback);
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
onActionReady(name, callback) {
|
|
61
|
+
const beacon = this[beaconsSymbol][name];
|
|
62
|
+
if (!beacon) {
|
|
63
|
+
throw new Error(error_1.ERRORS.BEACON_DOES_NOT_EXISTS);
|
|
64
|
+
}
|
|
65
|
+
if (beacon.status === constants_1.BeaconStatus.RESOLVED) {
|
|
66
|
+
callback();
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
this[beaconsSymbol][name].callbacks.push(callback);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
onError(errorHandler) {
|
|
73
|
+
this[errorHandlerSymbol] = errorHandler;
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
async [executeSymbol](beacon, attempt = 1) {
|
|
77
|
+
const { name, action, debug } = beacon;
|
|
78
|
+
const update = (status) => this[updateBeaconSymbol](name, status);
|
|
79
|
+
update(constants_1.BeaconStatus.PENDING);
|
|
80
|
+
const startTime = debug ? Date.now() : null;
|
|
81
|
+
try {
|
|
82
|
+
const result = action();
|
|
83
|
+
if (result instanceof Promise) {
|
|
84
|
+
await result;
|
|
85
|
+
}
|
|
86
|
+
if (debug && startTime !== null) {
|
|
87
|
+
const duration = Date.now() - startTime;
|
|
88
|
+
obs_1.logger.debug(`[ReadinessManager] Action "${name}" completed in ${duration}ms`);
|
|
89
|
+
}
|
|
90
|
+
update(constants_1.BeaconStatus.RESOLVED);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (debug && startTime !== null) {
|
|
94
|
+
const duration = Date.now() - startTime;
|
|
95
|
+
obs_1.logger.debug(`[ReadinessManager] Action "${name}" failed after ${duration}ms`);
|
|
96
|
+
}
|
|
97
|
+
update(constants_1.BeaconStatus.REJECTED);
|
|
98
|
+
this[errorHandlerSymbol](new error_1.ActionExecutionError(name, attempt, error), () => this[executeSymbol](beacon, attempt + 1));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
[updateBeaconSymbol](name, status) {
|
|
102
|
+
Object.assign(this[beaconsSymbol][name], { status });
|
|
103
|
+
if (status === constants_1.BeaconStatus.RESOLVED) {
|
|
104
|
+
this[beaconsSymbol][name].callbacks.forEach((callback) => callback());
|
|
105
|
+
}
|
|
106
|
+
this[trackBeaconUpdateSymbol]();
|
|
107
|
+
}
|
|
108
|
+
[trackBeaconUpdateSymbol]() {
|
|
109
|
+
if (readyState) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
readyState = Object.values(this[beaconsSymbol]).every((beacon) => beacon.status === constants_1.BeaconStatus.RESOLVED);
|
|
113
|
+
if (readyState) {
|
|
114
|
+
this[callbacksSymbol].forEach((callback) => callback());
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const manager = new ReadinessManagerImpl();
|
|
119
|
+
exports.default = manager;
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAA6C;AAC7C,mCAAgG;AAkPvF,qGAlPQ,4BAAoB,OAkPR;AAjP7B,2CAAyD;AAwBzD,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AACxC,MAAM,eAAe,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAC5C,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;AACxC,MAAM,uBAAuB,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAC5D,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAClD,MAAM,kBAAkB,GAAG,MAAM,CAAC,cAAc,CAAC,CAAC;AAKlD,IAAI,UAAU,GAAG,KAAK,CAAC;AAYvB,MAAM,oBAAoB;IAKtB;QACI,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,kBAAkB,CAAC,GAAG,2BAAmB,CAAC;QAE/C,IAAI,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzD,CAAC;IAKD,IAAI,KAAK;QACL,OAAO,UAAU,CAAC;IACtB,CAAC;IAKD,MAAM;QACF,OAAO,MAA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AAC,EAAE,CAAC;IACpC,CAAC;IAOO,CAAC,uBAAuB,CAAC;QAC7B,IAAI,UAAU,EAAE,CAAC;YACb,OAAO;QACX,CAAC;QAED,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,wBAAY,CAAC,QAAQ,CAAC,CAAC;QAE3G,IAAI,UAAU,EAAE,CAAC;YACb,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;IACL,CAAC;CACJ;AAED,MAAM,OAAO,GAAqB,IAAI,oBAAoB,EAAE,CAAC;AAE7D,kBAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReadinessManager } from '../src/index';
|
|
2
|
+
export interface ReadinessManagerMock extends ReadinessManager {
|
|
3
|
+
setReady: (isReady: boolean) => void;
|
|
4
|
+
orchestrate: () => void;
|
|
5
|
+
}
|
|
6
|
+
declare const manager: ReadinessManagerMock;
|
|
7
|
+
export default manager;
|
|
8
|
+
//# sourceMappingURL=mock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../../tests/mock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA6C,MAAM,cAAc,CAAC;AAG3F,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC1D,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,MAAM,IAAI,CAAC;CAC3B;AA+CD,QAAA,MAAM,OAAO,EAAE,oBAAqD,CAAC;AAErE,eAAe,OAAO,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ReadinessManagerMockImpl {
|
|
4
|
+
constructor() {
|
|
5
|
+
this._ready = false;
|
|
6
|
+
}
|
|
7
|
+
get ready() {
|
|
8
|
+
return this._ready;
|
|
9
|
+
}
|
|
10
|
+
status() {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
setReady(isReady) {
|
|
14
|
+
this._ready = isReady;
|
|
15
|
+
}
|
|
16
|
+
register(_name, _action, _debug) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
run() {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
orchestrate() {
|
|
23
|
+
this._ready = true;
|
|
24
|
+
}
|
|
25
|
+
onReady(callback) {
|
|
26
|
+
callback();
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
onActionReady(_name, callback) {
|
|
30
|
+
callback();
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
onError(_errorHandler) {
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const manager = new ReadinessManagerMockImpl();
|
|
38
|
+
exports.default = manager;
|
|
39
|
+
//# sourceMappingURL=mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../../tests/mock.ts"],"names":[],"mappings":";;AAWA,MAAM,wBAAwB;IAA9B;QACY,WAAM,GAAG,KAAK,CAAC;IAuC3B,CAAC;IArCG,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED,MAAM;QACF,OAAO,EAAmB,CAAC;IAC/B,CAAC;IAED,QAAQ,CAAC,OAAgB;QACrB,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,QAAQ,CAAC,KAAa,EAAE,OAAoB,EAAE,MAAgB;QAC1D,OAAO,SAAS,CAAC;IACrB,CAAC;IAED,GAAG;QACC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,WAAW;QACP,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,CAAC;IAED,OAAO,CAAC,QAAuB;QAC3B,QAAQ,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,aAAa,CAAC,KAAa,EAAE,QAAuB;QAChD,QAAQ,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,OAAO,CAAC,aAAiC;QACrC,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAED,MAAM,OAAO,GAAyB,IAAI,wBAAwB,EAAE,CAAC;AAErE,kBAAe,OAAO,CAAC"}
|