Skip to content

Commit

Permalink
feat(schemas): sequences (#128)
Browse files Browse the repository at this point in the history
* feat(schemas): WIP sequence syntax

* feat: conditional validation for sequence wait

* feat: conditional validation for sequence assert

* release(application-schema): 1-2-0

* fix typos and revise logic
  • Loading branch information
eeberhard authored Feb 19, 2024
1 parent 6e51221 commit dcf5706
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 13 deletions.
7 changes: 7 additions & 0 deletions schemas/applications/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@

Release Versions:

- [1-2-0](#120)
- [1-1-2](#112)
- [1-1-1](#111)
- [1-1-0](#110)
- [1-0-0](#100)

## 1-2-0

Version 2-0-0 adds a new syntax to manage sequential events as an array of steps to be handled in order. Sequence steps
are either standard state events or conditional blocks; the latter are used either to wait for a condition, predicate
or fixed time interval, or to assert the current value of a condition or predicate.

## 1-1-2

Version 1-1-2 allows a single item in the list of transitions of lifecycle events to be just the transition keyword
Expand Down
14 changes: 10 additions & 4 deletions schemas/applications/schema/application.schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "/1-1-2/application.schema.json",
"$id": "/1-2-0/application.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "YAML Application Description",
"description": "An AICA application graph description using YAML syntax.",
Expand All @@ -24,6 +24,9 @@
"switch_controllers": {
"$ref": "events/switch_controllers.schema.json"
},
"sequence": {
"$ref": "events/sequence.schema.json"
},
"position": {
"$ref": "common/position.schema.json"
}
Expand All @@ -32,14 +35,17 @@
"hardware": {
"$ref": "hardware.schema.json"
},
"conditions": {
"$ref": "conditions.schema.json"
},
"components": {
"$ref": "components.schema.json"
},
"buttons": {
"$ref": "buttons.schema.json"
},
"conditions": {
"$ref": "conditions.schema.json"
},
"sequences": {
"$ref": "sequences.schema.json"
}
}
}
10 changes: 2 additions & 8 deletions schemas/applications/schema/conditions.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
"$ref": "events/identifiers/component.schema.json"
},
"predicate": {
"title": "Predicate Name",
"description": "The name of a predicate associated with the component",
"type": "string",
"pattern": "^[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]$"
"$ref": "events/identifiers/predicate.schema.json"
}
},
"oneOf": [
Expand Down Expand Up @@ -171,10 +168,7 @@
"$ref": "events/identifiers/component.schema.json"
},
"predicate": {
"title": "Predicate Name",
"description": "The name of a predicate associated with the component",
"type": "string",
"pattern": "^[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]$"
"$ref": "events/identifiers/predicate.schema.json"
}
},
"required": [
Expand Down
5 changes: 4 additions & 1 deletion schemas/applications/schema/events.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Events",
"description": "Events",
"description": "A description of application events to be triggered",
"type": "object",
"additionalProperties": false,
"properties": {
Expand All @@ -25,6 +25,9 @@
},
"switch_controllers": {
"$ref": "events/switch_controllers.schema.json"
},
"sequence": {
"$ref": "events/sequence.schema.json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Condition Name",
"description": "The name of a condition",
"type": "string",
"pattern": "(^[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]$)|(^[a-zA-Z]$)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Predicate Name",
"description": "The name of a predicate",
"type": "string",
"pattern": "^[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]$"
}
55 changes: 55 additions & 0 deletions schemas/applications/schema/events/sequence.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Manage a sequence",
"description": "Start, restart or abort a sequence",
"oneOf": [
{
"type": "array",
"minItems": 1,
"items": {
"$ref": "#/$defs/sequence_object"
}
},
{
"$ref": "#/$defs/sequence_object"
}
],
"$defs": {
"sequence_object": {
"title": "Sequence event",
"type": "object",
"additionalProperties": false,
"properties": {
"start": {
"description": "Name of the sequence to start",
"type": "string"
},
"restart": {
"description": "Name of the sequence to restart",
"type": "string"
},
"abort": {
"description": "Name of the sequence to abort",
"type": "string"
}
},
"oneOf": [
{
"required": [
"start"
]
},
{
"required": [
"restart"
]
},
{
"required": [
"abort"
]
}
]
}
}
}
177 changes: 177 additions & 0 deletions schemas/applications/schema/sequences.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "Sequences",
"description": "A description of sequences used to trigger events events in a specific order",
"type": "object",
"additionalProperties": false,
"patternProperties": {
"(^[a-zA-Z][a-zA-Z0-9_]*[a-zA-Z0-9]$)|(^[a-zA-Z]$)": {
"title": "Sequence",
"description": "A named event sequence",
"type": "array",
"items": {
"oneOf": [
{
"$ref": "events.schema.json"
},
{
"title": "Wait",
"additionalProperties": false,
"properties": {
"wait": {
"oneOf": [
{
"$ref": "#/$defs/wait_for_condition"
},
{
"$ref": "#/$defs/wait_for_predicate"
},
{
"$ref": "#/$defs/wait_for_time"
}
]
}
},
"required": [
"wait"
]
},
{
"title": "Assert",
"additionalProperties": false,
"properties": {
"assert": {
"oneOf": [
{
"$ref": "#/$defs/assert_condition"
},
{
"$ref": "#/$defs/assert_predicate"
}
]
}
},
"required": [
"assert"
]
}
]
}
}
},
"$defs": {
"seconds": {
"title": "Seconds to wait",
"description": "The duration to wait in seconds",
"type": "number"
},
"timeout": {
"type": "object",
"additionalProperties": false,
"properties": {
"seconds": {
"$ref": "#/$defs/seconds"
},
"events": {
"$ref": "events.schema.json"
}
},
"required": [
"seconds",
"events"
]
},
"wait_for_condition": {
"title": "Wait for Condition",
"description": "Wait until a condition is true with an optional timeout to abort the sequence and handle breakout events",
"type": "object",
"additionalProperties": false,
"properties": {
"condition": {
"$ref": "events/identifiers/condition.schema.json"
},
"timeout": {
"$ref": "#/$defs/timeout"
}
},
"required": [
"condition"
]
},
"wait_for_predicate": {
"title": "Wait for Predicate",
"description": "Wait until a component predicate is true with an optional timeout to abort the sequence and handle breakout events",
"type": "object",
"additionalProperties": false,
"properties": {
"component": {
"$ref": "events/identifiers/component.schema.json"
},
"predicate": {
"$ref": "events/identifiers/predicate.schema.json"
},
"timeout": {
"$ref": "#/$defs/timeout"
}
},
"required": [
"component",
"predicate"
]
},
"wait_for_time": {
"title": "Wait",
"description": "Wait for a defined time",
"type": "object",
"additionalProperties": false,
"properties": {
"seconds": {
"$ref": "#/$defs/seconds"
}
},
"required": [
"seconds"
]
},
"assert_condition": {
"title": "Assert Condition",
"description": "Assert that a condition is true or else abort the sequence and handle breakout events",
"type": "object",
"additionalProperties": false,
"properties": {
"condition": {
"$ref": "events/identifiers/condition.schema.json"
},
"else": {
"description": "A description of application events to be triggered if the assertion fails",
"$ref": "events.schema.json"
}
},
"required": [
"condition"
]
},
"assert_predicate": {
"title": "Assert Predicate",
"description": "Assert that a component predicate is true or else abort the sequence and handle breakout events",
"type": "object",
"additionalProperties": false,
"properties": {
"component": {
"$ref": "events/identifiers/component.schema.json"
},
"predicate": {
"$ref": "events/identifiers/predicate.schema.json"
},
"else": {
"description": "A description of application events to be triggered if the assertion fails",
"$ref": "events.schema.json"
}
},
"required": [
"component",
"predicate"
]
}
}
}

0 comments on commit dcf5706

Please sign in to comment.