Skip to content

Bootstrap-time validation for custom command/guard registries #19

Description

@camcima

Background

WorkflowValidationOptions currently accepts Set<string> for knownCommandNames and knownGuardNames. This means bootstrap-time validation of command and guard refs only works when callers can enumerate all registered names — i.e., when using the convenience commands / guards arrays in WorkflowModule.

When a caller supplies their own commandRegistry or guardRegistry (e.g., a DI-backed custom implementation), validation is skipped. Unresolved refs surface only when the event fires, as a runtime WorkflowError.

PR #18 documented this limitation for guards in docs/nestjs-integration.md (see commit 33040e2). Commands have the same shape but have not been called out yet.

Proposal

Extend WorkflowValidationOptions so each known-name option accepts either a Set<string> (today) or a predicate (name: string) => boolean. The validator branches on type:

  • Set<string>set.has(name) (current behavior)
  • (name) => boolean → call the predicate

Then in WorkflowModule, when commandRegistry / guardRegistry is supplied, pass (name) => registry.has(name) as the validation option. Both registry interfaces already expose has(name), so no new surface area is needed there.

This restores bootstrap-time validation parity between the array-based and registry-based forms, without requiring a getRegisteredNames() method on the registry interfaces.

Scope

  • packages/duraflows-core/src/validation/workflow-validator.ts — widen the option type and branch on it
  • packages/duraflows-nestjs/src/workflow.module.ts — wire the predicate when the custom registry path is taken (both forRoot and forRootAsync)
  • Tests for both code paths
  • Update docs/nestjs-integration.md to drop the limitation note added in 33040e2

Notes

Discovered during Copilot's review of PR #18 (event guards). Two of Copilot's comments touched this: one inline comment on docs/nestjs-integration.md:296, and one suppressed comment on workflow.module.ts:132.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions