Standard libraries that lift up your code.
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.
 
 
 

43 lines
1.7 KiB

import {PushedToQueue} from './PushedToQueue'
import {Queueable, SerialPayload, ShouldQueue} from '../../types'
import {PushingToQueue} from './PushingToQueue'
import {BaseSerializer} from '../../serial/BaseSerializer'
import {JSONState} from '../../../../util'
import {ObjectSerializer} from '../../serial/decorators'
export type QueueEvent = PushedToQueue<ShouldQueue<Queueable>> | PushingToQueue<ShouldQueue<Queueable>>
export interface QueueEventSerialPayload extends JSONState {
eventName: '@extollo/lib.PushedToQueue' | '@extollo/lib.PushingToQueue'
itemPayload: SerialPayload<Queueable, JSONState>
queueName: string
}
@ObjectSerializer()
export class QueueEventSerializer extends BaseSerializer<QueueEvent, QueueEventSerialPayload> {
protected async decodeSerial(serial: QueueEventSerialPayload): Promise<QueueEvent> {
const item = await this.getSerialization().decode(serial.itemPayload)
if ( serial.eventName === '@extollo/lib.PushedToQueue' ) {
return new PushedToQueue(item as ShouldQueue<Queueable>, serial.queueName)
} else {
return new PushingToQueue(item as ShouldQueue<Queueable>, serial.queueName)
}
}
protected async encodeActual(actual: QueueEvent): Promise<QueueEventSerialPayload> {
return {
eventName: actual.eventName,
queueName: actual.queueName,
itemPayload: await this.getSerialization().encode(actual.item),
}
}
protected getName(): string {
return '@extollo/lib.QueueEventSerializer'
}
matchActual(some: QueueEvent): boolean {
return some instanceof PushedToQueue || some instanceof PushingToQueue
}
}