-
Notifications
You must be signed in to change notification settings - Fork 4
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
Upgrade Prisma to 5.4.2
and Brackets Manager to 1.6.4
#9
base: master
Are you sure you want to change the base?
Conversation
A patch is needed for the `brackets-model` in order to work with the numeric Ids. Support for String Ids can be added later.
* Depending on your storage system, you might prefer strings or numbers. | ||
*/ | ||
-export type Id = string | number; | ||
+export type Id = number; |
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.
@Tandashi I don't understand how this relates to #8. Could you share the exact error / issue you were facing without this patch?
there is no way to prevent Id types (number and string) from mixing
What do you mean here? Is the problem with the input seeding maybe?
And how would a generic solve the issue?
Do you have an idea of what changed between Prisma 4 and 5?
And brackets-model
only defines types, so what was the problem exactly? Does Prisma generate something based on types automatically? Or did you have TypeScript compilation errors?
Will this fix through a patch work for the users of brackets-prisma-db
as well? (I doubt that 😁)
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.
I don't understand how this relates to #8. Could you share the exact error / issue you were facing without this patch?
The patch is not related to #8. It is related to the brackets-manager
upgrade to the latest version. Thought I could upgrade Prisma
as well as the Brackets Manager
at the same time to not have to submit multiple Pull Requests if I am editing the same file anyways.
What do you mean here? Is the problem with the input seeding maybe?
And how would a generic solve the issue?
I mean currently the Id
type is specified as string | number
. Which means it would be allowed to mix id
types.
For one stage the id
it could be a number
for another it could be a string
. There is nothing on the type level that would prevent that. In reality that wouldn't make much sense though since in my opinion all ids
should be of the same type.
Furthermore if I know that my ids
are all of type number
and I have written functions that expect an id
as number
I would need to explicitly check that the id
I received is not a string
because from the Id
type it could be a string
.
I know for a fact though that it can't be. In case for brackets-prisma-db
its specified in the database schema that ids
are numeric.
Maybe an example to make it more clear if it isn't already:
// The type from `brackets-model` (unions.ts)
type Id = string | number
// Cut down manager type to make the example
// easiert to understand.
// (Should be equivilant to the `brackets-manager` type though)
type Manager = {
create: {
stage: ({ tournamentId }: { tournamentId: Id }) => { id: Id }
}
}
declare const manager: Manager;
// Imagine this is a database method
// In the database schema it is defined that the
// id has to be numeric
declare function something(id: number): void;
const stage = manager.create.stage({
tournamentId: 0
});
stage.id;
// ^? (property) id: string | number
// I have to explicitly check now to type narrow back to number
// although I did know for certain that it has to be a number.
something(stage.id) // Type 'string' is not assignable to type 'number'
// A possible solution
// Through the `Id extends string | number` the Id can only be number or string
type ManagerGeneric<Id extends string | number> = {
create: {
stage: ({ tournamentId }: { tournamentId: Id }) => { id: Id }
}
}
// Type 'boolean' does not satisfy the constraint 'string | number'
declare const dummy: ManagerGeneric<boolean>;
declare const manager2: ManagerGeneric<number>;
const stage2 = manager2.create.stage({
tournamentId: 0
});
stage2.id;
// ^? (property) id: number
// I don't have to check anything to narrow the type because I know it can only be number
something(stage2.id) // Works fine
Do you have an idea of what changed between Prisma 4 and 5?
No clue what exactly changed but seems like they dont work together (as an increase in mayor version indicates a breaking change at least in semver terms)
And brackets-model only defines types, so what was the problem exactly? Does Prisma generate something based on types automatically? Or did you have TypeScript compilation errors?
TypeScript type errors due to the fact that the new brackets-manager
returns the new brackets-model
Ids
which can either be a string
or number
. For a database schema I can either define number
or string
. Since a database column can't be both at the same time. Its an either or.
Will this fix through a patch work for the users of brackets-prisma-db as well? (I doubt that 😁)
I don't see why it shouldn't. Could you elaborate more why it shouldn't work?
My reasoning is that if the consumer installs the package via npm install brackets-prisma-db
the postinstall
will be triggered patching the type for the brackets-model
package. The consumer then can only use numeric Ids but they have to do that anyways because the current schema doesn't allow for any other type (like uuids
) as of yet.
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.
Ok, I'll put this PR on hold for now, and I'll probably make the manager take a generic Id
parameter later.
Thanks for the explanation!
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.
If you need help with that or want me to draft something let me know :)
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.
Sorry for the bunch of questions, but I have to understand first 😉 And thank you for making that PR so quickly!
A patch using
patch-package
is needed for thebrackets-model
in order to work with the numeric Ids.String Ids are not supported for now since there is no way to prevent Id types (
number
andstring
) from mixing. Maybe a generic for the Manager itself could prevent that?Related Issue: #8