import { TopicRoot, TopicServiceName, TopicType } from '../types' const { RPC, RPC_RESPONSE, MESSAGE, MESSAGE_RESPONSE, } = TopicType export class TopicBuilder { public get root (): string { return TopicRoot } } // tslint:disable-next-line:max-classes-per-file export class RPCRequestTopic extends TopicBuilder { private readonly _serviceName: TopicServiceName private readonly _deviceId?: string constructor (serviceName: TopicServiceName, deviceId?: string) { super() this._serviceName = serviceName this._deviceId = deviceId } public get topic (): string { if (!this._deviceId) { return `${this.root}/${RPC}/${this._serviceName}` } return `${this.root}/${RPC}/${this._serviceName}/${this._deviceId}` } } // tslint:disable-next-line:max-classes-per-file export class RPCResponseTopic extends TopicBuilder { private readonly _clientId: string constructor (clientId: string) { super() this._clientId = clientId } public get topic (): string { return `${this.root}/${RPC_RESPONSE}/${this._clientId}` } } // tslint:disable-next-line:max-classes-per-file export class RPCInternalResponseTopic { private readonly _type: string private readonly _requestId: string constructor (type: string, requestId: string) { this._type = type this._requestId = requestId } public get type (): string { return this._type } public get topic (): string { return `${this.type}/${this._requestId}` } } // tslint:disable-next-line:max-classes-per-file export class MessageRequestTopic extends TopicBuilder { private readonly _clientId: string constructor (clientId: string) { super() this._clientId = clientId } public get topic (): string { return `${this.root}/${MESSAGE}/${this._clientId}/#` } } // tslint:disable-next-line:max-classes-per-file export class MessageResponseTopic extends TopicBuilder { constructor () { super() } public get topic (): string { return `${this.root}/${MESSAGE_RESPONSE}` } }