@stalfh233/omc-cli 0.8.31 → 0.8.33
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/dist/arg-vocabulary.js +223 -0
- package/dist/artifact-cmd.js +443 -0
- package/dist/batch-call.js +56 -3
- package/dist/call-command.js +70 -0
- package/dist/call-execute.js +228 -0
- package/dist/call-input.js +557 -0
- package/dist/call-output.js +240 -0
- package/dist/cli.js +23 -1360
- package/dist/command-transport.js +4 -1
- package/dist/field-add.js +2 -1
- package/dist/form-support.js +17 -4
- package/dist/intent/plan-apply.js +14 -24
- package/dist/lanes/datarule.js +21 -0
- package/dist/lanes/field.js +31 -0
- package/dist/lanes/list-view-shapes.js +8 -1
- package/dist/lanes/list-view.js +64 -2
- package/dist/lanes/runtime-data/aggregate-support.js +209 -0
- package/dist/lanes/runtime-data/aggregate.js +679 -0
- package/dist/lanes/runtime-data/field-options.js +52 -0
- package/dist/lanes/runtime-data/lane.js +4 -0
- package/dist/lanes/runtime-data/record-delete.js +419 -0
- package/dist/lanes/runtime-data/record-read.js +984 -0
- package/dist/lanes/runtime-data/record-write.js +562 -0
- package/dist/lanes/runtime-data/registration.js +22 -0
- package/dist/lanes/runtime-data/shapes.js +594 -0
- package/dist/lanes/runtime-data/submission.js +1293 -0
- package/dist/lanes/runtime-data/write-support.js +875 -0
- package/dist/lanes/runtime-data-contract.js +1 -1
- package/dist/lanes/runtime-data.js +10 -5556
- package/dist/lanes/workflow/approval-ops.js +983 -0
- package/dist/lanes/workflow/instance-read.js +284 -0
- package/dist/lanes/workflow/lifecycle-write.js +1499 -0
- package/dist/lanes/workflow/permissions.js +571 -0
- package/dist/lanes/workflow/recovery.js +361 -0
- package/dist/lanes/workflow/registration.js +14 -0
- package/dist/lanes/workflow/shapes.js +811 -0
- package/dist/lanes/workflow/template-fetch.js +197 -0
- package/dist/lanes/workflow/template-merge.js +1351 -0
- package/dist/lanes/workflow/template-read.js +327 -0
- package/dist/lanes/workflow.js +11 -6312
- package/dist/model-scaffold.js +3 -1
- package/dist/path-projection.js +27 -6
- package/dist/read-projection.js +442 -0
- package/dist/read.js +40 -335
- package/dist/rollback.js +17 -23
- package/dist/runtime-support.js +1 -1
- package/dist/verification.js +39 -0
- package/dist/write-coordinator.js +152 -0
- package/dist/write-outcome.js +295 -0
- package/dist/write.js +34 -115
- package/package.json +3 -3
- package/skills/omc-refusals.md +1 -1
- package/skills/omc-start-here.md +3 -3
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
import { WireError, wireCall, wireRows } from "../../wire.js";
|
|
2
|
+
import { ENDPOINTS } from "../../endpoints.js";
|
|
3
|
+
import { ENGINE_OWNED_KEYS, RUNTIME_DATA_WIRE } from "../runtime-data-contract.js";
|
|
4
|
+
import { choiceCodesFromFieldOptions, parseOptions } from "./field-options.js";
|
|
5
|
+
import { RELATION_PROPERTY_TYPES, RUNTIME_SYSTEM_FIELD_CODES } from "./shapes.js";
|
|
6
|
+
import { CHILD_TABLE_PROPERTY_TYPE } from "../../runtime-support.js";
|
|
7
|
+
import { ToolRefusalError } from "../../tool-types.js";
|
|
8
|
+
/**
|
|
9
|
+
* Resolve a model's single published workflow code, or null when the model has
|
|
10
|
+
* no workflow. A workflow-backed data submit must START the workflow
|
|
11
|
+
* (runtime/form/submit formType=1 + workflowCode), not merely save a sheet row
|
|
12
|
+
* (formType=2): only the former creates the workflow instance and runs node
|
|
13
|
+
* routing / approval. Detection via workflow/isworkflow (WorkflowTemplateController
|
|
14
|
+
* :1338), code via workflow/getWorkflow (returns the published template).
|
|
15
|
+
*/
|
|
16
|
+
export async function resolvePublishedWorkflowCode(session, schemaCode) {
|
|
17
|
+
const isWorkflow = (await wireCall(session, { path: ENDPOINTS.workflowIsWorkflow, query: { schemaCode } })).data === true;
|
|
18
|
+
if (!isWorkflow)
|
|
19
|
+
return null;
|
|
20
|
+
const template = (await wireCall(session, { path: ENDPOINTS.workflowGetBySchema, query: { schemaCode } })).data;
|
|
21
|
+
const code = template && typeof template.workflowCode === "string" && template.workflowCode.length > 0 ? template.workflowCode : null;
|
|
22
|
+
return code;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* F2(w112 探针 H,P1):`data.save` 不带 `workflowCode` 落的是**普通 sheet
|
|
26
|
+
* 草稿**,没有流程实例。该模型若有已发布流程,这行之后永远提交不了:
|
|
27
|
+
* `data.submit` 只能走 `submit-existing-workflow-unsupported`。
|
|
28
|
+
*
|
|
29
|
+
* 检测只读**一次** `workflow/getWorkflow`:该面就是
|
|
30
|
+
* `WorkflowTemplateController.getWorkflow`(8.6.26 decompiled-engine
|
|
31
|
+
* `1372-1393`:按 schemaCode 取 published 头 `:1378`,返回已发布模板
|
|
32
|
+
* `:1383-1384`,无则 `data:null` `:1379-1380`),一次同时回答「有没有」和
|
|
33
|
+
* 「code 是什么」。不用 `workflow/isworkflow` 先探——它只证明「有任意头」,
|
|
34
|
+
* 且真机会滞后于真实绑定(BUG-05-F8),单读 getWorkflow 既少一跳也更准。
|
|
35
|
+
*
|
|
36
|
+
* 读失败只意味着「**本次无法确认**」,绝不把已落库的写退化成 error,也绝不
|
|
37
|
+
* 把「没查到」当「没流程」(回执带 `workflowCheckSkipped.reason`)。
|
|
38
|
+
*/
|
|
39
|
+
export async function resolvePublishedWorkflowCodeForNote(session, schemaCode) {
|
|
40
|
+
try {
|
|
41
|
+
const template = (await wireCall(session, { path: ENDPOINTS.workflowGetBySchema, query: { schemaCode } })).data;
|
|
42
|
+
return { code: template && typeof template.workflowCode === "string" && template.workflowCode.length > 0 ? template.workflowCode : null };
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
const detail = error instanceof WireError ? `errcode ${error.errcode ?? "?"}: ${error.message}` : error instanceof Error ? error.message : String(error);
|
|
46
|
+
return { code: null, skipped: { reason: `workflow/getWorkflow 读取失败,本次未能确认是否有已发布流程(${detail})` } };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Resolve the active form's sheetCode. Priority order: explicit caller arg
|
|
51
|
+
* (verbatim) > default-form sheetCode from bizsheet/get > schemaCode
|
|
52
|
+
* fallback. Returns the chosen sheetCode plus a provenance tag so callers
|
|
53
|
+
* can report which tier won.
|
|
54
|
+
*/
|
|
55
|
+
export async function resolveFormSheetCode(session, args) {
|
|
56
|
+
const explicit = typeof args.sheetCode === "string" && args.sheetCode.trim() ? args.sheetCode.trim() : "";
|
|
57
|
+
if (explicit)
|
|
58
|
+
return { sheetCode: explicit, resolvedFrom: "explicit" };
|
|
59
|
+
try {
|
|
60
|
+
const result = await wireCall(session, {
|
|
61
|
+
path: ENDPOINTS.sheetGet,
|
|
62
|
+
query: { schemaCode: args.schemaCode, sheetCode: args.schemaCode },
|
|
63
|
+
});
|
|
64
|
+
const data = result.data;
|
|
65
|
+
const candidate = data?.code ?? data?.sheetCode;
|
|
66
|
+
if (typeof candidate === "string" && candidate) {
|
|
67
|
+
return { sheetCode: candidate, resolvedFrom: "default-form" };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
// fall through to schemaCode fallback
|
|
72
|
+
}
|
|
73
|
+
return { sheetCode: args.schemaCode, resolvedFrom: "fallback" };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Read the record status from a form/load payload. The live face nests it as
|
|
77
|
+
* `bizObject.data.sequenceStatus`; the flat fake form carries it top-level.
|
|
78
|
+
*/
|
|
79
|
+
/**
|
|
80
|
+
* Read the workflow instance id from a form/load payload. The live face may
|
|
81
|
+
* carry it top-level, under `bizObject`, or under `bizObject.data` — the submit
|
|
82
|
+
* RESPONSE often omits it entirely (bench53: start/approval submits answered
|
|
83
|
+
* workflowInstanceId:null even though the instance existed), so the loaded row
|
|
84
|
+
* is the fallback the next-todo lookup depends on.
|
|
85
|
+
*/
|
|
86
|
+
export function extractWorkflowInstanceId(readback) {
|
|
87
|
+
if (!readback)
|
|
88
|
+
return null;
|
|
89
|
+
const candidates = [
|
|
90
|
+
readback.workflowInstanceId,
|
|
91
|
+
readback.bizObject?.workflowInstanceId,
|
|
92
|
+
readback.bizObject?.data?.workflowInstanceId,
|
|
93
|
+
];
|
|
94
|
+
for (const candidate of candidates)
|
|
95
|
+
if (typeof candidate === "string" && candidate.length > 0)
|
|
96
|
+
return candidate;
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
export function extractSequenceStatus(readback) {
|
|
100
|
+
if (!readback)
|
|
101
|
+
return null;
|
|
102
|
+
if (typeof readback.sequenceStatus === "string")
|
|
103
|
+
return readback.sequenceStatus;
|
|
104
|
+
const nested = readback.bizObject;
|
|
105
|
+
if (nested && typeof nested.sequenceStatus === "string")
|
|
106
|
+
return nested.sequenceStatus;
|
|
107
|
+
const nestedData = nested?.data;
|
|
108
|
+
if (nestedData && typeof nestedData.sequenceStatus === "string")
|
|
109
|
+
return nestedData.sequenceStatus;
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Engine-owned record keys that must never be echoed back in a submit
|
|
114
|
+
* payload: persisting the loaded `sequenceStatus` pins the row to its
|
|
115
|
+
* pre-submit status (live evidence ticket 17 — the portal client only
|
|
116
|
+
* submits form fields, never the status column). The key list is the
|
|
117
|
+
* contract constant the fake's merge also consumes (ticket 20).
|
|
118
|
+
*/
|
|
119
|
+
export function stripEngineOwnedKeys(data) {
|
|
120
|
+
const stripped = {};
|
|
121
|
+
for (const [key, value] of Object.entries(data)) {
|
|
122
|
+
if (ENGINE_OWNED_KEYS.includes(key))
|
|
123
|
+
continue;
|
|
124
|
+
stripped[key] = value;
|
|
125
|
+
}
|
|
126
|
+
return stripped;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Normalize a form/load payload to the flat record contract the tool surface
|
|
130
|
+
* promises: business fields plus `id`/`sequenceStatus`. The live face returns
|
|
131
|
+
* a FormLoadVO nesting them under `bizObject.data`; the flat fake form
|
|
132
|
+
* carries them top-level. A null payload stays null (absence).
|
|
133
|
+
*/
|
|
134
|
+
export function normalizeLoadedRecord(payload) {
|
|
135
|
+
if (!payload)
|
|
136
|
+
return null;
|
|
137
|
+
const bizObject = payload.bizObject;
|
|
138
|
+
if (!bizObject || typeof bizObject !== "object")
|
|
139
|
+
return payload;
|
|
140
|
+
const record = bizObject;
|
|
141
|
+
const fields = record.data && typeof record.data === "object"
|
|
142
|
+
? { ...record.data }
|
|
143
|
+
: {};
|
|
144
|
+
if (typeof record.id === "string")
|
|
145
|
+
fields.id = record.id;
|
|
146
|
+
if (typeof record.sequenceStatus === "string")
|
|
147
|
+
fields.sequenceStatus = record.sequenceStatus;
|
|
148
|
+
return fields;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* F4(w53,2026-11-26 真机):`options.mappings` 只在**门户表单运行时**用户选中
|
|
152
|
+
* 关联值时回填副本/快照列;`data.save` / `data.update` / `data.submit` 的服务端
|
|
153
|
+
* 写路径不执行映射(子表 `repairRef` 有 mappings,save 后快照仍为空)。
|
|
154
|
+
*
|
|
155
|
+
* 平台证据(8.6.26):门户 `runtime/form/save` 链路
|
|
156
|
+
* `FormRuntimeController.save:806-843` → `saveBizSheet:932-970` →
|
|
157
|
+
* `RuntimeController.saveBizObject:926-934` → `BizObjectFacadeImpl.saveBizObject`
|
|
158
|
+
* **没有** mapping 调用;表单运行时另走显式的
|
|
159
|
+
* `BaseController.executeDataRuleValidationAndMapping:1088-1103`(mappingList),
|
|
160
|
+
* 其调用方是 OpenAPI v2/v3(`OpenApiFormController.java:290` /
|
|
161
|
+
* `OpenApiBizObjectController.java:260`),不是本工具使用的 runtime 表单保存面。
|
|
162
|
+
* `options.mappings` 的消费实现见 `WorkSheetMappingServiceImpl.executeChildMapping`
|
|
163
|
+
* (bizdata `:207-230`)——只在被显式调用的 mapping 面执行。
|
|
164
|
+
* 「后端会不会代跑映射」如需逐版本闭环,仍需真机采样复核。
|
|
165
|
+
*
|
|
166
|
+
* 只在本次 formData 真的带了子表数组时才读子表 schema 的已发布字段(零数组 =
|
|
167
|
+
* 零 wire);读失败静默跳过,绝不阻断写。
|
|
168
|
+
*/
|
|
169
|
+
export const MAPPING_NOTE_LIMIT = 5;
|
|
170
|
+
export const MAPPING_NOTE_TARGET_LIMIT = 3;
|
|
171
|
+
/** 快照空值判据:null/undefined/空白串(0/false 是有效值,不算空)。 */
|
|
172
|
+
export function mappingTargetEmpty(value) {
|
|
173
|
+
return value === null || value === undefined || (typeof value === "string" && value.trim() === "");
|
|
174
|
+
}
|
|
175
|
+
export function childRowValues(row) {
|
|
176
|
+
if (row === null || typeof row !== "object" || Array.isArray(row))
|
|
177
|
+
return undefined;
|
|
178
|
+
const record = row;
|
|
179
|
+
return record.data !== null && typeof record.data === "object" && !Array.isArray(record.data)
|
|
180
|
+
? record.data
|
|
181
|
+
: record;
|
|
182
|
+
}
|
|
183
|
+
export function mappingSnapshotGapFor(hits) {
|
|
184
|
+
const gapHits = hits.filter((hit) => hit.gapRows.length > 0);
|
|
185
|
+
if (gapHits.length === 0)
|
|
186
|
+
return undefined;
|
|
187
|
+
const rows = [...new Set(gapHits.flatMap((hit) => hit.gapRows))].sort((a, b) => a - b);
|
|
188
|
+
const fields = [...new Set(gapHits.flatMap((hit) => hit.gapFields))];
|
|
189
|
+
const childTables = [...new Set(gapHits.map((hit) => hit.childTable))];
|
|
190
|
+
const location = gapHits
|
|
191
|
+
.slice(0, MAPPING_NOTE_LIMIT)
|
|
192
|
+
.map((hit) => `${hit.childTable} 第 ${hit.gapRows.join("/")} 行→${hit.gapFields.join("/")}`)
|
|
193
|
+
.join("、");
|
|
194
|
+
return {
|
|
195
|
+
rows,
|
|
196
|
+
fields,
|
|
197
|
+
childTables,
|
|
198
|
+
hint: `REST 写不跑关联映射,这些快照字段需在 formData 里自填(门户选值才会回填):${location}` +
|
|
199
|
+
`${gapHits.length > MAPPING_NOTE_LIMIT ? ` 等 ${gapHits.length} 处` : ""};映射配置以 field.get 的 options 为准。`,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
export function relationMappingsOf(row) {
|
|
203
|
+
const options = parseOptions(row.options);
|
|
204
|
+
let raw = options.mappings ?? row.mappings;
|
|
205
|
+
if (typeof raw === "string") {
|
|
206
|
+
if (raw.trim() === "")
|
|
207
|
+
return { declared: false, targets: [] };
|
|
208
|
+
try {
|
|
209
|
+
raw = JSON.parse(raw);
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
// 非空字符串仍是「声明了映射」(损坏 JSON 可能被平台原样保存)。
|
|
213
|
+
return { declared: true, targets: [] };
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!Array.isArray(raw))
|
|
217
|
+
return { declared: raw !== undefined && raw !== null, targets: [] };
|
|
218
|
+
const targets = raw
|
|
219
|
+
.map((entry) => entry && typeof entry === "object" && !Array.isArray(entry)
|
|
220
|
+
? String(entry.target ?? "").trim()
|
|
221
|
+
: "")
|
|
222
|
+
.filter((target) => target.length > 0);
|
|
223
|
+
return { declared: raw.length > 0, targets };
|
|
224
|
+
}
|
|
225
|
+
export async function childTableMappingHits(session, formData, childCodes) {
|
|
226
|
+
const present = childCodes.filter((code) => Array.isArray(formData[code]));
|
|
227
|
+
if (present.length === 0)
|
|
228
|
+
return [];
|
|
229
|
+
const hits = [];
|
|
230
|
+
for (const childTable of present) {
|
|
231
|
+
let rows;
|
|
232
|
+
try {
|
|
233
|
+
// 子表 schemaCode = 父模型 CHILD_TABLE 字段的 code(平台同源)。
|
|
234
|
+
rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: childTable, isPublish: "true" } })).data);
|
|
235
|
+
}
|
|
236
|
+
catch {
|
|
237
|
+
// 元数据读不到就不提示(读面副作用不能阻断写)。
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const formRows = Array.isArray(formData[childTable]) ? formData[childTable] : [];
|
|
241
|
+
for (const row of rows) {
|
|
242
|
+
const type = Number(row.propertyType ?? row.type);
|
|
243
|
+
if (!RELATION_PROPERTY_TYPES.has(type))
|
|
244
|
+
continue;
|
|
245
|
+
const mapping = relationMappingsOf(row);
|
|
246
|
+
if (!mapping.declared)
|
|
247
|
+
continue;
|
|
248
|
+
const relationField = String(row.code ?? row.propertyCode ?? "");
|
|
249
|
+
if (!relationField)
|
|
250
|
+
continue;
|
|
251
|
+
// F4(w153):同一份元数据顺带检查本次 formData 的快照空值,零额外 wire。
|
|
252
|
+
const gapRows = [];
|
|
253
|
+
const gapFields = [];
|
|
254
|
+
const targets = mapping.targets;
|
|
255
|
+
if (targets.length > 0) {
|
|
256
|
+
formRows.forEach((entry, index) => {
|
|
257
|
+
const values = childRowValues(entry);
|
|
258
|
+
if (values === undefined)
|
|
259
|
+
return;
|
|
260
|
+
const empty = targets.filter((target) => mappingTargetEmpty(values[target]));
|
|
261
|
+
if (empty.length === 0)
|
|
262
|
+
return;
|
|
263
|
+
gapRows.push(index + 1);
|
|
264
|
+
for (const target of empty)
|
|
265
|
+
if (!gapFields.includes(target))
|
|
266
|
+
gapFields.push(target);
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
hits.push({ childTable, relationField, targets, gapRows, gapFields });
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return hits;
|
|
273
|
+
}
|
|
274
|
+
export function mappingRuntimeNoteFor(hits) {
|
|
275
|
+
if (hits.length === 0)
|
|
276
|
+
return undefined;
|
|
277
|
+
const shown = hits.slice(0, MAPPING_NOTE_LIMIT);
|
|
278
|
+
const detail = shown
|
|
279
|
+
.map((hit) => {
|
|
280
|
+
const targets = hit.targets.slice(0, MAPPING_NOTE_TARGET_LIMIT).join("/");
|
|
281
|
+
const suffix = targets.length > 0 ? `→${targets}${hit.targets.length > MAPPING_NOTE_TARGET_LIMIT ? "…" : ""}` : "";
|
|
282
|
+
return `${hit.childTable}.${hit.relationField}${suffix}`;
|
|
283
|
+
})
|
|
284
|
+
.join("、");
|
|
285
|
+
return `REST 写不执行关联映射(options.mappings 只在门户选值时由表单运行时回填):${detail}${hits.length > shown.length ? ` 等 ${hits.length} 处` : ""};快照/映射目标字段需调用方在 formData 里自填,映射配置以 field.get 的 options 为准。`;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* F6(w153 探针 L,2026-11-28):`name` 是模型「数据标题」表达式(模型可配置
|
|
289
|
+
* summary,常见如 创建人+模型名+时间——不是固定文案),平台 insert/update
|
|
290
|
+
* 无条件覆盖(见 `nameOverwrittenNoteOf` 的源码链)。写前就要说清楚,而不是
|
|
291
|
+
* 等读回发现被改;只在 formData 真的传了 `name` 时提示。
|
|
292
|
+
*/
|
|
293
|
+
export const DATA_TITLE_NOTE = "`name` 是平台数据标题(模型可配置 summary,常见如 创建人+模型名+时间)——传入会被覆盖;业务标识(单号/编码)请用自建字段。";
|
|
294
|
+
export const NAME_NOTE_VALUE_LIMIT = 40;
|
|
295
|
+
export function shortReadbackValue(value) {
|
|
296
|
+
return value.length > NAME_NOTE_VALUE_LIMIT ? `${value.slice(0, NAME_NOTE_VALUE_LIMIT)}…` : value;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* F8(w63,2026-11-26 真机):调用方在 `data.save.formData` 里显式给了 `name`,
|
|
300
|
+
* 读回却是「用户名+模型名+时间」——平台每次 insert/update 都用模型「数据标题」
|
|
301
|
+
* (bizSchema.summary)覆盖 name,且没有任何提示。
|
|
302
|
+
*
|
|
303
|
+
* 平台证据(8.6.26):
|
|
304
|
+
* - `BizObjectInsertModel.convertBizObjectOpItem:59-62` 与
|
|
305
|
+
* `BizObjectUpdateModel.convertBizObjectOpItem:65-68` 在构建 op item 时无条件
|
|
306
|
+
* 调 `BizObjectTitleSetter.setTitle(code, bizSchema.getSummary(), data)`;
|
|
307
|
+
* - `BizObjectTitleSetter.setTitle(code, summary, map)`(:115-117)把 summary
|
|
308
|
+
* 求值结果直接 put 进 `DefaultPropertyType.NAME`(name)。
|
|
309
|
+
* 所以「传了 name」不是可用的业务标识面;回执必须说清,而不是静默改值。
|
|
310
|
+
* 只在**显式传了 name 且与权威读回不同**时给一句(一致/未传 → 零提示)。
|
|
311
|
+
*/
|
|
312
|
+
export function nameOverwrittenNoteOf(suppliedName, authoritativeName) {
|
|
313
|
+
if (typeof suppliedName !== "string" || suppliedName.trim() === "")
|
|
314
|
+
return undefined;
|
|
315
|
+
if (typeof authoritativeName !== "string" || authoritativeName === suppliedName)
|
|
316
|
+
return undefined;
|
|
317
|
+
return `平台按模型「数据标题」表达式自动覆盖了 name:传入“${shortReadbackValue(suppliedName)}”→读回“${shortReadbackValue(authoritativeName)}”;业务标识(单号/编码)请用自建字段,不要依赖 name。`;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* 权威读回里的 name——`data.load` 的行形状可能是平铺 name,也可能在 fields.name
|
|
321
|
+
* 下(ticket 17 的扁平契约与旧 VO 嵌套并存)。两形都认,空串当缺席。
|
|
322
|
+
*/
|
|
323
|
+
export function readbackRecordNameOf(record) {
|
|
324
|
+
if (record === null || typeof record !== "object" || Array.isArray(record))
|
|
325
|
+
return undefined;
|
|
326
|
+
const flat = record.name;
|
|
327
|
+
if (typeof flat === "string" && flat.trim() !== "")
|
|
328
|
+
return flat;
|
|
329
|
+
const fields = record.fields;
|
|
330
|
+
if (fields !== null && typeof fields === "object" && !Array.isArray(fields)) {
|
|
331
|
+
const nested = fields.name;
|
|
332
|
+
if (typeof nested === "string" && nested.trim() !== "")
|
|
333
|
+
return nested;
|
|
334
|
+
}
|
|
335
|
+
return undefined;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Approval-submit readback (issue 2026-10-25 §2).
|
|
339
|
+
*
|
|
340
|
+
* An approval submit changed almost nothing: the caller needs "did the flow
|
|
341
|
+
* advance" (sequenceStatus) plus "did the fields I typed persist". Returning the
|
|
342
|
+
* whole compact record made every approval level pay for the full row again
|
|
343
|
+
* (r12: 25 data.submit calls / 55.6 KB — the single largest read face).
|
|
344
|
+
* `summary`/`fields`/`full` still win when supplied; this is only the default.
|
|
345
|
+
*/
|
|
346
|
+
/**
|
|
347
|
+
* Which submitted values did the immediate readback NOT show? (r10 F8)
|
|
348
|
+
*
|
|
349
|
+
* The platform's form/load face can answer with only system columns right after
|
|
350
|
+
* a write transaction (r14: `readback.authoritative` held just `modifiedTime`
|
|
351
|
+
* while `data.load` a moment later had every business field). Without a note the
|
|
352
|
+
* caller reads that as "the write dropped my data" and writes again.
|
|
353
|
+
*/
|
|
354
|
+
export function submittedBusinessFields(formData) {
|
|
355
|
+
return Object.entries(formData).filter(([key]) => !RUNTIME_SYSTEM_FIELD_CODES.has(key) && !key.endsWith("_"));
|
|
356
|
+
}
|
|
357
|
+
export function ignoredNullDiagnostic(formData) {
|
|
358
|
+
const ignoredNull = submittedBusinessFields(formData).filter(([, value]) => value === null).map(([key]) => key);
|
|
359
|
+
return ignoredNull.length > 0 ? {
|
|
360
|
+
ignoredNull,
|
|
361
|
+
ignoredNullNote: "这些字段传了 null:平台写面把 null 当「未提交」,不会清空;当前版本无已验证的通用清空语义,不要把成功回执当作清空成功(r53 真机复现)",
|
|
362
|
+
} : {};
|
|
363
|
+
}
|
|
364
|
+
export function unknownFieldDiagnostic(formData, fieldCodes, childCodes, schemaLoaded) {
|
|
365
|
+
if (!schemaLoaded || !fieldCodes)
|
|
366
|
+
return schemaLoaded ? {} : {
|
|
367
|
+
unknownFieldKeysNote: "未能读取已发布 field.list,本次未覆盖未知字段键;子表行键也未检查。需要时用 model.inspect/field.list 核对 fieldCodes",
|
|
368
|
+
};
|
|
369
|
+
const known = new Set(fieldCodes);
|
|
370
|
+
const children = new Set(childCodes ?? []);
|
|
371
|
+
const unknownFieldKeys = Object.entries(formData)
|
|
372
|
+
.filter(([key, value]) => value !== null && !RUNTIME_SYSTEM_FIELD_CODES.has(key) && !key.endsWith("_") && !known.has(key) && !children.has(key) && !(value && typeof value === "object" && !Array.isArray(value) && key === "id"))
|
|
373
|
+
.map(([key]) => key);
|
|
374
|
+
return unknownFieldKeys.length > 0 ? {
|
|
375
|
+
unknownFieldKeys,
|
|
376
|
+
unknownFieldKeysNote: "这些键不在模型 schema 里,平台写面会静默丢弃(errcode 0)——多半是驼峰/下划线或字段编码写错;对照 model.inspect 的 fieldCodes 改键名。子表 row 内部键未检查(需另读子表 schema)",
|
|
377
|
+
} : {};
|
|
378
|
+
}
|
|
379
|
+
export function readbackEmptyFields(formData, record) {
|
|
380
|
+
const source = record !== null && typeof record === "object" && !Array.isArray(record) ? record : {};
|
|
381
|
+
return submittedBusinessFields(formData)
|
|
382
|
+
.filter(([key, value]) => value !== null && value !== undefined && (source[key] === null || source[key] === undefined))
|
|
383
|
+
.map(([key]) => key);
|
|
384
|
+
}
|
|
385
|
+
export function readbackWarningFor(emptyFields, toolName) {
|
|
386
|
+
if (emptyFields.length === 0)
|
|
387
|
+
return undefined;
|
|
388
|
+
return `${toolName} 已 DELIVERED,但即时读回里这些本次提交的字段为空/缺省:${emptyFields.join("、")}。平台 form/load 在写事务后可能先回系统字段、业务字段滞后(真机 1.1.25,r14 见过只回 modifiedTime 的一笔)。**先 omc call data.load 核对,不要重写**;若 data.load 仍为空,才按投影/字段 code 排查。`;
|
|
389
|
+
}
|
|
390
|
+
export const SERIAL_GENERATION_FAILURE_NOTE = "平台序列号生成失败是静默的(null 不报错);先 `field.list {schemaCode,code,full:true}` 核对段配置——段类型必须是 CONSTANT/DELIMITER/DATE/PROPERTY/SEQNO/UID(DATAITEM 不是段类型),字段引用必须存在;反编译 SequenceSettingServiceImpl catch→return null(:210-217),真机 r50(2026-11-10)复现。";
|
|
391
|
+
export function serialGenerationFailures(serialNumberCodes, record, sequenceStatus) {
|
|
392
|
+
if (sequenceStatus !== "COMPLETED" || !record)
|
|
393
|
+
return [];
|
|
394
|
+
return serialNumberCodes.filter((code) => record[code] === null);
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Runtime/form/save deliberately remains permissive: the platform stores the
|
|
398
|
+
* row even when the portal would reject it. These are advisory findings only.
|
|
399
|
+
* In particular, never manufacture a warning for a field which is absent from
|
|
400
|
+
* the published field face (the old `code/required` ghost warning did exactly
|
|
401
|
+
* that).
|
|
402
|
+
*/
|
|
403
|
+
export async function runtimeDataWarnings(session, schemaCode, sheetCode, formData, row = 1) {
|
|
404
|
+
const warnings = [];
|
|
405
|
+
let fields = [];
|
|
406
|
+
try {
|
|
407
|
+
fields = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode, isPublish: "true" } })).data);
|
|
408
|
+
}
|
|
409
|
+
catch {
|
|
410
|
+
return warnings;
|
|
411
|
+
}
|
|
412
|
+
const byCode = new Map(fields.map((field) => [String(field.code ?? field.propertyCode ?? ""), field]));
|
|
413
|
+
let required = new Set();
|
|
414
|
+
try {
|
|
415
|
+
const sheet = ((await wireCall(session, { path: ENDPOINTS.sheetGet, query: { schemaCode, sheetCode } })).data ?? {});
|
|
416
|
+
const face = typeof sheet.publishedAttributesJson === "string" ? sheet.publishedAttributesJson : typeof sheet.draftAttributesJson === "string" ? sheet.draftAttributesJson : undefined;
|
|
417
|
+
if (face) {
|
|
418
|
+
const controls = JSON.parse(face);
|
|
419
|
+
required = new Set(Object.entries(controls).filter(([, control]) => control?.options?.required === true || typeof control?.options?.requiredFormula === "string").map(([code]) => code));
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
// Advisory diagnostics must never affect the write.
|
|
424
|
+
}
|
|
425
|
+
for (const [field, value] of Object.entries(formData)) {
|
|
426
|
+
const meta = byCode.get(field);
|
|
427
|
+
if (!meta)
|
|
428
|
+
continue;
|
|
429
|
+
if ((required.has(field) || parseOptions(meta.options).required === true) && (value === null || value === undefined || (typeof value === "string" && value.trim() === ""))) {
|
|
430
|
+
warnings.push({ code: "required-empty", row, fieldCode: field, message: `字段 ${field} 声明必填但本行为空;平台照存,OMC 仅提示` });
|
|
431
|
+
}
|
|
432
|
+
const options = parseOptions(meta.options);
|
|
433
|
+
const optionSet = options.optionsSet && typeof options.optionsSet === "object" ? options.optionsSet : {};
|
|
434
|
+
const choiceCodes = choiceCodesFromFieldOptions(meta, options);
|
|
435
|
+
if (choiceCodes.length > 0 && value !== null && value !== undefined && value !== "") {
|
|
436
|
+
const allowed = new Set(choiceCodes);
|
|
437
|
+
const values = Array.isArray(value) ? value : [value];
|
|
438
|
+
const invalid = values.filter((entry) => !allowed.has(String(entry)));
|
|
439
|
+
if (invalid.length > 0)
|
|
440
|
+
warnings.push({ code: "choice-out-of-range", row, fieldCode: field, value: invalid.map(String), allowed: choiceCodes, message: `字段 ${field} 含未声明选项(实际值:${invalid.map(String).join("、")};合法集:${choiceCodes.join("、")});平台照存,OMC 仅提示` });
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return warnings;
|
|
444
|
+
}
|
|
445
|
+
/**
|
|
446
|
+
* Authoritative existence probe for an existing business object. The platform
|
|
447
|
+
* form/load face returns either a null payload or a business error
|
|
448
|
+
* (304001 业务对象不存在) when the object is absent; both are absence, not a
|
|
449
|
+
* read failure. `data.update` uses this to refuse an absent target instead of
|
|
450
|
+
* letting runtime/form/save silently insert (BizObjectFacadeImpl falls back to
|
|
451
|
+
* createBizObject when the id is not found).
|
|
452
|
+
*/
|
|
453
|
+
export async function loadExistingBizObject(session, schemaCode, sheetCode, objectId) {
|
|
454
|
+
try {
|
|
455
|
+
const result = await wireCall(session, {
|
|
456
|
+
path: ENDPOINTS.runtimeFormLoad,
|
|
457
|
+
query: { schemaCode, sheetCode, objectId },
|
|
458
|
+
});
|
|
459
|
+
const value = result.data;
|
|
460
|
+
if (value == null || value === false)
|
|
461
|
+
return null;
|
|
462
|
+
return typeof value === "object" ? value : {};
|
|
463
|
+
}
|
|
464
|
+
catch (error) {
|
|
465
|
+
if (error instanceof WireError && error.kind === "business" && error.errcode === RUNTIME_DATA_WIRE.absenceErrcode)
|
|
466
|
+
return null;
|
|
467
|
+
throw error;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
/** 提交面:formData 里出现任何非空人员字段值即返回(issue#10:两种形状都可能 50000,可靠链路是提交省略)。 */
|
|
471
|
+
export async function staffFieldsPresent(session, schemaCode, formData) {
|
|
472
|
+
const STAFF_TYPES = new Set([50, 51, 52]);
|
|
473
|
+
let rows;
|
|
474
|
+
try {
|
|
475
|
+
rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode, isPublish: "true" } })).data);
|
|
476
|
+
}
|
|
477
|
+
catch {
|
|
478
|
+
return [];
|
|
479
|
+
}
|
|
480
|
+
const staffCodes = new Set();
|
|
481
|
+
for (const row of rows) {
|
|
482
|
+
const type = Number(row.type ?? row.propertyType);
|
|
483
|
+
const code = String(row.code ?? row.propertyCode ?? "");
|
|
484
|
+
if (code && STAFF_TYPES.has(type))
|
|
485
|
+
staffCodes.add(code);
|
|
486
|
+
}
|
|
487
|
+
const out = [];
|
|
488
|
+
for (const [code, value] of Object.entries(formData)) {
|
|
489
|
+
if (!staffCodes.has(code))
|
|
490
|
+
continue;
|
|
491
|
+
if (value === null || value === undefined || value === "")
|
|
492
|
+
continue;
|
|
493
|
+
if (Array.isArray(value) && value.length === 0)
|
|
494
|
+
continue;
|
|
495
|
+
out.push({ code, got: Array.isArray(value) ? `array[${value.length}]` : typeof value });
|
|
496
|
+
}
|
|
497
|
+
return out;
|
|
498
|
+
}
|
|
499
|
+
/** save 面(无 submit):人员字段只接受对象数组 [{id,type,name}]——字符串/字符串数组会 50000(issue#10 A)。 */
|
|
500
|
+
export async function staffStringShapeViolations(session, schemaCode, formData) {
|
|
501
|
+
const STAFF_TYPES = new Set([50, 51, 52]);
|
|
502
|
+
let rows;
|
|
503
|
+
try {
|
|
504
|
+
rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode, isPublish: "true" } })).data);
|
|
505
|
+
}
|
|
506
|
+
catch {
|
|
507
|
+
return [];
|
|
508
|
+
}
|
|
509
|
+
const staffCodes = new Set();
|
|
510
|
+
for (const row of rows) {
|
|
511
|
+
const type = Number(row.type ?? row.propertyType);
|
|
512
|
+
const code = String(row.code ?? row.propertyCode ?? "");
|
|
513
|
+
if (code && STAFF_TYPES.has(type))
|
|
514
|
+
staffCodes.add(code);
|
|
515
|
+
}
|
|
516
|
+
const out = [];
|
|
517
|
+
for (const [code, value] of Object.entries(formData)) {
|
|
518
|
+
if (!staffCodes.has(code))
|
|
519
|
+
continue;
|
|
520
|
+
if (value === null || value === undefined || value === "")
|
|
521
|
+
continue;
|
|
522
|
+
if (typeof value === "string")
|
|
523
|
+
out.push({ code, got: "string" });
|
|
524
|
+
else if (Array.isArray(value) && value.every((entry) => typeof entry === "string"))
|
|
525
|
+
out.push({ code, got: `string[${value.length}]` });
|
|
526
|
+
}
|
|
527
|
+
return out;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* One published field.list read, reused by the child-row stamping AND the
|
|
531
|
+
* value-shape gates below, so the gates add zero extra wire calls.
|
|
532
|
+
*/
|
|
533
|
+
export async function loadPublishedFieldMeta(session, schemaCode) {
|
|
534
|
+
try {
|
|
535
|
+
const rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode, isPublish: "true" } })).data);
|
|
536
|
+
const childCodes = [];
|
|
537
|
+
const meta = new Map();
|
|
538
|
+
for (const row of rows) {
|
|
539
|
+
const code = String(row.code ?? row.propertyCode ?? "");
|
|
540
|
+
if (!code)
|
|
541
|
+
continue;
|
|
542
|
+
const type = Number(row.propertyType ?? row.type);
|
|
543
|
+
let format;
|
|
544
|
+
let serialNumber = false;
|
|
545
|
+
if (typeof row.options === "string" && row.options) {
|
|
546
|
+
try {
|
|
547
|
+
const parsed = JSON.parse(row.options);
|
|
548
|
+
if (typeof parsed.format === "string")
|
|
549
|
+
format = parsed.format;
|
|
550
|
+
serialNumber = parsed.formPropertyType === 100 || (Array.isArray(parsed.seqNoSetting) && parsed.seqNoSetting.length > 0);
|
|
551
|
+
}
|
|
552
|
+
catch {
|
|
553
|
+
// unparsable options: shape gates for this field are skipped
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const options = parseOptions(row.options);
|
|
557
|
+
serialNumber = serialNumber || options.formPropertyType === 100 || (Array.isArray(options.seqNoSetting) && options.seqNoSetting.length > 0);
|
|
558
|
+
meta.set(code, { type, ...(format !== undefined ? { format } : {}), ...(serialNumber ? { serialNumber: true } : {}) });
|
|
559
|
+
if (type === CHILD_TABLE_PROPERTY_TYPE)
|
|
560
|
+
childCodes.push(code);
|
|
561
|
+
}
|
|
562
|
+
return { childCodes, meta };
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* F6(w91,0.8.12 真机):`data.save` 传 2 行(风机皮带、润滑油),读回顺序相反、
|
|
570
|
+
* `sortKey:null`。平台证据:子表读回**固定按 sortKey ASC**(`BizObjectConverterImpl`
|
|
571
|
+
* 8.6.26:1235,1247 / 2.1.5 `BizObjectItem.toDataMap`:61-67;`SubBizObjectLoader`:137
|
|
572
|
+
* 同序),而表单运行时保存路径不补 sortKey(`BizObjectInsertModel`/`BizObjectUpdateItem`
|
|
573
|
+
* 无 sortKey 写入;补值只存在于导入合并 `IntegrationMergerUtils:34-37`、规则
|
|
574
|
+
* `CreateServiceExecutor:166`/`BizObjectUtil:131`、流程结束 `EndActivityRuntime:277-278`)。
|
|
575
|
+
* 所以新建保存/提交时,缺 sortKey 的子行按数组下标补 1..n;调用方显式值原样保留。
|
|
576
|
+
* 更新既有记录不补(既有行可能已有 sortKey,猜起点会撞号)。
|
|
577
|
+
*/
|
|
578
|
+
export function stampChildSortKeys(formData, childCodes) {
|
|
579
|
+
let changed = false;
|
|
580
|
+
const next = { ...formData };
|
|
581
|
+
for (const code of childCodes) {
|
|
582
|
+
const rows = formData[code];
|
|
583
|
+
if (!Array.isArray(rows))
|
|
584
|
+
continue;
|
|
585
|
+
let mutated = false;
|
|
586
|
+
const stamped = rows.map((entry, index) => {
|
|
587
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
588
|
+
return entry;
|
|
589
|
+
const row = entry;
|
|
590
|
+
if (row.sortKey !== null && row.sortKey !== undefined && String(row.sortKey).trim() !== "")
|
|
591
|
+
return row;
|
|
592
|
+
if (typeof row.rowStatus === "string" && row.rowStatus.trim().toLowerCase() === "deleted")
|
|
593
|
+
return row;
|
|
594
|
+
mutated = true;
|
|
595
|
+
return { ...row, sortKey: index + 1 };
|
|
596
|
+
});
|
|
597
|
+
if (mutated) {
|
|
598
|
+
next[code] = stamped;
|
|
599
|
+
changed = true;
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
return changed ? next : formData;
|
|
603
|
+
}
|
|
604
|
+
export async function stampChildRowStatuses(session, schemaCode, formData, preloaded) {
|
|
605
|
+
const loaded = preloaded !== undefined ? preloaded : await loadPublishedFieldMeta(session, schemaCode);
|
|
606
|
+
if (!loaded || loaded.childCodes.length === 0)
|
|
607
|
+
return { formData, childCodes: loaded?.childCodes ?? [], meta: loaded?.meta ?? new Map() };
|
|
608
|
+
const childCodes = new Set(loaded.childCodes);
|
|
609
|
+
let changed = false;
|
|
610
|
+
const next = { ...formData };
|
|
611
|
+
for (const code of childCodes) {
|
|
612
|
+
const value = formData[code];
|
|
613
|
+
if (!Array.isArray(value))
|
|
614
|
+
continue;
|
|
615
|
+
next[code] = value.map((entry) => {
|
|
616
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry))
|
|
617
|
+
return entry;
|
|
618
|
+
const row = entry;
|
|
619
|
+
if (typeof row.rowStatus === "string" && row.rowStatus.trim())
|
|
620
|
+
return row;
|
|
621
|
+
changed = true;
|
|
622
|
+
const hasId = typeof row.id === "string" && row.id.trim().length > 0;
|
|
623
|
+
return { ...row, rowStatus: hasId ? "Modified" : "Added" };
|
|
624
|
+
});
|
|
625
|
+
}
|
|
626
|
+
return { formData: changed ? next : formData, childCodes: [...childCodes], meta: loaded.meta };
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* The one write-path preflight shared by data.save / data.update / data.submit:
|
|
630
|
+
* load the published field metadata ONCE, refuse the proven bad value shapes
|
|
631
|
+
* (date/relation/child-row-id) BEFORE any mutation, then stamp rowStatus.
|
|
632
|
+
*
|
|
633
|
+
* `skipChildRowIdGate`:审批提交(workItemId/workflowInstanceId)先由
|
|
634
|
+
* `submit-approval-child-rows` 统一拒——无 id 子行的 `child-rows-missing-id`
|
|
635
|
+
* 教学会让调用方补 `rowStatus:"Added"`,然后再撞审批门(真机两道门互相打架)。
|
|
636
|
+
* `assignChildSortKeys`:仅新建记录(save/submit)补 1..n,见 stampChildSortKeys。
|
|
637
|
+
*/
|
|
638
|
+
export async function prepareRuntimeFormData(session, schemaCode, formData, opts) {
|
|
639
|
+
const loaded = await loadPublishedFieldMeta(session, schemaCode);
|
|
640
|
+
if (loaded)
|
|
641
|
+
assertRuntimeFieldValueShapes(loaded.meta, formData, loaded.childCodes, {
|
|
642
|
+
schemaCode,
|
|
643
|
+
isUpdate: opts.isUpdate && opts.skipChildRowIdGate !== true,
|
|
644
|
+
});
|
|
645
|
+
const stamped = await stampChildRowStatuses(session, schemaCode, formData, loaded);
|
|
646
|
+
const withSortKeys = opts.assignChildSortKeys === true ? stampChildSortKeys(stamped.formData, stamped.childCodes) : stamped.formData;
|
|
647
|
+
return { formData: withSortKeys, childCodes: stamped.childCodes, serialNumberCodes: loaded ? [...loaded.meta].filter(([, field]) => field.serialNumber).map(([code]) => code) : [], fieldCodes: loaded ? [...loaded.meta.keys()] : undefined, schemaLoaded: loaded !== null };
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Translate a platform DATE options.format into a validator regex. The format
|
|
651
|
+
* enum is UPPERCASE (`YYYY-MM-DD HH:mm:ss`), tokenized longest-first; literals
|
|
652
|
+
* (`-`, `/`, `:`, space, 年/月/日) are escaped. Unknown formats return null —
|
|
653
|
+
* the gate then stays silent rather than guessing.
|
|
654
|
+
*/
|
|
655
|
+
export function dateFormatRegex(format) {
|
|
656
|
+
const KNOWN = new Set([
|
|
657
|
+
"YYYY", "YYYY-MM", "YYYY/MM", "YYYY-MM-DD", "YYYY/MM/DD",
|
|
658
|
+
"YYYY-MM-DD HH:mm", "YYYY/MM/DD HH:mm", "YYYY-MM-DD HH:mm:ss", "YYYY/MM/DD HH:mm:ss",
|
|
659
|
+
"YYYY-MM-DD CN-APM", "YYYY/MM/DD CN-APM", "YYYY-MM-DD CN-APM HH:mm", "YYYY/MM/DD CN-APM HH:mm",
|
|
660
|
+
"YYYY-MM-DD EN-APM", "YYYY/MM/DD EN-APM", "YYYY-MM-DD EN-APM HH:mm", "YYYY/MM/DD EN-APM HH:mm",
|
|
661
|
+
"YYYY年MM月DD日", "YYYY年MM月",
|
|
662
|
+
]);
|
|
663
|
+
if (!KNOWN.has(format))
|
|
664
|
+
return null;
|
|
665
|
+
const pattern = format
|
|
666
|
+
.split("CN-APM").join("\u0001")
|
|
667
|
+
.split("EN-APM").join("\u0002")
|
|
668
|
+
.split("YYYY").join("\\d{4}")
|
|
669
|
+
.split("MM").join("\\d{2}")
|
|
670
|
+
.split("DD").join("\\d{2}")
|
|
671
|
+
.split("HH").join("\\d{2}")
|
|
672
|
+
.split("mm").join("\\d{2}")
|
|
673
|
+
.split("ss").join("\\d{2}")
|
|
674
|
+
.split("\u0001").join("(?:上午|下午)")
|
|
675
|
+
.split("\u0002").join("(?:AM|PM)")
|
|
676
|
+
.replace(/[-/]/g, (ch) => `\\${ch}`);
|
|
677
|
+
return new RegExp(`^${pattern}$`);
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* r17 (2026-10-26) live write-shape evidence on 1.1.25 — every case below was
|
|
681
|
+
* observed on the wire, none is speculative:
|
|
682
|
+
* - DATE(3): a plain string in the field's declared format lands correctly;
|
|
683
|
+
* a millisecond timestamp is ACCEPTED and stored NULL (silent data loss);
|
|
684
|
+
* a date-only or ISO-8601-with-timezone string against a datetime format
|
|
685
|
+
* answers 50000 服务异常.
|
|
686
|
+
* - WORK_SHEET(9): a single relation field takes the bare object id string;
|
|
687
|
+
* an array answers 50000 服务异常.
|
|
688
|
+
* - CHILD_TABLE rows on an UPDATE of an existing record: a row without `id`
|
|
689
|
+
* is INSERTED as a NEW child row (no upsert) — r17: four updates each
|
|
690
|
+
* resending two id-less rows turned 2 child rows into 8, and a roll-up
|
|
691
|
+
* SUM over them silently doubled. The portal always sends the id (→
|
|
692
|
+
* rowStatus Modified) for existing rows; a hand-built payload must too.
|
|
693
|
+
*/
|
|
694
|
+
export function assertRuntimeFieldValueShapes(meta, formData, childCodes, context) {
|
|
695
|
+
for (const [code, value] of Object.entries(formData)) {
|
|
696
|
+
if (value === null || value === undefined)
|
|
697
|
+
continue;
|
|
698
|
+
const field = meta.get(code);
|
|
699
|
+
if (!field)
|
|
700
|
+
continue;
|
|
701
|
+
if (field.type === 3 && typeof value === "number") {
|
|
702
|
+
throw new ToolRefusalError({
|
|
703
|
+
status: "refused",
|
|
704
|
+
blocker: "submit-date-shape",
|
|
705
|
+
schemaCode: context.schemaCode,
|
|
706
|
+
field: code,
|
|
707
|
+
message: `日期字段 ${code} 收到数字 ${value}(毫秒时间戳):平台接受但**静默落库 NULL**(r17 真机)。` +
|
|
708
|
+
`日期必须写成字段 format 对应的字符串(本字段 format=${field.format ?? "未知"}),如 "2026-10-26 11:00:00"。`,
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
if (field.type === 3 && typeof value === "string" && field.format) {
|
|
712
|
+
const re = dateFormatRegex(field.format);
|
|
713
|
+
if (re && !re.test(value.trim())) {
|
|
714
|
+
throw new ToolRefusalError({
|
|
715
|
+
status: "refused",
|
|
716
|
+
blocker: "submit-date-shape",
|
|
717
|
+
schemaCode: context.schemaCode,
|
|
718
|
+
field: code,
|
|
719
|
+
format: field.format,
|
|
720
|
+
message: `日期字段 ${code} 的值 "${value}" 不匹配字段声明的 format "${field.format}"——平台直接回 50000 服务异常(r17 真机:仅日期串/ISO8601 带时区都打回)。` +
|
|
721
|
+
`按 format 逐位对齐;改格式走 field.update。`,
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (field.type === 9 && Array.isArray(value)) {
|
|
726
|
+
// Same refusal as the post-hoc diagnoseRelationShapeFailure (which stays
|
|
727
|
+
// as the backstop for nested child-row relations); pre-write is cheaper.
|
|
728
|
+
throw new ToolRefusalError({
|
|
729
|
+
status: "refused",
|
|
730
|
+
blocker: "relation-single-array-shape",
|
|
731
|
+
schemaCode: context.schemaCode,
|
|
732
|
+
fields: [code],
|
|
733
|
+
message: `单选关联字段 ${code}(WORK_SHEET/propertyType 9)传了数组:平台稳定回 50000(r17b 2026-10-26 真机)。` +
|
|
734
|
+
`单值关联写 **id 字符串或 {id}**;多值关联(MULT_WORK_SHEET 11)与人员/组织(50/51)才用数组。`,
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (context.isUpdate) {
|
|
739
|
+
const problems = [];
|
|
740
|
+
for (const code of childCodes) {
|
|
741
|
+
const rows = formData[code];
|
|
742
|
+
if (!Array.isArray(rows))
|
|
743
|
+
continue;
|
|
744
|
+
const missing = rows.filter((row) => row !== null &&
|
|
745
|
+
typeof row === "object" &&
|
|
746
|
+
!Array.isArray(row) &&
|
|
747
|
+
!(typeof row.id === "string" && row.id.trim().length > 0) &&
|
|
748
|
+
!(typeof row.rowStatus === "string" && row.rowStatus.trim().length > 0));
|
|
749
|
+
if (missing.length > 0)
|
|
750
|
+
problems.push(`${code}(${missing.length}/${rows.length} 行无 id/rowStatus)`);
|
|
751
|
+
}
|
|
752
|
+
if (problems.length > 0) {
|
|
753
|
+
throw new ToolRefusalError({
|
|
754
|
+
status: "refused",
|
|
755
|
+
// r29b F7: blocker 名与工具无关(data.update / data.submit 共用);旧名保留兼容。
|
|
756
|
+
blocker: "child-rows-missing-id",
|
|
757
|
+
blockerAliases: ["submit-child-rows-missing-id"],
|
|
758
|
+
schemaCode: context.schemaCode,
|
|
759
|
+
childTables: problems,
|
|
760
|
+
message: `更新既有记录时子表行必须带 id:${problems.join("、")}。平台对无 id 的子行按**新增插入**(不判重)——` +
|
|
761
|
+
`r17 真机:同一条记录连发 4 次带 2 行无 id 子表的 update,子行从 2 变 8,聚合 SUM 翻倍。` +
|
|
762
|
+
`改既有行:先 data.load 拿子行 id 原样带回(平台走 rowStatus=Modified);` +
|
|
763
|
+
`有意追加新行:显式给该行 rowStatus:"Added";删除行:只传 {id, rowStatus:"Deleted"}(少传行不会删)。` +
|
|
764
|
+
`三合一示例见 describe data.update --example child-rows-upsert。`,
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
/**
|
|
770
|
+
* r29b F6: 「少传行」被平台静默忽略。比较提交行与库内行,缺 Deleted 标记时给 warning,
|
|
771
|
+
* **绝不**自动删(语义不能猜)。
|
|
772
|
+
*/
|
|
773
|
+
export function childRowsNotDeletedWarnings(formData, existingRecord, childCodes) {
|
|
774
|
+
if (!existingRecord)
|
|
775
|
+
return [];
|
|
776
|
+
const warnings = [];
|
|
777
|
+
for (const code of childCodes) {
|
|
778
|
+
const submitted = formData[code];
|
|
779
|
+
if (!Array.isArray(submitted))
|
|
780
|
+
continue;
|
|
781
|
+
const existing = existingRecord[code];
|
|
782
|
+
if (!Array.isArray(existing))
|
|
783
|
+
continue;
|
|
784
|
+
const existingIds = existing
|
|
785
|
+
.map((row) => (row && typeof row === "object" && !Array.isArray(row) ? String(row.id ?? "").trim() : ""))
|
|
786
|
+
.filter((id) => id.length > 0);
|
|
787
|
+
if (existingIds.length === 0)
|
|
788
|
+
continue;
|
|
789
|
+
const submittedIds = new Set(submitted
|
|
790
|
+
.map((row) => (row && typeof row === "object" && !Array.isArray(row) ? String(row.id ?? "").trim() : ""))
|
|
791
|
+
.filter((id) => id.length > 0));
|
|
792
|
+
const hasExplicitDelete = submitted.some((row) => row &&
|
|
793
|
+
typeof row === "object" &&
|
|
794
|
+
!Array.isArray(row) &&
|
|
795
|
+
typeof row.rowStatus === "string" &&
|
|
796
|
+
String(row.rowStatus).toLowerCase() === "deleted");
|
|
797
|
+
if (hasExplicitDelete)
|
|
798
|
+
continue;
|
|
799
|
+
if (submitted.length >= existingIds.length && submittedIds.size >= existingIds.length)
|
|
800
|
+
continue;
|
|
801
|
+
const omitted = existingIds.filter((id) => !submittedIds.has(id));
|
|
802
|
+
if (omitted.length === 0 && submitted.length >= existingIds.length)
|
|
803
|
+
continue;
|
|
804
|
+
const missing = omitted.length > 0 ? omitted : existingIds.slice(submitted.length);
|
|
805
|
+
if (missing.length === 0)
|
|
806
|
+
continue;
|
|
807
|
+
warnings.push({
|
|
808
|
+
code: "child-rows-not-deleted",
|
|
809
|
+
childTable: code,
|
|
810
|
+
rows: missing,
|
|
811
|
+
hint: "少传行不会删除;删除需显式 rowStatus:'Deleted'(只给 id)",
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
return warnings;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* r18 (2026-10-26 live): `errcode 40000 调用数据库发生异常` carries NO detail and
|
|
818
|
+
* `omc-refusals` had nothing for it. A probe burned ~40 calls bisecting it:
|
|
819
|
+
* the cause was an AGGREGATION field whose `schemaCode` pointed at a CHILD-TABLE
|
|
820
|
+
* schema — publish succeeds, then every write on that model 40000s. A FORMULA
|
|
821
|
+
* field whose config cannot serialize does the same.
|
|
822
|
+
*
|
|
823
|
+
* Metadata is read ONLY on failure (zero cost on the success path). The refusal
|
|
824
|
+
* names the model's FORMULA/AGGREGATION fields so the caller bisects the right
|
|
825
|
+
* thing instead of guessing at forms/permissions.
|
|
826
|
+
*/
|
|
827
|
+
export async function diagnoseDbException(session, schemaCode, error) {
|
|
828
|
+
// Non-40000 errors fall through untouched (callers keep their own branches).
|
|
829
|
+
if (!(error instanceof WireError && error.kind === "business" && error.errcode === 40000))
|
|
830
|
+
return false;
|
|
831
|
+
let rows = [];
|
|
832
|
+
try {
|
|
833
|
+
rows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode, isPublish: "true" } })).data);
|
|
834
|
+
}
|
|
835
|
+
catch {
|
|
836
|
+
// metadata unavailable: still explain what 40000 means
|
|
837
|
+
}
|
|
838
|
+
const formulaFields = [];
|
|
839
|
+
for (const row of rows) {
|
|
840
|
+
if (Number(row.propertyType ?? row.type) !== 100)
|
|
841
|
+
continue;
|
|
842
|
+
let formulaType;
|
|
843
|
+
let aggregationSchemaCode;
|
|
844
|
+
if (typeof row.options === "string" && row.options) {
|
|
845
|
+
try {
|
|
846
|
+
const options = JSON.parse(row.options);
|
|
847
|
+
const config = typeof options.formulaConfig === "string" ? JSON.parse(options.formulaConfig) : undefined;
|
|
848
|
+
if (typeof config?.formulaType === "string")
|
|
849
|
+
formulaType = config.formulaType;
|
|
850
|
+
if (typeof config?.aggregation === "string") {
|
|
851
|
+
const agg = JSON.parse(config.aggregation);
|
|
852
|
+
if (typeof agg.schemaCode === "string")
|
|
853
|
+
aggregationSchemaCode = agg.schemaCode;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
catch {
|
|
857
|
+
formulaType = "unparsable-formulaConfig";
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
formulaFields.push({ code: String(row.code ?? row.propertyCode ?? ""), ...(formulaType ? { formulaType } : {}), ...(aggregationSchemaCode ? { aggregationSchemaCode } : {}) });
|
|
861
|
+
}
|
|
862
|
+
throw new ToolRefusalError({
|
|
863
|
+
status: "refused",
|
|
864
|
+
blocker: "runtime-write-db-exception",
|
|
865
|
+
schemaCode,
|
|
866
|
+
errcode: 40000,
|
|
867
|
+
formulaFields,
|
|
868
|
+
message: `平台回 40000「调用数据库发生异常」——这是**无明细的掩码**,不是表单/权限问题(r18 真机)。` +
|
|
869
|
+
`本模型上的公式字段:${formulaFields.length > 0 ? formulaFields.map((field) => `${field.code}(${field.formulaType ?? "?"}${field.aggregationSchemaCode ? `→${field.aggregationSchemaCode}` : ""})`).join("、") : "(读不到 field.list,或没有 FORMULA 字段)"}。` +
|
|
870
|
+
`最常见原因:**AGGREGATION 字段的 schemaCode 指向子表 schema** —— 平台允许发布,但该模型从此整个不可写。` +
|
|
871
|
+
`其次是 FORMULA 的 formulaConfig 无法序列化。` +
|
|
872
|
+
`定位:依次禁用/删除可疑公式字段再写一次(可逆);形状见 omc describe field.create --example formula-aggregation-cross-model。`,
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
//# sourceMappingURL=write-support.js.map
|