LetsFlow
  • Introduction
  • Tutorial
    • The basics
    • A handshake
    • A conversation
    • A proper introduction
    • Group meeting
    • Quote
  • Cookbook
  • ENGINE
    • Installation
    • Authentication
    • API
    • Services
      • Configuration
      • Messaging
        • ZeroMQ
        • AMQP 0-9-1
        • Webhook
      • Engine service
  • Integration
    • Frontend
      • React
      • Angular
      • Vue
      • Svelte
    • Backend
  • Reference
    • Scenario
      • Actor
      • Action
        • Update instruction
      • State
        • Transition
          • Log
        • Notify
      • Data function
    • Schema
    • Process
      • Current state
      • Previous log
      • Prediction
      • Events
        • Instantiate event
        • Action event
        • Timeout event
  • Libraries
    • Core library
    • JMESPath
    • Test suite
      • Given
      • When
      • Then
        • Assert state
        • Assert actor
        • Assert variable
        • Assert service
        • Assert event
      • Customize
  • Advanced topics
    • Deep integration
    • Decentralized workflows
    • Custom JMESPath functions
    • Custom YAML tags
Powered by GitBook
On this page
  • <ref>
  • <tpl>
  • <select>

Was this helpful?

  1. Reference
  2. Scenario

Data function

PreviousNotifyNextSchema

Last updated 1 month ago

Was this helpful?

Data functions allow you to dynamically set properties of a state or actions when they are instantiated using data from the projected process.

Functions are applied before a state transition to the executed action and the possible state transitions.

After a state transition, functions are applied to create the of the process. This includes the list of actions that can be executed in the state.

<ref>

Apply a JMESPath query to the process. You can retrieve and transform any part of the process, including the scenario and events.

actors:
  team:
    role: team
  client:
    properties:
      name: string
      email: !format email

actions:
  update_client:
    response: !ref scenario.actors.client
    update:
      set: actors.client
      value: !ref current.response | { name: name, email: email }

states:
  initial:
    transitions:
      - on: update_client
        by: team
        goto: ~
      - on: approve
        by: client
        if: !ref actors.client.email
        goto: (approved)
      - on: reject
        by: client
        goto: (rejected)
{
  "actors": {
    "team": {
      "role": "team"
    },
    "client": {
      "properties": {
        "name": "string",
        "email": {
          "type": "string",
          "format": "email"
        }
      }
    }
  },
  "actions": {
    "update_client": {
      "response": {
        "<ref>": "scenario.actors.client"
      },
      "update": {
        "set": "actors.client",
        "value": {
          "<ref>": "current.response | { name: name, email: email }"
        }
      }
    }
  },
  "states": {
    "initial": {
      "transitions": [
        {
          "on": "update_client",
          "by": "team",
          "goto": null
        },
        {
          "on": "approve",
          "by": "client",
          "if": {
            "<ref>": "actors.client.email"
          },
          "goto": "(approved)"
        },
        {
          "on": "reject",
          "by": "client",
          "goto": "(rejected)"
        }
      ]
    }
  }
}

It's important to know and understand how to use JMESPath expressions to unlock the full potential of LetsFlow. You can find more examples in the JMESPath documentation.

<tpl>

When a function receives a simple string, it is treated as a Mustache template, with the process itself serving as the data (also known as the Mustache view).

actors:
  admin:
    role: admin
  client_*:
    properties:
      name: string
      approved: boolean

actions:
  send_sms:
    $schema: https://schemas.example.com/sms
    message: !tpl Hello {{ current.actor.name }}

states:
  main:
    instructions:
      admin: !tpl
        template: "{{#clients}}{{name}}: {{approved}}{{/}}"
        view: !ref "{ clients: actors.* | @[?role==null] }"
{
  "actors": {
    "admin": {
      "role": "admin"
    },
    "client_*": {
      "properties": {
        "name": "string",
        "approved": "boolean"
      }
    }
  },
  "actions": {
    "send_sms": {
      "$schema": "https://schemas.example.com/sms",
      "message": {
        "<tpl>": "Hello {{ current.actor.name }}"
      }
    }
  },
  "states": {
    "instructions": {
      "admin": {
        "<tpl>": {
          "template": "{{#clients}}{{name}}: {{approved}}{{/}}",
          "view": {
            "<ref>": "{ clients: actors.* | @[?role==null] }"
          }
        }
      }
    }
  }
}

You can explicitly specify both the template and the view for more flexibility. This allows you to apply a JSON query using <ref> to filter or transform the data before rendering the template.

!tpl
  template: string
  view: object
  partials: map of key => template

<select>

The select data function picks one of the options based on value.

The selection value is specified as $. The default value is specified with the * key. The other properties is used as map of option ⇒ value.

states:
  (cancelled):
    description: !select
      $: !ref previous[-1].actor.key
      client: Cancelled by the client
      team: !tpl Could not be completed because {{reason}}
      '*': Aborted
{
  "states": {
    "cancelled": {
      "description": {
        "<select>": {
          "$": {
            "<ref>": "previous[-1].actor.key"
          },
          "client": "Cancelled by the client",
          "team": {
            "<tpl>": "Could not be completed because {{reason}}"
          },
          "*": "Aborted"
        }
      }
    }
  }
}

The selection value must be a string, number, or boolean. For a boolean value use the keys true and false.

If no default value is specified, the selected value will be null if there's no match.

Parse text as a template.

current state
JMESPath
Mustache