@ticketto/protocol
Version:
Library that defines the interfaces of the ticketto protocol to be implemented on a client
36 lines (35 loc) • 1.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TickettoClientBuilder = void 0;
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);
}
}
exports.TickettoClientBuilder = TickettoClientBuilder;