@coda-console/protocol 5.12.0 → 5.13.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 +4 -0
- package/README.md +5 -1
- package/package.json +1 -1
- package/workflow/moddle.json +17 -2
- package/workflow/options.json +24 -0
- package/workflow/values.json +14 -2
- package/workflow.mjs +20 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
版本规矩见 README 的[「版本」一节](README.md#版本)。协议自己的大版本写在协议名里(如 `coda/run@1`),与 npm 包版本、插件清单的 v2 独立;更早的版本见 git 历史。
|
|
4
4
|
|
|
5
|
+
## 5.13.0 — 2026-11-13
|
|
6
|
+
|
|
7
|
+
- 流程方言的答复加 `coda:optionList`:`value` 是表达式,任务打开时读出一组勾选项,在它写的位置展开,与 `coda:option` 按写的顺序排(moddle 里两者同属答复的 `options`,类型 `ChoiceOption`)。打开后的整组由新的 `workflow/options.json` 定义(`{ id, name, detail?, default? }`,最多 12 项,id 不重复),`optionsProblem` 检查它,`CODA_OPTIONS` 导出同一份 schema。只加写法,已有流程不变(Coda #2521 第 1 步)。
|
|
8
|
+
|
|
5
9
|
## 5.12.0 — 2026-11-13
|
|
6
10
|
|
|
7
11
|
- 圈定第三方稳定面:随包发布 53 条清单路径及页面接口、外观清单,各从 revision 1 起;增加只增不减、schema 路径可达与第三方清单样本校验,PR 对目标分支、发布前对 npm latest 检查。补充清单的 displayName、version;稳定面只增不减,内部面删改不升主版本(coda#2463)。
|
package/README.md
CHANGED
|
@@ -14,6 +14,8 @@ Coda 与插件之间的约定,Coda 和插件都引用它,独立演进:
|
|
|
14
14
|
|
|
15
15
|
读取定义时原有的 Coda 结构规则已全部纳入协议。Coda 接入 1.8.0 后,`parseBpmn` 只需调用 `readWorkflow`,再把 `root` 编译成引擎、任务、调度和图所需的结构;运行时才能知道的表达式结果、动态字段引用、调度设置实际值及能力是否存在,仍由宿主在运行时检查。
|
|
16
16
|
|
|
17
|
+
流程方言的 **勾选项**写在答复(外层的 `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 完成。
|
|
18
|
+
|
|
17
19
|
流程方言的 **卡片字段**由 `workflow/fields.json` 定义:七种字段各能写哪些属性、必填项、文字长度与单行限制、路径与网址、视图参数、输入框与密钥选项;`values.json` 的 `Field` 引用它,`Fields` 声明读出 JSON 字段列表的表达式,`UserTask.children` 限定最多 12 个静态字段、id 不重复,以及全部字段已知时答复的 `fields` 只能引用输入字段(含按住出现的答复)。
|
|
18
20
|
|
|
19
21
|
脚本步骤的 **工作副本** 由 `coda:source` 声明:这一步在哪个工作副本目录里跑,写本机上的绝对路径,可以写 FEEL 表达式。它只用于 `coda:checkout="false"` 的步骤:在本机跑就在那个目录里就地跑,不检出提交;交给别的执行环境时,由调用方给这个目录所在的工作副本拍快照(含未提交、未跟踪的改动,不含忽略的文件),对方检出快照、在对应的子目录里跑。协议里 `coda/executor@1` 的 `execute` 输入已有 `source.snapshot` 与 `workingDirectory`,交给别台时就用这两项,执行器协议本身不改。
|
|
@@ -61,7 +63,7 @@ invocationResponseProblem({ run: { kind: 'coda/run@1', id: 'run-1' } });
|
|
|
61
63
|
```
|
|
62
64
|
|
|
63
65
|
```js
|
|
64
|
-
import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, CODA_FIELDS } from '@coda-console/protocol/workflow';
|
|
66
|
+
import { workflowProblem, readWorkflow, fieldProblem, fieldsProblem, optionsProblem, CODA_FIELDS, CODA_OPTIONS } from '@coda-console/protocol/workflow';
|
|
65
67
|
|
|
66
68
|
// 一份流程(名字不带 .bpmn,用在说明里):方言里都有就返回 null,否则是一句说明。
|
|
67
69
|
const problem = await workflowProblem(readFileSync('.coda/workflows/deploy.bpmn', 'utf8'), 'deploy');
|
|
@@ -70,6 +72,8 @@ const { root } = await readWorkflow(source, 'deploy');
|
|
|
70
72
|
// 任务打开、接受答复时检查已求值的字段,不填默认值,不执行表达式。
|
|
71
73
|
fieldProblem({ type: 'text', id: 'name', label: '名称' }, 'ask 的字段 name');
|
|
72
74
|
fieldsProblem(JSON.parse(fieldsJSON), 'ask');
|
|
75
|
+
// 一个答复打开后的整组勾选项(静态项已求值、coda:optionList 已展开)。
|
|
76
|
+
optionsProblem([{ id: 'deploy', name: '部署', default: false }], 'approve 的答复 merge');
|
|
73
77
|
// CODA_FIELDS 是同一份 fields.json,也可从 @coda-console/protocol/workflow/fields.json 导入。
|
|
74
78
|
```
|
|
75
79
|
|
package/package.json
CHANGED
package/workflow/moddle.json
CHANGED
|
@@ -182,12 +182,19 @@
|
|
|
182
182
|
{"name": "note", "isAttr": true, "type": "String"},
|
|
183
183
|
{"name": "fields", "isAttr": true, "type": "String"},
|
|
184
184
|
{"name": "choices", "type": "Choice", "isMany": true},
|
|
185
|
-
{"name": "options", "type": "
|
|
185
|
+
{"name": "options", "type": "ChoiceOption", "isMany": true}
|
|
186
186
|
]
|
|
187
187
|
},
|
|
188
188
|
{
|
|
189
|
-
"name": "
|
|
189
|
+
"name": "ChoiceOption",
|
|
190
|
+
"isAbstract": true,
|
|
190
191
|
"superClass": ["Element"],
|
|
192
|
+
"description": "答复里的勾选项:一个 coda:option,或一组由 coda:optionList 在任务打开时读出的勾选项,按写的顺序排",
|
|
193
|
+
"properties": []
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
"name": "Option",
|
|
197
|
+
"superClass": ["ChoiceOption"],
|
|
191
198
|
"description": "一个答复上可以独立勾选的附加项:default(是否默认勾上)与 shown(是否给出)都在任务打开时读;没给出的总是 false",
|
|
192
199
|
"properties": [
|
|
193
200
|
{"name": "id", "isAttr": true, "type": "String"},
|
|
@@ -197,6 +204,14 @@
|
|
|
197
204
|
{"name": "default", "isAttr": true, "type": "String"}
|
|
198
205
|
]
|
|
199
206
|
},
|
|
207
|
+
{
|
|
208
|
+
"name": "OptionList",
|
|
209
|
+
"superClass": ["ChoiceOption"],
|
|
210
|
+
"description": "一组勾选项:value 是表达式,任务打开时读出勾选项的列表(或它的 JSON),在它所在的位置展开",
|
|
211
|
+
"properties": [
|
|
212
|
+
{"name": "value", "isAttr": true, "type": "String"}
|
|
213
|
+
]
|
|
214
|
+
},
|
|
200
215
|
{
|
|
201
216
|
"name": "Field",
|
|
202
217
|
"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
|
@@ -155,14 +155,14 @@
|
|
|
155
155
|
"options": {"type": "array", "maxItems": 12, "x-unique-by": ["id"], "description": "最多 12 个勾选项"}
|
|
156
156
|
},
|
|
157
157
|
"required": ["id", "name"],
|
|
158
|
-
"allOf": [{"description": "勾选项(coda:option)只能属于没有嵌套 choice 的外层 choice", "not": {"required": ["choices", "options"]}}]
|
|
158
|
+
"allOf": [{"description": "勾选项(coda:option、coda:optionList)只能属于没有嵌套 choice 的外层 choice", "not": {"required": ["choices", "options"]}}]
|
|
159
159
|
},
|
|
160
160
|
"NestedChoice": {
|
|
161
161
|
"allOf": [{"$ref": "#/$defs/Choice"}],
|
|
162
162
|
"properties": {
|
|
163
163
|
"primary": {"const": false, "description": "只有最外层的选项能是主按钮"},
|
|
164
164
|
"choices": {"maxItems": 0, "description": "按住出现的选项里不能再嵌套"},
|
|
165
|
-
"options": {"maxItems": 0, "description": "勾选项(coda:option)只能属于没有嵌套 choice 的外层 choice"}
|
|
165
|
+
"options": {"maxItems": 0, "description": "勾选项(coda:option、coda:optionList)只能属于没有嵌套 choice 的外层 choice"}
|
|
166
166
|
}
|
|
167
167
|
},
|
|
168
168
|
"Option": {
|
|
@@ -176,6 +176,18 @@
|
|
|
176
176
|
},
|
|
177
177
|
"required": ["id", "name"]
|
|
178
178
|
},
|
|
179
|
+
"OptionList": {
|
|
180
|
+
"type": "object",
|
|
181
|
+
"properties": {
|
|
182
|
+
"value": {"type": "string", "pattern": "^\\s*=", "x-feel": true, "description": "coda:optionList 须用 value 写一个「=」开头的表达式(勾选项的列表)"}
|
|
183
|
+
},
|
|
184
|
+
"required": ["value"],
|
|
185
|
+
"description": "coda:optionList 须用 value 写一个「=」开头的表达式(勾选项的列表)"
|
|
186
|
+
},
|
|
187
|
+
"ChoiceOption": {
|
|
188
|
+
"not": {},
|
|
189
|
+
"description": "勾选项写 coda:option,一组读出来的勾选项写 coda:optionList"
|
|
190
|
+
},
|
|
179
191
|
"Process.children": {
|
|
180
192
|
"type": "object",
|
|
181
193
|
"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();
|
|
@@ -148,7 +151,7 @@ function said(error, at, attribute) {
|
|
|
148
151
|
if (error.keyword === 'x-unique-by') return `${at}:${error.message}`;
|
|
149
152
|
return `${at}:${description(error)}`;
|
|
150
153
|
}
|
|
151
|
-
const description = (error, object = {}) => (described(error, { schemas: [values, fields] }) ?? error.message)
|
|
154
|
+
const description = (error, object = {}) => (described(error, { schemas: [values, fields, options] }) ?? error.message)
|
|
152
155
|
.replace(/\{(\w+)\}/g, (whole, key) => Object.hasOwn(error.params, key) ? String(error.params[key])
|
|
153
156
|
: object && Object.hasOwn(object, key) ? String(object[key]) : whole);
|
|
154
157
|
// Required values and allowed attributes come from the same schema as validation; none of the field types is named here.
|
|
@@ -181,6 +184,22 @@ export function fieldsProblem(list, where = '任务') {
|
|
|
181
184
|
const validate = ajv.getSchema(`${values.$id}#/$defs/UserTask.children/properties/field`);
|
|
182
185
|
return validate(list) ? null : `${where}:字段 id 重复:${validate.errors[0].message.slice('id 不能重复:'.length)}`;
|
|
183
186
|
}
|
|
187
|
+
// One answer's options as the task opens: the static ones resolved and each coda:optionList read and put where it is
|
|
188
|
+
// written, in order. Each is an object of id, name and optionally detail and a boolean default; at most 12, ids unique.
|
|
189
|
+
let optionsBound;
|
|
190
|
+
export function optionsProblem(list, where = '答复') {
|
|
191
|
+
const { $id, $schema, $defs, items, 'x-unique-by': unique, ...shape } = options;
|
|
192
|
+
// The bound first, then each option, then uniqueness, so that what is said is about the first thing wrong.
|
|
193
|
+
const bound = optionsBound ??= ajv.compile(shape);
|
|
194
|
+
if (!bound(list)) return `${where}:${description(bound.errors[0])}`;
|
|
195
|
+
const validate = ajv.getSchema(`${options.$id}#/$defs/option`);
|
|
196
|
+
for (const [index, option] of list.entries()) {
|
|
197
|
+
const at = `${where} 的勾选项 ${typeof option?.id === 'string' && option.id ? option.id : index + 1}`;
|
|
198
|
+
if (!validate(option)) return `${at}:${description(validate.errors[0], option)}`;
|
|
199
|
+
}
|
|
200
|
+
const all = ajv.getSchema(options.$id);
|
|
201
|
+
return all(list) ? null : `${where}:勾选项的 ${all.errors[0].message}`;
|
|
202
|
+
}
|
|
184
203
|
// What of the coda: values in the definition its schemas do not take, or null: each element in order, its coda:
|
|
185
204
|
// attributes by each type of Coda's extending what it is, the coda: elements it holds by kind, and each coda: element.
|
|
186
205
|
function valuesProblem(root) {
|