@tsed/config 8.9.2 → 8.9.3
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "@tsed/ajv";
|
|
2
|
-
import { configuration, constant,
|
|
3
|
-
import { $on } from "@tsed/hooks";
|
|
2
|
+
import { configuration, constant, injectable, logger } from "@tsed/di";
|
|
3
|
+
import { $off, $on, $once } from "@tsed/hooks";
|
|
4
4
|
import { CONFIG_SOURCES } from "../constants/constants.js";
|
|
5
5
|
import { getConfigSources } from "../utils/getConfigSources.js";
|
|
6
6
|
import { validate } from "../utils/validate.js";
|
|
@@ -8,6 +8,8 @@ export async function afterResolveConfiguration() {
|
|
|
8
8
|
const sources = getConfigSources(constant("extends", []));
|
|
9
9
|
for (const source of sources.values()) {
|
|
10
10
|
const { instance, watch, refreshOn, name, validationSchema } = source;
|
|
11
|
+
const seed = Math.floor(Math.random() * 10000);
|
|
12
|
+
const ref = name + "-" + seed;
|
|
11
13
|
if (instance?.$onInit) {
|
|
12
14
|
await instance.$onInit();
|
|
13
15
|
}
|
|
@@ -26,17 +28,15 @@ export async function afterResolveConfiguration() {
|
|
|
26
28
|
// manage watcher
|
|
27
29
|
if (watch && instance?.watch) {
|
|
28
30
|
const closer = await instance.watch(refresh);
|
|
29
|
-
closer && $
|
|
31
|
+
closer && $once("$onDestroy", ref, closer);
|
|
30
32
|
}
|
|
31
33
|
// manager refresh on request
|
|
32
34
|
if (refreshOn === "request") {
|
|
33
|
-
$on("$onRequest",
|
|
34
|
-
return refresh();
|
|
35
|
-
});
|
|
35
|
+
$on("$onRequest", ref, refresh);
|
|
36
36
|
}
|
|
37
37
|
// manager refresh on response
|
|
38
38
|
if (refreshOn === "response") {
|
|
39
|
-
|
|
39
|
+
const onResponse = () => {
|
|
40
40
|
refresh().catch((error) => {
|
|
41
41
|
logger().error({
|
|
42
42
|
event: "CONFIG_SOURCE_REFRESH_ERROR",
|
|
@@ -46,8 +46,16 @@ export async function afterResolveConfiguration() {
|
|
|
46
46
|
error_stack: error.stack
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
|
+
$on("$onResponse", ref, onResponse);
|
|
50
51
|
}
|
|
52
|
+
$once("$onDestroy", ref, () => {
|
|
53
|
+
if (instance?.$onDestroy) {
|
|
54
|
+
// clean all event related to the same ref
|
|
55
|
+
$off(ref);
|
|
56
|
+
return instance.$onDestroy();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
51
59
|
}
|
|
52
60
|
const configs = Object.fromEntries([...sources.entries()].map(([key, source]) => {
|
|
53
61
|
return [key, source.instance];
|
|
@@ -55,11 +63,4 @@ export async function afterResolveConfiguration() {
|
|
|
55
63
|
injectable(CONFIG_SOURCES).value(configs);
|
|
56
64
|
}
|
|
57
65
|
$on("$afterResolveConfiguration", afterResolveConfiguration);
|
|
58
|
-
$on("$onDestroy", () => {
|
|
59
|
-
const configs = inject(CONFIG_SOURCES);
|
|
60
|
-
const promises = Object.values(configs).map((config) => {
|
|
61
|
-
return config.$onDestroy?.();
|
|
62
|
-
});
|
|
63
|
-
return Promise.all(promises);
|
|
64
|
-
});
|
|
65
66
|
//# sourceMappingURL=afterResolveConfiguration.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"afterResolveConfiguration.js","sourceRoot":"","sources":["../../../src/hooks/afterResolveConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAC;AAEnB,OAAO,EAAC,aAAa,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"afterResolveConfiguration.js","sourceRoot":"","sources":["../../../src/hooks/afterResolveConfiguration.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,CAAC;AAEnB,OAAO,EAAC,aAAa,EAAE,QAAQ,EAAU,UAAU,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAC7E,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,KAA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