@sincpro/client-framework 1.6.1 → 1.8.0
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/AGENTS.md +13 -6
- package/README.md +53 -25
- package/dist/event_driven/adapters/memory-message-store.d.ts +10 -0
- package/dist/event_driven/adapters/{memory-event-store.js → memory-message-store.js} +3 -3
- package/dist/event_driven/adapters/stored-queue.d.ts +51 -42
- package/dist/event_driven/adapters/stored-queue.js +137 -89
- package/dist/event_driven/adapters/sync-queue.d.ts +4 -3
- package/dist/event_driven/adapters/sync-queue.js +11 -5
- package/dist/event_driven/domain/queue.d.ts +19 -10
- package/dist/event_driven/domain/store.d.ts +26 -21
- package/dist/event_driven/domain/verdict.d.ts +86 -0
- package/dist/event_driven/domain/verdict.js +80 -0
- package/dist/event_driven/entrypoint/publisher.d.ts +14 -8
- package/dist/event_driven/entrypoint/publisher.js +16 -5
- package/dist/event_driven/entrypoint/subscriber.d.ts +9 -1
- package/dist/event_driven/entrypoint/subscriber.js +16 -5
- package/dist/event_driven/index.d.ts +13 -12
- package/dist/event_driven/index.js +11 -10
- package/dist/event_driven/services/messages.d.ts +7 -0
- package/dist/event_driven/services/messages.js +22 -0
- package/dist/observability/adapters/console.d.ts +4 -6
- package/dist/observability/adapters/console.js +8 -9
- package/dist/observability/domain/logging.d.ts +27 -0
- package/dist/observability/domain/logging.js +21 -1
- package/dist/observability/index.d.ts +2 -2
- package/dist/observability/index.js +2 -1
- package/dist/observability/services/logging.d.ts +8 -1
- package/dist/observability/services/logging.js +16 -0
- package/package.json +1 -1
- package/dist/event_driven/adapters/memory-event-store.d.ts +0 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { isLogLevel, speaks, } from "../domain/logging.js";
|
|
2
2
|
/**
|
|
3
3
|
* Built-in console engine: silent in production, configurable
|
|
4
4
|
* development layers, and WARN/ERROR preserved. Other sinks are filtered independently.
|
|
@@ -15,19 +15,18 @@ export function consoleLogger(options) {
|
|
|
15
15
|
if (mode !== "development" && mode !== "production") {
|
|
16
16
|
throw new TypeError("Console logger mode must be development or production");
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
if (!Object.hasOwn(RANK, level)) {
|
|
18
|
+
if (options.level !== undefined && !isLogLevel(options.level)) {
|
|
20
19
|
throw new TypeError("Console logger level must be debug, info, warn or error");
|
|
21
20
|
}
|
|
22
|
-
const
|
|
21
|
+
const filter = {
|
|
22
|
+
level: options.level ?? "debug",
|
|
23
|
+
layers: { ...options.layers },
|
|
24
|
+
boundedContexts: { ...options.boundedContexts },
|
|
25
|
+
};
|
|
23
26
|
return {
|
|
24
27
|
log(record) {
|
|
25
|
-
if (mode === "production")
|
|
28
|
+
if (mode === "production" || !speaks(record, filter))
|
|
26
29
|
return;
|
|
27
|
-
if (record.level !== "warn" && record.level !== "error") {
|
|
28
|
-
if (layers[record.layer] === false || RANK[record.level] < RANK[level])
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
30
|
const prefix = `${record.timestamp} [${record.layer}] ${record.level.toUpperCase()}`;
|
|
32
31
|
const method = record.level === "debug"
|
|
33
32
|
? console.debug
|
|
@@ -71,3 +71,30 @@ export interface LayerLogger {
|
|
|
71
71
|
warn(message: string, attributes?: Attributes): void;
|
|
72
72
|
error(message: string, attributes?: Attributes): void;
|
|
73
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Which INFO and DEBUG lines speak — by level, by layer and by bounded context. WARN and ERROR
|
|
76
|
+
* always do: a failure is never silenced. What a filter does not name speaks.
|
|
77
|
+
*
|
|
78
|
+
* { level: "info", layers: { adapter: false }, boundedContexts: { common: false } }
|
|
79
|
+
*
|
|
80
|
+
* Context: only lines are filtered, never spans — a quiet line still has its span, so a trace
|
|
81
|
+
* shows every run. A line outside a run (the infrastructure's `logger`) has no bounded context
|
|
82
|
+
* and is filtered by its layer alone.
|
|
83
|
+
*/
|
|
84
|
+
export type LogFilter = {
|
|
85
|
+
/** The lowest level of INFO and DEBUG that speaks (`debug`: every one). */
|
|
86
|
+
readonly level?: LogLevel;
|
|
87
|
+
/** By layer: `false` keeps a layer's INFO and DEBUG quiet. */
|
|
88
|
+
readonly layers?: Readonly<Partial<Record<LogLayer, boolean>>>;
|
|
89
|
+
/** By bounded context's name: `false` keeps its INFO and DEBUG quiet. */
|
|
90
|
+
readonly boundedContexts?: Readonly<Record<string, boolean>>;
|
|
91
|
+
};
|
|
92
|
+
/** Whether `level` is one a line can have. */
|
|
93
|
+
export declare function isLogLevel(level: unknown): level is LogLevel;
|
|
94
|
+
/**
|
|
95
|
+
* Whether `record` speaks under `filter`:
|
|
96
|
+
* 1. WARN and ERROR, always.
|
|
97
|
+
* 2. INFO and DEBUG at the filter's level or above, from a layer and a bounded context it does
|
|
98
|
+
* not keep quiet.
|
|
99
|
+
*/
|
|
100
|
+
export declare function speaks(record: LogRecord, filter: LogFilter): boolean;
|
|
@@ -1 +1,21 @@
|
|
|
1
|
-
|
|
1
|
+
const RANK = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
2
|
+
/** Whether `level` is one a line can have. */
|
|
3
|
+
export function isLogLevel(level) {
|
|
4
|
+
return typeof level === "string" && Object.hasOwn(RANK, level);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Whether `record` speaks under `filter`:
|
|
8
|
+
* 1. WARN and ERROR, always.
|
|
9
|
+
* 2. INFO and DEBUG at the filter's level or above, from a layer and a bounded context it does
|
|
10
|
+
* not keep quiet.
|
|
11
|
+
*/
|
|
12
|
+
export function speaks(record, filter) {
|
|
13
|
+
if (record.level === "warn" || record.level === "error")
|
|
14
|
+
return true;
|
|
15
|
+
if (RANK[record.level] < RANK[filter.level ?? "debug"])
|
|
16
|
+
return false;
|
|
17
|
+
if (filter.layers?.[record.layer] === false)
|
|
18
|
+
return false;
|
|
19
|
+
const boundedContext = record.boundedContext;
|
|
20
|
+
return !(boundedContext !== undefined && filter.boundedContexts?.[boundedContext] === false);
|
|
21
|
+
}
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
*/
|
|
11
11
|
export type { ErrorAbout, ErrorReporter, } from "./domain/errors.js";
|
|
12
12
|
export { type IdentityKeys, identityOf, type ProcessIdentity, RELEASE, TENANT, tenantOf, USER_ID, userOf, } from "./domain/identity.js";
|
|
13
|
-
export type
|
|
13
|
+
export { type FailureDescription, isLogLevel, type LayerLogger, type LogFilter, type Logger, type LogLayer, type LogLevel, type LogRecord, speaks, } from "./domain/logging.js";
|
|
14
14
|
export { type Attributes, NO_TRACER, type Outcome, type Span, type Tracer, } from "./domain/tracing.js";
|
|
15
15
|
export { describeFailure } from "./services/failure.js";
|
|
16
|
-
export { combineLoggers, logger, loggerAdapter, } from "./services/logging.js";
|
|
16
|
+
export { combineLoggers, filteredLogger, logger, loggerAdapter, } from "./services/logging.js";
|
|
17
17
|
export { outcomeOf } from "./services/outcome.js";
|
|
18
18
|
export { reportError } from "./services/reporting.js";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { identityOf, RELEASE, TENANT, tenantOf, USER_ID, userOf, } from "./domain/identity.js";
|
|
2
|
+
export { isLogLevel, speaks, } from "./domain/logging.js";
|
|
2
3
|
export { NO_TRACER, } from "./domain/tracing.js";
|
|
3
4
|
export { describeFailure } from "./services/failure.js";
|
|
4
|
-
export { combineLoggers, logger, loggerAdapter, } from "./services/logging.js";
|
|
5
|
+
export { combineLoggers, filteredLogger, logger, loggerAdapter, } from "./services/logging.js";
|
|
5
6
|
export { outcomeOf } from "./services/outcome.js";
|
|
6
7
|
export { reportError } from "./services/reporting.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Execution } from "../../context/domain/execution.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type FailureDescription, type LayerLogger, type LogFilter, type Logger, type LogLayer } from "../domain/logging.js";
|
|
3
3
|
import type { Outcome } from "../domain/tracing.js";
|
|
4
4
|
/** The infrastructure's logger — the global one: the code that starts and holds the application. */
|
|
5
5
|
export declare const logger: LayerLogger;
|
|
@@ -11,6 +11,13 @@ export declare function boundedContextLogger(name: string): LayerLogger;
|
|
|
11
11
|
type RunLogLayer = Extract<LogLayer, "feature" | "application_service" | "event_handler">;
|
|
12
12
|
/** @internal — what a Feature or ApplicationService finds as `this.logger` while it runs. */
|
|
13
13
|
export declare function executionLogger(layer: RunLogLayer, execution: Execution): LayerLogger;
|
|
14
|
+
/**
|
|
15
|
+
* `engine`, hearing only the lines `filter` lets speak — WARN and ERROR always (`speaks`). A
|
|
16
|
+
* function is read on every line, so a debug switch changes what speaks without rebuilding:
|
|
17
|
+
*
|
|
18
|
+
* filteredLogger(combineLoggers(console, loki), () => (debugging ? everything : production))
|
|
19
|
+
*/
|
|
20
|
+
export declare function filteredLogger(engine: Logger, filter: LogFilter | (() => LogFilter)): Logger;
|
|
14
21
|
/** Each destination keeps its own policy; one failing sink does not hold back the others. */
|
|
15
22
|
export declare function combineLoggers(...loggers: readonly Logger[]): Logger;
|
|
16
23
|
/** @internal — lifecycle records contain correlation and outcome, never business payloads. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { BIND } from "../../context/domain/execution.js";
|
|
2
2
|
import { tenantOf, userOf } from "../domain/identity.js";
|
|
3
|
+
import { speaks, } from "../domain/logging.js";
|
|
3
4
|
import { observabilityNow } from "../infrastructure/registry.js";
|
|
4
5
|
const processSink = () => observabilityNow().logger;
|
|
5
6
|
/** Sink failures cannot replace a business outcome or cause unhandled async rejections. */
|
|
@@ -77,6 +78,21 @@ export function boundedContextLogger(name) {
|
|
|
77
78
|
export function executionLogger(layer, execution) {
|
|
78
79
|
return layerLogger(layer, processSink, correlationOf(execution));
|
|
79
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* `engine`, hearing only the lines `filter` lets speak — WARN and ERROR always (`speaks`). A
|
|
83
|
+
* function is read on every line, so a debug switch changes what speaks without rebuilding:
|
|
84
|
+
*
|
|
85
|
+
* filteredLogger(combineLoggers(console, loki), () => (debugging ? everything : production))
|
|
86
|
+
*/
|
|
87
|
+
export function filteredLogger(engine, filter) {
|
|
88
|
+
const current = typeof filter === "function" ? filter : () => filter;
|
|
89
|
+
return {
|
|
90
|
+
log: (record) => {
|
|
91
|
+
if (speaks(record, current()))
|
|
92
|
+
deliver(engine, record);
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
}
|
|
80
96
|
/** Each destination keeps its own policy; one failing sink does not hold back the others. */
|
|
81
97
|
export function combineLoggers(...loggers) {
|
|
82
98
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/client-framework",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "The client side of sincpro_framework, for every platform: Feature and ApplicationService traced and reported by default, applications made of domains, and the typed client generated from a service's contract. No React, no DOM.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { EventStore, StoredEvent } from "../domain/store.js";
|
|
2
|
-
/** A memory store, and what it holds — in the order added — for whoever inspects it. */
|
|
3
|
-
export type MemoryEventStore = EventStore & {
|
|
4
|
-
readonly events: readonly StoredEvent[];
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* The events of a stored queue in this process's memory: what a browser tab or a test keeps.
|
|
8
|
-
* Gone with the process — a phone's store is a table.
|
|
9
|
-
*/
|
|
10
|
-
export declare function memoryEventStore(): MemoryEventStore;
|