Skip to content

Enhancements to Decorators and Workflow Metadata Management

Compare
Choose a tag to compare
@pilsy pilsy released this 16 Sep 06:48
· 96 commits to main since this release
a023bc1

Release Notes

Enhancements to Decorators and Workflow Metadata Management

In this release, we've made significant improvements to the way decorators handle metadata registration for workflows. These changes ensure robust, isolated metadata management, avoiding cross-contamination and correctly registering workflow queries, signals, and properties. The updates will enhance the developer experience and provide more predictable behavior in Temporal workflows.

Key Changes:
  1. Improved Property Decorator for Workflow Properties:

    • The Property decorator now directly uses the propertyKey (name of the property) to define both queryName and signalName. This ensures that queries and signals are uniquely and clearly associated with the properties they manage.
    • The decorator utilizes Reflect metadata to safely register and retrieve metadata on the class or instance, ensuring no interference between classes or prototypes.
  2. Refined Getter and Setter Registration with Get and Set Decorators:

    • Get and Set decorators now properly define and manage metadata for getters and setters, using Reflect to avoid potential prototype pollution.
    • Each decorated property is registered with a unique getter and setter, preventing any unwanted sharing of state or behavior across different workflow classes.
  3. Consistent Metadata Keys and Usage:

    • Introduced constants for metadata keys (PROPERTY_METADATA_KEY, GETTER_METADATA_KEY, SETTER_METADATA_KEY) to maintain consistency across the codebase.
    • The metadata keys are used with Reflect API to ensure that metadata is correctly isolated and retrieved for each specific class or instance.
  4. Robust Binding of Queries, Signals, and Properties in Workflows:

    • Improved binding functions (bindProperties, bindQueries, bindSignals) to correctly collect and bind metadata using the Reflect API. This guarantees that all queries, signals, and properties are properly registered during the workflow initialization phase.
    • Enhanced error handling and logging to provide more informative error messages if queries or signals are not registered correctly.
  5. Enhanced Workflow Execution Reliability:

    • The improvements ensure that workflows correctly register handlers for all expected signals and queries, avoiding issues such as QueryNotRegisteredError.
    • Added robust metadata collection and binding logic to support complex workflows with dynamic state management and signal/query handling.
Benefits:
  • Increased Stability and Predictability: The changes ensure that workflows operate as expected without unintended side effects due to improperly registered signals or queries.
  • Better Developer Experience: Clearer, more predictable behavior when using decorators, making it easier for developers to define and manage Temporal workflows.
  • Improved Metadata Management: Using Reflect for metadata ensures a clean, isolated metadata state, avoiding conflicts between classes or instances.