-
Notifications
You must be signed in to change notification settings - Fork 554
DRAFT: Preliminary presence runtime schema validation support #23677
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
DRAFT: Preliminary presence runtime schema validation support #23677
Conversation
fbe458d
to
cdaeb15
Compare
@@ -494,6 +517,7 @@ export function LatestMap< | |||
Keys extends string | number = string | number, | |||
RegistrationKey extends string = string, | |||
>( | |||
validator: ValueTypeSchemaValidatorForKey<T, Keys>, |
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.
Should be optional.
This is a tricky aspect. Refers to: packages/framework/presence/src/latestValueManager.ts:195 in cdaeb15. [](commit_id = cdaeb15, deletion_comment = False) |
Is the Refers to: packages/framework/presence/src/latestValueManager.ts:188 in cdaeb15. [](commit_id = cdaeb15, deletion_comment = False) |
* Contains the validated data, or `undefined` if the value has not been validated. | ||
*/ | ||
// valid?: JsonDeserialized<TValue> | undefined; | ||
valid?: TValue | undefined; | ||
} | ||
|
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.
valid
can be added here but it will need to be removed from ClientUpdateEntry
and any places calling with that.
It may be that we need to create a separate type for remote versus local value state.
Local value state which should be the only think that ever is sent as ClientUpdateEntry
should never have valid
(as we rely on caller to always provide confirming values).
So maybe the stripping of valid
would just need to happen when generating the complete update in response to a join. (And eventually that should be less common code path when we start using targeted signals.)
> = ( | ||
key: Keys, | ||
unvalidatedData: unknown, | ||
) => |
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.
Is key
useful? Required?
Maybe the validator functions should all follow (unvalidatedData: unknown, metadata: ...): T | undefined
and we could stick extra info in metadata.
I function declared as (unvalidatedData: unknown): T | undefined
should still be acceptable as validator.
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.
Not sure I understand. Are you suggesting there be a single type for all validators, and pass metadata in the second
function arg that customer code can use to determine what logic to run?
Or are you thinking more like two different types that vary on the type/contents of the metadata arg?
I'm not clear how customer code can declare validators for each key, so I thought the validator for maps would use the
key to determine what validator to run (i.e. the map validator would return a value validator). Seems like that logic is still necessary, but would be moved inside the
customer's code to read the metadata and act accordingly?
🔗 No broken links found! ✅ Your attention to detail is admirable. linkcheck output
|
Superseded by more recent PRs. Closing. |
Adds preliminary support for runtime validation of presence data. I am mostly interested in feedback about the signature changes, the types, and where I put them.
For ease of review, there are three commits that can be reviewed separately.
Update April 9
The change now incorporates some of the initial feedback.
validator
andcontrols
are now part of an options object rather than direct function args.validator
is always optional in Latest and LatestMapkey
property that will be set if the value being validated is from a ValueMap.Not yet addressed: