Services - Options

You can pass CrudOptions when performing operations or commands.

export interface ICrudOptions {
    populate?: string[];
    mockRole?: string;
    fields?: string[];
    limit?: number;
    offset?: number;
    cached?: boolean;
    allowIdOverride?: boolean;
}

Options are passed via the context:

import { CrudContext } from "@eicrud/core/crud";

const query: Partial<Profile> = {
    astroSign: "Aries"
}
const ctx: Partial<CrudContext> = {
    options: {
        limit: 20
    }
}

const {data, total, limit} = await profileService.$find(query, ctx);

Note

Check out the client options page to use CrudOptions in your front-end.

populate

Corresponds to MikroOrm's populate option.

mockRole

Requests that include this option will perform as if the logged user has the role mockRole. To activate, CrudRole->canMock must be set.

Note

mockRole is useful for testing authorizations without switching accounts. You can set ClientConfig->globalMockRole to mock roles from the client.

fields

Corresponds to MikroOrm's fields option.

limit

Corresponds to MikroOrm's limit option.

offset

Corresponds to MikroOrm's offset option.

cached

Indicate if findOne results should be fetched from the cache.

Note

cached only works in client calls.

allowIdOverride

Allow Entity primary keys to be pre-generated in $create operations.

Warning

Letting users set their Entities' ID opens security risks. For example, impersonation of deleted entities.