Hello, it would be really nice to have an enum type. Currently this can be done with i.string() but it doesn't provide type safety. For getting the type safety I have to override AppSchema and also use as MyEnum in the data returned by useQuery. I also need to add perms to make sure invalid data never gets inserted.
For example let's say I have a status: i.string().indexed() field in a groupInvitations entity that only accepts 'pending' | 'accepted' | 'declined'
I need to override the AppSchema like this:
export type InvitationStatus = 'pending' | 'accepted' | 'declined'
export type AppSchema = Omit<_AppSchema, 'entities'> & {
entities: Omit<_AppSchema['entities'], 'groupInvitations'> & {
groupInvitations: Omit<_AppSchema['entities']['groupInvitations'], 'status'> & {
status: InvitationStatus
}
}
}
And when I use the data:
const { data } = db.useQuery(...)
const status = data.groupInvitations[0].status as InvitationStatus
And in the instant.perms.ts file:
groupInvitations: {
allow: {
create: 'validStatus',
update: 'validStatus',
},
bind: {
validStatus: "data.status in ['pending', 'accepted', 'declined']",
},
},
With support for an enum type I would hope to be able to get all of this automatically just by specifying the valid enum values.
Hello, it would be really nice to have an enum type. Currently this can be done with
i.string()but it doesn't provide type safety. For getting the type safety I have to override AppSchema and also useas MyEnumin the data returned byuseQuery. I also need to add perms to make sure invalid data never gets inserted.For example let's say I have a
status: i.string().indexed()field in agroupInvitationsentity that only accepts'pending' | 'accepted' | 'declined'I need to override the AppSchema like this:
And when I use the data:
And in the
instant.perms.tsfile:With support for an enum type I would hope to be able to get all of this automatically just by specifying the valid enum values.