Loading and Validating Decisions
Setup
Dependencies
The following packages are required:
Decision data
Populate your design decisions data source.
As illustrated in the Capturing Design Decisions guide, you can simply create one or more JSON files anywhere in your project.
Directorydata/
Directorydecisions/
- color.json
- space.json
- …
Validation input schemas
Add a script to load decisions and print eventual validation errors.
Directorydata/
- …
Directoryscripts
- validate-decisions.js
We will use the all-in-one createDecisionLoader() providing it with:
- The schemas for the built-in decision models https://github.com/noodlestan/designer/blob/main/packages/libs/designer-schemas/src/constants.ts
- A directory to load decision data from.
- A function to resolve the physical location of node modules containing the schemas.
The loader returns a populated decision store asynchronously.
We can use this store to inspect validation errors.
You can run this directly from the command line:
The output should look something like:
In case of validation errors these will be printed using the formatValidationError()
formatter.
For instance, if we delete the param
attribute from a couple of decision input records:
Inspecting and validating decision values
Schema validation does not check for data errors such as
- missing references between decisions
- color values out of range
These values are only resolved on-demand.
To show all errors you can use the getDecisionStatus()
and formatDecision()
utility functions.
In the following example output, using formatDecision()
default options, the
reference error is expanded after the value.
You can customize the output by providing a second argument to formatDecision()
specifying which columns should be printed and in which order.
The following values are accepted:
status
uuid
name
model
value
error-count
Additionally, the following two items - when provided in whatever order - determine how status and errors are displayed:
status-colors
- print 🟩/🟥 (when absent, prints-/X
instead)error-details
- when present, eventual errors are show in full after each decision
If you wish to filter out decisions that produce valid values, and inspect only the errors, you can adjust your script to the following:
Next steps
The next guides provide step by step instructions on practical uses cases for your decision data: