export function convertEntitiesToDocuments()

in src/Explorer/Tables/TableEntityProcessor.ts [110:160]


export function convertEntitiesToDocuments(
  entities: Entities.ITableEntityForTablesAPI[],
  collection: ViewModels.Collection,
): any[] {
  let results: any[] = [];
  entities &&
    entities.forEach((entity) => {
      let document: any = {
        $id: entity.RowKey._,
        id: entity.RowKey._,
        ts: DateTimeUtilities.convertJSDateToUnix(entity.Timestamp._), // Convert back to unix time
        rid: entity._rid._,
        self: entity._self._,
        etag: entity._etag._,
        attachments: entity._attachments._,
        collection: collection,
      };
      if (collection.partitionKey) {
        document["partitionKey"] = collection.partitionKey;
        document[collection.partitionKeyProperties[0]] = entity.PartitionKey._;
        document["partitionKeyValue"] = entity.PartitionKey._;
      }
      for (var property in entity) {
        if (
          property !== Constants.EntityKeyNames.PartitionKey &&
          property !== Constants.EntityKeyNames.RowKey &&
          property !== Constants.EntityKeyNames.Timestamp &&
          property !== keyProperties.resourceId &&
          property !== keyProperties.self &&
          property !== keyProperties.etag &&
          property !== keyProperties.attachments &&
          property !== keyProperties.Id2
        ) {
          if (entity[property].$ === Constants.TableType.DateTime) {
            // Convert javascript date back to ticks with 20 zeros padding
            document[property] = {
              $t: (<any>DataTypes)[entity[property].$],
              $v: DateTimeUtilities.convertJSDateToTicksWithPadding(entity[property]._),
            };
          } else {
            document[property] = {
              $t: (<any>DataTypes)[entity[property].$],
              $v: entity[property]._,
            };
          }
        }
      }
      results.push(document);
    });
  return results;
}