@thi.ng/system 2.1.84 → 2.1.86
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 +1 -1
- package/README.md +1 -1
- package/api.js +6 -8
- package/package.json +9 -7
- package/system.js +64 -60
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
package/api.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { NULL_LOGGER } from "@thi.ng/logger/null";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
export const setLogger = (logger) => (LOGGER = logger);
|
|
2
|
+
let LOGGER = NULL_LOGGER;
|
|
3
|
+
const setLogger = (logger) => LOGGER = logger;
|
|
4
|
+
export {
|
|
5
|
+
LOGGER,
|
|
6
|
+
setLogger
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/system",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.86",
|
|
4
4
|
"description": "Minimal and explicit dependency-injection & lifecycle container for stateful app components",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -27,7 +27,9 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"scripts": {
|
|
30
|
-
"build": "yarn
|
|
30
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
31
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
32
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
31
33
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
32
34
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
33
35
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -36,13 +38,13 @@
|
|
|
36
38
|
"test": "bun test"
|
|
37
39
|
},
|
|
38
40
|
"dependencies": {
|
|
39
|
-
"@thi.ng/api": "^8.9.
|
|
40
|
-
"@thi.ng/dgraph": "^2.1.
|
|
41
|
-
"@thi.ng/logger": "^2.0.
|
|
41
|
+
"@thi.ng/api": "^8.9.12",
|
|
42
|
+
"@thi.ng/dgraph": "^2.1.82",
|
|
43
|
+
"@thi.ng/logger": "^2.0.2"
|
|
42
44
|
},
|
|
43
45
|
"devDependencies": {
|
|
44
46
|
"@microsoft/api-extractor": "^7.38.3",
|
|
45
|
-
"
|
|
47
|
+
"esbuild": "^0.19.8",
|
|
46
48
|
"rimraf": "^5.0.5",
|
|
47
49
|
"tools": "^0.0.1",
|
|
48
50
|
"typedoc": "^0.25.4",
|
|
@@ -83,5 +85,5 @@
|
|
|
83
85
|
"thi.ng": {
|
|
84
86
|
"year": 2020
|
|
85
87
|
},
|
|
86
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
87
89
|
}
|
package/system.js
CHANGED
|
@@ -1,66 +1,70 @@
|
|
|
1
1
|
import { DGraph } from "@thi.ng/dgraph";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
this.topology = this.graph.sort();
|
|
17
|
-
this.components = {};
|
|
18
|
-
for (let id of this.topology) {
|
|
19
|
-
this.components[id] = map[id].factory(this.components);
|
|
20
|
-
}
|
|
2
|
+
import {
|
|
3
|
+
LOGGER
|
|
4
|
+
} from "./api.js";
|
|
5
|
+
const defSystem = (map) => new System(map);
|
|
6
|
+
class System {
|
|
7
|
+
components;
|
|
8
|
+
topology;
|
|
9
|
+
graph;
|
|
10
|
+
constructor(map) {
|
|
11
|
+
this.graph = new DGraph();
|
|
12
|
+
for (let id in map) {
|
|
13
|
+
const deps = map[id].deps;
|
|
14
|
+
deps ? this.graph.addDependencies(id, deps) : this.graph.addNode(id);
|
|
21
15
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*
|
|
27
|
-
* Also any errors thrown during child component startup will not be
|
|
28
|
-
* intercepted.
|
|
29
|
-
*/
|
|
30
|
-
async start() {
|
|
31
|
-
for (let id of this.topology) {
|
|
32
|
-
const comp = this.components[id];
|
|
33
|
-
if (comp.start && !(await comp.start())) {
|
|
34
|
-
LOGGER.warn(`error starting component: ${String(id)}`);
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
16
|
+
this.topology = this.graph.sort();
|
|
17
|
+
this.components = {};
|
|
18
|
+
for (let id of this.topology) {
|
|
19
|
+
this.components[id] = map[id].factory(this.components);
|
|
39
20
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
return true;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Initializes all system components in dependency order. If any
|
|
24
|
+
* component's `start()` method returns false, system start up will
|
|
25
|
+
* be stopped and this method returns false itself.
|
|
26
|
+
*
|
|
27
|
+
* Also any errors thrown during child component startup will not be
|
|
28
|
+
* intercepted.
|
|
29
|
+
*/
|
|
30
|
+
async start() {
|
|
31
|
+
for (let id of this.topology) {
|
|
32
|
+
const comp = this.components[id];
|
|
33
|
+
if (comp.start && !await comp.start()) {
|
|
34
|
+
LOGGER.warn(`error starting component: ${String(id)}`);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
59
37
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Stops all system components in reverse dependency order. If any
|
|
42
|
+
* component's `stop()` method returns false, a warning message will
|
|
43
|
+
* be logged, but unlike {@link System.start}, the shutdown
|
|
44
|
+
* process of other components will not be stopped.
|
|
45
|
+
*
|
|
46
|
+
* Any errors thrown during child component shutdown will not be
|
|
47
|
+
* intercepted.
|
|
48
|
+
*/
|
|
49
|
+
async stop() {
|
|
50
|
+
const topo = this.topology;
|
|
51
|
+
for (let i = topo.length; i-- > 0; ) {
|
|
52
|
+
const id = topo[i];
|
|
53
|
+
const comp = this.components[id];
|
|
54
|
+
if (comp.stop && !await comp.stop()) {
|
|
55
|
+
LOGGER.warn(`error stopping component: ${String(id)}`);
|
|
56
|
+
}
|
|
65
57
|
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Syntax sugar for `stop() && start()` sequence.
|
|
62
|
+
*/
|
|
63
|
+
async reset() {
|
|
64
|
+
return await this.stop() && await this.start();
|
|
65
|
+
}
|
|
66
66
|
}
|
|
67
|
+
export {
|
|
68
|
+
System,
|
|
69
|
+
defSystem
|
|
70
|
+
};
|