Convert one or several entities instance (gstore) to Datastore format

@param {any} entities Entity(ies) to format
@returns {array} the formated entity(ies)
169284
function entitiesToDatastore(entities, options) {
    const multiple = is.array(entities);
    entities = arrify(entities);

    if (entities[0].className !== 'Entity') {
        // Not an entity instance, nothing to do here...
        return entities;
    }

    const result = entities.map(e => toDatastore(e, options));

    return multiple ? result : result[0];
}
540829
public function data($entity = '') {
        $entities = [];

        foreach ($this->_data as $line) {
            if ($entity != '') {
                /** @var  $entityObject \Gcs\Framework\Core\Orm\Entity\Entity */
                $entityObject = self::Entity()->$entity();

                foreach ($line as $key => $field) {
                    $value = null;
                    $parent = '';

                    $key = str_replace('count_one_' . $entityObject->name() . '_', '', $key);
                    $key = str_replace('count_many_' . $entityObject->name() . '_', '', $key);
                    $key = str_replace($entityObject->name() . '_', '', $key);

                    if ($entityObject->getField($key) != null) {
                        if (in_array($entityObject->getField($key)->type, [Field::INCREMENT, Field::INT, Field::TEXT, Field::FLOAT, Field::STRING, Field::CHAR, Field::BOOL, Field::DATE, Field::DATETIME, Field::TIMESTAMP, Field::ENUM])) {
                            if ($entityObject->getField($key)->foreign == null) {
                                //If the field is a Datetime or Date or Timestamp we must convert it to \DateTime
                                switch ($entityObject->getField($key)->type) {
                                    case Field::DATETIME:
                                        $value = new \DateTime($field);
                                        break;

                                    case Field::DATE:
                                        $value = new \DateTime($field);
                                        break;

                                    case Field::TIMESTAMP:
                                        $value = new \DateTime($field);
                                        break;

                                    default:
                                        $value = $field;
                                        break;
                                }
                            }
                            elseif (in_array($entityObject->getField($key)->foreign->type(), [ForeignKey::ONE_TO_MANY, ForeignKey::MANY_TO_MANY])) {
                                $value = $field;
                            }
                            else {
                                foreach ($entityObject->fields() as $fieldIsRightForeign) {
                                    if ($fieldIsRightForeign->foreign != null) {
                                        $parent = $fieldIsRightForeign->name . '_';
                                        $value = $this->_getDataRelation($line, $entityObject->getField(str_replace($fieldIsRightForeign->name . '_', '', $key))->foreign, $parent);
                                    }
                                }
                            }
                        }
                        else {
                            switch ($entityObject->getField($key)->type) {
                                case Field::FILE :
                                    $file = new File('', '', '', '');
                                    $file->hydrate($field);
                                    $value = $file;
                                    break;
                            }
                        }

                        $fieldName = str_replace($parent, '', $key);
                        $entityObject->set($fieldName, $value);
                    }
                }
            }
            else {
                $entityObject = new Multiple($line);
            }

            array_push($entities, $entityObject);
        }

        return new Collection($entities);
    }
204615
public Element toElement(final MongoDbDatastore datastore) {
        final Element ds = getDocument().createElement("mongodb-datastore");
        ds.setAttribute("name", datastore.getName());
        if (!Strings.isNullOrEmpty(datastore.getDescription())) {
            ds.setAttribute("description", datastore.getDescription());
        }

        appendElement(ds, "hostname", datastore.getHostname());
        appendElement(ds, "port", datastore.getPort());
        appendElement(ds, "database-name", datastore.getDatabaseName());
        appendElement(ds, "username", datastore.getUsername());
        appendElement(ds, "password", encodePassword(datastore.getPassword()));

        return ds;
    }
606752
def datastores
      datastores = []
      @_host.datastore.each do |ds|
        datastores << Datastore.wrap(ds)
      end
      datastores
    end
1220564
function(entity, options) {
  options = options || {};
  options.checkext = options.checkext || checkext;
  options.extlist = options.extlist || extlist;
  options.logFormat = options.logFormat || '%s: %s';
  options.logger = options.logger || console;
  options.ignore = options.ignore || false;
  options.cwd = options.cwd || '';

  this.options = options;
  this.scripts = [];
  if (!(options.extlist instanceof RegExp) && options.extlist instanceof Array){
      this.__log('Converting extension list to regular expression');
      options.extlist = new RegExp('(.*)(' + options.extlist.join('$|').replace(/\./g,'\\.') + ')');
  };
  this.__log('Using regular expression' + options.extlist + 'for extenstion matching');
  this.then(entity);

  return this;
}
363005
function EntityInstantiator(options) {
  if (!options.store) throw new Error("Missing store");
  if (!options.Entity) throw new Error("Missing entity constructor");
  if (!options.logger) throw new Error("Missing logger");
  this.store  = options.store;
  this.Entity = options.Entity;
  this.logger = options.logger;
}
345511
function etag (entity, options) {
  if (entity == null) {
    throw new TypeError('argument entity is required')
  }

  // support fs.Stats object
  var isStats = isstats(entity)
  var weak = options && typeof options.weak === 'boolean'
    ? options.weak
    : isStats

  // validate argument
  if (!isStats && typeof entity !== 'string' && !Buffer.isBuffer(entity)) {
    throw new TypeError('argument entity must be string, Buffer, or fs.Stats')
  }

  // generate entity tag
  var tag = isStats
    ? stattag(entity)
    : entitytag(entity)

  return weak
    ? 'W/' + tag
    : tag
}
1118626
private Object convertParameter(Object value) {
        if (entityInstanceManager.isInstance(value)) {
            return entityInstanceManager.getDatastoreType(value);
        } else if (relationInstanceManager.isInstance(value)) {
            return relationInstanceManager.getDatastoreType(value);
        } else if (value instanceof Collection) {
            Collection collection = (Collection) value;
            List<Object> values = new ArrayList<>();
            for (Object o : collection) {
                values.add(convertParameter(o));
            }
            return values;
        }
        return value;
    }
