Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
app.emit('init', app, eventArg);
app._inited = true;
return true;
}
catch (ex) {
midError.write(res, ex);
}
};
};
var appGainer = function(set) {
return new mvcApp(set);
};
// export
module.exports = utils.extend(appGainer, {
utils: utils,
caching: caching,
//
area: mvcArea.api,
model: mvcModelMeta.api,
controller: mvcController.api,
//
modelling: modelling,
attributes: attributes,
viewEngines: viewEngines,
actionResults: actionResults,
//
gainApp: function(set) {
return appGainer(set);
},
allApps: function() {
var handleErrorAttribute = module.exports = function(set) {
if (utils.isBoolean(set)) {
this.enabled = set;
} else {
utils.extend(this, set);
}
};
var sampleModelBinderAttribute = module.exports = function(set) {
if (utils.isString(set)) {
this.paramName = set;
} else {
utils.extend(this, set);
}
if (!this.paramName) {
throw new Error('The "paramName" of sampleModelBinderAttribute is required');
}
};
var validateInputAttribute = module.exports = function(set) {
if (utils.isBoolean(set)) {
this.enableValidation = set;
} else {
utils.extend(this, set);
}
};
var mvcModelBinderAttribute = module.exports = function(set) {
if (utils.isString(set)) {
this.paramName = set;
} else {
utils.extend(this, set);
}
if (!this.paramName) {
throw new Error('The "paramName" of mvcModelBinderAttribute is required');
}
};
var mvcViewData = module.exports = function(set) {
utils.extend(this, set);
if (!this.model) { this.model = {}; }
this.modelState = new mvcModelState();
mvcViewData.superclass.constructor.call(this, true);
};
clearCookie: function(name, options) {
var opts = { expires: new Date(1), path: '/' };
return this.cookie(name, '', options ? utils.extend(opts, options) : opts);
},
bindModel: function(controllerContext, bindingContext) {
var metadata = this.modelMeta.inner();
var rootNs = bindingContext.paramName;
var paramsDict = bindingContext.paramsDict;
var modelState = bindingContext.modelState;
var modelling = controllerContext.app.modelling;
var datas = controllerContext.requestDatas('lowerAll');
//
var metas = modelling.resolve(metadata);
if (metas.has()) {
var value = utils.readObj(datas, rootNs);
return metas.exe(value, rootNs, function(err) {
modelState.addModelError(rootNs, err);
});
} else {
var clone = utils.extend(true, {}, metadata);
var walk = function(obj, parentNs) {
var t = utils.type(obj);
var isArr = (t === 'array')
var isObj = (t === 'object');
if (!isArr && !isObj) { return; }
//
utils.each(obj, function(key, item) {
var partNs = isArr ? ('[' + key + ']') : ('.' + key.toLowerCase());
var currNs = parentNs + partNs;
//
var metas = modelling.resolve(item);
if (metas.has()) {
var fullNs = rootNs + currNs, stateNs = fullNs;
var value = utils.readObj(datas, fullNs);
//
if (!value && !parentNs) {
new: function(modelName) {
var metadata = this.get(modelName);
if (!metadata) { return; }
//
var modelling = this.httpContext.app.modelling;
var metas = modelling.resolve(metadata);
if (metas.has()) {
return metas.parse(null, '', function(err) { });
}
//
var clone = utils.extend(true, {}, metadata);
var walk = function(obj) {
var t = utils.type(obj);
if (t === 'array' || t === 'object') {
utils.each(obj, function(key, item) {
var metas = modelling.resolve(item);
if (metas.has()) {
obj[key] = metas.parse(null, '', function(err) { });
} else {
walk(item);
}
});
}
};
walk(clone);
clone.__metadata = metadata;
return clone;
cookie: function(name, value, options) {
options = utils.extend({}, options);
var signed = options.signed, secret = this.req._zoo.secret;
//
if (signed && !secret) {
throw new Error('cookieParser("secret") required for signed cookies');
}
if (utils.isNumber(value)) {
value = value.toString();
} else if (utils.isObject(value)) {
value = 'j:' + JSON.stringify(value);
}
if (signed) {
value = 's:' + sign(value, secret);
}
if ('maxAge' in options) {
options.expires = new Date(Date.now() + options.maxAge);
options.maxAge /= 1000;