fix(client-presence): [BREAKING CHANGE] LatestMap keys limited to strings#25904
fix(client-presence): [BREAKING CHANGE] LatestMap keys limited to strings#25904jason-ha merged 14 commits intomicrosoft:mainfrom
LatestMap keys limited to strings#25904Conversation
A `keyValidator` may now be given when creating a `LatestMap` such that only validated keys are enumerated.
tylerbutler
left a comment
There was a problem hiding this comment.
If I understand correctly, there's no way for a user to access or enumerate keys for which the validator returns undefined. I can understand this behavior for iteration, but it seems odd that .get(invalidKey) is the same as .get(missingKey). In practice maybe that distinction doesn't matter much.
packages/framework/presence/api-report/presence.legacy.alpha.api.md
Outdated
Show resolved
Hide resolved
Good question. With a keyValidator, the difference would be that the keyValidator would be invoked. So, it could be written to snoop whether something was invalid or missing. |
…testMap` `number`s have always propagated as `string`s at runtime. Removal of specification makes API types reflect this. Internally, `objectEntries` appears to fail to fully preserve key enumeration not that `number` is not possible.
add key validator test coverage
LatestMap keys limited to strings
There was a problem hiding this comment.
Pull request overview
This PR introduces a breaking change to the LatestMap API by restricting keys to string type only, removing support for number keys. Since keys are stored as strings at runtime, this change clarifies the actual behavior. Additionally, it adds a keyValidator option to enable runtime validation of custom key types.
Key Changes
- Removed
numberfrom theKeystype parameter constraint across allLatestMapinterfaces and types - Added
KeySchemaValidator<Keys>type andkeyValidatoroptional parameter toLatestMapArguments - Implemented key validation logic in
getRemote()andupdate()methods to filter out invalid keys - Added comprehensive test coverage for the new keyValidator functionality
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
packages/framework/presence/src/latestMapValueManager.ts |
Main implementation: removed number from Keys constraint, added KeySchemaValidator type, implemented key validation in getRemote and update methods |
packages/framework/presence/src/exposedInternalTypes.ts |
Updated MapValueState interface to constrain Keys to string only |
packages/framework/presence/src/index.ts |
Exported the new KeySchemaValidator type |
packages/framework/presence/src/stateDatastore.ts |
Renamed generic parameter from TUpdateValue to TLocalUpdateValue for clarity |
packages/framework/presence/src/internalTypes.ts |
Added documentation for the update method in ValueManager interface |
packages/framework/presence/src/test/schemaValidation/valueManagers.spec.ts |
Added comprehensive tests for keyValidator including validation behavior, event handling for invalid keys, and iterator behavior |
packages/framework/presence/src/test/latestMapValueManager.spec.ts |
Updated type parameters to use template literal type instead of number |
packages/service-clients/end-to-end-tests/azure-client/src/test/multiprocess/childClient.tool.ts |
Removed second type parameter from LatestMap type annotations |
packages/framework/presence/api-report/presence.legacy.alpha.api.md |
Updated API surface to reflect breaking changes |
packages/framework/presence/api-report/presence.beta.api.md |
Updated API surface to reflect breaking changes |
.changeset/modern-candies-clean.md |
Documented the breaking change with appropriate section marker |
packages/framework/presence/src/test/schemaValidation/valueManagers.spec.ts
Outdated
Show resolved
Hide resolved
packages/framework/presence/src/test/schemaValidation/valueManagers.spec.ts
Outdated
Show resolved
Hide resolved
packages/framework/presence/src/test/schemaValidation/valueManagers.spec.ts
Outdated
Show resolved
Hide resolved
|
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output |
…string`s (microsoft#25904) Remove `number` as a possible type for `LatestMap` keys. All given keys are stored as string record entries at runtime and thus numbers become keys. To use "number" keys, string pattern `${number}` can be used for the type. Add `keyValidator` to support enabling consumers to only work with validated keys. A `keyValidator` is recommended anytime `Keys` type is not `string`.
Remove
numberas a possible type forLatestMapkeys. All given keys are stored as string record entries at runtime and thus numbers become keys. To use "number" keys, string pattern${number}can be used for the type.Add
keyValidatorto support enabling consumers to only work with validated keys. AkeyValidatoris recommended anytimeKeystype is notstring.