UNPKG

@ticketto/protocol

Version:

Library that defines the interfaces of the ticketto protocol to be implemented on a client

32 lines (31 loc) 866 B
export class TickettoClientBuilder { consumerLike; config; constructor() { } withConsumer(consumer) { this.consumerLike = consumer; return this; } withConfig(config) { this.config = config; return this; } isConstructorOf(consumerLike) { return (typeof consumerLike === "function" && consumerLike?.constructor !== undefined); } build() { if (this.consumerLike === undefined) { throw new Error("InvalidArgument: Missing `backend`"); } let consumer; if (this.isConstructorOf(this.consumerLike)) { let ConsumerConstructor = this.consumerLike; consumer = new ConsumerConstructor(); } else { consumer = this.consumerLike; } return consumer.build(this.config); } }