@coda-console/protocol 5.12.0 → 5.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/README.md +7 -1
- package/package.json +1 -1
- package/workflow/actions.json +4 -2
- package/workflow/moddle.json +31 -4
- package/workflow/options.json +24 -0
- package/workflow/values.json +29 -3
- package/workflow.mjs +34 -11
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 5.14.0 — 2026-11-13
|
|
6
|
+
|
|
7
|
+
- 流程方言加挂点:流程可写多个 `coda:join`(`hook` 必填,`name`、`detail`、`default` 为 true/false、`order` 为整数,同一流程 hook 不重复),流程属性加 `coda:mergedOnly`(只运行已合并进默认分支的提交,由流程自己声明)。动作加 `hook-joiners`(参数 `hook`、`commit`),`run-workflows` 加参数 `hook`、`only`。只加写法,`coda:kind` 与 `coda:deploy` 不变(Coda #2521 第 2 步)。
|
|
8
|
+
- 报错位置里 `coda:join` 以 hook 称呼。
|
|
9
|
+
- `coda:mergedOnly` 只认 true、false:与字段的布尔、整数属性一样先按文字读、核对拼写后才换成布尔值,写错的读流程时拒绝,不会被当成 false 放开只跑已合并提交的限制。
|
|
10
|
+
|
|
11
|
+
## 5.13.0 — 2026-11-13
|
|
12
|
+
|
|
13
|
+
- 流程方言的答复加 `coda:optionList`:`value` 是表达式,任务打开时读出一组勾选项,在它写的位置展开,与 `coda:option` 按写的顺序排(moddle 里两者同属答复的 `options`,类型 `ChoiceOption`)。打开后的整组由新的 `workflow/options.json` 定义(`{ id, name, detail?, default? }`,最多 12 项,id 不重复),`optionsProblem` 检查它,`CODA_OPTIONS` 导出同一份 schema。只加写法,已有流程不变(Coda #2521 第 1 步)。
|
|
14
|
+
|
|
5
15
|
## 5.12.0 — 2026-11-13
|
|
6
16
|
|
|
7
17
|
- 圈定第三方稳定面:随包发布 53 条清单路径及页面接口、外观清单,各从 revision 1 起;增加只增不减、schema 路径可达与第三方清单样本校验,PR 对目标分支、发布前对 npm latest 检查。补充清单的 displayName、version;稳定面只增不减,内部面删改不升主版本(coda#2463)。
|
package/README.md
CHANGED
|
@@ -14,6 +14,10 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
|
|
|
14
14
|
|
|
15
15
|
读取定义时原有的 Coda 结构规则已全部纳入协议。Coda 接入 1.8.0 后,`parseBpmn` 只需调用 `readWorkflow`,再把 `root` 编译成引擎、任务、调度和图所需的结构;运行时才能知道的表达式结果、动态字段引用、调度设置实际值及能力是否存在,仍由宿主在运行时检查。
|
|
16
16
|
|
|
17
|
+
流程方言的 **挂点**是流程之间互相找到的方式:被调用的流程在自己的 extensionElements 里写 `<coda:join hook name? detail? default? order?/>` 加入一个挂点(`hook` 是小写字母开头的名字,一个流程每个挂点只加入一次),`name`、`detail` 是它作为勾选项时的名字与说明,`default` 是否默认勾上(只写 true 或 false:挂点的列表在任何运行之外读出),`order` 是整数,小的在前。宿主用动作 `hook-joiners` 列出一个挂点的加入者(勾选项形状,可直接给 `coda:optionList`),用 `run-workflows` 的 `hook` 调用它们,`only` 只调用勾中的几个。挂点名是普通字符串,传哪些参数、怎么选由声明它的宿主写在自己的说明里。流程属性 `coda:mergedOnly` 说它是否只运行已合并进默认分支的提交。
|
|
18
|
+
|
|
19
|
+
流程方言的 **勾选项**写在答复(外层的 `coda:choice`)里:`coda:option` 是一项,`coda:optionList` 的 `value` 是一个表达式,任务打开时读出一组勾选项(列表或它的 JSON),在它写的位置展开,两者按写的顺序排。`<coda:options>` 不是它的写法(那个名字是答复自己的勾选项集合)。定义里每个 `coda:optionList` 算一项;打开后的整组由 `workflow/options.json` 定义:每项是 `{ id, name, detail?, default? }`(`default` 为布尔值,没有 `shown`),最多 12 项,id 不重复。`optionsProblem(options, where)` 检查一个答复打开后的整组(静态项已求值、各组已展开),合法时返回 `null`,否则返回「位置:说明」;表达式求值与展开仍由 Coda 完成。
|
|
20
|
+
|
|
17
21
|
流程方言的 **卡片字段**由 `workflow/fields.json` 定义:七种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
|
|
18
22
|
|
|
19
23
|
脚本步骤的 **工作副本** 由 `coda:source` 声明:这一步在哪个工作副本目录里跑,写本机上的绝对路径,可以写 FEEL 表达式。它只用于 `coda:checkout="false"` 的步骤:在本机跑就在那个目录里就地跑,不检出提交;交给别的执行环境时,由调用方给这个目录所在的工作副本拍快照(含未提交、未跟踪的改动,不含忽略的文件),对方检出快照、在对应的子目录里跑。协议里 `coda/executor@1` 的 `execute` 输入已有 `source.snapshot` 与 `workingDirectory`,交给别台时就用这两项,执行器协议本身不改。
|
|
@@ -61,7 +65,7 @@ invocationResponseProblem({ run: { kind: 'coda/run@1', id: 'run-1' } });
|
|
|
61
65
|
```
|
|
62
66
|
|
|
63
67
|
```js
|
|
64
|
-
import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, CODA_FIELDS } from '@coda-console/protocol/workflow';
|
|
68
|
+
import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, optionsProblem, CODA_FIELDS, CODA_OPTIONS } from '@coda-console/protocol/workflow';
|
|
65
69
|
|
|
66
70
|
// 一份流程(名字不带 .bpmn,用在说明里):方言里都有就返回 null,否则是一句说明。
|
|
67
71
|
const problem = await workflowProblem(readFileSync('.coda/workflows/deploy.bpmn', 'utf8'), 'deploy');
|
|
@@ -70,6 +74,8 @@ const { root } = await readWorkflow(source, 'deploy');
|
|
|
70
74
|
// 任务打开、接受答复时检查已求值的字段,不填默认值,不执行表达式。
|
|
71
75
|
fieldProblem({ type: 'text', id: 'name', label: '名称' }, 'ask 的字段 name');
|
|
72
76
|
fieldsProblem(JSON.parse(fieldsJSON), 'ask');
|
|
77
|
+
// 一个答复打开后的整组勾选项(静态项已求值、coda:optionList 已展开)。
|
|
78
|
+
optionsProblem([{ id: 'deploy', name: '部署', default: false }], 'approve 的答复 merge');
|
|
73
79
|
// CODA_FIELDS 是同一份 fields.json,也可从 @coda-console/protocol/workflow/fields.json 导入。
|
|
74
80
|
```
|
|
75
81
|
|
package/package.json
CHANGED
package/workflow/actions.json
CHANGED
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
"description": "请运行主体的会话的 Agent 压缩上下文(_coda/session/compact,见 docs/agent-protocol.md),从不失败:没压缩就写明原因"},
|
|
12
12
|
"hold-group": {"params": ["group", "capacity", "borrow", "exclusive"],
|
|
13
13
|
"description": "为这一步所在的那一段排进并发组 group,离开这一段或运行结束才放开;borrow 为 only 只借不排、no 从不借,exclusive 为 true 占满整组"},
|
|
14
|
-
"run-workflows": {"params": ["kind", "commit", "inputs"],
|
|
15
|
-
"description": "在 commit(默认本次运行的)上启动项目里所选种类(kind
|
|
14
|
+
"run-workflows": {"params": ["kind", "hook", "only", "commit", "inputs"],
|
|
15
|
+
"description": "在 commit(默认本次运行的)上启动项目里所选种类(kind,逗号分隔)或加入挂点 hook 的全部流程(两者写一个),only(流程名的 JSON 数组或逗号分隔)只启动其中这几个;各给它声明了的 inputs(JSON 对象),等它们都结束;有一个失败就失败"},
|
|
16
16
|
"workflow-kinds": {"params": ["commit"],
|
|
17
17
|
"description": "项目在这个提交上有没有各种类可调用的流程(项目自己的和启用插件的),各是布尔值"},
|
|
18
|
+
"hook-joiners": {"params": ["hook", "commit"],
|
|
19
|
+
"description": "项目在这个提交上加入挂点 hook 的流程(项目自己的和启用插件的):list 是勾选项形状的数组(id 为流程名、name、detail、default),按 order 排好,可直接给 coda:optionList;count 是个数"},
|
|
18
20
|
"expire-tool-details": {"params": ["olderThan"],
|
|
19
21
|
"description": "运行所属项目的会话里,已结束、最后活动距今超过 olderThan(ISO 8601 时长,如 P7D)的工具调用(含后台任务、用户自己的命令,不含原生子 Agent 卡片),删除完整输入输出,只留卡片摘要;删除不可恢复"},
|
|
20
22
|
"cold-store": {"params": ["anyAfter", "archivedAfter"],
|
package/workflow/moddle.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"name": "ProcessProperties",
|
|
11
11
|
"isAbstract": true,
|
|
12
12
|
"extends": ["bpmn:Process"],
|
|
13
|
-
"description": "流程本身:concurrency 并发、key 未结束运行的业务键、deploy 只跑默认分支的提交、title 运行在卡片上的名字(同 GitHub 的 run-name)、kind 种类(见 dialect.json 的 kinds)、dispatch 能否手动发起、inline Agent 用 workflow_run 发起时等它结束再回答、subagents 为 false 时会话 Agent 的原生子 Agent 不能发起、agents 生命周期流程跟随哪些 Agent 的会话(ID,逗号或空格分隔,不写是全部)、autoRun 事件(如 PR)来时会话与目录都没设「自动运行」的,按它决定起不起运行:true、false 或 =vars
|
|
13
|
+
"description": "流程本身:concurrency 并发、key 未结束运行的业务键、deploy 只跑默认分支的提交、title 运行在卡片上的名字(同 GitHub 的 run-name)、kind 种类(见 dialect.json 的 kinds)、dispatch 能否手动发起、inline Agent 用 workflow_run 发起时等它结束再回答、subagents 为 false 时会话 Agent 的原生子 Agent 不能发起、agents 生命周期流程跟随哪些 Agent 的会话(ID,逗号或空格分隔,不写是全部)、autoRun 事件(如 PR)来时会话与目录都没设「自动运行」的,按它决定起不起运行:true、false 或 =vars.<插件>.<设置>(不写为起)、mergedOnly 只运行已合并进默认分支的提交(写了就按它,不写由 kind 推出)",
|
|
14
14
|
"properties": [
|
|
15
15
|
{"name": "concurrency", "isAttr": true, "type": "String"},
|
|
16
16
|
{"name": "key", "isAttr": true, "type": "String"},
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
{"name": "inline", "isAttr": true, "type": "Boolean"},
|
|
22
22
|
{"name": "subagents", "isAttr": true, "type": "Boolean"},
|
|
23
23
|
{"name": "agents", "isAttr": true, "type": "String"},
|
|
24
|
-
{"name": "autoRun", "isAttr": true, "type": "String"}
|
|
24
|
+
{"name": "autoRun", "isAttr": true, "type": "String"}, {"name": "mergedOnly", "isAttr": true, "type": "Boolean"}
|
|
25
25
|
]
|
|
26
26
|
},
|
|
27
27
|
{
|
|
@@ -119,6 +119,18 @@
|
|
|
119
119
|
{"name": "noteLabel", "isAttr": true, "type": "String"}
|
|
120
120
|
]
|
|
121
121
|
},
|
|
122
|
+
{
|
|
123
|
+
"name": "Join",
|
|
124
|
+
"superClass": ["Element"],
|
|
125
|
+
"description": "流程加入一个挂点:hook 是挂点名,宿主按它找到这个流程;name、detail 是它作为勾选项时的名字与说明,default 是否默认勾上,order 排序(小的在前,不写排最后,同序按流程名)",
|
|
126
|
+
"properties": [
|
|
127
|
+
{"name": "hook", "isAttr": true, "type": "String"},
|
|
128
|
+
{"name": "name", "isAttr": true, "type": "String"},
|
|
129
|
+
{"name": "detail", "isAttr": true, "type": "String"},
|
|
130
|
+
{"name": "default", "isAttr": true, "type": "String"},
|
|
131
|
+
{"name": "order", "isAttr": true, "type": "String"}
|
|
132
|
+
]
|
|
133
|
+
},
|
|
122
134
|
{
|
|
123
135
|
"name": "Input",
|
|
124
136
|
"superClass": ["Element"],
|
|
@@ -182,12 +194,19 @@
|
|
|
182
194
|
{"name": "note", "isAttr": true, "type": "String"},
|
|
183
195
|
{"name": "fields", "isAttr": true, "type": "String"},
|
|
184
196
|
{"name": "choices", "type": "Choice", "isMany": true},
|
|
185
|
-
{"name": "options", "type": "
|
|
197
|
+
{"name": "options", "type": "ChoiceOption", "isMany": true}
|
|
186
198
|
]
|
|
187
199
|
},
|
|
188
200
|
{
|
|
189
|
-
"name": "
|
|
201
|
+
"name": "ChoiceOption",
|
|
202
|
+
"isAbstract": true,
|
|
190
203
|
"superClass": ["Element"],
|
|
204
|
+
"description": "答复里的勾选项:一个 coda:option,或一组由 coda:optionList 在任务打开时读出的勾选项,按写的顺序排",
|
|
205
|
+
"properties": []
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"name": "Option",
|
|
209
|
+
"superClass": ["ChoiceOption"],
|
|
191
210
|
"description": "一个答复上可以独立勾选的附加项:default(是否默认勾上)与 shown(是否给出)都在任务打开时读;没给出的总是 false",
|
|
192
211
|
"properties": [
|
|
193
212
|
{"name": "id", "isAttr": true, "type": "String"},
|
|
@@ -197,6 +216,14 @@
|
|
|
197
216
|
{"name": "default", "isAttr": true, "type": "String"}
|
|
198
217
|
]
|
|
199
218
|
},
|
|
219
|
+
{
|
|
220
|
+
"name": "OptionList",
|
|
221
|
+
"superClass": ["ChoiceOption"],
|
|
222
|
+
"description": "一组勾选项:value 是表达式,任务打开时读出勾选项的列表(或它的 JSON),在它所在的位置展开",
|
|
223
|
+
"properties": [
|
|
224
|
+
{"name": "value", "isAttr": true, "type": "String"}
|
|
225
|
+
]
|
|
226
|
+
},
|
|
200
227
|
{
|
|
201
228
|
"name": "Field",
|
|
202
229
|
"superClass": ["Element"],
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://coda.pub/schema/bpmn/1.0/options.json",
|
|
4
|
+
"title": "一个答复在任务打开时的勾选项",
|
|
5
|
+
"description": "勾选项须为数组",
|
|
6
|
+
"type": "array",
|
|
7
|
+
"items": {"$ref": "#/$defs/option"},
|
|
8
|
+
"x-unique-by": ["id"],
|
|
9
|
+
"allOf": [{"maxItems": 12, "description": "最多 12 个勾选项"}],
|
|
10
|
+
"$defs": {
|
|
11
|
+
"option": {
|
|
12
|
+
"type": "object",
|
|
13
|
+
"properties": {
|
|
14
|
+
"id": {"type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_-]{0,63}$", "description": "id 须为字母开头的字母、数字、「_」「-」"},
|
|
15
|
+
"name": {"type": "string", "pattern": "\\S", "maxLength": 40, "description": "name 须为 1–40 个字"},
|
|
16
|
+
"detail": {"type": "string", "maxLength": 200, "description": "detail 不超过 200 字"},
|
|
17
|
+
"default": {"type": "boolean", "description": "default 须为 true 或 false"}
|
|
18
|
+
},
|
|
19
|
+
"required": ["id", "name"],
|
|
20
|
+
"additionalProperties": false,
|
|
21
|
+
"description": "勾选项须为对象,有 id 与 name,可有 detail 与 default"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
package/workflow/values.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"key": {"type": "string", "pattern": "\\S", "maxLength": 4000, "x-feel": {"names": ["inputs", "github", "vars"]}, "description": "coda:key 须为 1–4000 个字符"},
|
|
12
12
|
"title": {"type": "string", "pattern": "\\S", "maxLength": 200, "x-feel": true, "description": "coda:title 须为 1–200 个字符"},
|
|
13
13
|
"kind": {"enum": ["deploy", "preview", "release", "check", "premerge", "prebuild", "develop"], "description": "coda:kind 只能是 deploy、preview、release、check、premerge、prebuild、develop"},
|
|
14
|
+
"mergedOnly": {"type": "boolean", "description": "coda:mergedOnly 只能是 true 或 false"},
|
|
14
15
|
"agents": {"type": "string", "pattern": "^[\\s,]*[a-z][a-z0-9-]{0,39}(?:[\\s,]+[a-z][a-z0-9-]{0,39})*[\\s,]*$",
|
|
15
16
|
"description": "coda:agents 写 Agent 的 ID,用逗号或空格分隔(小写字母、数字和「-」,以字母开头,至多 40 个字符),不能为空"},
|
|
16
17
|
"autoRun": {"type": "string", "anyOf": [{"enum": ["true", "false"]}, {"pattern": "^\\s*=\\s*vars(\\.[A-Za-z_][A-Za-z0-9_-]*)+\\s*$"}], "x-feel": {"names": ["vars"]},
|
|
@@ -155,14 +156,14 @@
|
|
|
155
156
|
"options": {"type": "array", "maxItems": 12, "x-unique-by": ["id"], "description": "最多 12 个勾选项"}
|
|
156
157
|
},
|
|
157
158
|
"required": ["id", "name"],
|
|
158
|
-
"allOf": [{"description": "勾选项(coda:option)只能属于没有嵌套 choice 的外层 choice", "not": {"required": ["choices", "options"]}}]
|
|
159
|
+
"allOf": [{"description": "勾选项(coda:option、coda:optionList)只能属于没有嵌套 choice 的外层 choice", "not": {"required": ["choices", "options"]}}]
|
|
159
160
|
},
|
|
160
161
|
"NestedChoice": {
|
|
161
162
|
"allOf": [{"$ref": "#/$defs/Choice"}],
|
|
162
163
|
"properties": {
|
|
163
164
|
"primary": {"const": false, "description": "只有最外层的选项能是主按钮"},
|
|
164
165
|
"choices": {"maxItems": 0, "description": "按住出现的选项里不能再嵌套"},
|
|
165
|
-
"options": {"maxItems": 0, "description": "勾选项(coda:option)只能属于没有嵌套 choice 的外层 choice"}
|
|
166
|
+
"options": {"maxItems": 0, "description": "勾选项(coda:option、coda:optionList)只能属于没有嵌套 choice 的外层 choice"}
|
|
166
167
|
}
|
|
167
168
|
},
|
|
168
169
|
"Option": {
|
|
@@ -176,12 +177,37 @@
|
|
|
176
177
|
},
|
|
177
178
|
"required": ["id", "name"]
|
|
178
179
|
},
|
|
180
|
+
"OptionList": {
|
|
181
|
+
"type": "object",
|
|
182
|
+
"properties": {
|
|
183
|
+
"value": {"type": "string", "pattern": "^\\s*=", "x-feel": true, "description": "coda:optionList 须用 value 写一个「=」开头的表达式(勾选项的列表)"}
|
|
184
|
+
},
|
|
185
|
+
"required": ["value"],
|
|
186
|
+
"description": "coda:optionList 须用 value 写一个「=」开头的表达式(勾选项的列表)"
|
|
187
|
+
},
|
|
188
|
+
"ChoiceOption": {
|
|
189
|
+
"not": {},
|
|
190
|
+
"description": "勾选项写 coda:option,一组读出来的勾选项写 coda:optionList"
|
|
191
|
+
},
|
|
179
192
|
"Process.children": {
|
|
180
193
|
"type": "object",
|
|
181
194
|
"properties": {
|
|
182
|
-
"input": {"type": "array", "x-unique-by": ["name"], "description": "coda:input 的 name 不能重复"}
|
|
195
|
+
"input": {"type": "array", "x-unique-by": ["name"], "description": "coda:input 的 name 不能重复"},
|
|
196
|
+
"join": {"type": "array", "x-unique-by": ["hook"], "description": "coda:join 的 hook 不能重复:一个流程在一个挂点只加入一次"}
|
|
183
197
|
}
|
|
184
198
|
},
|
|
199
|
+
"Join": {
|
|
200
|
+
"type": "object",
|
|
201
|
+
"properties": {
|
|
202
|
+
"hook": {"type": "string", "pattern": "^[a-z][a-z0-9-]{0,63}$", "description": "hook 须为小写字母开头的小写字母、数字、「-」(至多 64 个字符)"},
|
|
203
|
+
"name": {"type": "string", "pattern": "\\S", "maxLength": 40, "description": "name 须为 1–40 个字"},
|
|
204
|
+
"detail": {"type": "string", "maxLength": 200, "description": "detail 不超过 200 字"},
|
|
205
|
+
"default": {"enum": ["true", "false"], "description": "default 只能是 true 或 false:挂点的列表在任何运行之外读出,不写表达式"},
|
|
206
|
+
"order": {"type": "string", "pattern": "^-?[0-9]{1,6}$", "description": "order 须为整数(至多 6 位)"}
|
|
207
|
+
},
|
|
208
|
+
"required": ["hook"],
|
|
209
|
+
"description": "coda:join 需要 hook"
|
|
210
|
+
},
|
|
185
211
|
"UserTask.children": {
|
|
186
212
|
"type": "object",
|
|
187
213
|
"properties": {
|
package/workflow.mjs
CHANGED
|
@@ -22,6 +22,7 @@ import values from './workflow/values.json' with { type: 'json' };
|
|
|
22
22
|
import actions from './workflow/actions.json' with { type: 'json' };
|
|
23
23
|
import dialect from './workflow/dialect.json' with { type: 'json' };
|
|
24
24
|
import fields from './workflow/fields.json' with { type: 'json' };
|
|
25
|
+
import options from './workflow/options.json' with { type: 'json' };
|
|
25
26
|
import { valueKeywords } from './workflow/keywords.mjs';
|
|
26
27
|
import { structureChecker } from './workflow/structure.mjs';
|
|
27
28
|
export { CODA_STRUCTURE } from './workflow/structure.mjs';
|
|
@@ -30,6 +31,7 @@ export const CODA_MODDLE = moddle;
|
|
|
30
31
|
export const CODA_NAMESPACE = moddle.uri;
|
|
31
32
|
export const CODA_VALUES = values;
|
|
32
33
|
export const CODA_FIELDS = fields;
|
|
34
|
+
export const CODA_OPTIONS = options;
|
|
33
35
|
// Each action by name, with the parameters it takes (`coda:param`).
|
|
34
36
|
export const CODA_ACTIONS = Object.fromEntries(Object.entries(actions.actions).map(([name, action]) => [name, action.params]));
|
|
35
37
|
export const WORKFLOW_KINDS = Object.keys(dialect.kinds);
|
|
@@ -95,6 +97,7 @@ ajv.addKeyword({
|
|
|
95
97
|
ajv.addKeyword({ keyword: 'x-duration', type: 'string', schemaType: 'boolean', compile: spec => value => !spec || isDuration(value) });
|
|
96
98
|
ajv.addKeyword({ keyword: 'x-number', type: 'string', schemaType: 'boolean', compile: spec => value => !spec || Number.isFinite(Number(value)) });
|
|
97
99
|
ajv.addSchema(fields);
|
|
100
|
+
ajv.addSchema(options);
|
|
98
101
|
ajv.addSchema(values);
|
|
99
102
|
const structureProblem = structureChecker(ajv, { feelProblem, isExpression });
|
|
100
103
|
const checks = new Map();
|
|
@@ -108,12 +111,15 @@ const SIZE_LIMIT = 1_000_000;
|
|
|
108
111
|
// bpmn-moddle rewrites a descriptor as it takes it in (its names get their prefix), and whoever imports CODA_MODDLE may hand
|
|
109
112
|
// it to one: what is read here is a copy taken as this loads, and each parse is given a copy of its own.
|
|
110
113
|
const DESCRIPTOR = structuredClone(moddle);
|
|
111
|
-
// moddle's Boolean/Integer coercion accepts `no` as false and `1.5` as 1. Keep
|
|
112
|
-
// complete spelling is known; valid ones are restored to the descriptor's types before returning the parsed workflow
|
|
113
|
-
|
|
114
|
+
// moddle's Boolean/Integer coercion accepts `no` as false and `1.5` as 1. Keep these attributes as text until their
|
|
115
|
+
// complete spelling is known; valid ones are restored to the descriptor's types before returning the parsed workflow,
|
|
116
|
+
// and the schemas say no to the rest. A field's, and coda:mergedOnly: a misspelling there would quietly run unmerged
|
|
117
|
+
// commits.
|
|
118
|
+
const SCALARS = [['Field', 'coda:Field'], ['ProcessProperties', 'bpmn:Process', ['mergedOnly']]].map(([name, on, only]) => ({ name, on,
|
|
119
|
+
properties: DESCRIPTOR.types.find(type => type.name === name).properties.filter(p => ['Boolean', 'Integer'].includes(p.type) && (!only || only.includes(p.name))) }));
|
|
114
120
|
const PARSER_DESCRIPTOR = structuredClone(DESCRIPTOR);
|
|
115
|
-
for (const property of PARSER_DESCRIPTOR.types.find(type => type.name ===
|
|
116
|
-
if (
|
|
121
|
+
for (const { name, properties } of SCALARS) for (const property of PARSER_DESCRIPTOR.types.find(type => type.name === name).properties)
|
|
122
|
+
if (properties.some(p => p.name === property.name)) property.type = 'String';
|
|
117
123
|
const children = element => Object.values(element).flatMap(v => (Array.isArray(v) ? v : [v])).filter(v => v?.$type && v.$parent === element);
|
|
118
124
|
// Everything in the definition under `element`, depth first, by a stack of its own, pushed one at a time: a definition may
|
|
119
125
|
// nest deeper than the call stack goes, and hold more in one place than a call takes arguments.
|
|
@@ -148,7 +154,7 @@ function said(error, at, attribute) {
|
|
|
148
154
|
if (error.keyword === 'x-unique-by') return `${at}:${error.message}`;
|
|
149
155
|
return `${at}:${description(error)}`;
|
|
150
156
|
}
|
|
151
|
-
const description = (error, object = {}) => (described(error, { schemas: [values, fields] }) ?? error.message)
|
|
157
|
+
const description = (error, object = {}) => (described(error, { schemas: [values, fields, options] }) ?? error.message)
|
|
152
158
|
.replace(/\{(\w+)\}/g, (whole, key) => Object.hasOwn(error.params, key) ? String(error.params[key])
|
|
153
159
|
: object && Object.hasOwn(object, key) ? String(object[key]) : whole);
|
|
154
160
|
// Required values and allowed attributes come from the same schema as validation; none of the field types is named here.
|
|
@@ -181,6 +187,22 @@ export function fieldsProblem(list, where = '任务') {
|
|
|
181
187
|
const validate = ajv.getSchema(`${values.$id}#/$defs/UserTask.children/properties/field`);
|
|
182
188
|
return validate(list) ? null : `${where}:字段 id 重复:${validate.errors[0].message.slice('id 不能重复:'.length)}`;
|
|
183
189
|
}
|
|
190
|
+
// One answer's options as the task opens: the static ones resolved and each coda:optionList read and put where it is
|
|
191
|
+
// written, in order. Each is an object of id, name and optionally detail and a boolean default; at most 12, ids unique.
|
|
192
|
+
let optionsBound;
|
|
193
|
+
export function optionsProblem(list, where = '答复') {
|
|
194
|
+
const { $id, $schema, $defs, items, 'x-unique-by': unique, ...shape } = options;
|
|
195
|
+
// The bound first, then each option, then uniqueness, so that what is said is about the first thing wrong.
|
|
196
|
+
const bound = optionsBound ??= ajv.compile(shape);
|
|
197
|
+
if (!bound(list)) return `${where}:${description(bound.errors[0])}`;
|
|
198
|
+
const validate = ajv.getSchema(`${options.$id}#/$defs/option`);
|
|
199
|
+
for (const [index, option] of list.entries()) {
|
|
200
|
+
const at = `${where} 的勾选项 ${typeof option?.id === 'string' && option.id ? option.id : index + 1}`;
|
|
201
|
+
if (!validate(option)) return `${at}:${description(validate.errors[0], option)}`;
|
|
202
|
+
}
|
|
203
|
+
const all = ajv.getSchema(options.$id);
|
|
204
|
+
return all(list) ? null : `${where}:勾选项的 ${all.errors[0].message}`;
|
|
205
|
+
}
|
|
184
206
|
// What of the coda: values in the definition its schemas do not take, or null: each element in order, its coda:
|
|
185
207
|
// attributes by each type of Coda's extending what it is, the coda: elements it holds by kind, and each coda: element.
|
|
186
208
|
function valuesProblem(root) {
|
|
@@ -195,7 +217,8 @@ function valuesProblem(root) {
|
|
|
195
217
|
for (const element of elements) {
|
|
196
218
|
const type = codaType(element);
|
|
197
219
|
if (type) {
|
|
198
|
-
|
|
220
|
+
// What names the element where it is said: its id, a join's hook, or its own name.
|
|
221
|
+
const name = element.id ?? element.hook ?? element.name, kind = type.name === 'Choice' && element.$parent?.$type === 'coda:Choice' ? 'NestedChoice' : type.name;
|
|
199
222
|
const problem = failed(check(kind), codaObject(element), `${owner(element)?.id} 的 coda:${lower(type.name)}${name ? ` ${name}` : ''}`, false, ['Field', 'Fields'].includes(kind));
|
|
200
223
|
if (problem) return problem;
|
|
201
224
|
continue;
|
|
@@ -238,10 +261,10 @@ export async function readWorkflow(source, file = 'workflow') {
|
|
|
238
261
|
catch (e) { return { problem: `${file}.bpmn 不是有效的 BPMN 2.0:${e.message}` }; }
|
|
239
262
|
const { rootElement: root, warnings } = parsed;
|
|
240
263
|
if (warnings.length) return { problem: `${file}.bpmn 有无法识别的内容:${warnings.slice(0, 3).map(w => w.message).join(';')}` };
|
|
241
|
-
for (const
|
|
242
|
-
const value =
|
|
243
|
-
if (type === 'Boolean' && ['true', 'false'].includes(value))
|
|
244
|
-
if (type === 'Integer' && typeof value === 'string' && /^[+-]?\d+$/.test(value))
|
|
264
|
+
for (const { on, properties } of SCALARS) for (const element of all(root).filter(e => e.$type === on)) for (const { name, type } of properties) {
|
|
265
|
+
const value = element[name];
|
|
266
|
+
if (type === 'Boolean' && ['true', 'false'].includes(value)) element[name] = value === 'true';
|
|
267
|
+
if (type === 'Integer' && typeof value === 'string' && /^[+-]?\d+$/.test(value)) element[name] = Number(value);
|
|
245
268
|
}
|
|
246
269
|
for (const task of all(root).filter(e => e.$type === 'bpmn:ServiceTask' && e.action !== undefined)) {
|
|
247
270
|
if (!Object.hasOwn(CODA_ACTIONS, task.action)) return { problem: `${task.id}:coda:action 只能是 ${Object.keys(CODA_ACTIONS).join('、')}` };
|