@bgord/bun 1.14.2 → 1.14.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgord/bun",
3
- "version": "1.14.2",
3
+ "version": "1.14.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": "Bartosz Gordon",
package/readme.md CHANGED
@@ -126,6 +126,7 @@ src/
126
126
  ├── event-store-collecting.adapter.ts
127
127
  ├── event-store-dispatching.adapter.ts
128
128
  ├── event-store-noop.adapter.ts
129
+ ├── event-store-with-logger.adapter.ts
129
130
  ├── event-store.adapter.ts
130
131
  ├── event-store.port.ts
131
132
  ├── event-stream.vo.ts
@@ -2,7 +2,7 @@ import * as tools from "@bgord/tools";
2
2
  import * as z from "zod/v4";
3
3
  import type { ClockPort } from "./clock.port";
4
4
  import { CorrelationStorage } from "./correlation-storage.service";
5
- import type { EventStreamType } from "./event-stream.vo";
5
+ import { EventStream, type EventStreamType } from "./event-stream.vo";
6
6
  import type { IdProviderPort } from "./id-provider.port";
7
7
  import { UUID } from "./uuid.vo";
8
8
 
@@ -12,7 +12,7 @@ export const EventEnvelopeSchema = {
12
12
  id: UUID,
13
13
  correlationId: UUID,
14
14
  createdAt: tools.TimestampValue,
15
- stream: z.string().min(1),
15
+ stream: EventStream,
16
16
  version: z.literal(1),
17
17
  revision: tools.RevisionValue.optional(),
18
18
  };
@@ -6,8 +6,8 @@ export class EventRevisionAssignerAdapter implements EventRevisionAssignerPort {
6
6
 
7
7
  assign(
8
8
  events: ReadonlyArray<GenericEventSerialized>,
9
- currentMax: number,
9
+ max: number = EventRevisionAssignerAdapter.EMPTY_STREAM_REVISION,
10
10
  ): ReadonlyArray<GenericEventSerialized> {
11
- return events.map((event, index) => ({ ...event, revision: currentMax + index + 1 }));
11
+ return events.map((event, index) => ({ ...event, revision: max + index + 1 }));
12
12
  }
13
13
  }
@@ -1,8 +1,5 @@
1
1
  import type { GenericEventSerialized } from "./event.types";
2
2
 
3
3
  export interface EventRevisionAssignerPort {
4
- assign(
5
- events: ReadonlyArray<GenericEventSerialized>,
6
- currentMax: number,
7
- ): ReadonlyArray<GenericEventSerialized>;
4
+ assign(events: ReadonlyArray<GenericEventSerialized>, max?: number): ReadonlyArray<GenericEventSerialized>;
8
5
  }
@@ -0,0 +1,48 @@
1
+ import { CorrelationStorage } from "./correlation-storage.service";
2
+ import type { GenericEvent } from "./event.types";
3
+ import type { EventStorePort } from "./event-store.port";
4
+ import type { EventStreamType } from "./event-stream.vo";
5
+ import type { EventValidatorRegistryPort } from "./event-validator-registry.port";
6
+ import type { LoggerPort } from "./logger.port";
7
+
8
+ type Dependencies<TEvent extends GenericEvent> = {
9
+ inner: EventStorePort<TEvent>;
10
+ Logger: LoggerPort;
11
+ };
12
+
13
+ export class EventStoreWithLoggerAdapter<Event extends GenericEvent> implements EventStorePort<Event> {
14
+ constructor(private readonly deps: Dependencies<Event>) {}
15
+
16
+ async find<FoundEvent extends Event>(
17
+ registry: EventValidatorRegistryPort<FoundEvent>,
18
+ stream: EventStreamType,
19
+ ): Promise<ReadonlyArray<FoundEvent>> {
20
+ const result = await this.deps.inner.find(registry, stream);
21
+
22
+ this.deps.Logger.info({
23
+ message: "Event store find",
24
+ component: "infra",
25
+ operation: "event_store_find",
26
+ correlationId: CorrelationStorage.get(),
27
+ metadata: { stream, names: registry.names, count: result.length },
28
+ });
29
+
30
+ return result;
31
+ }
32
+
33
+ async save<SavedEvent extends Event>(
34
+ events: ReadonlyArray<SavedEvent>,
35
+ ): Promise<ReadonlyArray<SavedEvent>> {
36
+ const result = await this.deps.inner.save(events);
37
+
38
+ this.deps.Logger.info({
39
+ message: "Event store save",
40
+ component: "infra",
41
+ operation: "event_store_save",
42
+ correlationId: CorrelationStorage.get(),
43
+ metadata: { stream: events[0]?.stream, names: events.map((event) => event.name), count: events.length },
44
+ });
45
+
46
+ return result;
47
+ }
48
+ }
@@ -1,10 +1,13 @@
1
- // TODO: use proper VO types.
1
+ import type * as tools from "@bgord/tools";
2
+ import type { EventStreamType } from "./event-stream.vo";
3
+ import type { UUIDType } from "./uuid.vo";
4
+
2
5
  export type GenericEvent = {
3
- id: string;
4
- correlationId: string;
5
- createdAt: number;
6
- stream: string;
7
- revision?: number;
6
+ id: UUIDType;
7
+ correlationId: UUIDType;
8
+ createdAt: tools.TimestampValueType;
9
+ stream: EventStreamType;
10
+ revision?: tools.RevisionValueType;
8
11
  name: string;
9
12
  version: number;
10
13
  payload: unknown;
package/src/index.ts CHANGED
@@ -101,6 +101,7 @@ export * from "./event-store-collecting.adapter";
101
101
  export * from "./event-store-collecting.adapter";
102
102
  export * from "./event-store-dispatching.adapter";
103
103
  export * from "./event-store-noop.adapter";
104
+ export * from "./event-store-with-logger.adapter";
104
105
  export * from "./event-stream.vo";
105
106
  export * from "./event-validator-registry.port";
106
107
  export * from "./event-validator-registry-zod.adapter";