unmock-core
Version:
[][npmjs] [](https://circleci.com/gh/unmock/unmock-js) [](h
29 lines • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const url = require("url");
const service_1 = require("./service");
const serviceCore_1 = require("./serviceCore");
class ServiceStore {
constructor(coreServices) {
this.cores = coreServices.reduce((o, core) => (Object.assign(Object.assign({}, o), { [core.name]: core })), {});
this.services = coreServices.reduce((o, core) => (Object.assign(Object.assign({}, o), { [core.name]: new service_1.Service(core) })), {});
}
updateOrAdd(input) {
const serviceName = input.name || url.parse(input.baseUrl).hostname || input.baseUrl;
const baseSchema = serviceName !== undefined && this.cores[serviceName] !== undefined
?
this.cores[serviceName].schema
:
{
openapi: "3.0.0",
info: { title: "Internally built by unmock", version: "0.0.0" },
paths: {},
};
const newServiceCore = serviceCore_1.ServiceCore.from(baseSchema, Object.assign(Object.assign({}, input), { name: serviceName }));
this.cores[serviceName] = newServiceCore;
this.services[serviceName] = new service_1.Service(newServiceCore);
return this;
}
}
exports.ServiceStore = ServiceStore;
//# sourceMappingURL=serviceStore.js.map