Widgets

Based on the flow-based programming idea, YAO encapsulates a series of atomic operations into processes; these processes can be called in YAO DSL or JavaScript scripts.

According to business characteristics, YAO defines a set of YAO DSL to describe functional modules such as data structure, data flow, API interface, concurrent tasks, scheduled tasks, and Socket services. These functional modules are defined as Widgets.

When the engine starts, it is parsed into a set of API interfaces and a set of handlers according to the Widget logic. In application development, by writing a Widget DSL to describe the differences, the corresponding functional modules can be implemented, thereby improving coding efficiency.

YAO DSL and YAO Widget support the definition of extensions according to their own business characteristics, which makes it easier to build a low-code platform based on YAO that meets their own business characteristics.

YAO abstracts common function modules into widgets, describes differences through YAO DSL, and quickly replicates various functions.

During development, if you develop a similar function module, you need to copy and paste the existing functions and replace the differences in batches.

YAO provides a new way to use DSL to describe the difference content and quickly "copy and paste" a function module to improve development efficiency.

Widget Model

View Documentation

Add models/ccategory.mod.json file and write the following:

View source code

Use yao migrate -n category to migrate data table files

Widget Table

View Documentation

Create a new category table tables/category.tab.json code:

View source code

Widget Flows

View Documentation

New flows/category.flow.json

{
"label": "Category Tree",
"version": "1.0.0",
"description": "Category Tree",
"nodes": [
{
"name": "Category",
"engine": "xiang",
"query": {
"select": ["id", "name", "name as label", "id as value", "parent_id"],
"wheres": [{ ":deleted_at": "deleted", "=": null }],
"from": "category",
"limit": 1000
}
},
{
"name": "Category Tree",
"process": "xiang.helper.ArrayTree",
"args": ["{{$res.category}}", { "parent": "parent_id" }]
}
],
"output": "{{$res.category tree}}"
}

##Widget API

View Documentation

New apis/select.http.json

{
"name": "Drop down search",
"version": "1.0.0",
"description": "Drop down search",
"guard": "bearer-jwt",
"group": "select",
"paths": [
{
"path": "/category",
"method": "GET",
"process": "flows.category",
"in": [],
"out": {
"status": 200,
"type": "application/json"
}
}
]
}

Run yao start, visit 127.0.0.1:5099/api/select/category

Widget Task

View Documentation

  • NewFile directory /tasks/task.js:
{
"name": "Test task",
"worker_nums": 10,
"attempts": 3,
"attempt_after": 200,
"timeout": 2,
"size": 1000,
"process": "scripts.task.Send",
"event": {
"next": "scripts.task.NextID",
"add": "scripts.task.OnAdd",
"success": "scripts.task.OnSuccess",
"error": "scripts.task.OnError",
"progress": "scripts.task.OnProgress"
}
}
ParametersMeaningDescription
nameTask name
worker_numsSpecifies the number of processes
attemptsNumber of failed retries
attempt_afterretry interval
timeouttimeout period
processThe process bound to this task
nextGenerate task unique id
addMethod triggered when a task is added
successTrigger method after successful task processing
errorTrigger method after task failure
progressCalled during task processing

New scripts/task.js

View source code

New route apis/task.http.json

{
"name": "Task",
"version": "1.0.0",
"description": "Task",
"guard": "",
"group": "task",
"paths": [
{
"path": "/task",
"method": "GET",
"process": "scripts.test.task",
"in": [],
"out": {
"status": 200,
"type": "application/json"
}
}
]
}

New test function scripts/test.js

function task() {
for (i = 1; i < 100; i++) {
Process("tasks.test.Add", "Enter task" + i);
}
}

Run the project yao start and visit the url 127.0.0.1:5099/api/task/task to see the print information

Widget Schedule

View Documentation

  • Create a new /schedules/test.sch.json, the writing method of the scheduled task is the same as the Linux crontab, the code:
{
"name": "Called every minute",
"schedule": "*/1 * * * *",
"process": "scripts.schedules.Send",
"args": []
}
  • New scripts/schedules.js code:
function Send() {
console.log("Enter the scheduled task!");
}

Execute yao start and wait for 1 minute to see the print information

