-
Notifications
You must be signed in to change notification settings - Fork 9
RFC: Use io-ts to validate user input. #65
base: master
Are you sure you want to change the base?
Conversation
17cdf7c
to
dfe26d4
Compare
dfe26d4
to
1707b88
Compare
When the typescript is converted to javascript, all type checks are lost. Instead, define the requirements in terms of io-ts types and check them at runtime.
1707b88
to
449fca0
Compare
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.
This is fine in theory. It's hard to know if this doesn't break anything, in particular after the removal of Babel. It seems like it's unused, but I'm not wholly confident that the tests would pick this up 😅
package.json
Outdated
@@ -41,6 +46,6 @@ | |||
"publish-please": "^5.1.1", | |||
"tap-colorize": "^1.2.0", | |||
"tape": "^4.9.1", | |||
"typescript": "^2.6.1" | |||
"typescript": "^2.8.1" |
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.
May as well bump to 2.8.3, which includes some bug fixes
src/chatkit.ts
Outdated
import * as t from 'io-ts' | ||
import "unknown-ts" | ||
|
||
const NonEmptyString = t.refinement(t.string, s => s.length != 0, "NonEmptyString"); |
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.
Though it wouldn't make a difference here, triple equals is always preferred (i.e. !==)
src/chatkit.ts
Outdated
userId: NonEmptyString | ||
},"UserIdOptions"); | ||
type UserIdOptions = t.TypeOf<typeof UserIdOptions>; | ||
export { UserIdOptions }; |
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.
The use of the same name for two different things is confusing at a glance (though I know you mentioned the docs gave an example like this)
I like it. Hadn't seen When you say should the check be for values only... do you mean that some people might be feeding numbers to I think the real issue here is with the API being too "clever" and interpreting an empty string room ID as indicating a global role. Maybe we should change that in V7 instead and then all the SDKs would get this fix for free. I'd be surprised if this issue didn't also feature in all our other SDKs. |
src/chatkit.ts
Outdated
import * as t from 'io-ts' | ||
import "unknown-ts" | ||
|
||
const NonEmptyString = t.refinement(t.string, s => s.length !== 0, "NonEmptyString"); |
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.
can pull this in from https://github.com/gcanti/io-ts-types#usage
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.
It seems to be more restrictive; it won't take an normal string.
error TS2322: Type 'string' is not assignable to type 'Branded<string, NonEmptyStringBrand>'. Type 'string' is not assignable to type 'Brand<NonEmptyStringBrand>'.
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.
ah I see. never mind then
Update io-ts, fp-ts, typescript
The intention is to use it everywhere.
More likely it would be a parameter on another method, perhaps
Fair enough.
That makes sense to me. |
RFC: This implements checks for
RemoveRoomRoleForUserOptions
only.allowJs
without removeddeclaration: true
What?
Define the requirements in terms of io-ts types and check them at runtime.
Add tests for Room Roles
Why?
When the typescript is converted to javascript, all type checks are lost.