Malla文档

工作流操作

每个工作流步骤:它做什么、在哪里运行,以及它的参数。

用户指南

工作流的每个步骤都运行一个动作。参数可以是固定值或表达式;结果存入 steps.<stepId>。控制流动作(branch、switch、loop、parallel、try/catch、stop、log)在客户端和服务端工作流中都可用。

客户端动作

数据

操作参数结果
Set variable
core.setVar
Sets a variable, or a dotted path inside it (filters.category).
var Variable name or path, without vars.
value New value.
The value that was set.
Reset variable
core.resetVar
Restores a variable to its default value.
var Variable name or path.
The value after the reset.
Refetch query
core.refetch
Runs a client query again and waits for it.
query Query name.
The query state after the run (data, error, updatedAt).
Run operation
core.runOperation
Not available in client workflows: plugin operations need secret keys and run in server workflows.
integrationId Integration id.
operation Plugin operation id, e.g. rest.request.
input? Operation input.
Nothing: the step always fails in a client workflow.
Run server workflow
core.runServerWorkflow
Runs a server workflow called from pages (plugin operations, tables, emails) and waits for its result.
workflow Server workflow with the trigger "Called from pages".
input? Becomes input in that workflow.
The value of its Return step.

控制流

操作参数结果
If / else
core.branch
Runs then when the condition is truthy, otherwise else.
if Condition.
[then] 步骤列表
[else] 步骤列表
The branch that ran: "then" or "else".
For each
core.loop
Runs body once per item, with item and index in scope (outer loop row in parent). At most 1000 items.
items An array (null or undefined runs zero times).
[body] 步骤列表
The number of iterations.
Try / catch
core.tryCatch
Runs try; if a step fails, runs catch with error in scope. Limits and cancellation are not caught.
[try] 步骤列表
[catch] 步骤列表
{ ok: true }, or { ok: false, error } when catch ran.
Switch
core.switch
Runs the steps of the first case whose value equals value, otherwise default.
value Value to match.
cases? Cases { id, label, equals } (at most 32); each id is a branch.
[default] 步骤列表
The id of the case that ran, or "default".
Run in parallel
core.parallel
Runs every lane at the same time and waits for all (at most 8 lanes). A failing lane fails the step.
—{ a: true, b: true, … } once every lane finished.
Break
core.break
Leaves the nearest For each loop. Only inside a loop body.
—Nothing.
Continue
core.continue
Skips to the next item of the nearest For each loop. Only inside a loop body.
—Nothing.
Wait
core.delay
Waits a number of milliseconds (at most 60000).
ms Duration in ms.
The milliseconds waited.
Stop
core.stop
Ends this workflow successfully. Later steps do not run.
—Nothing.
Run workflow
core.runWorkflow
Runs another workflow of the page and waits for it (call depth at most 8, no cycles).
workflow Workflow id.
input? Becomes input in the called workflow.
The called workflow's step results (steps).

导航

操作参数结果
Go to page
core.navigate
Navigates to a page of the site or a URL.
to A page ({ pageId }), a path (/about) or an http(s) URL.
Nothing.
Open URL
core.openUrl
Opens a URL (http, https, mailto, tel or a relative path).
url URL to open.
newTab? Open in a new tab.
Nothing.

界面

操作参数结果
Show toast
core.toast
Shows a short notification.
message Text to show.
variant? Style.
Nothing.
Scroll to element
core.scrollTo
Scrolls an element into view.
node Node id.
behavior? Scroll behavior.
Nothing.
Copy to clipboard
core.copyToClipboard
Copies text to the clipboard.
text Text to copy (non-strings are JSON-encoded).
Nothing.
Play interaction
core.playInteraction
Plays an interaction (animation) of the page.
interaction Interaction id.
Nothing.

访客账户

操作参数结果
Log in visitor
core.login
Signs a site visitor in with email and password and updates user.
仅限已发布的站点。
email Visitor email.
password Visitor password (bind it to a form field).
The signed-in user.
Sign up visitor
core.signup
Creates a visitor account, signs it in and updates user.
仅限已发布的站点。
email Visitor email.
password New password.
name? Display name.
The new user.
Log out visitor
core.logout
Signs the visitor out and resets user.
仅限已发布的站点。
—null.
Send sign-in link
core.sendMagicLink
Emails the visitor a one-time sign-in link (same answer whether or not the account exists).
仅限已发布的站点。
email Visitor email.
true.
Refresh user
core.refreshUser
Reloads the signed-in visitor into user.
仅限已发布的站点。
—The signed-in user, or null.

调试

操作参数结果
Log
core.log
Writes a value to the run log (the browser console on the published site).
value Value to log.
The logged value.

仅限服务端的动作

在服务端工作流中可用,每个步骤可选配置重试。

动作参数作用
HTTP request
core.httpRequest
url, method, headers, body从服务端调用外部 HTTPS URL(禁止私有地址,15 秒,1 MB)。
Send email
core.sendEmail
to, subject, text, html发送一封事务性邮件。
Run operation
core.runOperation
integrationId, operation, input使用集成的密钥运行该集成的一个操作。
Run server workflow
core.runServerWorkflow
workflow, input运行另一个服务端工作流并等待其结果。
Run JavaScript
core.runJs
code, input在沙箱中运行代码,作用域内有 input 和 steps;无网络、无绑定、无密钥。
Return
core.return
value以一个结果结束本次运行;对端点而言即响应体。
Query table
core.tableQuery
table, filter, limit, cursor读取原生表的行。结果:{ rows, nextCursor }。
Get row
core.tableGet
table, id按 id 读取一行。
Insert row
core.tableInsert
table, values插入一行。
Update row
core.tableUpdate
table, id, values更新一行。
Delete row
core.tableDelete
table, id删除一行。
Set visitor roles
core.visitorSetRoles
userId, roles替换访客的角色。角色必须已在站点中存在。
Sleep
core.sleep
duration暂停本次运行,例如 "5 minutes"。会让工作流变为持久化运行。
Wait for event
core.waitForEvent
event, timeout暂停直到该类型的事件到达;结果是事件的载荷。持久化。
Emit event
core.emitEvent
runId, type, payload恢复一个正在等待该事件类型的运行。