Is there a reliable way to infer the proper return type of loadAfterMutationEntities and loadBeforeMutationEntities?
https://github.com/zenstackhq/zenstack-v3/blob/35a9e0d6575d7baf7d0aa3e29484d7aedb56b4d0/packages/runtime/src/client/plugin.ts#L170-L174
https://github.com/zenstackhq/zenstack-v3/blob/35a9e0d6575d7baf7d0aa3e29484d7aedb56b4d0/packages/runtime/src/client/plugin.ts#L153-L158
If the return data is typed, it becomes easier working with any follow up queries:
export const onAfterPostDelete = definePlugin<SchemaType>({
id: "onAfterPostDelete",
onEntityMutation: {
async beforeEntityMutation({ model, action, loadBeforeMutationEntities, client, queryId }) {
const deletedPost = await loadBeforeMutationEntities() // <--- typed as Record<string, unknown>[] | undefined but its really a Post[]
if (action === "delete" && model === "Post") {
// Do some logic
const tags = await client.tag.findMany({
where: {
postId: deletedPost[0].id, // <-- This doesn't work unless we cast deletedPost to proper type like Post[]
},
})
}
},
},
})
Is there a reliable way to infer the proper return type of
loadAfterMutationEntitiesandloadBeforeMutationEntities?https://github.com/zenstackhq/zenstack-v3/blob/35a9e0d6575d7baf7d0aa3e29484d7aedb56b4d0/packages/runtime/src/client/plugin.ts#L170-L174
https://github.com/zenstackhq/zenstack-v3/blob/35a9e0d6575d7baf7d0aa3e29484d7aedb56b4d0/packages/runtime/src/client/plugin.ts#L153-L158
If the return data is typed, it becomes easier working with any follow up queries: