lib/utils/normalizeIds.js
function normalizeIds(ids, prop, opt) {
  opt = opt || {};

  let isComposite = prop.size > 1;
  let ret;

  if (isComposite) {
    // For composite ids these are okay:
    //
    // 1. [1, 'foo', 4]
    // 2. {a: 1, b: 'foo', c: 4}
    // 3. [[1, 'foo', 4], [4, 'bar', 1]]
    // 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}]
    //
    if (Array.isArray(ids)) {
      if (Array.isArray(ids[0])) {
        ret = new Array(ids.length);

        // 3.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = convertIdArrayToObject(ids[i], prop);
        }
      } else if (isObject(ids[0])) {
        ret = new Array(ids.length);

        // 4.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = ensureObject(ids[i], prop);
        }
      } else {
        // 1.
        ret = [convertIdArrayToObject(ids, prop)];
      }
    } else if (isObject(ids)) {
      // 2.
      ret = [ids];
    } else {
      throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
    }
  } else {
    // For non-composite ids, these are okay:
    //
    // 1. 1
    // 2. {id: 1}
    // 3. [1, 'foo', 4]
    // 4. [{id: 1}, {id: 'foo'}, {id: 4}]
    //
    if (Array.isArray(ids)) {
      if (isObject(ids[0])) {
        ret = new Array(ids.length);

        // 4.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = ensureObject(ids[i]);
        }
      } else {
        ret = new Array(ids.length);

        // 3.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = {};
          prop.setProp(ret[i], 0, ids[i]);
        }
      }
    } else if (isObject(ids)) {
      // 2.
      ret = [ids];
    } else {
      // 1.
      const obj = {};
      prop.setProp(obj, 0, ids);
      ret = [obj];
    }
  }

  checkProperties(ret, prop);

  if (opt.arrayOutput) {
    return normalizedToArray(ret, prop);
  } else {
    return ret;
  }
}
function normalizeIds(ids, prop, opt) {
  opt = opt || {};

  let isComposite = prop.size > 1;
  let ret;

  if (isComposite) {
    // For composite ids these are okay:
    //
    // 1. [1, 'foo', 4]
    // 2. {a: 1, b: 'foo', c: 4}
    // 3. [[1, 'foo', 4], [4, 'bar', 1]]
    // 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}]
    //
    if (Array.isArray(ids)) {
      if (Array.isArray(ids[0])) {
        ret = new Array(ids.length);

        // 3.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = convertIdArrayToObject(ids[i], prop);
        }
      } else if (isObject(ids[0])) {
        ret = new Array(ids.length);

        // 4.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = ensureObject(ids[i], prop);
        }
      } else {
        // 1.
        ret = [convertIdArrayToObject(ids, prop)];
      }
    } else if (isObject(ids)) {
      // 2.
      ret = [ids];
    } else {
      throw new Error(`invalid composite key ${JSON.stringify(ids)}`);
    }
  } else {
    // For non-composite ids, these are okay:
    //
    // 1. 1
    // 2. {id: 1}
    // 3. [1, 'foo', 4]
    // 4. [{id: 1}, {id: 'foo'}, {id: 4}]
    //
    if (Array.isArray(ids)) {
      if (isObject(ids[0])) {
        ret = new Array(ids.length);

        // 4.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = ensureObject(ids[i]);
        }
      } else {
        ret = new Array(ids.length);

        // 3.
        for (let i = 0, l = ids.length; i < l; ++i) {
          ret[i] = {};
          prop.setProp(ret[i], 0, ids[i]);
        }
      }
    } else if (isObject(ids)) {
      // 2.
      ret = [ids];
    } else {
      // 1.
      const obj = {};
      prop.setProp(obj, 0, ids);
      ret = [obj];
    }
  }

  checkProperties(ret, prop);

  if (opt.arrayOutput) {
    return normalizedToArray(ret, prop);
  } else {
    return ret;
  }
}
function normalizeIds ( ids , prop , opt ) { opt = opt || { } ; let isComposite = prop . size > 1 ; let ret ; if ( isComposite ) { // For composite ids these are okay: // // 1. [1, 'foo', 4] // 2. {a: 1, b: 'foo', c: 4} // 3. [[1, 'foo', 4], [4, 'bar', 1]] // 4. [{a: 1, b: 'foo', c: 4}, {a: 4, b: 'bar', c: 1}] // if ( Array . isArray ( ids ) ) { if ( Array . isArray ( ids [ 0 ] ) ) { ret = new Array ( ids . length ) ; // 3. for ( let i = 0 , l = ids . length ; i < l ; ++ i ) { ret [ i ] = convertIdArrayToObject ( ids [ i ] , prop ) ; } } else if ( isObject ( ids [ 0 ] ) ) { ret = new Array ( ids . length ) ; // 4. for ( let i = 0 , l = ids . length ; i < l ; ++ i ) { ret [ i ] = ensureObject ( ids [ i ] , prop ) ; } } else { // 1. ret = [ convertIdArrayToObject ( ids , prop ) ] ; } } else if ( isObject ( ids ) ) { // 2. ret = [ ids ] ; } else { throw new Error ( ` ${ JSON . stringify ( ids ) } ` ) ; } } else { // For non-composite ids, these are okay: // // 1. 1 // 2. {id: 1} // 3. [1, 'foo', 4] // 4. [{id: 1}, {id: 'foo'}, {id: 4}] // if ( Array . isArray ( ids ) ) { if ( isObject ( ids [ 0 ] ) ) { ret = new Array ( ids . length ) ; // 4. for ( let i = 0 , l = ids . length ; i < l ; ++ i ) { ret [ i ] = ensureObject ( ids [ i ] ) ; } } else { ret = new Array ( ids . length ) ; // 3. for ( let i = 0 , l = ids . length ; i < l ; ++ i ) { ret [ i ] = { } ; prop . setProp ( ret [ i ] , 0 , ids [ i ] ) ; } } } else if ( isObject ( ids ) ) { // 2. ret = [ ids ] ; } else { // 1. const obj = { } ; prop . setProp ( obj , 0 , ids ) ; ret = [ obj ] ; } } checkProperties ( ret , prop ) ; if ( opt . arrayOutput ) { return normalizedToArray ( ret , prop ) ; } else { return ret ; } }
ids is of type RelationProperty.
ids is of type RelationProperty .