Deploy rules for a database project.

It deploy the rules only if the previous deployed rules were different.

@param  {object}     options          Request options
@param  {RestClient} options.client   Client
@param  {object}     options.rules    Rules to deploy
@param  {string}     options.secret   Secret to authenticate the request
@return {Promise<void,Error>}
function deployRules({client, rules, secret}) {
  const lastRequest = rulesRequests.get(client.projectId);

  return Promise.resolve(lastRequest).then(oldRulesHash => {
    const newRuleHash = hash(rules);

    if (oldRulesHash === newRuleHash) {
      return oldRulesHash;
    }

    const request = client.rules({rules, secret});

    rulesRequests.set(client.projectId, request.then(
      () => newRuleHash,
      () => oldRulesHash
    ));

    return request;
  });
}