@vtex/api
Version:
VTEX I/O API client
58 lines (57 loc) • 2.08 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getService = exports.getServiceJSON = exports.serviceJsonPath = exports.bundlePath = exports.appPath = void 0;
const os_1 = require("os");
const path_1 = require("path");
const IOClients_1 = require("../clients/IOClients");
const constants_1 = require("../constants");
exports.appPath = (0, path_1.join)(process.cwd(), './service/src/node/');
exports.bundlePath = (0, path_1.join)(exports.appPath, 'index');
exports.serviceJsonPath = (0, path_1.join)(process.cwd(), './service/service.json');
const getWorkers = (workers) => {
// We need to have only one worker while linking so the debugger
// works properly
if (constants_1.LINKED) {
return 1;
}
// If user didn't set workers property, let's use the cpu count
const workersFromUser = workers && Number.isInteger(workers) ? workers : (0, os_1.cpus)().length;
// never spawns more than MAX_WORKERS
return Math.min(workersFromUser, constants_1.MAX_WORKERS);
};
const getServiceJSON = () => {
const service = require(exports.serviceJsonPath);
return {
...service,
workers: getWorkers(service.workers),
};
};
exports.getServiceJSON = getServiceJSON;
const defaultClients = {
options: {
messages: {
concurrency: 10,
retries: 2,
timeout: 1000,
},
messagesGraphQL: {
concurrency: 12,
retries: 2,
timeout: 2000,
},
},
};
const getService = () => {
var _a;
const { default: service } = require(exports.bundlePath);
const { config: { clients } } = service;
service.config.clients = {
implementation: (_a = clients === null || clients === void 0 ? void 0 : clients.implementation) !== null && _a !== void 0 ? _a : IOClients_1.IOClients,
options: {
...defaultClients.options,
...clients === null || clients === void 0 ? void 0 : clients.options,
},
};
return service;
};
exports.getService = getService;
;