Skip to content

Commit b8cc52f

Browse files
committed
fix: add proper checks for Hierarchical PartionKeys
1 parent fb1c063 commit b8cc52f

File tree

7 files changed

+254
-257
lines changed

7 files changed

+254
-257
lines changed

lib/cosmos-db/cosmos-db-core.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class AzureCosmosDbCoreModule {
4747
const connectionProvider = {
4848
provide: cosmosConnectionName,
4949
useFactory: async (cosmosModuleOptions: AzureCosmosDbOptions): Promise<any> => {
50-
const { dbName, retryAttempts, retryDelay, connectionName, ...cosmosOptions } = cosmosModuleOptions;
50+
const { dbName, retryAttempts, retryDelay, ...cosmosOptions } = cosmosModuleOptions;
5151

5252
return await defer(async () => {
5353
cosmosOptions.userAgentSuffix = await getuserAgentSuffix();

lib/cosmos-db/cosmos-db.decorators.spec.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { AZURE_COSMOS_DB_ENTITY, CosmosPartitionKey } from './cosmos-db.decorato
22
import { PartitionKeyDefinitionVersion, PartitionKeyKind } from '@azure/cosmos';
33

44
describe('Azure CosmosDB Decorators', () => {
5-
beforeEach(() => {
6-
// tslint:disable-next-line: no-empty
7-
function MockEntity() {}
8-
});
5+
beforeEach(() => {});
96

107
describe('@CosmosPartitionKey()', () => {
118
it('should add a PartitionKey ', () => {

lib/cosmos-db/cosmos-db.providers.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@ export function createAzureCosmosDbProviders(
5252
}
5353

5454
if (partitionKey != null) {
55-
containerOptions.partitionKey = {
56-
paths: [`/${partitionKey}`],
57-
};
55+
if (typeof partitionKey === 'string') {
56+
containerOptions.partitionKey = {
57+
paths: [`/${partitionKey}`],
58+
};
59+
}
60+
else if (typeof partitionKey === 'object') {
61+
containerOptions.partitionKey = partitionKey;
62+
} else {
63+
throw new Error(`Invalid PartitionKey definition for model ${model.dto.name}`);
64+
}
65+
5866
}
5967
const coResponse = await database.containers.createIfNotExists(containerOptions);
6068

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"dependencies": {
3535
"@azure/cosmos": "^4.0.0",
3636
"@azure/data-tables": "^13.2.2",
37-
"@nestjs/common": "^11.0.0",
38-
"@nestjs/core": "^11.0.0"
37+
"@nestjs/common": "^10.0.0 || ^11.0.0",
38+
"@nestjs/core": "^10.0.0 || ^11.0.0"
3939
},
4040
"devDependencies": {
4141
"@commitlint/cli": "19.8.1",
@@ -45,7 +45,7 @@
4545
"@nestjs/testing": "11.1.3",
4646
"@types/jest": "29.5.14",
4747
"@types/node": "22.13.8",
48-
"azurite": "3.34.0",
48+
"azurite": "^3.34.0",
4949
"dotenv": "16.5.0",
5050
"eslint": "9.28.0",
5151
"eslint-config-prettier": "10.1.5",

0 commit comments

Comments
 (0)