UNPKG

1.26 kBJavaScriptView Raw
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT license.
3import { parsePath } from "./common";
4/**
5 * @hidden
6 */
7export function extractPartitionKey(document, partitionKeyDefinition) {
8 if (partitionKeyDefinition &&
9 partitionKeyDefinition.paths &&
10 partitionKeyDefinition.paths.length > 0) {
11 const partitionKey = [];
12 partitionKeyDefinition.paths.forEach((path) => {
13 const pathParts = parsePath(path);
14 let obj = document;
15 for (const part of pathParts) {
16 if (typeof obj === "object" && part in obj) {
17 obj = obj[part];
18 }
19 else {
20 obj = undefined;
21 break;
22 }
23 }
24 partitionKey.push(obj);
25 });
26 if (partitionKey.length === 1 && partitionKey[0] === undefined) {
27 return undefinedPartitionKey(partitionKeyDefinition);
28 }
29 return partitionKey;
30 }
31}
32/**
33 * @hidden
34 */
35export function undefinedPartitionKey(partitionKeyDefinition) {
36 if (partitionKeyDefinition.systemKey === true) {
37 return [];
38 }
39 else {
40 return [{}];
41 }
42}
43//# sourceMappingURL=extractPartitionKey.js.map
\No newline at end of file