38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import {BaseSerializer, ObjectSerializer} from '../../../support/bus'
|
|
import {QueryExecutedEvent} from './QueryExecutedEvent'
|
|
import {Awaitable, JSONState} from '../../../util'
|
|
import {Container, Inject, Injectable} from '../../../di'
|
|
import {DatabaseService} from '../../DatabaseService'
|
|
|
|
export interface QueryExecutedEventSerialPayload extends JSONState {
|
|
connectionName: string
|
|
query: string
|
|
}
|
|
|
|
@ObjectSerializer()
|
|
@Injectable()
|
|
export class QueryExecutedEventSerializer extends BaseSerializer<QueryExecutedEvent, QueryExecutedEventSerialPayload> {
|
|
@Inject()
|
|
protected readonly injector!: Container
|
|
|
|
protected decodeSerial(serial: QueryExecutedEventSerialPayload): Awaitable<QueryExecutedEvent> {
|
|
const connection = this.injector.make<DatabaseService>(DatabaseService).get(serial.connectionName)
|
|
return new QueryExecutedEvent(serial.connectionName, connection, serial.query)
|
|
}
|
|
|
|
protected encodeActual(actual: QueryExecutedEvent): Awaitable<QueryExecutedEventSerialPayload> {
|
|
return {
|
|
connectionName: actual.connectionName,
|
|
query: actual.query,
|
|
}
|
|
}
|
|
|
|
protected getName(): string {
|
|
return '@extollo/lib.QueryExecutedEventSerializer'
|
|
}
|
|
|
|
matchActual(some: QueryExecutedEvent): boolean {
|
|
return some instanceof QueryExecutedEvent
|
|
}
|
|
}
|