@bgord/bun 1.11.0 → 1.12.1
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/command-bus-collecting.adapter.d.ts +8 -0
- package/dist/command-bus-collecting.adapter.d.ts.map +1 -0
- package/dist/command-bus-collecting.adapter.js +8 -0
- package/dist/command-bus-collecting.adapter.js.map +1 -0
- package/dist/command-bus-emittery-v1.adapter.d.ts +9 -0
- package/dist/command-bus-emittery-v1.adapter.d.ts.map +1 -0
- package/dist/command-bus-emittery-v1.adapter.js +14 -0
- package/dist/command-bus-emittery-v1.adapter.js.map +1 -0
- package/dist/command-bus-noop.adapter.d.ts +7 -0
- package/dist/command-bus-noop.adapter.d.ts.map +1 -0
- package/dist/command-bus-noop.adapter.js +5 -0
- package/dist/command-bus-noop.adapter.js.map +1 -0
- package/dist/command-bus-with-logger.adapter.d.ts +16 -0
- package/dist/command-bus-with-logger.adapter.d.ts.map +1 -0
- package/dist/command-bus-with-logger.adapter.js +21 -0
- package/dist/command-bus-with-logger.adapter.js.map +1 -0
- package/dist/command-bus.port.d.ts +6 -0
- package/dist/command-bus.port.d.ts.map +1 -0
- package/dist/command-bus.port.js +2 -0
- package/dist/command-bus.port.js.map +1 -0
- package/dist/dispatching-event-store.d.ts +2 -3
- package/dist/dispatching-event-store.d.ts.map +1 -1
- package/dist/dispatching-event-store.js.map +1 -1
- package/dist/event-bus-collecting.adapter.d.ts +8 -0
- package/dist/event-bus-collecting.adapter.d.ts.map +1 -0
- package/dist/event-bus-collecting.adapter.js +8 -0
- package/dist/event-bus-collecting.adapter.js.map +1 -0
- package/dist/event-bus-emittery-v1.adapter.d.ts +9 -0
- package/dist/event-bus-emittery-v1.adapter.d.ts.map +1 -0
- package/dist/event-bus-emittery-v1.adapter.js +14 -0
- package/dist/event-bus-emittery-v1.adapter.js.map +1 -0
- package/dist/event-bus-noop.adapter.d.ts +7 -0
- package/dist/event-bus-noop.adapter.d.ts.map +1 -0
- package/dist/event-bus-noop.adapter.js +5 -0
- package/dist/event-bus-noop.adapter.js.map +1 -0
- package/dist/event-bus-with-logger.adapter.d.ts +16 -0
- package/dist/event-bus-with-logger.adapter.d.ts.map +1 -0
- package/dist/event-bus-with-logger.adapter.js +21 -0
- package/dist/event-bus-with-logger.adapter.js.map +1 -0
- package/dist/event-bus.port.d.ts +6 -0
- package/dist/event-bus.port.d.ts.map +1 -0
- package/dist/event-bus.port.js +2 -0
- package/dist/event-bus.port.js.map +1 -0
- package/dist/event-handler-bare.strategy.d.ts +2 -5
- package/dist/event-handler-bare.strategy.d.ts.map +1 -1
- package/dist/event-handler-bare.strategy.js.map +1 -1
- package/dist/event-handler-noop.strategy.d.ts +2 -5
- package/dist/event-handler-noop.strategy.d.ts.map +1 -1
- package/dist/event-handler-noop.strategy.js +1 -1
- package/dist/event-handler-noop.strategy.js.map +1 -1
- package/dist/event-handler-with-logger.strategy.d.ts +2 -5
- package/dist/event-handler-with-logger.strategy.d.ts.map +1 -1
- package/dist/event-handler-with-logger.strategy.js +2 -2
- package/dist/event-handler-with-logger.strategy.js.map +1 -1
- package/dist/event-handler.strategy.d.ts +2 -5
- package/dist/event-handler.strategy.d.ts.map +1 -1
- package/dist/event-store-like.types.d.ts +3 -4
- package/dist/event-store-like.types.d.ts.map +1 -1
- package/dist/index.d.ts +11 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/message.types.d.ts +7 -0
- package/dist/message.types.d.ts.map +1 -0
- package/dist/message.types.js +2 -0
- package/dist/message.types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -4
- package/readme.md +11 -5
- package/src/command-bus-collecting.adapter.ts +18 -0
- package/src/command-bus-emittery-v1.adapter.ts +25 -0
- package/src/command-bus-noop.adapter.ts +14 -0
- package/src/command-bus-with-logger.adapter.ts +34 -0
- package/src/command-bus.port.ts +13 -0
- package/src/dispatching-event-store.ts +4 -4
- package/src/event-bus-collecting.adapter.ts +18 -0
- package/src/event-bus-emittery-v1.adapter.ts +25 -0
- package/src/event-bus-noop.adapter.ts +14 -0
- package/src/event-bus-with-logger.adapter.ts +34 -0
- package/src/event-bus.port.ts +13 -0
- package/src/event-handler-bare.strategy.ts +3 -4
- package/src/event-handler-noop.strategy.ts +3 -4
- package/src/event-handler-with-logger.strategy.ts +4 -5
- package/src/event-handler.strategy.ts +2 -5
- package/src/event-store-like.types.ts +4 -2
- package/src/index.ts +11 -4
- package/src/message.types.ts +5 -0
- package/dist/command-logger.service.d.ts +0 -13
- package/dist/command-logger.service.d.ts.map +0 -1
- package/dist/command-logger.service.js +0 -16
- package/dist/command-logger.service.js.map +0 -1
- package/dist/event-bus-like.types.d.ts +0 -12
- package/dist/event-bus-like.types.d.ts.map +0 -1
- package/dist/event-bus-like.types.js +0 -2
- package/dist/event-bus-like.types.js.map +0 -1
- package/dist/event-logger.service.d.ts +0 -13
- package/dist/event-logger.service.d.ts.map +0 -1
- package/dist/event-logger.service.js +0 -16
- package/dist/event-logger.service.js.map +0 -1
- package/dist/event-publisher.types.d.ts +0 -4
- package/dist/event-publisher.types.d.ts.map +0 -1
- package/dist/event-publisher.types.js +0 -2
- package/dist/event-publisher.types.js.map +0 -1
- package/dist/to-event-map.types.d.ts +0 -6
- package/dist/to-event-map.types.d.ts.map +0 -1
- package/dist/to-event-map.types.js +0 -2
- package/dist/to-event-map.types.js.map +0 -1
- package/src/command-logger.service.ts +0 -23
- package/src/event-bus-like.types.ts +0 -10
- package/src/event-logger.service.ts +0 -23
- package/src/event-publisher.types.ts +0 -3
- package/src/to-event-map.types.ts +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bgord/bun",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Bartosz Gordon",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"preinstall": "bunx only-allow bun"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@biomejs/biome": "2.4.
|
|
23
|
+
"@biomejs/biome": "2.4.6",
|
|
24
24
|
"@commitlint/cli": "20.4.3",
|
|
25
25
|
"@commitlint/config-conventional": "20.4.3",
|
|
26
26
|
"@stryker-mutator/core": "9.6.0",
|
|
27
27
|
"@types/bun": "1.3.10",
|
|
28
28
|
"@types/nodemailer": "7.0.11",
|
|
29
29
|
"@types/yazl": "3.3.0",
|
|
30
|
-
"better-auth": "1.5.
|
|
30
|
+
"better-auth": "1.5.4",
|
|
31
31
|
"cspell": "9.7.0",
|
|
32
32
|
"csv": "6.4.1",
|
|
33
33
|
"knip": "5.85.0",
|
|
@@ -44,11 +44,12 @@
|
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@bgord/tools": "1.3.22",
|
|
47
|
+
"emittery": "1.2.1",
|
|
47
48
|
"hono": "4.12.5",
|
|
48
49
|
"node-cache": "5.1.2"
|
|
49
50
|
},
|
|
50
51
|
"peerDependencies": {
|
|
51
|
-
"better-auth": "1.5.
|
|
52
|
+
"better-auth": "1.5.4",
|
|
52
53
|
"csv": "6.4.1",
|
|
53
54
|
"nodemailer": "8.0.1",
|
|
54
55
|
"resend": "6.9.3",
|
package/readme.md
CHANGED
|
@@ -73,8 +73,12 @@ src/
|
|
|
73
73
|
├── clock-offset.adapter.ts
|
|
74
74
|
├── clock-system.adapter.ts
|
|
75
75
|
├── clock.port.ts
|
|
76
|
+
├── command-bus-collecting.adapter.ts
|
|
77
|
+
├── command-bus-emittery-v1.adapter.ts
|
|
78
|
+
├── command-bus-noop.adapter.ts
|
|
79
|
+
├── command-bus-with-logger.adapter.ts
|
|
80
|
+
├── command-bus.port.ts
|
|
76
81
|
├── command-envelope.ts
|
|
77
|
-
├── command-logger.service.ts
|
|
78
82
|
├── command.types.ts
|
|
79
83
|
├── commit-sha-value.vo.ts
|
|
80
84
|
├── commit-sha.vo.ts
|
|
@@ -112,16 +116,18 @@ src/
|
|
|
112
116
|
├── error-normalizer.service.ts
|
|
113
117
|
├── etag-extractor-hono.middleware.ts
|
|
114
118
|
├── etag-extractor.middleware.ts
|
|
115
|
-
├── event-bus-
|
|
119
|
+
├── event-bus-collecting.adapter.ts
|
|
120
|
+
├── event-bus-emittery-v1.adapter.ts
|
|
121
|
+
├── event-bus-noop.adapter.ts
|
|
122
|
+
├── event-bus-with-logger.adapter.ts
|
|
123
|
+
├── event-bus.port.ts
|
|
116
124
|
├── event-envelope.ts
|
|
117
125
|
├── event-handler-bare.strategy.ts
|
|
118
126
|
├── event-handler-noop.strategy.ts
|
|
119
127
|
├── event-handler-with-logger.strategy.ts
|
|
120
128
|
├── event-handler.strategy.ts
|
|
121
|
-
├── event-logger.service.ts
|
|
122
129
|
├── event-loop-lag.service.ts
|
|
123
130
|
├── event-loop-utilization.service.ts
|
|
124
|
-
├── event-publisher.types.ts
|
|
125
131
|
├── event-store-like.types.ts
|
|
126
132
|
├── event-store.ts
|
|
127
133
|
├── event-stream.vo.ts
|
|
@@ -241,6 +247,7 @@ src/
|
|
|
241
247
|
├── markdown-generator.adapter.ts
|
|
242
248
|
├── markdown-generator.port.ts
|
|
243
249
|
├── memory-consumption.service.ts
|
|
250
|
+
├── message.types.ts
|
|
244
251
|
├── middleware-hono-noop.adapter.ts
|
|
245
252
|
├── middleware-hono.port.ts
|
|
246
253
|
├── modules
|
|
@@ -444,7 +451,6 @@ src/
|
|
|
444
451
|
├── timeout-runner.port.ts
|
|
445
452
|
├── timing-hono.middleware.ts
|
|
446
453
|
├── timing.middleware.ts
|
|
447
|
-
├── to-event-map.types.ts
|
|
448
454
|
├── trailing-slash-hono.middleware.ts
|
|
449
455
|
├── trailing-slash.middleware.ts
|
|
450
456
|
├── translations-hono.handler.ts
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CommandBusPort } from "./command-bus.port";
|
|
2
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
3
|
+
|
|
4
|
+
export class CommandBusCollectingAdapter<Command extends Message> implements CommandBusPort<Command> {
|
|
5
|
+
public commands: Array<Command> = [];
|
|
6
|
+
|
|
7
|
+
async emit<CommandName extends keyof ToMessageMap<Command>>(
|
|
8
|
+
_name: CommandName,
|
|
9
|
+
command: ToMessageMap<Command>[CommandName],
|
|
10
|
+
): Promise<void> {
|
|
11
|
+
this.commands.push(command as Command);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
on<CommandName extends keyof ToMessageMap<Command>>(
|
|
15
|
+
_name: CommandName,
|
|
16
|
+
_handler: (command: ToMessageMap<Command>[CommandName]) => void | Promise<void>,
|
|
17
|
+
): void {}
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Emittery from "emittery";
|
|
2
|
+
import type { CommandBusPort } from "./command-bus.port";
|
|
3
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
4
|
+
|
|
5
|
+
export class CommandBusEmitteryV1Adapter<Command extends Message> implements CommandBusPort<Command> {
|
|
6
|
+
private readonly emittery: Emittery<ToMessageMap<Command>>;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.emittery = new Emittery<ToMessageMap<Command>>();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async emit<CommandName extends keyof ToMessageMap<Command>>(
|
|
13
|
+
name: CommandName,
|
|
14
|
+
command: ToMessageMap<Command>[CommandName],
|
|
15
|
+
): Promise<void> {
|
|
16
|
+
await this.emittery.emit(name, command);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
on<CommandName extends keyof ToMessageMap<Command>>(
|
|
20
|
+
name: CommandName,
|
|
21
|
+
handler: (command: ToMessageMap<Command>[CommandName]) => void | Promise<void>,
|
|
22
|
+
): void {
|
|
23
|
+
this.emittery.on(name, handler);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CommandBusPort } from "./command-bus.port";
|
|
2
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
3
|
+
|
|
4
|
+
export class CommandBusNoopAdapter<Command extends Message> implements CommandBusPort<Command> {
|
|
5
|
+
async emit<CommandName extends keyof ToMessageMap<Command>>(
|
|
6
|
+
_name: CommandName,
|
|
7
|
+
_command: ToMessageMap<Command>[CommandName],
|
|
8
|
+
): Promise<void> {}
|
|
9
|
+
|
|
10
|
+
on<CommandName extends keyof ToMessageMap<Command>>(
|
|
11
|
+
_name: CommandName,
|
|
12
|
+
_handler: (command: ToMessageMap<Command>[CommandName]) => void | Promise<void>,
|
|
13
|
+
): void {}
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CommandBusPort } from "./command-bus.port";
|
|
2
|
+
import type { LogCoreType, LoggerPort } from "./logger.port";
|
|
3
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
4
|
+
|
|
5
|
+
type Dependencies = { Logger: LoggerPort };
|
|
6
|
+
|
|
7
|
+
export class CommandBusWithLoggerAdapter<Command extends Message> implements CommandBusPort<Command> {
|
|
8
|
+
private readonly base = { component: "infra", operation: "command_emitted" };
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly inner: CommandBusPort<Command>,
|
|
12
|
+
private readonly deps: Dependencies,
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
async emit<CommandName extends keyof ToMessageMap<Command>>(
|
|
16
|
+
name: CommandName,
|
|
17
|
+
command: ToMessageMap<Command>[CommandName],
|
|
18
|
+
): Promise<void> {
|
|
19
|
+
this.deps.Logger.info({
|
|
20
|
+
message: `${name.toString()} emitted`,
|
|
21
|
+
metadata: command as LogCoreType["metadata"],
|
|
22
|
+
...this.base,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return this.inner.emit(name, command);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
on<CommandName extends keyof ToMessageMap<Command>>(
|
|
29
|
+
name: CommandName,
|
|
30
|
+
handler: (command: ToMessageMap<Command>[CommandName]) => void | Promise<void>,
|
|
31
|
+
): void {
|
|
32
|
+
this.inner.on(name, handler);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
2
|
+
|
|
3
|
+
export interface CommandBusPort<Command extends Message> {
|
|
4
|
+
emit<CommandName extends keyof ToMessageMap<Command>>(
|
|
5
|
+
name: CommandName,
|
|
6
|
+
command: ToMessageMap<Command>[CommandName],
|
|
7
|
+
): Promise<void>;
|
|
8
|
+
|
|
9
|
+
on<CommandName extends keyof ToMessageMap<Command>>(
|
|
10
|
+
name: CommandName,
|
|
11
|
+
handler: (command: ToMessageMap<Command>[CommandName]) => void | Promise<void>,
|
|
12
|
+
): void;
|
|
13
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Stryker disable all
|
|
2
2
|
import type * as z from "zod/v4";
|
|
3
3
|
import type { GenericEventSchema, GenericParsedEventSchema } from "./event.types";
|
|
4
|
-
import type {
|
|
4
|
+
import type { EventBusPort } from "./event-bus.port";
|
|
5
5
|
import { EventStore as BaseStore } from "./event-store";
|
|
6
6
|
import type { EventStreamType } from "./event-stream.vo";
|
|
7
|
-
import type {
|
|
7
|
+
import type { ToMessageMap } from "./message.types";
|
|
8
8
|
|
|
9
9
|
export class DispatchingEventStore<AllEvents extends GenericEventSchema> extends BaseStore<AllEvents> {
|
|
10
10
|
static EMPTY_STREAM_REVISION = -1;
|
|
@@ -19,7 +19,7 @@ export class DispatchingEventStore<AllEvents extends GenericEventSchema> extends
|
|
|
19
19
|
events: ReadonlyArray<z.infer<GenericParsedEventSchema>>,
|
|
20
20
|
) => Promise<ReadonlyArray<z.infer<GenericParsedEventSchema>>>;
|
|
21
21
|
},
|
|
22
|
-
private readonly publisher:
|
|
22
|
+
private readonly publisher: EventBusPort<z.infer<AllEvents>>,
|
|
23
23
|
) {
|
|
24
24
|
super(config);
|
|
25
25
|
}
|
|
@@ -31,7 +31,7 @@ export class DispatchingEventStore<AllEvents extends GenericEventSchema> extends
|
|
|
31
31
|
|
|
32
32
|
await Promise.all(
|
|
33
33
|
events.map((event) =>
|
|
34
|
-
this.publisher.emit(event.name as keyof
|
|
34
|
+
this.publisher.emit(event.name as keyof ToMessageMap<z.infer<AllEvents>>, event as any),
|
|
35
35
|
),
|
|
36
36
|
);
|
|
37
37
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { EventBusPort } from "./event-bus.port";
|
|
2
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
3
|
+
|
|
4
|
+
export class EventBusCollectingAdapter<Event extends Message> implements EventBusPort<Event> {
|
|
5
|
+
public events: Array<Event> = [];
|
|
6
|
+
|
|
7
|
+
async emit<EventName extends keyof ToMessageMap<Event>>(
|
|
8
|
+
_name: EventName,
|
|
9
|
+
event: ToMessageMap<Event>[EventName],
|
|
10
|
+
): Promise<void> {
|
|
11
|
+
this.events.push(event as Event);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
on<EventName extends keyof ToMessageMap<Event>>(
|
|
15
|
+
_name: EventName,
|
|
16
|
+
_handler: (event: ToMessageMap<Event>[EventName]) => void | Promise<void>,
|
|
17
|
+
): void {}
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import Emittery from "emittery";
|
|
2
|
+
import type { EventBusPort } from "./event-bus.port";
|
|
3
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
4
|
+
|
|
5
|
+
export class EventBusEmitteryV1Adapter<Event extends Message> implements EventBusPort<Event> {
|
|
6
|
+
private readonly emittery: Emittery<ToMessageMap<Event>>;
|
|
7
|
+
|
|
8
|
+
constructor() {
|
|
9
|
+
this.emittery = new Emittery<ToMessageMap<Event>>();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async emit<EventName extends keyof ToMessageMap<Event>>(
|
|
13
|
+
name: EventName,
|
|
14
|
+
event: ToMessageMap<Event>[EventName],
|
|
15
|
+
): Promise<void> {
|
|
16
|
+
await this.emittery.emit(name, event);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
on<EventName extends keyof ToMessageMap<Event>>(
|
|
20
|
+
name: EventName,
|
|
21
|
+
handler: (event: ToMessageMap<Event>[EventName]) => void | Promise<void>,
|
|
22
|
+
): void {
|
|
23
|
+
this.emittery.on(name, handler);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EventBusPort } from "./event-bus.port";
|
|
2
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
3
|
+
|
|
4
|
+
export class EventBusNoopAdapter<Event extends Message> implements EventBusPort<Event> {
|
|
5
|
+
async emit<EventName extends keyof ToMessageMap<Event>>(
|
|
6
|
+
_name: EventName,
|
|
7
|
+
_event: ToMessageMap<Event>[EventName],
|
|
8
|
+
): Promise<void> {}
|
|
9
|
+
|
|
10
|
+
on<EventName extends keyof ToMessageMap<Event>>(
|
|
11
|
+
_name: EventName,
|
|
12
|
+
_handler: (event: ToMessageMap<Event>[EventName]) => void | Promise<void>,
|
|
13
|
+
): void {}
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { EventBusPort } from "./event-bus.port";
|
|
2
|
+
import type { LogCoreType, LoggerPort } from "./logger.port";
|
|
3
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
4
|
+
|
|
5
|
+
type Dependencies = { Logger: LoggerPort };
|
|
6
|
+
|
|
7
|
+
export class EventBusWithLoggerAdapter<Event extends Message> implements EventBusPort<Event> {
|
|
8
|
+
private readonly base = { component: "infra", operation: "event_emitted" };
|
|
9
|
+
|
|
10
|
+
constructor(
|
|
11
|
+
private readonly inner: EventBusPort<Event>,
|
|
12
|
+
private readonly deps: Dependencies,
|
|
13
|
+
) {}
|
|
14
|
+
|
|
15
|
+
async emit<EventName extends keyof ToMessageMap<Event>>(
|
|
16
|
+
name: EventName,
|
|
17
|
+
event: ToMessageMap<Event>[EventName],
|
|
18
|
+
): Promise<void> {
|
|
19
|
+
this.deps.Logger.info({
|
|
20
|
+
message: `${name.toString()} emitted`,
|
|
21
|
+
metadata: event as LogCoreType["metadata"],
|
|
22
|
+
...this.base,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
return this.inner.emit(name, event);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
on<EventName extends keyof ToMessageMap<Event>>(
|
|
29
|
+
name: EventName,
|
|
30
|
+
handler: (event: ToMessageMap<Event>[EventName]) => void | Promise<void>,
|
|
31
|
+
): void {
|
|
32
|
+
this.inner.on(name, handler);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Message, ToMessageMap } from "./message.types";
|
|
2
|
+
|
|
3
|
+
export interface EventBusPort<Event extends Message> {
|
|
4
|
+
emit<EventName extends keyof ToMessageMap<Event>>(
|
|
5
|
+
name: EventName,
|
|
6
|
+
event: ToMessageMap<Event>[EventName],
|
|
7
|
+
): Promise<void>;
|
|
8
|
+
|
|
9
|
+
on<EventName extends keyof ToMessageMap<Event>>(
|
|
10
|
+
name: EventName,
|
|
11
|
+
handler: (event: ToMessageMap<Event>[EventName]) => void | Promise<void>,
|
|
12
|
+
): void;
|
|
13
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type * as z from "zod/v4";
|
|
2
|
-
import type { GenericEventSchema } from "./event.types";
|
|
3
1
|
import type { EventHandlerStrategy } from "./event-handler.strategy";
|
|
2
|
+
import type { Message } from "./message.types";
|
|
4
3
|
|
|
5
4
|
export class EventHandlerBareStrategy implements EventHandlerStrategy {
|
|
6
|
-
handle<
|
|
7
|
-
return async (event:
|
|
5
|
+
handle<Event extends Message>(fn: (event: Event) => Promise<void>) {
|
|
6
|
+
return async (event: Event) => fn(event);
|
|
8
7
|
}
|
|
9
8
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import type * as z from "zod/v4";
|
|
2
|
-
import type { GenericEventSchema } from "./event.types";
|
|
3
1
|
import type { EventHandlerStrategy } from "./event-handler.strategy";
|
|
2
|
+
import type { Message } from "./message.types";
|
|
4
3
|
|
|
5
4
|
export class EventHandlerNoopStrategy implements EventHandlerStrategy {
|
|
6
|
-
handle<
|
|
7
|
-
return async (_event:
|
|
5
|
+
handle<Event extends Message>(_handler: (event: Event) => Promise<void>) {
|
|
6
|
+
return async (_event: Event) => {};
|
|
8
7
|
}
|
|
9
8
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type * as z from "zod/v4";
|
|
2
1
|
import type { ClockPort } from "./clock.port";
|
|
3
|
-
import type { GenericEventSchema } from "./event.types";
|
|
4
2
|
import type { EventHandlerStrategy } from "./event-handler.strategy";
|
|
5
3
|
import type { LoggerPort } from "./logger.port";
|
|
4
|
+
import type { Message } from "./message.types";
|
|
6
5
|
import { Stopwatch } from "./stopwatch.service";
|
|
7
6
|
|
|
8
7
|
type Dependencies = { Logger: LoggerPort; Clock: ClockPort };
|
|
@@ -10,12 +9,12 @@ type Dependencies = { Logger: LoggerPort; Clock: ClockPort };
|
|
|
10
9
|
export class EventHandlerWithLoggerStrategy implements EventHandlerStrategy {
|
|
11
10
|
constructor(private readonly deps: Dependencies) {}
|
|
12
11
|
|
|
13
|
-
handle<
|
|
14
|
-
return async (event:
|
|
12
|
+
handle<Event extends Message>(handler: (event: Event) => Promise<void>) {
|
|
13
|
+
return async (event: Event) => {
|
|
15
14
|
const duration = new Stopwatch(this.deps);
|
|
16
15
|
|
|
17
16
|
try {
|
|
18
|
-
await
|
|
17
|
+
await handler(event);
|
|
19
18
|
} catch (error) {
|
|
20
19
|
this.deps.Logger.error({
|
|
21
20
|
message: `Unknown ${event.name} event handler error`,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { GenericEventSchema } from "./event.types";
|
|
1
|
+
import type { Message } from "./message.types";
|
|
3
2
|
|
|
4
3
|
export interface EventHandlerStrategy {
|
|
5
|
-
handle<
|
|
6
|
-
fn: (event: T) => Promise<void>,
|
|
7
|
-
): (event: T) => Promise<void>;
|
|
4
|
+
handle<Event extends Message>(fn: (event: Event) => Promise<void>): (event: Event) => Promise<void>;
|
|
8
5
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { Message } from "./message.types";
|
|
2
|
+
|
|
3
|
+
export type EventStoreLike<Event extends Message> = {
|
|
4
|
+
save(events: ReadonlyArray<Event>): Promise<unknown>;
|
|
3
5
|
};
|
package/src/index.ts
CHANGED
|
@@ -48,8 +48,12 @@ export * from "./clock-fixed.adapter";
|
|
|
48
48
|
export * from "./clock-offset.adapter";
|
|
49
49
|
export * from "./clock-system.adapter";
|
|
50
50
|
export * from "./command.types";
|
|
51
|
+
export * from "./command-bus.port";
|
|
52
|
+
export * from "./command-bus-collecting.adapter";
|
|
53
|
+
export * from "./command-bus-emittery-v1.adapter";
|
|
54
|
+
export * from "./command-bus-noop.adapter";
|
|
55
|
+
export * from "./command-bus-with-logger.adapter";
|
|
51
56
|
export * from "./command-envelope";
|
|
52
|
-
export * from "./command-logger.service";
|
|
53
57
|
export * from "./commit-sha.vo";
|
|
54
58
|
export * from "./commit-sha-value.vo";
|
|
55
59
|
export * from "./correlation-hono.middleware";
|
|
@@ -83,13 +87,16 @@ export * from "./environment-loader-process-safe.adapter";
|
|
|
83
87
|
export * from "./error-normalizer.service";
|
|
84
88
|
export * from "./etag-extractor.middleware";
|
|
85
89
|
export * from "./event.types";
|
|
86
|
-
export * from "./event-bus
|
|
90
|
+
export * from "./event-bus.port";
|
|
91
|
+
export * from "./event-bus-collecting.adapter";
|
|
92
|
+
export * from "./event-bus-emittery-v1.adapter";
|
|
93
|
+
export * from "./event-bus-noop.adapter";
|
|
94
|
+
export * from "./event-bus-with-logger.adapter";
|
|
87
95
|
export * from "./event-envelope";
|
|
88
96
|
export * from "./event-handler.strategy";
|
|
89
97
|
export * from "./event-handler-bare.strategy";
|
|
90
98
|
export * from "./event-handler-noop.strategy";
|
|
91
99
|
export * from "./event-handler-with-logger.strategy";
|
|
92
|
-
export * from "./event-logger.service";
|
|
93
100
|
export * from "./event-loop-lag.service";
|
|
94
101
|
export * from "./event-loop-utilization.service";
|
|
95
102
|
export * from "./event-store";
|
|
@@ -209,6 +216,7 @@ export * from "./markdown-generator.adapter";
|
|
|
209
216
|
export * from "./markdown-generator.port";
|
|
210
217
|
export * from "./markdown-generator-noop.adapter";
|
|
211
218
|
export * from "./memory-consumption.service";
|
|
219
|
+
export * from "./message.types";
|
|
212
220
|
export * from "./middleware-hono.port";
|
|
213
221
|
export * from "./middleware-hono-noop.adapter";
|
|
214
222
|
export * as History from "./modules/history";
|
|
@@ -367,7 +375,6 @@ export * from "./timeout-runner-monitor.adapter";
|
|
|
367
375
|
export * from "./timeout-runner-noop.adapter";
|
|
368
376
|
export * from "./timing.middleware";
|
|
369
377
|
export * from "./timing-hono.middleware";
|
|
370
|
-
export * from "./to-event-map.types";
|
|
371
378
|
export * from "./trailing-slash.middleware";
|
|
372
379
|
export * from "./trailing-slash.middleware";
|
|
373
380
|
export * from "./trailing-slash-hono.middleware";
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LoggerPort } from "./logger.port";
|
|
2
|
-
type Dependencies = {
|
|
3
|
-
Logger: LoggerPort;
|
|
4
|
-
};
|
|
5
|
-
export declare class CommandLogger {
|
|
6
|
-
private readonly deps;
|
|
7
|
-
private readonly base;
|
|
8
|
-
constructor(deps: Dependencies);
|
|
9
|
-
private _handle;
|
|
10
|
-
handle: (type: string, _debugName: string, commandName: string | undefined, commandData: Record<string, any> | undefined) => void;
|
|
11
|
-
}
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=command-logger.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-logger.service.d.ts","sourceRoot":"","sources":["../src/command-logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,KAAK,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAE3C,qBAAa,aAAa;IAGZ,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAwD;gBAEhD,IAAI,EAAE,YAAY;IAE/C,OAAO,CAAC,OAAO;IAYf,MAAM,SAXE,MAAM,cACA,MAAM,eACL,MAAM,GAAG,SAAS,eAClB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,UAQb;CAClC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export class CommandLogger {
|
|
2
|
-
deps;
|
|
3
|
-
base = { component: "infra", operation: "command_emitted" };
|
|
4
|
-
constructor(deps) {
|
|
5
|
-
this.deps = deps;
|
|
6
|
-
}
|
|
7
|
-
_handle(type, _debugName, commandName, commandData) {
|
|
8
|
-
if (type === "subscribe")
|
|
9
|
-
return;
|
|
10
|
-
if (typeof commandName === "symbol")
|
|
11
|
-
return;
|
|
12
|
-
this.deps.Logger.info({ message: `${commandName} emitted`, metadata: commandData, ...this.base });
|
|
13
|
-
}
|
|
14
|
-
handle = this._handle.bind(this);
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=command-logger.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-logger.service.js","sourceRoot":"","sources":["../src/command-logger.service.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,aAAa;IAGK;IAFZ,IAAI,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,CAAC;IAE7E,YAA6B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;IAAG,CAAC;IAE3C,OAAO,CACb,IAAY,EACZ,UAAkB,EAClB,WAA+B,EAC/B,WAA4C;QAE5C,IAAI,IAAI,KAAK,WAAW;YAAE,OAAO;QACjC,IAAI,OAAO,WAAW,KAAK,QAAQ;YAAE,OAAO;QAE5C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,WAAW,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACpG,CAAC;IAED,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CAClC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { ToEventMap } from "./to-event-map.types";
|
|
2
|
-
export type EventBusLike<E extends {
|
|
3
|
-
name: string;
|
|
4
|
-
}> = {
|
|
5
|
-
on<K extends keyof ToEventMap<E> & string>(name: K, handler: (event: ToEventMap<E>[K]) => void | Promise<void>): void;
|
|
6
|
-
};
|
|
7
|
-
export type CommandBusLike<C extends {
|
|
8
|
-
name: string;
|
|
9
|
-
}> = {
|
|
10
|
-
emit(name: C["name"], command: C): Promise<void>;
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=event-bus-like.types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus-like.types.d.ts","sourceRoot":"","sources":["../src/event-bus-like.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,IAAI;IACrD,EAAE,CAAC,CAAC,SAAS,MAAM,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,EACvC,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,GACzD,IAAI,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,IAAI;IAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus-like.types.js","sourceRoot":"","sources":["../src/event-bus-like.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LoggerPort } from "./logger.port";
|
|
2
|
-
type Dependencies = {
|
|
3
|
-
Logger: LoggerPort;
|
|
4
|
-
};
|
|
5
|
-
export declare class EventLogger {
|
|
6
|
-
private readonly deps;
|
|
7
|
-
private readonly base;
|
|
8
|
-
constructor(deps: Dependencies);
|
|
9
|
-
private _handle;
|
|
10
|
-
handle: (type: string, _debugName: string, eventName: string | undefined, eventData: Record<string, any> | undefined) => void;
|
|
11
|
-
}
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=event-logger.service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-logger.service.d.ts","sourceRoot":"","sources":["../src/event-logger.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,KAAK,YAAY,GAAG;IAAE,MAAM,EAAE,UAAU,CAAA;CAAE,CAAC;AAE3C,qBAAa,WAAW;IAGV,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAsD;gBAE9C,IAAI,EAAE,YAAY;IAE/C,OAAO,CAAC,OAAO;IAYf,MAAM,SAXE,MAAM,cACA,MAAM,aACP,MAAM,GAAG,SAAS,aAClB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,UAQX;CAClC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export class EventLogger {
|
|
2
|
-
deps;
|
|
3
|
-
base = { component: "infra", operation: "event_emitted" };
|
|
4
|
-
constructor(deps) {
|
|
5
|
-
this.deps = deps;
|
|
6
|
-
}
|
|
7
|
-
_handle(type, _debugName, eventName, eventData) {
|
|
8
|
-
if (type === "subscribe")
|
|
9
|
-
return;
|
|
10
|
-
if (typeof eventName === "symbol")
|
|
11
|
-
return;
|
|
12
|
-
this.deps.Logger.info({ message: `${eventName} emitted`, metadata: eventData, ...this.base });
|
|
13
|
-
}
|
|
14
|
-
handle = this._handle.bind(this);
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=event-logger.service.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-logger.service.js","sourceRoot":"","sources":["../src/event-logger.service.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,WAAW;IAGO;IAFZ,IAAI,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,CAAC;IAE3E,YAA6B,IAAkB;QAAlB,SAAI,GAAJ,IAAI,CAAc;IAAG,CAAC;IAE3C,OAAO,CACb,IAAY,EACZ,UAAkB,EAClB,SAA6B,EAC7B,SAA0C;QAE1C,IAAI,IAAI,KAAK,WAAW;YAAE,OAAO;QACjC,IAAI,OAAO,SAAS,KAAK,QAAQ;YAAE,OAAO;QAE1C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;CAClC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-publisher.types.d.ts","sourceRoot":"","sources":["../src/event-publisher.types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc,CAAC,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAClE,IAAI,CAAC,IAAI,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"event-publisher.types.js","sourceRoot":"","sources":["../src/event-publisher.types.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-event-map.types.d.ts","sourceRoot":"","sources":["../src/to-event-map.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,IAAI;KAClD,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE;CAC5B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"to-event-map.types.js","sourceRoot":"","sources":["../src/to-event-map.types.ts"],"names":[],"mappings":""}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { LoggerPort } from "./logger.port";
|
|
2
|
-
|
|
3
|
-
type Dependencies = { Logger: LoggerPort };
|
|
4
|
-
|
|
5
|
-
export class CommandLogger {
|
|
6
|
-
private readonly base = { component: "infra", operation: "command_emitted" };
|
|
7
|
-
|
|
8
|
-
constructor(private readonly deps: Dependencies) {}
|
|
9
|
-
|
|
10
|
-
private _handle(
|
|
11
|
-
type: string,
|
|
12
|
-
_debugName: string,
|
|
13
|
-
commandName: string | undefined,
|
|
14
|
-
commandData: Record<string, any> | undefined,
|
|
15
|
-
) {
|
|
16
|
-
if (type === "subscribe") return;
|
|
17
|
-
if (typeof commandName === "symbol") return;
|
|
18
|
-
|
|
19
|
-
this.deps.Logger.info({ message: `${commandName} emitted`, metadata: commandData, ...this.base });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
handle = this._handle.bind(this);
|
|
23
|
-
}
|