Custom entities (EAV)
Beyond module-defined MikroORM entities, Open Mercato ships an Entities module that implements an Entity-Attribute-Value (EAV) store. It powers runtime configurable objects—think CRM-style records, dynamic forms, or metadata catalogs.
Definitions
ce.ts– each module can export anentitiesarray describing custom entities and their fields.- Fields support core types (
text,textarea,integer,float,boolean,date,select,relation,attachment) and you can add more via the field registry. - Generators compile definitions into
modules.generated.tsso runtime registries know which modules supply which custom entities.
src/modules/example/ce.ts
import { defineFields, cf } from '@open-mercato/modules/dsl';
export const entities = [
{
id: 'example:todo',
title: 'Example Todo',
fields: defineFields([
cf.enum('priority', {
label: 'Priority',
options: ['low', 'medium', 'high'],
}),
cf.boolean('blocked', { label: 'Blocked' }),
]),
},
];
Values
- Custom field values are stored in the shared
entitiesmodule tables. Each record is scoped byentity_id,record_id,organization_id, andtenant_id. - The data engine persists values and emits events after updates.
- The query engine can project custom fields using the
cf:<key>syntax (e.g.,cf:priority).
Admin experience
- The admin UI reads definitions to render configuration pages where operators can add/remove fields.
- CRUD forms detect custom fields automatically and render the right input components.
Use custom entities when you need flexible data structures without shipping a new migration for every customer request.