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
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 viaMagek.configureCurrentEnv(). Consider separating creation from registration.2.
methodsfield is confusing for DSL usersThe
methodsproperty onCommandMetadatacontains return type information from@returnsdecorator. For DSL users, providing amethodsarray with a fake "handle" method entry to declare a return type is awkward. AreturnTypeoption would be cleaner.3.
nonExposedGraphQLMetadataKeyhandled separatelyIn the decorator, non-exposed fields require a second
Magek.configureCurrentEnv()call. This could be part of CommandMetadata itself.4.
authorizeoption accepts heterogeneous typesThe authorize option accepts
'all' | Array<Class<RoleInterface>> | CommandAuthorizer. For the DSL, it might be cleaner to just accept a function, with helpers likeauthorizeAll()andauthorizeRoles([...]).5. Name duplication
In
commandHandlers[name] = { name: ... }, the name is both the key and in the metadata.Acceptance Criteria