Documentation: Validations


Please support us to improve our service. We would like to use statistics anonymously.

We do not pass on your data! You can find more information in our privacy policy.

Decline

< Back to documentation

Base concept

In Flowy, validations are a powerful feature that ensures the integrity of the data that flows into your system. They allow you to define specific constraints and rules for your data, such as data type, minimum and maximum values, length requirements, and more.

While validations in Flowy are designed to enforce data integrity by checking that the input data meets a set of predefined rules, it's important to understand what they are not designed to do. One key point to remember is that validations are not responsible for checking permissions or access to data.

Data access permissions typically relate to determining whether a user or system has the authority to view, modify, or delete certain data. This is a crucial aspect of data security and is typically managed by an access control system or mechanism. For instance, you might have rules stating that only administrators can delete user accounts, or only the creator of a record can update it.

While Flowy validations can ensure that a user provides a valid ID for an account they wish to update, for example, they don't check whether that user actually has permission to update that account. This responsibility lies with the application's authorization or access control system.

In short, while validations are a powerful tool for maintaining data consistency and integrity, they work in tandem with other mechanisms such as access control systems to ensure overall data security and proper application functioning. Each has its own important role to play and should be implemented and maintained with care.

Data types and rules

Validations support the following data types:

  • Array
  • Boolean
  • Double
  • File JSON
  • File XML
  • Float
  • Integer
  • Long
  • Number: "support" for both integer and float values within the same field
  • Object: allow the reference to a different validation rule
  • String
  • Timestamp

Depending on the data type, it is possible to define additional rules:

  • Array: member data type
  • File data type: maximum size in bytes
  • Float/Integer/Number: minimum and maximum values
  • Object: reference to validation rule
  • String: minimum and maximum length as well as regex

Fields can be set as required or mandatory independently of their data type.

Streamline the validation process by combining one or multiple validations. With this feature, all combined rules are thoroughly examined.

Inheritance using the Object Data Type

One of the powerful features of Flowy validations is the ability to create inheritance-like structures using the Object data type. This is particularly useful when dealing with complex data schemas, where certain validation rules are shared across multiple types of data inputs.

Let's take an example. Assume we have a basic validation rule that checks for "name" and "email". This rule can be considered as a "base" rule, and it might be used for various entities in your application, such as users, companies, or contacts.

Now, suppose we have another entity – "employee" – which has all the attributes of a "user" (i.e., name and email), but also includes additional fields, such as "employeeId". Instead of creating a new validation rule from scratch, you can create an "employee" validation rule and reference the "user" validation rule as an "Object". Then, you can simply add the additional rules for the "employeeId".

This "Object" data type allows you to reuse and extend existing validation rules, resulting in less redundant code and easier maintenance. This feature of Flowy validations enables you to create more efficient, organized, and flexible validation schemas.

Common patterns

Create and Update

There is a very common pattern in Flowy validations, especially when dealing with Create and Update operations.

Typically, when you're creating a new record certain fields are required. These fields are defined and validated during the Create operation to ensure we have all the necessary data to create a new record.

However, when it comes to the Update operation, we essentially need the same information. After all, you're likely updating the same fields as used during creation. But there's one crucial difference: in order to know which user to update, we need an additional piece of information - typically an ID.

So for the Update operation, your validation would include all the fields from the Create operation, plus the additional ID field. This ensures that you not only have the right data to update a record but also the necessary information to identify which record to update.

This pattern is common across many systems and operations, not just in Flowy. It's a powerful way of ensuring data integrity while maximizing code and validation reuse. By understanding and using this pattern, you can make your workflow automation more efficient and reliable.

In Flowy, you can streamline this process by combining validations. You can define all the necessary fields and values within a Create validation, reuse it within the Update validation, and extend it with the necessary ID field. This makes your validations more efficient and easier to maintain, as you don't have to define the same rules twice.