Skip to content

v2: Read Models + Projections DSL #752

@javiertoledo

Description

@javiertoledo

Parent

Part of #739

Context

Read models currently use class-based metadata:

interface ReadModelMetadata<TReadModel extends ReadModelInterface = ReadModelInterface> {
  readonly class: Class<ReadModelInterface>
  readonly properties: Array<PropertyMetadata>
  readonly authorizer: ReadModelAuthorizer
  readonly before: NonNullable<ReadModelFilterHooks<TReadModel>['before']>
}

Projections are stored separately in config:

projections: Record<EntityName, Array<ProjectionMetadata>>
unProjections: Record<EntityName, Array<ProjectionMetadata>>

Proposed Changes

  1. Create readModel() DSL function in packages/core/src/dsl/read-model.ts
  2. Create projection() DSL function (or integrate with read model)
  3. Update metadata types to remove class references
  4. Update read model reader and searcher to use new metadata
  5. Reimplement decorators as wrappers
  6. Update GraphQL subscription infrastructure

Design Considerations

  • Read models are the query side of CQRS — they need property metadata for GraphQL
  • Projections link entities to read models — the DSL needs a clean way to express this
  • Read models have authorization and before hooks (similar to commands)
  • GraphQL subscriptions use read model classes — needs careful migration

Acceptance Criteria

  • readModel() and projection() DSL functions created
  • Metadata updated to data-oriented format
  • Decorators reimplemented as wrappers
  • GraphQL queries and subscriptions work with new metadata
  • All existing tests pass
  • New tests for DSL definitions

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions