Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Added Hierarchical Partition Key Support" #24806

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions sdk/cosmosdb/cosmos/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
{
"version": "0.2.0",
"configurations": [
{
"name": "Test: Current Open File",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"type": "node",
"args": [
"--timeout",
"100000",
"-r",
"test/mocha.env.ts",
"-r",
"ts-node/register",
"-r",
"esm",
"-r",
"dotenv/config",
"-r",
"./test/public/common/setup.ts",
"--colors",
"**/${fileBasenameNoExtension}.ts"
],
"internalConsoleOptions": "openOnSessionStart",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
},
{
"name": "Test: Selected Test Case",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"type": "node",
"args": [
"--timeout",
"100000",
"-r",
"test/mocha.env.ts",
"-r",
"ts-node/register",
"-r",
"esm",
"-r",
"dotenv/config",
"-r",
"./test/public/common/setup.ts",
"--colors",
"**/${fileBasenameNoExtension}.ts",
"-g",
"${selectedText}"
],
"internalConsoleOptions": "openOnSessionStart",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
}
]
}
35 changes: 14 additions & 21 deletions sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ClientContext {
batch<T>({ body, path, partitionKey, resourceId, options, }: {
body: T;
path: string;
partitionKey: PartitionKey;
partitionKey: string;
resourceId: string;
options?: RequestOptions;
}): Promise<Response_2<any>>;
Expand Down Expand Up @@ -585,7 +585,7 @@ export interface CreateOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Create;
// (undocumented)
partitionKey?: PartitionKey;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
// (undocumented)
resourceBody: JSONObject;
}
Expand Down Expand Up @@ -695,7 +695,7 @@ export interface DeleteOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Delete;
// (undocumented)
partitionKey?: PartitionKey;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
}

// @public (undocumented)
Expand Down Expand Up @@ -735,10 +735,8 @@ export type ExistingKeyOperation = {
path: string;
};

// Warning: (ae-forgotten-export) The symbol "PartitionKeyInternal" needs to be exported by the entry point index.d.ts
//
// @public
export function extractPartitionKey(document: unknown, partitionKeyDefinition?: PartitionKeyDefinition): PartitionKeyInternal | undefined;
// @public (undocumented)
export function extractPartitionKey(document: unknown, partitionKeyDefinition: PartitionKeyDefinition): PartitionKey[];

