Options
The NextCrud
function accepts one argument which is an object with the following keys
models
An object with the following shape:
type TModelOption = {
name?: string
only?: RouteType[] // An array of routes to serve, by default it serves all possible routes
exclude?: RouteType[] // An array of routes to exclude from being served, by default no route is excluded
formatResourceId?: (resourceId: string) => string | number
}
type TModelsOptions<M extends string = string> = {
[key in M]?: TModelOption
}
Each key of the object must correspond to the models passed to your adapter, see this section.
Example:
NextCrud({
adapter: new PrismaAdapter<User | Post, Prisma.ModelName>({
prismaClient: myPrismaClient,
}),
models: {
[Prisma.ModelName.User]: {
name: 'users',
only: [RouteType.READ_ALL],
},
},
defaultExposeStrategy: 'all',
})
only
and exclude
can have the following values:
CREATE
READ_ONE
READ_ALL
UPDATE
DELETE
TypeScript users: you can import the following enum and use it in the array
import { RouteType } from '@premieroctet/next-crud'
adapter
A required instance of an adaptater class, see this section.
defaultExposeStrategy
If all
, all routes are exposed, if none
, only the routes specified in the only
option are exposed. Default to all
.
formatResourceId
An optional function that allows you to format the retrieve resource id for the routes implying a single resource. By default it transforms number strings as numbers, else keep them as strings.
onRequest
An optional function, see this section
onSuccess
An optional function, see this section
onError
An optional function, see this section
middlewares
An optional array of functions, see this section
pagination
The pagination config accepts the following shape:
interface IPaginationConfig {
perPage: number // default number of elements to display on each page
}