-
Notifications
You must be signed in to change notification settings - Fork 53
fix: add proper checks for Hierarchical PartionKeys #1283
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,9 +52,17 @@ export function createAzureCosmosDbProviders( | |
} | ||
|
||
if (partitionKey != null) { | ||
containerOptions.partitionKey = { | ||
paths: [`/${partitionKey}`], | ||
}; | ||
if (typeof partitionKey === 'string') { | ||
containerOptions.partitionKey = { | ||
paths: [`/${partitionKey}`], | ||
}; | ||
} | ||
else if (typeof partitionKey === 'object') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the partition key might be an array, which will still resolve to object and in this case will work just fine. Looks good to me :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the confusion here, but |
||
containerOptions.partitionKey = partitionKey; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found one issue, it throws an error if the property path is an empty array @CosmosPartitionKey({
paths: [],
version: PartitionKeyDefinitionVersion.V2,
kind: PartitionKeyKind.MultiHash,
}) |
||
} else { | ||
throw new Error(`Invalid PartitionKey definition for model ${model.dto.name}`); | ||
} | ||
|
||
} | ||
const coResponse = await database.containers.createIfNotExists(containerOptions); | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
connectionName
is no longer excluded and will be spread intocosmosOptions
, potentially passing an unsupported option to the Azure SDK. Re-introduceconnectionName
in the destructuring exclusion or explicitly delete it fromcosmosOptions
.Copilot uses AI. Check for mistakes.