first commit

This commit is contained in:
2026-10-03 13:40:26 +02:00
parent 732a5b5a16
commit 566f415fa7
555 changed files with 62704 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
import { Injectable, Type } from '@nestjs/common';
import {
EventClsRegistry,
SerializableEvent,
} from '@task-stream/api/shared/domain';
@Injectable()
export class EventDeserializer {
deserialize<T>(event: SerializableEvent): SerializableEvent<T> {
const eventCls = EventClsRegistry.get(event.type);
return {
streamId: event.streamId,
type: event.type,
position: event.position,
data: this.instantiateSerializedEvent(eventCls, event.data),
};
}
/** Rebuilds the event with its class prototype, without running the constructor. */
instantiateSerializedEvent<T extends Type>(
eventCls: T,
data: Record<string, unknown>,
) {
return Object.assign(Object.create(eventCls.prototype), data);
}
}