Skip to main content

@idpass/data-collect-core / EventApplier

Interface: EventApplier

Defined in: interfaces/types.ts:514

Event applier interface for transforming events into entity state changes.

Core component of the event sourcing system that knows how to apply specific event types to entities. Custom event appliers can be registered for domain-specific operations.

Example​

const customApplier: EventApplier = {
apply: async (entity, form, getEntity, saveEntity) => {
if (form.type === 'custom-operation') {
const updatedEntity = { ...entity, data: { ...entity.data, ...form.data } };
return updatedEntity;
}
throw new Error(`Unsupported event type: ${form.type}`);
}
};

Methods​

apply()​

apply(entity, form, getEntity, saveEntity): Promise<EntityDoc>

Defined in: interfaces/types.ts:524

Apply an event (form submission) to an entity to produce the new state.

Parameters​

entity​

EntityDoc

The current entity state

form​

FormSubmission

The form submission/event to apply

getEntity​

(id) => Promise<EntityPair | null>

Function to retrieve related entities

saveEntity​

(action, existingEntity, modifiedEntity, changes) => Promise<void>

Function to save entity changes

Returns​

Promise<EntityDoc>

The updated entity after applying the event