Promise version of `form`.
See `form`.
@param  {Object}   req       A HTTP request object which can be used to customised the form
@param  {String}   modelName The name of the model
@return {Promise} A promise with the decorated form DSL.
431434
function formAsPromise (req, modelName, formDsl) {

    return new Promise((resolve, reject) => {

        form(req, modelName, (err, decoratedForm) => {

            if (err) {
                return reject(err);
            }

            return resolve(decoratedForm);

        }, formDsl);

    });

}
589675
function(methodMapper, request, response, callback) {
      var modelMethod = methodMapper[request.method];
      if (access[modelMethod] === true) {
        return callback(null, true);
      }

      return application.access(request, access[modelMethod], callback);
    }
47439
function createModel (app, name, options) {
  const mongooseClient = app.get('mongoose');
  assert(mongooseClient, 'mongoose client not set by app');
  const schema = new mongooseClient.Schema({ any: {} }, {strict: false});
  return mongooseClient.model(name, schema);
}
1308060
function providePromise(obj, providePromiseName) {
    if(!isString(providePromiseName)) {
      throw new Error('Must provide string as name of promised module');
    }
    di.annotate(obj, new di.ProvidePromise(providePromiseName));
  }
1270493
function create(model) {
  var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];

  if (!model) {
    throw new Error('No model provided.');
  }
  return _destructure2['default'](model.forge(), params).then(function (destructured) {
    var attributes = destructured.attributes;
    var relations = destructured.relations;

    return _transact2['default'](model, function (transaction) {
      return model.forge(attributes).save(null, {
        method: 'insert',
        transacting: transaction
      }).tap(function (newModel) {
        return _relate2['default'](newModel, relations, 'create', transaction);
      }).then(function (newModel) {
        return model.forge({ id: newModel.id }).fetch({ transacting: transaction });
      });
    });
  });
}
574245
function modelQuery(options) {
            return models.Post.edit(options.data.posts[0], omit(options, ['data']))
                .then((model) => {
                    if (!model) {
                        return Promise.reject(new common.errors.NotFoundError({
                            message: common.i18n.t('errors.api.posts.postNotFound')
                        }));
                    }

                    const post = urlsForPost(model.id, model.toJSON(options), options);

                    // If previously was not published and now is (or vice versa), signal the change
                    // @TODO: `statusChanged` get's added for the API headers only. Reconsider this.
                    post.statusChanged = false;
                    if (model.previous('status') !== model.get('status')) {
                        post.statusChanged = true;
                    }

                    return {
                        posts: [post]
                    };
                });
        }
67702
function modelQuery(options) {
            return models.Post.findOne(options.data, omit(options, ['data']))
                .then((model) => {
                    if (!model) {
                        return Promise.reject(new common.errors.NotFoundError({
                            message: common.i18n.t('errors.api.posts.postNotFound')
                        }));
                    }

                    return {
                        posts: [urlsForPost(model.id, model.toJSON(options), options)]
                    };
                });
        }
1198280
function requestHandler(req, res, next) {
  const start = Date.now();
  let source;

  return Promise.try(() => {
    source = core.getPublicSource(req.params.src);
    return source.getHandler().getInfoAsync().then(info => [info, infoHeaders]);
  }).spread((data, dataHeaders) => {
    core.setResponseHeaders(res, source, dataHeaders);

    if (req.query && req.query.format) {
      const escapedText = JSON.stringify(data, null, ' ').replace(/&/g, '&amp;').replace(/</g, '&lt;');
      res.send(`<pre>${escapedText}</pre>`);
    } else {
      res.json(data);
    }

    const mx = util.format('req.%s.info', req.params.src);
    core.metrics.endTiming(mx, start);
  }).catch(err => core.reportRequestError(err, res)).catch(next);
}
1100467
function (reqContext, name, args) {
    return BPromise.resolve()
        .bind(this)
        .then(function () {
            var method = this._methods[name];
            if (!method) {
                throw new MWError(404, "Method not found");
            }
            var context = R.merge(method.context, reqContext);
            return method.fn.apply(context, args);
        });
}
1142602
function promiseMiddleware (request, response, middleware) {
  return new promiseMiddleware.Promise(function (resolve, reject) {
    middleware(request, response, function next (error) {
      return error ? reject(error) : resolve()
    })
  })
}
1161358
function responseCallback(response, model, success) {
        // Add response to a hash that will eventually be returned through the promise
        responses[model.cid] = {
            success: success,
            response: response
          };
        // If we have reached the total of number of expected responses, then resolve or reject the promise
        if (responsesFailed + responsesSucceeded === numberOfSaves) {
          if (responsesFailed > 0) {
            // Rollback if any responses have failed
            if (options.rollback) {
              _.each(formModel.getTrackedModels(), function(model) {
                model.set(oldValues[model.cid]);
                if (responses[model.cid].success) {
                  model.save();
                }
              });
            }
            formModel.trigger('save-fail', responses);
            deferred.reject(responses);
          } else {
            formModel.trigger('save-success', responses);
            deferred.resolve(responses);
          }
        }
      }
