Skip to content

v2: Review and harden command DSL design #741

Description

@javiertoledo

Parent

Part of #739

Context

The command DSL (PR #733) is the first concept migrated. Before proceeding with other concepts, we should review the design and fix any issues so the pattern is solid for reuse.

Issues Identified

1. Side-effectful registration

The command() function both creates metadata AND registers it as a side effect via Magek.configureCurrentEnv(). Consider separating creation from registration.

2. methods field is confusing for DSL users

The methods property on CommandMetadata contains return type information from @returns decorator. For DSL users, providing a methods array with a fake "handle" method entry to declare a return type is awkward. A returnType option would be cleaner.

3. nonExposedGraphQLMetadataKey handled separately

In the decorator, non-exposed fields require a second Magek.configureCurrentEnv() call. This could be part of CommandMetadata itself.

4. authorize option accepts heterogeneous types

The authorize option accepts 'all' | Array<Class<RoleInterface>> | CommandAuthorizer. For the DSL, it might be cleaner to just accept a function, with helpers like authorizeAll() and authorizeRoles([...]).

5. Name duplication

In commandHandlers[name] = { name: ... }, the name is both the key and in the metadata.

Acceptance Criteria

  • Identify which issues to fix now vs. defer
  • Fix critical design issues before migrating more concepts
  • Ensure the pattern is clean for reuse in event(), entity(), etc.
  • Update tests for any changes

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions