sardines-core
Version:
Core of sardines.js
147 lines (146 loc) • 7.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sardines = void 0;
var Sardines;
(function (Sardines) {
var Platform;
(function (Platform) {
Platform["nodejs"] = "nodejs";
Platform["browser"] = "browser";
Platform["reactNative"] = "reactNative";
})(Platform = Sardines.Platform || (Sardines.Platform = {}));
var LocationType;
(function (LocationType) {
LocationType["npm_link"] = "npm_link";
LocationType["npm"] = "npm";
LocationType["file"] = "file";
LocationType["git"] = "git";
})(LocationType = Sardines.LocationType || (Sardines.LocationType = {}));
var Runtime;
(function (Runtime) {
var ServiceEntryType;
(function (ServiceEntryType) {
ServiceEntryType["dedicated"] = "dedicated";
ServiceEntryType["proxy"] = "proxy";
})(ServiceEntryType = Runtime.ServiceEntryType || (Runtime.ServiceEntryType = {}));
var LoadBalancingStrategy;
(function (LoadBalancingStrategy) {
LoadBalancingStrategy["workloadFocusing"] = "workloadFocusing";
LoadBalancingStrategy["evenWorkload"] = "evenWorkload";
LoadBalancingStrategy["random"] = "random";
})(LoadBalancingStrategy = Runtime.LoadBalancingStrategy || (Runtime.LoadBalancingStrategy = {}));
var RuntimeStatus;
(function (RuntimeStatus) {
RuntimeStatus["ready"] = "ready";
RuntimeStatus["pending"] = "pending";
RuntimeStatus["deploying"] = "deploying";
})(RuntimeStatus = Runtime.RuntimeStatus || (Runtime.RuntimeStatus = {}));
var RuntimeTargetType;
(function (RuntimeTargetType) {
RuntimeTargetType["service"] = "service";
RuntimeTargetType["host"] = "host";
})(RuntimeTargetType = Runtime.RuntimeTargetType || (Runtime.RuntimeTargetType = {}));
var ResourceType;
(function (ResourceType) {
ResourceType["host"] = "host";
})(ResourceType = Runtime.ResourceType || (Runtime.ResourceType = {}));
})(Runtime = Sardines.Runtime || (Sardines.Runtime = {}));
var Transform;
(function (Transform) {
Transform.fromServiceToEmptyRuntime = function (service) {
if (!service.application)
return null;
return {
identity: {
application: service.application,
module: service.module,
name: service.name
},
arguments: service.arguments,
returnType: service.returnType,
entries: []
};
};
Transform.fromServiceDescriptionFileToServiceCache = function (descfile, options) {
if (options === void 0) { options = { booleanValue: true, version: '*' }; }
if (!descfile || !descfile.application || !descfile.services || !descfile.services.length)
return null;
var cache = {};
cache[descfile.application] = {};
for (var _i = 0, _a = descfile.services; _i < _a.length; _i++) {
var service = _a[_i];
if (!service.module || !service.name)
continue;
if (!cache[descfile.application][service.module])
cache[descfile.application][service.module] = {};
if (!cache[descfile.application][service.module][service.name]) {
cache[descfile.application][service.module][service.name] = {};
}
cache[descfile.application][service.module][service.name][options.version] = options.booleanValue ? true : service;
}
return cache;
};
Transform.mergeServiceCaches = function (to, from) {
if (!to || !from)
return;
for (var _i = 0, _a = Object.keys(from); _i < _a.length; _i++) {
var appName = _a[_i];
if (!to[appName])
to[appName] = {};
for (var _b = 0, _c = Object.keys(from[appName]); _b < _c.length; _b++) {
var moduleName = _c[_b];
if (!to[appName][moduleName])
to[appName][moduleName] = {};
for (var _d = 0, _e = Object.keys(from[appName][moduleName]); _d < _e.length; _d++) {
var serviceName = _e[_d];
if (!to[appName][moduleName][serviceName])
to[appName][moduleName][serviceName] = {};
for (var _f = 0, _g = Object.keys(from[appName][moduleName][serviceName]); _f < _g.length; _f++) {
var version = _g[_f];
to[appName][moduleName][serviceName][version] = from[appName][moduleName][serviceName][version];
}
}
}
}
};
Transform.pushServiceIntoProviderCache = function (pvdrCache, pvdrkey, pvdr, service, value) {
if (value === void 0) { value = true; }
if (!pvdrCache || !pvdrkey
|| !service || !service.application || !service.module || !service.name || !service.version) {
return;
}
if (!pvdrCache[pvdrkey])
pvdrCache[pvdrkey] = {
providerInfo: pvdr,
serviceCache: {},
serviceRuntimeIds: []
};
pvdrCache[pvdrkey].serviceRuntimeIds;
if (typeof value === 'string' && pvdrCache[pvdrkey].serviceRuntimeIds.indexOf(value) < 0) {
pvdrCache[pvdrkey].serviceRuntimeIds.push(value);
}
if (!pvdrCache[pvdrkey].serviceCache[service.application]) {
pvdrCache[pvdrkey].serviceCache[service.application] = {};
}
if (!pvdrCache[pvdrkey].serviceCache[service.application][service.module]) {
pvdrCache[pvdrkey].serviceCache[service.application][service.module] = {};
}
if (!pvdrCache[pvdrkey].serviceCache[service.application][service.module][service.name]) {
pvdrCache[pvdrkey].serviceCache[service.application][service.module][service.name] = {};
}
var cacheItem = {};
var currentValue = pvdrCache[pvdrkey].serviceCache[service.application][service.module][service.name][service.version || '*'];
if (typeof currentValue === 'string')
cacheItem.serviceRuntimeId = currentValue;
else if (typeof currentValue === 'object')
Object.assign(cacheItem, currentValue);
if (typeof value === 'string') {
cacheItem.serviceRuntimeId = value;
}
else if (value && typeof value === 'object' && Object.keys(value).length) {
cacheItem.serviceSettingsInProvider = value;
}
pvdrCache[pvdrkey].serviceCache[service.application][service.module][service.name][service.version || '*'] = cacheItem;
};
})(Transform = Sardines.Transform || (Sardines.Transform = {}));
})(Sardines = exports.Sardines || (exports.Sardines = {}));