The imperative way to define a resource: an object instead of a class.
Parity is the rule, so this declares exactly what a class declares and gets exactly what a class gets. It needs nothing injected: this module reads schemas with its own checker.
The schema, and optionally fragments and a data() hook.
data()
Optional explicit services, for a resource used outside a request.
A resource.
export const userResource = defineResource<User>({ schema: z.object({ id: z.number(), name: z.string() }), fragments: { summary: z.object({ id: z.number() }) }, data: async (user) => ({ ...user, posts: await posts.titlesOf(user.id) })}) Copy
export const userResource = defineResource<User>({ schema: z.object({ id: z.number(), name: z.string() }), fragments: { summary: z.object({ id: z.number() }) }, data: async (user) => ({ ...user, posts: await posts.titlesOf(user.id) })})
The imperative way to define a resource: an object instead of a class.
Parity is the rule, so this declares exactly what a class declares and gets exactly what a class gets. It needs nothing injected: this module reads schemas with its own checker.