You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/support/bus/serial/JSONMessageEvent.ts

36 lines
1.0 KiB

import {BaseSerializer} from './BaseSerializer'
import {Awaitable, JSONState, uuid4} from '../../../util'
import {ObjectSerializer} from './decorators'
import {Event} from '../types'
export class JSONMessageEvent<T extends JSONState> implements Event {
constructor(
public readonly value: T,
) {}
eventName = '@extollo/lib:JSONMessageEvent'
eventUuid = uuid4()
}
@ObjectSerializer()
export class JSONMessageEventSerializer extends BaseSerializer<JSONMessageEvent<JSONState>, { value: JSONState }> {
protected decodeSerial(serial: { value: JSONState }): Awaitable<JSONMessageEvent<JSONState>> {
return new JSONMessageEvent(serial.value)
}
protected encodeActual(actual: JSONMessageEvent<JSONState>): Awaitable<{ value: JSONState }> {
return {
value: actual.value,
}
}
protected getName(): string {
return '@extollo/lib:JSONMessageEventSerializer'
}
matchActual(some: JSONMessageEvent<JSONState>): boolean {
return some instanceof JSONMessageEvent
}
}