@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.
@@ -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 primary = this.datasources[0];
14
- return (await primary?.find?.(filter)) ?? [];
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.all(this.datasources.map((ds) => ds.flush?.() ?? Promise.resolve()));
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.all(this.datasources.map((ds) => ds.dispose?.() ?? Promise.resolve()));
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jmlq/logger",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.2",
4
4
  "author": "MLahuasi",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",