<commit_before>import Ember from 'ember';
import { first } from './proxy';

const {
  merge
} = Ember;

const buildExcludeNew = (opts, document) => {
  let opt = opts.new;
  if(typeof opt === 'boolean') {
    document.push('isNew');
    return doc => {
      let isNew = doc.get('isNew');
      if(opt === true && !isNew) {
        return true;
      }
      if(opt === false && isNew) {
        return true;
      }
      return false;
    };
  }
  return () => false;
}

export default opts => {
  opts = merge({ id: 'id' }, opts);
  let { database, id } = opts;

  let owner = [ id ];
  let document = [ 'id' ];

  let excludeNew = buildExcludeNew(opts, document);

  return first({
    database,
    owner,
    document,
    query(owner) {
      let id = owner.get('id');
      return { id };
    },
    matches(doc, owner) {
      if(excludeNew(doc)) {
        return;
      }
      let id = owner.get('id');
      return doc.get('id') === id;
    }
  });
};<commit_msg>doc-by-id fix<commit_after>import Ember from 'ember';
import { first } from './proxy';

const {
  merge
} = Ember;

const buildExcludeNew = (opts, document) => {
  let opt = opts.new;
  if(typeof opt === 'boolean') {
    document.push('isNew');
    return doc => {
      let isNew = doc.get('isNew');
      if(opt === true && !isNew) {
        return true;
      }
      if(opt === false && isNew) {
        return true;
      }
      return false;
    };
  }
  return () => false;
}

export default opts => {
  opts = merge({ id: 'id' }, opts);
  let { database, id } = opts;

  let owner = [ id ];
  let document = [ 'id' ];

  let excludeNew = buildExcludeNew(opts, document);

  return first({
    database,
    owner,
    document,
    query(owner) {
      let id = owner.get(opts.id);
      return { id };
    },
    matches(doc, owner) {
      if(excludeNew(doc)) {
        return;
      }
      let id = owner.get(opts.id);
      return doc.get('id') === id;
    }
  });
};
{'fraction_non_alphanumeric': 0.17177914110429449, 'fraction_numerical': 0.0, 'mean_word_length': 2.1162420382165603, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '96724', 'n_tokens_mistral': 672, 'n_tokens_neox': 663, 'n_words': 169}