Widgets

Based on the flow-based programming idea, YAO encapsulates a series of atomic operations into processes; these processes can be called in YAO DSL or JavaScript scripts.

According to business characteristics, YAO defines a set of YAO DSL to describe functional modules such as data structure, data flow, API interface, concurrent tasks, scheduled tasks, and Socket services. These functional modules are defined as Widgets.

When the engine starts, it is parsed into a set of API interfaces and a set of handlers according to the Widget logic. In application development, by writing a Widget DSL to describe the differences, the corresponding functional modules can be implemented, thereby improving coding efficiency.

YAO DSL and YAO Widget support the definition of extensions according to their own business characteristics, which makes it easier to build a low-code platform based on YAO that meets their own business characteristics.

YAO abstracts common function modules into widgets, describes differences through YAO DSL, and quickly replicates various functions.

During development, if you develop a similar function module, you need to copy and paste the existing functions and replace the differences in batches.

YAO provides a new way to use DSL to describe the difference content and quickly "copy and paste" a function module to improve development efficiency.

Widget Model

View Documentation

Add models/ccategory.mod.json file and write the following:

View source code

Use yao migrate -n category to migrate data table files

Widget Table

View Documentation

Create a new category table tables/category.tab.json code:

View source code

Widget Flows

View Documentation

New flows/category.flow.json

{
"label": "Category Tree",
"version": "1.0.0",
"description": "Category Tree",
"nodes": [
{
"name": "Category",
"engine": "xiang",
"query": {
"select": ["id", "name", "name as label", "id as value", "parent_id"],
"wheres": [{ ":deleted_at": "deleted", "=": null }],
"from": "category",
"limit": 1000
}
},
{
"name": "Category Tree",
"process": "xiang.helper.ArrayTree",
"args": ["{{$res.category}}", { "parent": "parent_id" }]
}
],
"output": "{{$res.category tree}}"
}

##Widget API

View Documentation

New apis/select.http.json

{
"name": "Drop down search",
"version": "1.0.0",
"description": "Drop down search",
"guard": "bearer-jwt",
"group": "select",
"paths": [
{
"path": "/category",
"method": "GET",
"process": "flows.category",
"in": [],
"out": {
"status": 200,
"type": "application/json"
}
}
]
}

Run yao start, visit 127.0.0.1:5099/api/select/category

Widget Task

View Documentation

  • NewFile directory /tasks/task.js:
{
"name": "Test task",
"worker_nums": 10,
"attempts": 3,
"attempt_after": 200,
"timeout": 2,
"size": 1000,
"process": "scripts.task.Send",
"event": {
"next": "scripts.task.NextID",
"add": "scripts.task.OnAdd",
"success": "scripts.task.OnSuccess",
"error": "scripts.task.OnError",
"progress": "scripts.task.OnProgress"
}
}
ParametersMeaningDescription
nameTask name
worker_numsSpecifies the number of processes
attemptsNumber of failed retries
attempt_afterretry interval
timeouttimeout period
processThe process bound to this task
nextGenerate task unique id
addMethod triggered when a task is added
successTrigger method after successful task processing
errorTrigger method after task failure
progressCalled during task processing

New scripts/task.js

View source code

New route apis/task.http.json

{
"name": "Task",
"version": "1.0.0",
"description": "Task",
"guard": "",
"group": "task",
"paths": [
{
"path": "/task",
"method": "GET",
"process": "scripts.test.task",
"in": [],
"out": {
"status": 200,
"type": "application/json"
}
}
]
}

New test function scripts/test.js

function task() {
for (i = 1; i < 100; i++) {
Process("tasks.test.Add", "Enter task" + i);
}
}

Run the project yao start and visit the url 127.0.0.1:5099/api/task/task to see the print information

Widget Schedule

View Documentation

  • Create a new /schedules/test.sch.json, the writing method of the scheduled task is the same as the Linux crontab, the code:
{
"name": "Called every minute",
"schedule": "*/1 * * * *",
"process": "scripts.schedules.Send",
"args": []
}
  • New scripts/schedules.js code:
function Send() {
console.log("Enter the scheduled task!");
}

Execute yao start and wait for 1 minute to see the print information