* Adds chip to chips array and chips_by_module array
* @param {string} type - chip type ex. access-strategy, channel
* @param {string} name - chip name
* @param {object} chip - chip itselfs
* @returns void
*/
this.add_chip=function(type,name,chip){
if(chips[type]==undefined){
chips[type]=[];
}
chips[type][name]=chip;
}
/**
* Gets all resource types
* @returns {array} Array of names of resource types.
*/
this.get_all_resource_types=function(){
varnames=[];
for(resource_typeinchips.resource_type){
names.push(resource_type);
}
returnnames;
}
/**
* Checks if chip exists
* @param {string} type - chip type
* @param {string} name - chip name
* @returns {boolean} true if exists, otherwise false
*/
this.chip_exists=function(type,name){
if(chips[type]&&chips[type][name]){
returntrue;
}else{
returnfalse;
}
}
/**
* Gets chip
* @param {string} type - chip type
* @param {string} name - chip name
* @returns {object} requested chip or throws error
*/
this.get_chip=function(type,name){
try{
varret=chips[type][name];
if(ret==undefined){
thrownewError("Chip of type "+type+" and name "+name+" has not yet been registered.");
}
returnret;
}catch(e){
thrownewSealious.Errors.ValidationError("ChipManager was asked to return a chip of type `"+type+"` and name `"+name+"`, but it was not found",{},{short_message:"chip_not_found"});
}
}
/*
* Gets chip by long id
* @param {string} longid - longid is chip_type.chip_name ex. chanell.cli
* @returns {object} requested chip or throws error
*/
this.get_chip_by_longid=function(longid){
vartype=longid.split(".")[0];
varname=longid.split(".")[1];
returnthis.get_chip(type,name);
}
/*
* Checks if chip is registered
* @param {string} longid - longid is chip_type.chip_name ex. chanell.cli
* @returns {boolean} true if chip is registered, otherwise false
*/
this.chip_is_registred=function(longid){
returnthis.get_chip_by_longid(longid)!=undefined;
}
/*
Gets amount of chips in given type
* @param {string} type - type name ex. chanell, access_strategy
* @returns {integer} amount of chips of this type
*/
this.get_chip_amount_by_type=function(type){
if(chips[type]){
returnObject.keys(chips[type]).length;
}else{
return0;
}
}
/**
* Gets proper datastore chip
* @returns {object} datastore chip for application or throws error if no datastore chip is defined
thrownewSealious.Errors.Error("Chip manager was requested to return a datastore chip. Multiple chips of type `datastore` have been registered, and no default provided in configuration.")