@jmlq/logger 0.1.0-alpha.1 → 0.1.0-alpha.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/dist/Composite/index.js +36 -5
- package/package.json +1 -1
package/dist/Composite/index.js
CHANGED
|
@@ -7,17 +7,48 @@ class CompositeDatasource {
|
|
|
7
7
|
this.datasources = datasources;
|
|
8
8
|
}
|
|
9
9
|
async save(log) {
|
|
10
|
-
await Promise.allSettled(this.datasources.map((ds) => ds.save(log)));
|
|
10
|
+
const results = await Promise.allSettled(this.datasources.map((ds) => ds.save(log)));
|
|
11
|
+
for (const r of results) {
|
|
12
|
+
if (r.status === "rejected") {
|
|
13
|
+
// Evita romper el flujo si un destino falla.
|
|
14
|
+
// Aquí podrías enrutar a "dead-letter", métricas, etc.
|
|
15
|
+
// eslint-disable-next-line no-console
|
|
16
|
+
console.warn("[CompositeDatasource] save failed:", r.reason);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
11
19
|
}
|
|
12
20
|
async find(filter = {}) {
|
|
13
|
-
const
|
|
14
|
-
|
|
21
|
+
for (const ds of this.datasources) {
|
|
22
|
+
if (typeof ds.find === "function") {
|
|
23
|
+
try {
|
|
24
|
+
return await ds.find(filter);
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// eslint-disable-next-line no-console
|
|
28
|
+
console.warn("[CompositeDatasource] find failed on a datasource:", e);
|
|
29
|
+
// probar siguiente datasource
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return [];
|
|
15
34
|
}
|
|
16
35
|
async flush() {
|
|
17
|
-
await Promise.
|
|
36
|
+
const results = await Promise.allSettled(this.datasources.map((ds) => ds.flush?.() ?? Promise.resolve()));
|
|
37
|
+
for (const r of results) {
|
|
38
|
+
if (r.status === "rejected") {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.warn("[CompositeDatasource] flush failed:", r.reason);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
18
43
|
}
|
|
19
44
|
async dispose() {
|
|
20
|
-
await Promise.
|
|
45
|
+
const results = await Promise.allSettled(this.datasources.map((ds) => ds.dispose?.() ?? Promise.resolve()));
|
|
46
|
+
for (const r of results) {
|
|
47
|
+
if (r.status === "rejected") {
|
|
48
|
+
// eslint-disable-next-line no-console
|
|
49
|
+
console.warn("[CompositeDatasource] dispose failed:", r.reason);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
21
52
|
}
|
|
22
53
|
}
|
|
23
54
|
exports.CompositeDatasource = CompositeDatasource;
|