553974
private Object makeModelObject(String formName) {
		Object object = null;
		Class modelClass = null;
		try {
			modelClass = (Class) modelFactory.getModelClasses(formName);
			if (modelClass == null) {
				throw new Exception(" not found the model in config xml, formName=" + formName);
			}
			object = modelClass.newInstance();
			// inject
			modelProxyInjection.injectProperties(object);
		} catch (Exception e) {
			Debug.logError("[JdonFramework]--> call Model: " + modelClass + " error:" + e, module);
		}
		return object;
	}
1253407
function _ensureModel(model) {
      if (model instanceof this.model) {
        return model;
      } else if (typeof model === "object") {
        return new this.model(model);
      } else {
        return new this.model({ id: model });
      }
    }
1351992
function ( req, model ) {
		// Create data object (monolithic combination of all parameters)
		// Omit the blacklisted params (like JSONP callback param, etc.)

		// Allow customizable blacklist for params NOT to include as values.
		req.options.values = req.options.values || {};
		req.options.values.blacklist = req.options.values.blacklist;

		// Validate blacklist to provide a more helpful error msg.
		var blacklist = req.options.values.blacklist;
		if ( blacklist && !_.isArray( blacklist ) ) {
			throw new Error( 'Invalid `req.options.values.blacklist`. Should be an array of strings (parameter names.)' );
		}

		// Get values using the model identity as resource identifier
		var values = req.param( _.kebabCase( model.globalId ) ) || {};

		// Omit built-in runtime config (like query modifiers)
		values = _.omit( values, blacklist || [] );

		// Omit any params w/ undefined values
		values = _.omit( values, function ( p ) {
			if ( _.isUndefined( p ) ) return true;
		} );

		// Omit jsonp callback param (but only if jsonp is enabled)
		var jsonpOpts = req.options.jsonp && !req.isSocket;
		jsonpOpts = _.isObject( jsonpOpts ) ? jsonpOpts : {
			callback: JSONP_CALLBACK_PARAM
		};
		if ( jsonpOpts ) {
			values = _.omit( values, [ jsonpOpts.callback ] );
		}

		return values;
	}
891091
function requireModel(modelName, full) {
		if(!modelName) {
			return false;
		}

		var model = this.models[modelName];

		if(full) {
			return (model ? model : false);
		}
		return (model ? model.serverModel : false);
	}
943384
function (req, res) {
        var id = req.params.id;
        {modelName}.findOne({_id: id}, function (err, {name}) {
            if (err) {
                return res.status(500).json({
                    message: 'Error when getting {name}',
                    error: err
                });
            }
            if (!{name}) {
                return res.status(404).json({
                    message: 'No such {name}'
                });
            }

            {updateFields}
            {name}.save(function (err, {name}) {
                if (err) {
                    return res.status(500).json({
                        message: 'Error when updating {name}.',
                        error: err
                    });
                }

                return res.json({name});
            });
        });
    }
621294
function(modelObj, type, success, error, method) {
                var args;

                // If `modelObj` is an Array, it it means we are coming from
                // the queued request, and we're passing already-serialized data.
                if (can.isArray(modelObj)) {
                    // In that case, modelObj's signature will be `[modelObj, serializedData]`, so we need to unpack it.
                    args = modelObj[1];
                    modelObj = modelObj[0];
                } else {
                    // If we aren't supplied with serialized data, we'll make our own.
                    args = modelObj.serialize();
                }
                args = [args];

                var deferred,
                    model = modelObj.constructor,
                    jqXHR;

                // When calling `update` and `destroy`, the current ID needs to be the first parameter in the AJAX call.
                if (type === 'update' || type === 'destroy') {
                    args.unshift(getId(modelObj));
                }
                jqXHR = model[type].apply(model, args);

                // Make sure that can.Model can react to the request before anything else does.
                deferred = pipe(jqXHR, modelObj, function(data) {
                    // `method` is here because `"destroyed" !== "destroy" + "d"`.
                    // TODO: Do something smarter/more consistent here?
                    modelObj[method || type + "d"](data, jqXHR);
                    return modelObj;
                });

                // Hook up `abort`
                if (jqXHR.abort) {
                    deferred.abort = function() {
                        jqXHR.abort();
                    };
                }

                deferred.then(success, error);
                return deferred;
            }