wasp icon indicating copy to clipboard operation
wasp copied to clipboard

Improve docs for `ensureValidEmail`, `ensurePasswordIsPresent`, `ensureValidPassword`

Open Martinsos opened this issue 2 years ago • 2 comments

In our docs, we just say they take args, but don't say what args are. Also, in Typescript, it is not types what these args are, args is unknown.

We should explain in docs that it should be { email: string } for ensureValidEmail, ... . We should also update types so they reflect this. And for other functions the same thing.

Martinsos avatar Jan 24 '24 15:01 Martinsos

args are typed to receive unknown since it's truly unknown content which we receive from the client.

Maybe we can make the functions work to ensure that the content after their perform their check changes e.g. if the function validates that a password exists, the args type changes to include the password field.

infomiho avatar Jan 24 '24 15:01 infomiho

Aha, I see what you mean. We can't say we expect type system to expect email in that args, when we don't know if args contains email, that is what we are validating among other things?

You are right, we could make it so that after the function is done, type system knows args has email on it -> type predicate I guess.

Also, we could at least document the functions with comments/words -> we could say that ensureValidEmail will check that args has valid .email field. And similar for others. RIght now docs look like these are internal functions which we quickly made public but didn't bother really documenting them (which is correct if I am right :D).

Martinsos avatar Jan 26 '24 09:01 Martinsos