in src/Explorer/Tables/TableEntityProcessor.ts [35:107]
export function convertDocumentsToEntities(documents: any[]): Entities.ITableEntityForTablesAPI[] {
let results: Entities.ITableEntityForTablesAPI[] = [];
documents &&
documents.forEach((document) => {
if (!document.hasOwnProperty(keyProperties.PartitionKey) || !document.hasOwnProperty(keyProperties.Id)) {
//Document does not match the current required format for Tables, so we ignore it
return; // The rest of the key properties should be guaranteed as DocumentDB properties
}
let entity: Entities.ITableEntityForTablesAPI = <Entities.ITableEntityForTablesAPI>{
PartitionKey: {
_: document[keyProperties.PartitionKey],
$: Constants.TableType.String,
},
RowKey: {
_: document[keyProperties.Id],
$: Constants.TableType.String,
},
Timestamp: {
// DocumentDB Timestamp is unix time so we convert to Javascript date here
_: DateTimeUtilities.convertUnixToJSDate(document[keyProperties.Timestamp]).toUTCString(),
$: Constants.TableType.DateTime,
},
_rid: {
_: document[keyProperties.resourceId],
$: Constants.TableType.String,
},
_self: {
_: document[keyProperties.self],
$: Constants.TableType.String,
},
_etag: {
_: document[keyProperties.etag],
$: Constants.TableType.String,
},
_attachments: {
_: document[keyProperties.attachments],
$: Constants.TableType.String,
},
};
for (var property in document) {
if (document.hasOwnProperty(property)) {
if (
property !== keyProperties.PartitionKey &&
property !== keyProperties.Id &&
property !== keyProperties.Timestamp &&
property !== keyProperties.resourceId &&
property !== keyProperties.self &&
property !== keyProperties.etag &&
property !== keyProperties.attachments &&
property !== keyProperties.Id2
) {
if (!document[property].hasOwnProperty("$v") || !document[property].hasOwnProperty("$t")) {
return; //Document property does not match the current required format for Tables, so we ignore it
}
if (DataTypes[document[property][tablesIndexers.Type]] === DataTypes[DataTypes.DateTime]) {
// Convert Ticks datetime to javascript date for better visualization in table
entity[property] = {
_: DateTimeUtilities.convertTicksToJSDate(document[property][tablesIndexers.Value]).toUTCString(),
$: DataTypes[document[property][tablesIndexers.Type]],
};
} else {
entity[property] = {
_: document[property][tablesIndexers.Value],
$: DataTypes[document[property][tablesIndexers.Type]],
};
}
}
}
}
results.push(entity);
});
return results;
}