AutowiredFromClient - TheOpenCloudEngine/metaworks GitHub Wiki

AutowiredFromClient annotation

Introduction

Usage

options

  • select
  • payload
//filt out the undesired fields for optimizing payload size
if(autowiredBeanPath)
try{
	var autowiredBeanPaths;
	eval("autowiredBeanPaths = " + autowiredBeanPath);

	if(autowiredBeanPaths){

		var origValue = autowiredObjects[fieldName];
		var filteredValue = {__className: origValue.__className};

		if(!autowiredBeanPaths.length){
			autowiredBeanPaths = [autowiredBeanPaths];
		}

		for(var i=0; i<autowiredBeanPaths.length; i++){
			var beanPath = autowiredBeanPaths[i];

			var whereCondition = beanPath.indexOf('[');

			if (whereCondition > -1){
				var whereConditionEnd = beanPath.indexOf(']');

				var conditionPart = beanPath.substring(whereCondition+1, whereConditionEnd);
				var arrayPropName = beanPath.substring(0, whereCondition);
				var arrayBeanPath = beanPath.substring(whereConditionEnd+1);
				var arrayOfOrigValue = origValue[arrayPropName];

				filteredValue[arrayPropName] = [];

				for(var j=0; j<arrayOfOrigValue.length; j++){

					var accept = false;
					var value = object;

					with(arrayOfOrigValue[j]){
						try{
							eval("accept = " + (conditionPart));
						}catch(ex){console.log(ex);}
					}

					if(!accept) continue;

					var elem = this.___beanCopy(arrayBeanPath, arrayOfOrigValue[j]);

					filteredValue[arrayPropName].push(elem);

				}

			}else{

				if(beanPath.indexOf(".") > -1){

					var filteredValueWithProp = this.___beanCopy("."+ beanPath, origValue);

					var propName = beanPath.split(".")[0];
					eval("filteredValue." + propName + " = filteredValueWithProp." + propName);

				}else{
					eval("filteredValue." + beanPath + " = origValue." + beanPath);
				}
			}

		}

		autowiredObjects[fieldName] = filteredValue;
	}

}catch(e){console.log(e);}