1268706
function createStorageValueStore(playerId, keys) {
		var convertedKeys = [];
		keys.forEach(function(key) {
			var ck = {};
			for (var k in key) {
				ck[k] = key[k];
			}
			ck.userId = playerId;
			convertedKeys.push(ck);
		});
		var values = props.gameStorage.load(convertedKeys);
		return new g.StorageValueStore(convertedKeys, values);
	}
607274
def _convert_json_response_to_entities(response, property_resolver):
    ''' 
    '''
    if response is None:
        return response

    entities = _list()

    entities.next_marker = _get_continuation_from_response_headers(response)

    root = loads(response.body.decode('utf-8'))

    if 'value' in root:
        for entity in root['value']:
            entities.append(_convert_json_to_entity(entity, 
                                                 property_resolver))
    else:
        entities.append(_convert_json_to_entity(entity, 
                                             property_resolver))

    return entities
102570
function (store, json) {
    var handledRecords = [], key, records, handleRecord, Model;
    handleRecord = function (record) {
      this.completeJsonForRecord(store, record, Model, json, handledRecords);
    };
    for (key in json) {
      if (json.hasOwnProperty(key)) {
        records = json[key];
        Model = store.modelFor(singularize(key));
        forEach(records, handleRecord, this);
      }
    }
    return json;
  }
1219100
function clearStore(_options) {
    const store = this;
    const state = store.state;
    entityRecords = {}, entityRefs = {}, weakParts = [];
    entityNames.forEach((name) => {
      entityRefs[name] = {};
      entityRecords[name] = state[_entityName2StoreKey[name]];
    });

    options = _options && typeof _options === 'object' ? _options : {};
    if (typeof options.truncate === 'number' && options.truncate >= 0) options.truncate = ~~options.truncate;
    else options.truncate = -1;

    if (beforeClear && typeof beforeClear === 'function') {
      const customRefs = beforeClear.call(store, state);
      if (customRefs && customRefs.length > 0) {
        customRefs.forEach((ref) => {
          const refs = entityRefs[ref.entity];
          if (!refs) return;
          refs[ref.id] = true;
        });
      }
    }

    // first run: calc non-weak and non-chain position
    _calcRef(state, structure);

    // second run: calc weak parts
    weakParts.forEach((part) => {
      let refs = entityRefs[part.entity],
        partState = part.state,
        partStruct = part.structure;
      Object.keys(part.state).forEach((id) => {
        if (!refs[id]) return;
        _calcRefForValue(partState[id], partStruct);
      });
    });

    // last run: calc ref in entity structure(for the chain ref)
    entityNameLastRefCount = {};
    Object.keys(_entityNameChain).forEach((entityName) => {
      _calcEntityOwnStructure(entityName);
    });

    // remove entities which not referenced
    const newState = Object.assign({}, state);
    entityNames.forEach((entityName) => {
      const storeKey = _entityName2StoreKey[entityName];
      let entities = newState[storeKey],
        refs = entityRefs[entityName];
      Object.keys(entities).forEach((id) => {
        if (!refs[id]) delete entities[id];
      });
    });

    options = null, entityRecords = null, entityRefs = null, weakParts = null, entityNameLastRefCount = null;
    store.setState(newState);
  }
1267234
static List<Entity> fetch(Datastore reader, Key[] keys, ReadOption... options) {
    return compileEntities(keys, reader.get(Arrays.asList(keys), options));
  }
840069
function baseFormat(data, strict) {
  const isArray = Array.isArray(data);

  if (!isArray && (data === null || typeof data !== 'object')) {
    throw new TypeError('data must be an Object or Array');
  }

  const records = [];

  if (isArray) {
    for (let i = 0, len = data.length; i < len; ++i) {
      records[i] = objectToRecord(data[i], strict);
    }
  } else {
    records.push(objectToRecord(data, strict));
  }

  return records.join('\n');
}
389489
function parse(args) {
  const merged = merge(defaults(), args);
  if (!args || !merged.jdlObject || !args.databaseType) {
    throw new Error('The JDL object and the database type are both mandatory.');
  }
  if (merged.applicationType !== GATEWAY) {
    checkNoSQLModeling(merged.jdlObject, args.databaseType);
  }
  init(merged);
  initializeEntities();
  setOptions();
  fillEntities();
  setApplicationToEntities();
  return entities;
}
584286
function toJS(entity) {
  let data = {};
  Object.keys(entity).forEach(key => {
    if (_.some(customObjects, obj => entity[key] instanceof obj)) {
      data[key] = toJS(entity[key])
    } else {
      data[key] = entity[key]
    }
  });
  return data
}
945667
function (store) {
            var eas = [];
            all_ws(store);
            if (!consume(OTHER, "[")) return eas;
            eas[0] = simple_extended_attr(store) || error("Extended attribute with not content");
            all_ws();
            while (consume(OTHER, ",")) {
                eas.push(simple_extended_attr(store) || error("Trailing comma in extended attribute"));
                all_ws();
            }
            consume(OTHER, "]") || error("No end of extended attribute");
            return eas;
        }