// @public
export interface FeedOptions extends SharedOptions {
Expand All @@ -755,7 +753,7 @@ export interface FeedOptions extends SharedOptions {
forceQueryPlan?: boolean;
maxDegreeOfParallelism?: number;
maxItemCount?: number;
partitionKey?: PartitionKey;
partitionKey?: any;
populateQueryMetrics?: boolean;
useIncrementalFeed?: boolean;
}
Expand Down Expand Up @@ -873,7 +871,7 @@ export enum IndexKind {

// @public
export class Item {
constructor(container: Container, id: string, clientContext: ClientContext, partitionKey?: PartitionKey);
constructor(container: Container, id: string, partitionKey: PartitionKey, clientContext: ClientContext);
// (undocumented)
readonly container: Container;
delete<T extends ItemDefinition = any>(options?: RequestOptions): Promise<ItemResponse<T>>;
Expand Down Expand Up @@ -903,7 +901,7 @@ export class ItemResponse<T extends ItemDefinition> extends ResourceResponse<T &
// @public
export class Items {
constructor(container: Container, clientContext: ClientContext);
batch(operations: OperationInput[], partitionKey?: PartitionKey, options?: RequestOptions): Promise<Response_2<OperationResponse[]>>;
batch(operations: OperationInput[], partitionKey?: string, options?: RequestOptions): Promise<Response_2<OperationResponse[]>>;
bulk(operations: OperationInput[], bulkOptions?: BulkOptions, options?: RequestOptions): Promise<OperationResponse[]>;
changeFeed(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
changeFeed(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<any>;
Expand Down Expand Up @@ -1079,20 +1077,15 @@ export interface PartitionedQueryExecutionInfo {
queryRanges: QueryRange[];
}

// Warning: (ae-forgotten-export) The symbol "PrimitivePartitionKeyValue" needs to be exported by the entry point index.d.ts
//
// @public (undocumented)
export type PartitionKey = PrimitivePartitionKeyValue | PrimitivePartitionKeyValue[];
export type PartitionKey = PartitionKeyDefinition | string | number | unknown;

// @public (undocumented)
export interface PartitionKeyDefinition {
// Warning: (ae-forgotten-export) The symbol "PartitionKeyKind" needs to be exported by the entry point index.d.ts
kind?: PartitionKeyKind;
paths: string[];
// (undocumented)
systemKey?: boolean;
// Warning: (ae-forgotten-export) The symbol "PartitionKeyDefinitionVersion" needs to be exported by the entry point index.d.ts
version?: PartitionKeyDefinitionVersion;
version?: number;
}

// @public (undocumented)
Expand Down Expand Up @@ -1137,7 +1130,7 @@ export interface PatchOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Patch;
// (undocumented)
partitionKey?: PartitionKey;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
// (undocumented)
resourceBody: PatchRequestBody;
}
Expand Down Expand Up @@ -1391,7 +1384,7 @@ export interface ReadOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Read;
// (undocumented)
partitionKey?: PartitionKey;
partitionKey?: string | number | boolean | null | Record<string, unknown> | undefined;
}

// @public (undocumented)
Expand All @@ -1417,7 +1410,7 @@ export interface ReplaceOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Replace;
// (undocumented)
partitionKey?: PartitionKey;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
// (undocumented)
resourceBody: JSONObject;
}
Expand Down Expand Up @@ -2024,7 +2017,7 @@ export interface UpsertOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Upsert;
// (undocumented)
partitionKey?: PartitionKey;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
// (undocumented)
resourceBody: JSONObject;
}
Expand Down
18 changes: 4 additions & 14 deletions sdk/cosmosdb/cosmos/src/ClientContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ import { Constants, HTTPMethod, OperationType, ResourceType } from "./common/con
import { getIdFromLink, getPathFromLink, parseLink } from "./common/helper";
import { StatusCodes, SubStatusCodes } from "./common/statusCodes";
import { Agent, CosmosClientOptions } from "./CosmosClientOptions";
import {
ConnectionPolicy,
ConsistencyLevel,
DatabaseAccount,
PartitionKey,
convertToInternalPartitionKey,
} from "./documents";
import { ConnectionPolicy, ConsistencyLevel, DatabaseAccount, PartitionKey } from "./documents";
import { GlobalEndpointManager } from "./globalEndpointManager";
import { PluginConfig, PluginOn, executePlugins } from "./plugins/Plugin";
import { FetchFunctionCallback, SqlQuerySpec } from "./queryExecutionContext";
Expand Down Expand Up @@ -606,7 +600,7 @@ export class ClientContext {
}: {
body: T;
path: string;
partitionKey: PartitionKey;
partitionKey: string;
resourceId: string;
options?: RequestOptions;
}): Promise<Response<any>> {
Expand Down Expand Up @@ -763,16 +757,12 @@ export class ClientContext {
options: requestContext.options,
partitionKeyRangeId: requestContext.partitionKeyRangeId,
useMultipleWriteLocations: this.connectionPolicy.useMultipleWriteLocations,
partitionKey:
requestContext.partitionKey !== undefined
? convertToInternalPartitionKey(requestContext.partitionKey)
: undefined, // TODO: Move this check from here to PartitionKey
partitionKey: requestContext.partitionKey,
});
}

/**
* Returns collection of properties which are derived from the context for Request Creation.
* These properties have client wide scope, as opposed to request specific scope.
* Returns collection of properties which are derived from the context for Request Creation
* @returns
*/
private getContextDerivedPropsForRequestCreation(): {
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/client/Container/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class Container {
* `const {body: replacedItem} = await container.item("<item id>", "<partition key value>").replace({id: "<item id>", title: "Updated post", authorID: 5});`
*/
public item(id: string, partitionKeyValue?: PartitionKey): Item {
return new Item(this, id, this.clientContext, partitionKeyValue);
return new Item(this, id, partitionKeyValue, this.clientContext);
}

/**
Expand Down
11 changes: 5 additions & 6 deletions sdk/cosmosdb/cosmos/src/client/Item/Item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ResourceType,
StatusCodes,
} from "../../common";
import { PartitionKey, PartitionKeyInternal, convertToInternalPartitionKey } from "../../documents";
import { PartitionKey } from "../../documents";
import { extractPartitionKey, undefinedPartitionKey } from "../../extractPartitionKey";
import { RequestOptions, Response } from "../../request";
import { PatchRequestBody } from "../../utils/patch";
Expand All @@ -24,7 +24,7 @@ import { ItemResponse } from "./ItemResponse";
* @see {@link Items} for operations on all items; see `container.items`.
*/
export class Item {
private partitionKey: PartitionKeyInternal;
private partitionKey: PartitionKey;
/**
* Returns a reference URL to the resource. Used for linking in Permissions.
*/
Expand All @@ -41,11 +41,10 @@ export class Item {
constructor(
public readonly container: Container,
public readonly id: string,
private readonly clientContext: ClientContext,
partitionKey?: PartitionKey
partitionKey: PartitionKey,
private readonly clientContext: ClientContext
) {
this.partitionKey =
partitionKey === undefined ? undefined : convertToInternalPartitionKey(partitionKey);
this.partitionKey = partitionKey;
}

/**
Expand Down
Loading