@hexaijs/application 0.1.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/LICENSE +21 -0
- package/README.md +331 -0
- package/dist/abstract-application-context.d.ts +13 -0
- package/dist/abstract-application-context.d.ts.map +1 -0
- package/dist/abstract-application-context.js +35 -0
- package/dist/abstract-application-context.js.map +1 -0
- package/dist/application-context.d.ts +2 -0
- package/dist/application-context.d.ts.map +1 -0
- package/dist/application-context.js +6 -0
- package/dist/application-context.js.map +1 -0
- package/dist/application-event-publisher.d.ts +16 -0
- package/dist/application-event-publisher.d.ts.map +1 -0
- package/dist/application-event-publisher.js +37 -0
- package/dist/application-event-publisher.js.map +1 -0
- package/dist/application.d.ts +59 -0
- package/dist/application.d.ts.map +1 -0
- package/dist/application.js +237 -0
- package/dist/application.js.map +1 -0
- package/dist/command-handler.d.ts +5 -0
- package/dist/command-handler.d.ts.map +1 -0
- package/dist/command-handler.js +3 -0
- package/dist/command-handler.js.map +1 -0
- package/dist/command.d.ts +12 -0
- package/dist/command.d.ts.map +1 -0
- package/dist/command.js +46 -0
- package/dist/command.js.map +1 -0
- package/dist/error.d.ts +37 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +28 -0
- package/dist/error.js.map +1 -0
- package/dist/event-handler.d.ts +6 -0
- package/dist/event-handler.d.ts.map +1 -0
- package/dist/event-handler.js +3 -0
- package/dist/event-handler.js.map +1 -0
- package/dist/event-publisher.d.ts +4 -0
- package/dist/event-publisher.d.ts.map +1 -0
- package/dist/event-publisher.js +3 -0
- package/dist/event-publisher.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/intercepted-application.d.ts +33 -0
- package/dist/intercepted-application.d.ts.map +1 -0
- package/dist/intercepted-application.js +111 -0
- package/dist/intercepted-application.js.map +1 -0
- package/dist/interceptor.d.ts +25 -0
- package/dist/interceptor.d.ts.map +1 -0
- package/dist/interceptor.js +3 -0
- package/dist/interceptor.js.map +1 -0
- package/dist/logging/create-logger.d.ts +16 -0
- package/dist/logging/create-logger.d.ts.map +1 -0
- package/dist/logging/create-logger.js +48 -0
- package/dist/logging/create-logger.js.map +1 -0
- package/dist/logging/index.d.ts +7 -0
- package/dist/logging/index.d.ts.map +1 -0
- package/dist/logging/index.js +32 -0
- package/dist/logging/index.js.map +1 -0
- package/dist/logging/logger.d.ts +42 -0
- package/dist/logging/logger.d.ts.map +1 -0
- package/dist/logging/logger.js +3 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/logging-interceptor.d.ts +9 -0
- package/dist/logging/logging-interceptor.d.ts.map +1 -0
- package/dist/logging/logging-interceptor.js +48 -0
- package/dist/logging/logging-interceptor.js.map +1 -0
- package/dist/logging/logging-utils.d.ts +16 -0
- package/dist/logging/logging-utils.d.ts.map +1 -0
- package/dist/logging/logging-utils.js +91 -0
- package/dist/logging/logging-utils.js.map +1 -0
- package/dist/logging/trace-interceptor.d.ts +16 -0
- package/dist/logging/trace-interceptor.d.ts.map +1 -0
- package/dist/logging/trace-interceptor.js +53 -0
- package/dist/logging/trace-interceptor.js.map +1 -0
- package/dist/message-handler.d.ts +4 -0
- package/dist/message-handler.d.ts.map +1 -0
- package/dist/message-handler.js +3 -0
- package/dist/message-handler.js.map +1 -0
- package/dist/messaging-support.d.ts +11 -0
- package/dist/messaging-support.d.ts.map +1 -0
- package/dist/messaging-support.js +40 -0
- package/dist/messaging-support.js.map +1 -0
- package/dist/query-handler.d.ts +5 -0
- package/dist/query-handler.d.ts.map +1 -0
- package/dist/query-handler.js +3 -0
- package/dist/query-handler.js.map +1 -0
- package/dist/query.d.ts +12 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +46 -0
- package/dist/query.js.map +1 -0
- package/dist/request.d.ts +3 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +19 -0
- package/dist/request.js.map +1 -0
- package/dist/result.d.ts +18 -0
- package/dist/result.d.ts.map +1 -0
- package/dist/result.js +28 -0
- package/dist/result.js.map +1 -0
- package/dist/selector-based-event-handler.d.ts +29 -0
- package/dist/selector-based-event-handler.d.ts.map +1 -0
- package/dist/selector-based-event-handler.js +78 -0
- package/dist/selector-based-event-handler.js.map +1 -0
- package/dist/simple-composite-application.d.ts +15 -0
- package/dist/simple-composite-application.d.ts.map +1 -0
- package/dist/simple-composite-application.js +61 -0
- package/dist/simple-composite-application.js.map +1 -0
- package/dist/test/expectations.d.ts +10 -0
- package/dist/test/expectations.d.ts.map +1 -0
- package/dist/test/expectations.js +33 -0
- package/dist/test/expectations.js.map +1 -0
- package/dist/test/fixtures/index.d.ts +24 -0
- package/dist/test/fixtures/index.d.ts.map +1 -0
- package/dist/test/fixtures/index.js +40 -0
- package/dist/test/fixtures/index.js.map +1 -0
- package/dist/test/fixtures/interceptor-test-helpers.d.ts +34 -0
- package/dist/test/fixtures/interceptor-test-helpers.d.ts.map +1 -0
- package/dist/test/fixtures/interceptor-test-helpers.js +59 -0
- package/dist/test/fixtures/interceptor-test-helpers.js.map +1 -0
- package/dist/test/index.d.ts +3 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/index.js +19 -0
- package/dist/test/index.js.map +1 -0
- package/package.json +64 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InterceptedApplication = exports.InterceptedApplicationBuilder = void 0;
|
|
4
|
+
class InterceptedApplicationBuilder {
|
|
5
|
+
delegate;
|
|
6
|
+
commandInterceptors = [];
|
|
7
|
+
queryInterceptors = [];
|
|
8
|
+
eventInterceptors = [];
|
|
9
|
+
commonInterceptors = [];
|
|
10
|
+
constructor(delegate) {
|
|
11
|
+
this.delegate = delegate;
|
|
12
|
+
}
|
|
13
|
+
withCommandInterceptor(interceptor) {
|
|
14
|
+
this.commandInterceptors.push(interceptor);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
withQueryInterceptor(interceptor) {
|
|
18
|
+
this.queryInterceptors.push(interceptor);
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
withEventInterceptor(interceptor) {
|
|
22
|
+
this.eventInterceptors.push(interceptor);
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
withInterceptor(interceptor) {
|
|
26
|
+
this.commonInterceptors.push(interceptor);
|
|
27
|
+
return this;
|
|
28
|
+
}
|
|
29
|
+
build() {
|
|
30
|
+
return new InterceptedApplication(this.delegate, this.commandInterceptors, this.queryInterceptors, this.eventInterceptors, this.commonInterceptors);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.InterceptedApplicationBuilder = InterceptedApplicationBuilder;
|
|
34
|
+
class InterceptedApplication {
|
|
35
|
+
delegate;
|
|
36
|
+
commandInterceptors;
|
|
37
|
+
queryInterceptors;
|
|
38
|
+
eventInterceptors;
|
|
39
|
+
commonInterceptors;
|
|
40
|
+
static wrap(delegate) {
|
|
41
|
+
return new InterceptedApplicationBuilder(delegate);
|
|
42
|
+
}
|
|
43
|
+
constructor(delegate, commandInterceptors, queryInterceptors, eventInterceptors, commonInterceptors) {
|
|
44
|
+
this.delegate = delegate;
|
|
45
|
+
this.commandInterceptors = commandInterceptors;
|
|
46
|
+
this.queryInterceptors = queryInterceptors;
|
|
47
|
+
this.eventInterceptors = eventInterceptors;
|
|
48
|
+
this.commonInterceptors = commonInterceptors;
|
|
49
|
+
}
|
|
50
|
+
async executeCommand(command) {
|
|
51
|
+
const context = {
|
|
52
|
+
intent: "command",
|
|
53
|
+
message: command,
|
|
54
|
+
metadata: {},
|
|
55
|
+
};
|
|
56
|
+
const finalHandler = () => this.delegate.executeCommand(command);
|
|
57
|
+
const chain = this.buildInterceptorChain(context, finalHandler, this.commandInterceptors);
|
|
58
|
+
return chain();
|
|
59
|
+
}
|
|
60
|
+
async executeQuery(query) {
|
|
61
|
+
const context = {
|
|
62
|
+
intent: "query",
|
|
63
|
+
message: query,
|
|
64
|
+
metadata: {},
|
|
65
|
+
};
|
|
66
|
+
const finalHandler = () => this.delegate.executeQuery(query);
|
|
67
|
+
const chain = this.buildInterceptorChain(context, finalHandler, this.queryInterceptors);
|
|
68
|
+
return chain();
|
|
69
|
+
}
|
|
70
|
+
async handleEvent(event) {
|
|
71
|
+
const context = {
|
|
72
|
+
intent: "event",
|
|
73
|
+
message: event,
|
|
74
|
+
metadata: {},
|
|
75
|
+
};
|
|
76
|
+
const finalHandler = () => this.delegate.handleEvent(event);
|
|
77
|
+
const chain = this.buildInterceptorChain(context, finalHandler, this.eventInterceptors);
|
|
78
|
+
return chain();
|
|
79
|
+
}
|
|
80
|
+
buildInterceptorChain(context, finalHandler, specificInterceptors) {
|
|
81
|
+
// Combine common interceptors with specific interceptors
|
|
82
|
+
// Common interceptors run first (outer), then specific interceptors (inner)
|
|
83
|
+
const allInterceptors = [
|
|
84
|
+
...this.commonInterceptors,
|
|
85
|
+
...specificInterceptors,
|
|
86
|
+
];
|
|
87
|
+
let wrappedHandler = finalHandler;
|
|
88
|
+
// Build chain from inside out (reverse order)
|
|
89
|
+
for (let i = allInterceptors.length - 1; i >= 0; i--) {
|
|
90
|
+
const interceptor = allInterceptors[i];
|
|
91
|
+
const nextHandler = wrappedHandler;
|
|
92
|
+
wrappedHandler = (() => {
|
|
93
|
+
const guardedNext = this.createSingleCallGuard(nextHandler);
|
|
94
|
+
return interceptor(context, guardedNext);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return wrappedHandler;
|
|
98
|
+
}
|
|
99
|
+
createSingleCallGuard(executor) {
|
|
100
|
+
let hasBeenCalled = false;
|
|
101
|
+
return (() => {
|
|
102
|
+
if (hasBeenCalled) {
|
|
103
|
+
throw new Error("next() can only be called once in an interceptor");
|
|
104
|
+
}
|
|
105
|
+
hasBeenCalled = true;
|
|
106
|
+
return executor();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.InterceptedApplication = InterceptedApplication;
|
|
111
|
+
//# sourceMappingURL=intercepted-application.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intercepted-application.js","sourceRoot":"","sources":["../src/intercepted-application.ts"],"names":[],"mappings":";;;AAkBA,MAAa,6BAA6B;IAMlB;IALZ,mBAAmB,GAAyB,EAAE,CAAC;IAC/C,iBAAiB,GAAuB,EAAE,CAAC;IAC3C,iBAAiB,GAAuB,EAAE,CAAC;IAC3C,kBAAkB,GAAkB,EAAE,CAAC;IAE/C,YAAoB,QAAqB;QAArB,aAAQ,GAAR,QAAQ,CAAa;IAAG,CAAC;IAE7C,sBAAsB,CAAC,WAA+B;QAClD,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC3C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,oBAAoB,CAAC,WAA6B;QAC9C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,oBAAoB,CAAC,WAA6B;QAC9C,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QACzC,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,eAAe,CAAC,WAAwB;QACpC,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,KAAK;QACD,OAAO,IAAI,sBAAsB,CAC7B,IAAI,CAAC,QAAQ,EACb,IAAI,CAAC,mBAAmB,EACxB,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,iBAAiB,EACtB,IAAI,CAAC,kBAAkB,CAC1B,CAAC;IACN,CAAC;CACJ;AArCD,sEAqCC;AAED,MAAa,sBAAsB;IAMnB;IACA;IACA;IACA;IACA;IATZ,MAAM,CAAC,IAAI,CAAC,QAAqB;QAC7B,OAAO,IA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C"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Message } from "@hexaijs/core";
|
|
2
|
+
import type { Command } from "./command";
|
|
3
|
+
import type { Query } from "./query";
|
|
4
|
+
import type { Result } from "./application";
|
|
5
|
+
export interface CommandInterceptionContext {
|
|
6
|
+
readonly intent: "command";
|
|
7
|
+
readonly message: Command;
|
|
8
|
+
metadata: Record<string | symbol, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface QueryInterceptionContext {
|
|
11
|
+
readonly intent: "query";
|
|
12
|
+
readonly message: Query;
|
|
13
|
+
metadata: Record<string | symbol, unknown>;
|
|
14
|
+
}
|
|
15
|
+
export interface EventInterceptionContext {
|
|
16
|
+
readonly intent: "event";
|
|
17
|
+
readonly message: Message;
|
|
18
|
+
metadata: Record<string | symbol, unknown>;
|
|
19
|
+
}
|
|
20
|
+
export type InterceptionContext = CommandInterceptionContext | QueryInterceptionContext | EventInterceptionContext;
|
|
21
|
+
export type CommandInterceptor = (ctx: CommandInterceptionContext, next: () => Promise<Result<unknown>>) => Promise<Result<unknown>>;
|
|
22
|
+
export type QueryInterceptor = (ctx: QueryInterceptionContext, next: () => Promise<Result<unknown>>) => Promise<Result<unknown>>;
|
|
23
|
+
export type EventInterceptor = (ctx: EventInterceptionContext, next: () => Promise<Result<unknown>>) => Promise<Result<unknown>>;
|
|
24
|
+
export type Interceptor = (ctx: InterceptionContext, next: () => Promise<Result<unknown>>) => Promise<Result<unknown>>;
|
|
25
|
+
//# sourceMappingURL=interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../src/interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,KAAK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,CAAC,CAAC;AAE9B,MAAM,MAAM,WAAW,GAAG,CACtB,GAAG,EAAE,mBAAmB,EACxB,IAAI,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KACnC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interceptor.js","sourceRoot":"","sources":["../src/interceptor.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Logger, LoggerConfig } from "./logger";
|
|
2
|
+
export declare function createLogger(config: LoggerConfig): Logger;
|
|
3
|
+
export interface TestLogEntry {
|
|
4
|
+
level: number;
|
|
5
|
+
time: number;
|
|
6
|
+
msg: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
export interface TestLogger extends Logger {
|
|
10
|
+
getLogs(): TestLogEntry[];
|
|
11
|
+
clear(): void;
|
|
12
|
+
findLog(predicate: (log: TestLogEntry) => boolean): TestLogEntry | undefined;
|
|
13
|
+
findLogs(predicate: (log: TestLogEntry) => boolean): TestLogEntry[];
|
|
14
|
+
}
|
|
15
|
+
export declare function createTestLogger(config?: Partial<LoggerConfig>): TestLogger;
|
|
16
|
+
//# sourceMappingURL=create-logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-logger.d.ts","sourceRoot":"","sources":["../../src/logging/create-logger.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAErD,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAmBzD;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,UAAW,SAAQ,MAAM;IACtC,OAAO,IAAI,YAAY,EAAE,CAAC;IAC1B,KAAK,IAAI,IAAI,CAAC;IACd,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC;IAC7E,QAAQ,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,GAAG,YAAY,EAAE,CAAC;CACvE;AAED,wBAAgB,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,UAAU,CA6B3E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createLogger = createLogger;
|
|
7
|
+
exports.createTestLogger = createTestLogger;
|
|
8
|
+
const pino_1 = __importDefault(require("pino"));
|
|
9
|
+
function createLogger(config) {
|
|
10
|
+
const pinoOptions = {
|
|
11
|
+
level: config.level,
|
|
12
|
+
base: config.base ?? {},
|
|
13
|
+
redact: config.redactPaths,
|
|
14
|
+
};
|
|
15
|
+
if (config.pretty) {
|
|
16
|
+
pinoOptions.transport = {
|
|
17
|
+
target: "pino-pretty",
|
|
18
|
+
options: {
|
|
19
|
+
colorize: true,
|
|
20
|
+
translateTime: "SYS:standard",
|
|
21
|
+
ignore: "pid,hostname",
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return (0, pino_1.default)(pinoOptions);
|
|
26
|
+
}
|
|
27
|
+
function createTestLogger(config) {
|
|
28
|
+
const logs = [];
|
|
29
|
+
const stream = {
|
|
30
|
+
write(msg) {
|
|
31
|
+
logs.push(JSON.parse(msg));
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
const pinoLogger = (0, pino_1.default)({
|
|
35
|
+
level: config?.level ?? "debug",
|
|
36
|
+
base: config?.base ?? {},
|
|
37
|
+
}, stream);
|
|
38
|
+
const testLogger = Object.assign(pinoLogger, {
|
|
39
|
+
getLogs: () => logs,
|
|
40
|
+
clear: () => {
|
|
41
|
+
logs.length = 0;
|
|
42
|
+
},
|
|
43
|
+
findLog: (predicate) => logs.find(predicate),
|
|
44
|
+
findLogs: (predicate) => logs.filter(predicate),
|
|
45
|
+
});
|
|
46
|
+
return testLogger;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=create-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-logger.js","sourceRoot":"","sources":["../../src/logging/create-logger.ts"],"names":[],"mappings":";;;;;AAIA,oCAmBC;AAgBD,4CA6BC;AApED,gDAAwB;AAIxB,SAAgB,YAAY,CAAC,MAAoB;IAC7C,MAAM,WAAW,GAAuB;QACpC,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,IAAI,EAAE,MAAM,CAAC,IAAI,IAAI,EAAE;QACvB,MAAM,EAAE,MAAM,CAAC,WAAW;KAC7B,CAAC;IAEF,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChB,WAAW,CAAC,SAAS,GAAG;YACpB,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE;gBACL,QAAQ,EAAE,IAAI;gBACd,aAAa,EAAE,cAAc;gBAC7B,MAAM,EAAE,cAAc;aACzB;SACJ,CAAC;IACN,CAAC;IAED,OAAO,IAAA,cAAI,EAAC,WAAW,CAAsB,CAAC;AAClD,CAAC;AAgBD,SAAgB,gBAAgB,CAAC,MAA8B;IAC3D,MAAM,IAAI,GAAmB,EAAE,CAAC;IAEhC,MAAM,MAAM,GAAG;QACX,KAAK,CAAC,GAAW;YACb,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,CAAC;KACJ,CAAC;IAEF,MAAM,UAAU,GAAG,IAAA,cAAI,EACnB;QACI,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,OAAO;QAC/B,IAAI,EAAE,MAAM,EAAE,IAAI,IAAI,EAAE;KAC3B,EACD,MAAM,CACM,CAAC;IAEjB,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;QACzC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;QACnB,KAAK,EAAE,GAAG,EAAE;YACR,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QACpB,CAAC;QACD,OAAO,EAAE,CAAC,SAAyC,EAAE,EAAE,CACnD,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;QACxB,QAAQ,EAAE,CAAC,SAAyC,EAAE,EAAE,CACpD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;KAC7B,CAAe,CAAC;IAEjB,OAAO,UAAU,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { Logger, LoggerConfig, LogContext, LogLevel } from "./logger";
|
|
2
|
+
export { createLogger, createTestLogger, type TestLogger, type TestLogEntry, } from "./create-logger";
|
|
3
|
+
export { type LoggingInterceptorConfig, type MessageKind, serializeError, buildLogContext, extractMetadataFields, getLogMessage, logCompletion, } from "./logging-utils";
|
|
4
|
+
export { createTraceInterceptor, traceCommandInterceptor, traceEventInterceptor, TraceCommandInterceptor, TraceEventInterceptor, getCurrentMessageTrace, getCorrelationTrace, CURRENT_MESSAGE_TRACE_KEY, CORRELATION_TRACE_KEY, } from "./trace-interceptor";
|
|
5
|
+
export { createLoggingInterceptor, LoggingInterceptor, } from "./logging-interceptor";
|
|
6
|
+
export { asTrace, causationOf, correlationOf, setCausationOf, setCorrelationOf, type MessageTrace, } from "../messaging-support";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/logging/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE3E,OAAO,EACH,YAAY,EACZ,gBAAgB,EAChB,KAAK,UAAU,EACf,KAAK,YAAY,GACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACH,KAAK,wBAAwB,EAC7B,KAAK,WAAW,EAChB,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,aAAa,GAChB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACH,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,yBAAyB,EACzB,qBAAqB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACH,wBAAwB,EACxB,kBAAkB,GACrB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACH,OAAO,EACP,WAAW,EACX,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,KAAK,YAAY,GACpB,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setCorrelationOf = exports.setCausationOf = exports.correlationOf = exports.causationOf = exports.asTrace = exports.LoggingInterceptor = exports.createLoggingInterceptor = exports.CORRELATION_TRACE_KEY = exports.CURRENT_MESSAGE_TRACE_KEY = exports.getCorrelationTrace = exports.getCurrentMessageTrace = exports.TraceEventInterceptor = exports.TraceCommandInterceptor = exports.traceEventInterceptor = exports.traceCommandInterceptor = exports.createTraceInterceptor = exports.logCompletion = exports.getLogMessage = exports.extractMetadataFields = exports.buildLogContext = exports.serializeError = exports.createTestLogger = exports.createLogger = void 0;
|
|
4
|
+
var create_logger_1 = require("./create-logger");
|
|
5
|
+
Object.defineProperty(exports, "createLogger", { enumerable: true, get: function () { return create_logger_1.createLogger; } });
|
|
6
|
+
Object.defineProperty(exports, "createTestLogger", { enumerable: true, get: function () { return create_logger_1.createTestLogger; } });
|
|
7
|
+
var logging_utils_1 = require("./logging-utils");
|
|
8
|
+
Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return logging_utils_1.serializeError; } });
|
|
9
|
+
Object.defineProperty(exports, "buildLogContext", { enumerable: true, get: function () { return logging_utils_1.buildLogContext; } });
|
|
10
|
+
Object.defineProperty(exports, "extractMetadataFields", { enumerable: true, get: function () { return logging_utils_1.extractMetadataFields; } });
|
|
11
|
+
Object.defineProperty(exports, "getLogMessage", { enumerable: true, get: function () { return logging_utils_1.getLogMessage; } });
|
|
12
|
+
Object.defineProperty(exports, "logCompletion", { enumerable: true, get: function () { return logging_utils_1.logCompletion; } });
|
|
13
|
+
var trace_interceptor_1 = require("./trace-interceptor");
|
|
14
|
+
Object.defineProperty(exports, "createTraceInterceptor", { enumerable: true, get: function () { return trace_interceptor_1.createTraceInterceptor; } });
|
|
15
|
+
Object.defineProperty(exports, "traceCommandInterceptor", { enumerable: true, get: function () { return trace_interceptor_1.traceCommandInterceptor; } });
|
|
16
|
+
Object.defineProperty(exports, "traceEventInterceptor", { enumerable: true, get: function () { return trace_interceptor_1.traceEventInterceptor; } });
|
|
17
|
+
Object.defineProperty(exports, "TraceCommandInterceptor", { enumerable: true, get: function () { return trace_interceptor_1.TraceCommandInterceptor; } });
|
|
18
|
+
Object.defineProperty(exports, "TraceEventInterceptor", { enumerable: true, get: function () { return trace_interceptor_1.TraceEventInterceptor; } });
|
|
19
|
+
Object.defineProperty(exports, "getCurrentMessageTrace", { enumerable: true, get: function () { return trace_interceptor_1.getCurrentMessageTrace; } });
|
|
20
|
+
Object.defineProperty(exports, "getCorrelationTrace", { enumerable: true, get: function () { return trace_interceptor_1.getCorrelationTrace; } });
|
|
21
|
+
Object.defineProperty(exports, "CURRENT_MESSAGE_TRACE_KEY", { enumerable: true, get: function () { return trace_interceptor_1.CURRENT_MESSAGE_TRACE_KEY; } });
|
|
22
|
+
Object.defineProperty(exports, "CORRELATION_TRACE_KEY", { enumerable: true, get: function () { return trace_interceptor_1.CORRELATION_TRACE_KEY; } });
|
|
23
|
+
var logging_interceptor_1 = require("./logging-interceptor");
|
|
24
|
+
Object.defineProperty(exports, "createLoggingInterceptor", { enumerable: true, get: function () { return logging_interceptor_1.createLoggingInterceptor; } });
|
|
25
|
+
Object.defineProperty(exports, "LoggingInterceptor", { enumerable: true, get: function () { return logging_interceptor_1.LoggingInterceptor; } });
|
|
26
|
+
var messaging_support_1 = require("../messaging-support");
|
|
27
|
+
Object.defineProperty(exports, "asTrace", { enumerable: true, get: function () { return messaging_support_1.asTrace; } });
|
|
28
|
+
Object.defineProperty(exports, "causationOf", { enumerable: true, get: function () { return messaging_support_1.causationOf; } });
|
|
29
|
+
Object.defineProperty(exports, "correlationOf", { enumerable: true, get: function () { return messaging_support_1.correlationOf; } });
|
|
30
|
+
Object.defineProperty(exports, "setCausationOf", { enumerable: true, get: function () { return messaging_support_1.setCausationOf; } });
|
|
31
|
+
Object.defineProperty(exports, "setCorrelationOf", { enumerable: true, get: function () { return messaging_support_1.setCorrelationOf; } });
|
|
32
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logging/index.ts"],"names":[],"mappings":";;;AAEA,iDAKyB;AAJrB,6GAAA,YAAY,OAAA;AACZ,iHAAA,gBAAgB,OAAA;AAKpB,iDAQyB;AALrB,+GAAA,cAAc,OAAA;AACd,gHAAA,eAAe,OAAA;AACf,sHAAA,qBAAqB,OAAA;AACrB,8GAAA,aAAa,OAAA;AACb,8GAAA,aAAa,OAAA;AAGjB,yDAU6B;AATzB,2HAAA,sBAAsB,OAAA;AACtB,4HAAA,uBAAuB,OAAA;AACvB,0HAAA,qBAAqB,OAAA;AACrB,4HAAA,uBAAuB,OAAA;AACvB,0HAAA,qBAAqB,OAAA;AACrB,2HAAA,sBAAsB,OAAA;AACtB,wHAAA,mBAAmB,OAAA;AACnB,8HAAA,yBAAyB,OAAA;AACzB,0HAAA,qBAAqB,OAAA;AAGzB,6DAG+B;AAF3B,+HAAA,wBAAwB,OAAA;AACxB,yHAAA,kBAAkB,OAAA;AAGtB,0DAO8B;AAN1B,4GAAA,OAAO,OAAA;AACP,gHAAA,WAAW,OAAA;AACX,kHAAA,aAAa,OAAA;AACb,mHAAA,cAAc,OAAA;AACd,qHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type LogLevel = "debug" | "info" | "warn" | "error" | "fatal";
|
|
2
|
+
export interface LogContext {
|
|
3
|
+
messageId?: string;
|
|
4
|
+
messageType?: string;
|
|
5
|
+
correlationId?: string;
|
|
6
|
+
correlationType?: string;
|
|
7
|
+
causationId?: string;
|
|
8
|
+
causationType?: string;
|
|
9
|
+
requestId?: string;
|
|
10
|
+
traceId?: string;
|
|
11
|
+
spanId?: string;
|
|
12
|
+
userId?: string;
|
|
13
|
+
tenantId?: string;
|
|
14
|
+
durationMs?: number;
|
|
15
|
+
error?: {
|
|
16
|
+
name: string;
|
|
17
|
+
message: string;
|
|
18
|
+
code?: string;
|
|
19
|
+
stack?: string;
|
|
20
|
+
};
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}
|
|
23
|
+
export interface Logger {
|
|
24
|
+
debug(msg: string): void;
|
|
25
|
+
debug(context: LogContext, msg: string): void;
|
|
26
|
+
info(msg: string): void;
|
|
27
|
+
info(context: LogContext, msg: string): void;
|
|
28
|
+
warn(msg: string): void;
|
|
29
|
+
warn(context: LogContext, msg: string): void;
|
|
30
|
+
error(msg: string): void;
|
|
31
|
+
error(context: LogContext, msg: string): void;
|
|
32
|
+
fatal(msg: string): void;
|
|
33
|
+
fatal(context: LogContext, msg: string): void;
|
|
34
|
+
child(bindings: LogContext): Logger;
|
|
35
|
+
}
|
|
36
|
+
export interface LoggerConfig {
|
|
37
|
+
level: LogLevel;
|
|
38
|
+
pretty?: boolean;
|
|
39
|
+
redactPaths?: string[];
|
|
40
|
+
base?: LogContext;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/logging/logger.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAErE,MAAM,WAAW,UAAU;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE;QACJ,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,MAAM;IACnB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9C,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7C,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7C,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9C,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9C,KAAK,CAAC,QAAQ,EAAE,UAAU,GAAG,MAAM,CAAC;CACvC;AAED,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,IAAI,CAAC,EAAE,UAAU,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logging/logger.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Interceptor } from "../interceptor";
|
|
2
|
+
import type { LoggingInterceptorConfig } from "./logging-utils";
|
|
3
|
+
export declare function createLoggingInterceptor(config: LoggingInterceptorConfig): Interceptor;
|
|
4
|
+
export declare class LoggingInterceptor {
|
|
5
|
+
private readonly interceptor;
|
|
6
|
+
constructor(config: LoggingInterceptorConfig);
|
|
7
|
+
asInterceptor(): Interceptor;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=logging-interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging-interceptor.d.ts","sourceRoot":"","sources":["../../src/logging/logging-interceptor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,WAAW,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,wBAAwB,EAAe,MAAM,iBAAiB,CAAC;AAY7E,wBAAgB,wBAAwB,CACpC,MAAM,EAAE,wBAAwB,GACjC,WAAW,CAiDb;AAGD,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAc;gBAE9B,MAAM,EAAE,wBAAwB;IAI5C,aAAa,IAAI,WAAW;CAG/B"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggingInterceptor = void 0;
|
|
4
|
+
exports.createLoggingInterceptor = createLoggingInterceptor;
|
|
5
|
+
const logging_utils_1 = require("./logging-utils");
|
|
6
|
+
function getMessageKind(ctx) {
|
|
7
|
+
return ctx.intent === "query" ? "command" : ctx.intent;
|
|
8
|
+
}
|
|
9
|
+
function createLoggingInterceptor(config) {
|
|
10
|
+
return async (ctx, next) => {
|
|
11
|
+
const message = ctx.message;
|
|
12
|
+
const messageType = message.getMessageType();
|
|
13
|
+
if (config.excludeTypes?.includes(messageType)) {
|
|
14
|
+
return next();
|
|
15
|
+
}
|
|
16
|
+
const kind = getMessageKind(ctx);
|
|
17
|
+
const logContext = (0, logging_utils_1.buildLogContext)(message, ctx.metadata, config.includeTracing !== false);
|
|
18
|
+
const logger = config.logger.child(logContext);
|
|
19
|
+
logger.info((0, logging_utils_1.getLogMessage)(kind, "started"));
|
|
20
|
+
const startTime = performance.now();
|
|
21
|
+
try {
|
|
22
|
+
const result = await next();
|
|
23
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
24
|
+
(0, logging_utils_1.logCompletion)(logger, result, durationMs, config.slowThresholdMs, kind);
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
const durationMs = Math.round(performance.now() - startTime);
|
|
29
|
+
logger.error({
|
|
30
|
+
durationMs,
|
|
31
|
+
error: (0, logging_utils_1.serializeError)(error),
|
|
32
|
+
}, (0, logging_utils_1.getLogMessage)(kind, "exception"));
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Backward compatibility - deprecated, use createLoggingInterceptor instead
|
|
38
|
+
class LoggingInterceptor {
|
|
39
|
+
interceptor;
|
|
40
|
+
constructor(config) {
|
|
41
|
+
this.interceptor = createLoggingInterceptor(config);
|
|
42
|
+
}
|
|
43
|
+
asInterceptor() {
|
|
44
|
+
return this.interceptor;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.LoggingInterceptor = LoggingInterceptor;
|
|
48
|
+
//# sourceMappingURL=logging-interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging-interceptor.js","sourceRoot":"","sources":["../../src/logging/logging-interceptor.ts"],"names":[],"mappings":";;;AAcA,4DAmDC;AA9DD,mDAKyB;AAEzB,SAAS,cAAc,CAAC,GAAwB;IAC5C,OAAO,GAAG,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;AAC3D,CAAC;AAED,SAAgB,wBAAwB,CACpC,MAAgC;IAEhC,OAAO,KAAK,EACR,GAAwB,EACxB,IAAoC,EACZ,EAAE;QAC1B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC5B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;QAE7C,IAAI,MAAM,CAAC,YAAY,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;YAC7C,OAAO,IAAI,EAAE,CAAC;QAClB,CAAC;QAED,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACjC,MAAM,UAAU,GAAG,IAAA,+BAAe,EAC9B,OAAO,EACP,GAAG,C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../application";
|
|
3
|
+
import type { Logger, LogContext } from "./logger";
|
|
4
|
+
export interface LoggingInterceptorConfig {
|
|
5
|
+
logger: Logger;
|
|
6
|
+
slowThresholdMs?: number;
|
|
7
|
+
excludeTypes?: string[];
|
|
8
|
+
includeTracing?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare function serializeError(error: unknown): LogContext["error"];
|
|
11
|
+
export declare function extractMetadataFields(metadata: Record<string, unknown>, logContext: LogContext): void;
|
|
12
|
+
export declare function buildLogContext(message: Message, metadata: Record<string, unknown>, includeTracing: boolean): LogContext;
|
|
13
|
+
export type MessageKind = "command" | "event";
|
|
14
|
+
export declare function getLogMessage(kind: MessageKind, phase: "started" | "completed" | "failed" | "exception" | "slow"): string;
|
|
15
|
+
export declare function logCompletion(logger: Logger, result: Result<unknown>, durationMs: number, slowThresholdMs: number | undefined, kind: MessageKind): void;
|
|
16
|
+
//# sourceMappingURL=logging-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging-utils.d.ts","sourceRoot":"","sources":["../../src/logging/logging-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAExC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,WAAW,wBAAwB;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC5B;AAUD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAalE;AAED,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,UAAU,EAAE,UAAU,GACvB,IAAI,CAMN;AAED,wBAAgB,eAAe,CAC3B,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,cAAc,EAAE,OAAO,GACxB,UAAU,CAyBZ;AAED,MAAM,MAAM,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AA4B9C,wBAAgB,aAAa,CACzB,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,MAAM,GACjE,MAAM,CAER;AAED,wBAAgB,aAAa,CACzB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,EACvB,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,IAAI,EAAE,WAAW,GAClB,IAAI,CAgBN"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeError = serializeError;
|
|
4
|
+
exports.extractMetadataFields = extractMetadataFields;
|
|
5
|
+
exports.buildLogContext = buildLogContext;
|
|
6
|
+
exports.getLogMessage = getLogMessage;
|
|
7
|
+
exports.logCompletion = logCompletion;
|
|
8
|
+
const messaging_support_1 = require("../messaging-support");
|
|
9
|
+
const COMMON_METADATA_FIELDS = [
|
|
10
|
+
"requestId",
|
|
11
|
+
"traceId",
|
|
12
|
+
"spanId",
|
|
13
|
+
"userId",
|
|
14
|
+
"tenantId",
|
|
15
|
+
];
|
|
16
|
+
function serializeError(error) {
|
|
17
|
+
if (error instanceof Error) {
|
|
18
|
+
return {
|
|
19
|
+
name: error.constructor.name,
|
|
20
|
+
message: error.message,
|
|
21
|
+
code: error.code,
|
|
22
|
+
stack: error.stack,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
name: "UnknownError",
|
|
27
|
+
message: String(error),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function extractMetadataFields(metadata, logContext) {
|
|
31
|
+
for (const field of COMMON_METADATA_FIELDS) {
|
|
32
|
+
if (typeof metadata[field] === "string") {
|
|
33
|
+
logContext[field] = metadata[field];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function buildLogContext(message, metadata, includeTracing) {
|
|
38
|
+
const trace = (0, messaging_support_1.asTrace)(message);
|
|
39
|
+
const logContext = {
|
|
40
|
+
messageId: trace.id,
|
|
41
|
+
messageType: trace.type,
|
|
42
|
+
};
|
|
43
|
+
if (includeTracing) {
|
|
44
|
+
const correlation = (0, messaging_support_1.correlationOf)(message);
|
|
45
|
+
if (correlation) {
|
|
46
|
+
logContext.correlationId = correlation.id;
|
|
47
|
+
logContext.correlationType = correlation.type;
|
|
48
|
+
}
|
|
49
|
+
const causation = (0, messaging_support_1.causationOf)(message);
|
|
50
|
+
if (causation) {
|
|
51
|
+
logContext.causationId = causation.id;
|
|
52
|
+
logContext.causationType = causation.type;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
extractMetadataFields(metadata, logContext);
|
|
56
|
+
return logContext;
|
|
57
|
+
}
|
|
58
|
+
const LOG_MESSAGES = {
|
|
59
|
+
command: {
|
|
60
|
+
started: "Command execution started",
|
|
61
|
+
completed: "Command execution completed",
|
|
62
|
+
failed: "Command execution failed",
|
|
63
|
+
exception: "Command execution failed with exception",
|
|
64
|
+
slow: "Slow command execution detected",
|
|
65
|
+
},
|
|
66
|
+
event: {
|
|
67
|
+
started: "Event handling started",
|
|
68
|
+
completed: "Event handling completed",
|
|
69
|
+
failed: "Event handling failed",
|
|
70
|
+
exception: "Event handling failed with exception",
|
|
71
|
+
slow: "Slow event handling detected",
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
function getLogMessage(kind, phase) {
|
|
75
|
+
return LOG_MESSAGES[kind][phase];
|
|
76
|
+
}
|
|
77
|
+
function logCompletion(logger, result, durationMs, slowThresholdMs, kind) {
|
|
78
|
+
if (slowThresholdMs && durationMs > slowThresholdMs) {
|
|
79
|
+
logger.warn({ durationMs }, getLogMessage(kind, "slow"));
|
|
80
|
+
}
|
|
81
|
+
if (result.isSuccess) {
|
|
82
|
+
logger.info({ durationMs }, getLogMessage(kind, "completed"));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
logger.error({
|
|
86
|
+
durationMs,
|
|
87
|
+
error: serializeError(result.error),
|
|
88
|
+
}, getLogMessage(kind, "failed"));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=logging-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging-utils.js","sourceRoot":"","sources":["../../src/logging/logging-utils.ts"],"names":[],"mappings":";;AAqBA,wCAaC;AAED,sDASC;AAED,0CA6BC;AA8BD,sCAKC;AAED,sCAsBC;AApID,2DAA0E;AAU1E,MAAM,sBAAsB,GAAG;IAC3B,WAAW;IACX,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,UAAU;CACJ,CAAC;AAEX,SAAgB,cAAc,CAAC,KAAc;IACzC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QACzB,OAAO;YACH,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,IAAI;YAC5B,OAAO,EAAE,KAAK,CAAC,OAAO;YACtB,IAAI,EAAG,KAA2B,CAAC,IAAI;YACvC,KAAK,EAAE,KAAK,CAAC,KAAK;SACrB,CAAC;IACN,CAAC;IACD,OAAO;QACH,IAAI,EAAE,cAAc;QACpB,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;KACzB,CAAC;AACN,CAAC;AAED,SAAgB,qBAAqB,CACjC,QAAiC,EACjC,UAAsB;IAEtB,KAAK,MAAM,KAAK,IAAI,sBAAsB,EAAE,CAAC;QACzC,IAAI,OAAO,QAAQ,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;YACtC,UAAU,CAAC,KAAK,CAAC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iB,EACjB,KAAgE;IAEhE,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC;AACrC,CAAC;AAED,SAAgB,aAAa,CACzB,MAAc,EACd,MAAuB,EACvB,UAAkB,EAClB,eAAmC,EACnC,IAAiB;IAEjB,IAAI,eAAe,IAAI,UAAU,GAAG,eAAe,EAAE,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,EAAE,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,CAAC,IAAI,CAAC,EAAE,UAAU,EAAE,EAAE,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAClE,CAAC;SAAM,CAAC;QACJ,MAAM,CAAC,KAAK,CACR;YACI,UAAU;YACV,KAAK,EAAE,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC;SACtC,EACD,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAChC,CAAC;IACN,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CommandInterceptor, EventInterceptor, Interceptor } from "../interceptor";
|
|
2
|
+
import { type MessageTrace } from "../messaging-support";
|
|
3
|
+
export declare const CURRENT_MESSAGE_TRACE_KEY: unique symbol;
|
|
4
|
+
export declare const CORRELATION_TRACE_KEY: unique symbol;
|
|
5
|
+
export declare function getCurrentMessageTrace(metadata: Record<string | symbol, unknown>): MessageTrace | undefined;
|
|
6
|
+
export declare function getCorrelationTrace(metadata: Record<string | symbol, unknown>): MessageTrace | undefined;
|
|
7
|
+
export declare function createTraceInterceptor(): Interceptor;
|
|
8
|
+
export declare const traceCommandInterceptor: CommandInterceptor;
|
|
9
|
+
export declare const traceEventInterceptor: EventInterceptor;
|
|
10
|
+
export declare class TraceCommandInterceptor {
|
|
11
|
+
asInterceptor(): CommandInterceptor;
|
|
12
|
+
}
|
|
13
|
+
export declare class TraceEventInterceptor {
|
|
14
|
+
asInterceptor(): EventInterceptor;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=trace-interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-interceptor.d.ts","sourceRoot":"","sources":["../../src/logging/trace-interceptor.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,kBAAkB,EAElB,gBAAgB,EAEhB,WAAW,EACd,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAGH,KAAK,YAAY,EACpB,MAAM,sBAAsB,CAAC;AAE9B,eAAO,MAAM,yBAAyB,eAAgC,CAAC;AACvE,eAAO,MAAM,qBAAqB,eAA6B,CAAC;AAEhE,wBAAgB,sBAAsB,CAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAC3C,YAAY,GAAG,SAAS,CAE1B;AAED,wBAAgB,mBAAmB,CAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAC3C,YAAY,GAAG,SAAS,CAE1B;AAWD,wBAAgB,sBAAsB,IAAI,WAAW,CAQpD;AAED,eAAO,MAAM,uBAAuB,EAAE,kBAMrC,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,gBAMnC,CAAC;AAGF,qBAAa,uBAAuB;IAChC,aAAa,IAAI,kBAAkB;CAGtC;AAGD,qBAAa,qBAAqB;IAC9B,aAAa,IAAI,gBAAgB;CAGpC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TraceEventInterceptor = exports.TraceCommandInterceptor = exports.traceEventInterceptor = exports.traceCommandInterceptor = exports.CORRELATION_TRACE_KEY = exports.CURRENT_MESSAGE_TRACE_KEY = void 0;
|
|
4
|
+
exports.getCurrentMessageTrace = getCurrentMessageTrace;
|
|
5
|
+
exports.getCorrelationTrace = getCorrelationTrace;
|
|
6
|
+
exports.createTraceInterceptor = createTraceInterceptor;
|
|
7
|
+
const messaging_support_1 = require("../messaging-support");
|
|
8
|
+
exports.CURRENT_MESSAGE_TRACE_KEY = Symbol("currentMessageTrace");
|
|
9
|
+
exports.CORRELATION_TRACE_KEY = Symbol("correlationTrace");
|
|
10
|
+
function getCurrentMessageTrace(metadata) {
|
|
11
|
+
return metadata[exports.CURRENT_MESSAGE_TRACE_KEY];
|
|
12
|
+
}
|
|
13
|
+
function getCorrelationTrace(metadata) {
|
|
14
|
+
return metadata[exports.CORRELATION_TRACE_KEY];
|
|
15
|
+
}
|
|
16
|
+
function propagateTrace(ctx) {
|
|
17
|
+
const message = ctx.message;
|
|
18
|
+
const currentTrace = (0, messaging_support_1.asTrace)(message);
|
|
19
|
+
ctx.metadata[exports.CURRENT_MESSAGE_TRACE_KEY] = currentTrace;
|
|
20
|
+
const correlationTrace = (0, messaging_support_1.correlationOf)(message) ?? currentTrace;
|
|
21
|
+
ctx.metadata[exports.CORRELATION_TRACE_KEY] = correlationTrace;
|
|
22
|
+
}
|
|
23
|
+
function createTraceInterceptor() {
|
|
24
|
+
return async (ctx, next) => {
|
|
25
|
+
propagateTrace(ctx);
|
|
26
|
+
return next();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const traceCommandInterceptor = async (ctx, next) => {
|
|
30
|
+
propagateTrace(ctx);
|
|
31
|
+
return next();
|
|
32
|
+
};
|
|
33
|
+
exports.traceCommandInterceptor = traceCommandInterceptor;
|
|
34
|
+
const traceEventInterceptor = async (ctx, next) => {
|
|
35
|
+
propagateTrace(ctx);
|
|
36
|
+
return next();
|
|
37
|
+
};
|
|
38
|
+
exports.traceEventInterceptor = traceEventInterceptor;
|
|
39
|
+
// Backward compatibility - deprecated, use traceCommandInterceptor instead
|
|
40
|
+
class TraceCommandInterceptor {
|
|
41
|
+
asInterceptor() {
|
|
42
|
+
return exports.traceCommandInterceptor;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.TraceCommandInterceptor = TraceCommandInterceptor;
|
|
46
|
+
// Backward compatibility - deprecated, use traceEventInterceptor instead
|
|
47
|
+
class TraceEventInterceptor {
|
|
48
|
+
asInterceptor() {
|
|
49
|
+
return exports.traceEventInterceptor;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.TraceEventInterceptor = TraceEventInterceptor;
|
|
53
|
+
//# sourceMappingURL=trace-interceptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace-interceptor.js","sourceRoot":"","sources":["../../src/logging/trace-interceptor.ts"],"names":[],"mappings":";;;AAkBA,wDAIC;AAED,kDAIC;AAWD,wDAQC;AAtCD,4DAI8B;AAEjB,QAAA,yBAAyB,GAAG,MAAM,CAAC,qBAAqB,CAAC,CAAC;AAC1D,QAAA,qBAAqB,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAEhE,SAAgB,sBAAsB,CAClC,QAA0C;IAE1C,OAAO,QAAQ,CAAC,iCAAyB,CAA6B,CAAC;AAC3E,CAAC;AAED,SAAgB,mBAAmB,CAC/B,QAA0C;IAE1C,OAAO,QAAQ,CAAC,6BAAqB,CAA6B,CAAC;AACvE,CAAC;AAED,SAAS,cAAc,CAAC,GAAwB;IAC5C,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;IAC5B,MAAM,YAAY,GAAG,IAAA,2BAAO,EAAC,OAAO,CAAC,CAAC;IACtC,GAAG,CAAC,QAAQ,CAAC,iCAAyB,CAAC,GAAG,YAAY,CAAC;IAEvD,MAAM,gBAAgB,GAAG,IAAA,iCAAa,EAAC,OAAO,CAAC,IAAI,YAAY,CAAC;IAChE,GAAG,CAAC,QAAQ,CAAC,6BAAqB,CAAC,GAAG,gBAAgB,CAAC;AAC3D,CAAC;AAED,SAAgB,sBAAsB;IAClC,OAAO,KAAK,EACR,GAAwB,EACxB,IAAoC,EACZ,EAAE;QAC1B,cAAc,CAAC,GAAG,CAAC,CAAC;QACpB,OAAO,IAAI,EAAE,CAAC;IAClB,CAAC,CAAC;AACN,CAAC;AAEM,MAAM,uBAAuB,GAAuB,KAAK,EAC5D,GAA+B,EAC/B,IAAoC,EACZ,EAAE;IAC1B,cAAc,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,IAAI,EAAE,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,uBAAuB,2BAMlC;AAEK,MAAM,qBAAqB,GAAqB,KAAK,EACxD,GAA6B,EAC7B,IAAoC,EACZ,EAAE;IAC1B,cAAc,CAAC,GAAG,CAAC,CAAC;IACpB,OAAO,IAAI,EAAE,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,qBAAqB,yBAMhC;AAEF,2EAA2E;AAC3E,MAAa,uBAAuB;IAChC,aAAa;QACT,OAAO,+BAAuB,CAAC;IACnC,CAAC;CACJ;AAJD,0DAIC;AAED,yEAAyE;AACzE,MAAa,qBAAqB;IAC9B,aAAa;QACT,OAAO,6BAAqB,CAAC;IACjC,CAAC;CACJ;AAJD,sDAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-handler.d.ts","sourceRoot":"","sources":["../src/message-handler.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG;IACrD,OAAO,CAAC,OAAO,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;CACnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message-handler.js","sourceRoot":"","sources":["../src/message-handler.ts"],"names":[],"mappings":""}
|