mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-27 16:07:01 +00:00
extract parition key
This commit is contained in:
parent
24860a6842
commit
0774ad4561
@ -85,20 +85,61 @@ export const queryPagesUntilContentPresent = async (
|
||||
};
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export const extractPartitionKeyValues = (
|
||||
documentContent: any,
|
||||
partitionKeyDefinition: PartitionKeyDefinition,
|
||||
): PartitionKey[] => {
|
||||
if (!partitionKeyDefinition.paths || partitionKeyDefinition.paths.length === 0) {
|
||||
return undefined;
|
||||
// export const extractPartitionKeyValues = (
|
||||
// documentContent: any,
|
||||
// partitionKeyDefinition: PartitionKeyDefinition,
|
||||
// ): PartitionKey[] => {
|
||||
// if (!partitionKeyDefinition.paths || partitionKeyDefinition.paths.length === 0) {
|
||||
// return undefined;
|
||||
// }
|
||||
|
||||
// const partitionKeyValues: PartitionKey[] = [];
|
||||
// partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => {
|
||||
// const partitionKeyPathWithoutSlash: string = partitionKeyPath.substring(1);
|
||||
// // if (documentContent[partitionKeyPathWithoutSlash]) {
|
||||
// // partitionKeyValues.push(documentContent[partitionKeyPathWithoutSlash]);
|
||||
// // }
|
||||
|
||||
// const partitionKeyPathParts: string[] = partitionKeyPathWithoutSlash.split("/");
|
||||
// let partitionKeyValue: any = documentContent;
|
||||
|
||||
// for(let partitionKeyPathPartIndex in partitionKeyPathParts) {
|
||||
// const partitionKeyPathPart: string = partitionKeyPathParts[partitionKeyPathPartIndex];
|
||||
// if (!(partitionKeyPathPart in documentContent)) {
|
||||
// partitionKeyValue = {};
|
||||
// break;
|
||||
// }
|
||||
// partitionKeyValue = partitionKeyValue[partitionKeyPathPart];
|
||||
// }
|
||||
|
||||
// partitionKeyValues.push(partitionKeyValue);
|
||||
// });
|
||||
// return partitionKeyValues;
|
||||
// };
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
export const extractPartitionKeyValues = (document: any, partitionKeyDefinition: PartitionKeyDefinition): PartitionKey[] => {
|
||||
if (partitionKeyDefinition && partitionKeyDefinition.paths && partitionKeyDefinition.paths.length > 0) {
|
||||
var partitionKey: any = [];
|
||||
partitionKeyDefinition.paths.forEach(function (path) {
|
||||
path = path.substring(1);
|
||||
const pathParts: string[] = path.split("/");
|
||||
|
||||
var obj = document;
|
||||
for (var i = 0; i < pathParts.length; ++i) {
|
||||
if (!((typeof obj === "object") && (pathParts[i] in obj))) {
|
||||
obj = {};
|
||||
break;
|
||||
}
|
||||
|
||||
const partitionKeyValues: PartitionKey[] = [];
|
||||
partitionKeyDefinition.paths.forEach((partitionKeyPath: string) => {
|
||||
const partitionKeyPathWithoutSlash: string = partitionKeyPath.substring(1);
|
||||
if (documentContent[partitionKeyPathWithoutSlash]) {
|
||||
partitionKeyValues.push(documentContent[partitionKeyPathWithoutSlash]);
|
||||
obj = obj[pathParts[i]];
|
||||
}
|
||||
|
||||
partitionKey.push(obj);
|
||||
});
|
||||
return partitionKeyValues;
|
||||
};
|
||||
|
||||
return partitionKey;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user