gearshaft
gearshaft copied to clipboard
Support entities without class constructors
Gearshaft's EntityStore and PostgresDocumentStore currently require entities to be implemented using classes. Class constructors are the expected value of the entity
parameter when creating such stores.
Existing users would be familiar with the following entity store declaration:
createEntityStore({
category: 'registration',
entity: Registration,
projection: RegistrationProjection,
messageStore
})
The proposed change would instead require users to provide a function to instantiate entities. For class-based entities, the syntax would look as follows:
createEntityStore({
category: 'registration',
entity: () => new Registration(),
projection: RegistrationProjection,
messageStore
})
Note, the entity
parameter now encapsulates how the entities are instantiated.
Reasoning
The proposed change enables more flexible construction of entities and lifts the requirement for all entities to be implemented as classes.
Plan
- [ ] PostgresDocumentStore: update
entity
parameter usage - [ ] EntityStoreSubstitute: receives
entity
parameter usage - [ ] EntityStore: receives
entity
parameter usage