fix: allow _patch to modify the entire base schema #3300
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
With this given schema
You may want a user to be able modify their own username, but obviously not set
isAdmin
totrue
whenever they want.So you have a patch schema that only permits the username to be modified.
But the backend still retains the ability to modify any property by using underscore methods.
_patch
ignores all hooks and can setisAdmin
totrue
The issue is that currently Feathers throws a type error if you try to modify anything that isn't part of the
userPatchSchema
, even if you are using_patch
. You get an error similar to this,Argument of type { isAdmin: boolean; } is not assignable to parameter of type { username: string; }
This is very frustrating to deal with, since the code is perfectly valid.
This PR attempts to address that type issue.
Other Information
I have tried my best in testing this, I ran the test script and all passed. I also tried this against my local feathers app and it seems to work correctly. I spent a decent bit of time on figuring out these whole 12 lines of changes. This was seemingly the simplest way of fixing the types, without breaking a lot of stuff