@stalfh233/omc-cli 0.8.2 → 0.8.4
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/bench/call-face-eval.js +1 -1
- package/dist/bench/scenario.js +3 -3
- package/dist/cli-contract.js +55 -2
- package/dist/cli-output.js +59 -8
- package/dist/cli.js +338 -59
- package/dist/field-families.js +19 -9
- package/dist/form-layout.js +19 -4
- package/dist/form-support.js +181 -9
- package/dist/graph.js +151 -29
- package/dist/intent/capabilities/field.js +98 -0
- package/dist/intent/plan-apply.js +9 -0
- package/dist/lanes/app.js +34 -6
- package/dist/lanes/field.js +360 -94
- package/dist/lanes/form.js +27 -5
- package/dist/lanes/model.js +42 -11
- package/dist/lanes/runtime-data.js +93 -4
- package/dist/lanes/workflow-contract.js +1 -1
- package/dist/lanes/workflow.js +30 -14
- package/dist/path-projection.js +25 -14
- package/dist/read.js +132 -3
- package/dist/refusal-guidance.js +14 -0
- package/dist/session.js +30 -2
- package/dist/support.js +3 -1
- package/dist/wire-failure.js +120 -0
- package/dist/wire.js +109 -5
- package/dist/workflow-support.js +41 -0
- package/package.json +3 -3
package/dist/lanes/field.js
CHANGED
|
@@ -15,6 +15,7 @@ import { executeFormDraftWrite, executeFormPublishWrite, readFormOrNull } from "
|
|
|
15
15
|
import { FIELD_LANE_CONTRACT } from "./field-contract.js";
|
|
16
16
|
import { flattenTreeRows, mapBounded } from "../support.js";
|
|
17
17
|
import { extractBizObjectPage } from "./runtime-data.js";
|
|
18
|
+
import { readModelRecord } from "../model-record.js";
|
|
18
19
|
const FIELD_LANE = FIELD_LANE_CONTRACT.lane;
|
|
19
20
|
const FIELD_TOOLS = FIELD_LANE_CONTRACT.tools;
|
|
20
21
|
/** Read actual model schema codes; bare modelList may expose internal node ids. */
|
|
@@ -85,34 +86,151 @@ function propertyTypeName(type) {
|
|
|
85
86
|
return name;
|
|
86
87
|
return String(type);
|
|
87
88
|
}
|
|
89
|
+
function pendingOwnFieldRows(pending) {
|
|
90
|
+
return pending.flatMap((field) => {
|
|
91
|
+
const raw = field.propertyType;
|
|
92
|
+
const type = typeof raw === "number" ? raw : FIELD_PROPERTY_TYPES[String(raw)];
|
|
93
|
+
return field.code ? [{ code: field.code, ...(type !== undefined ? { type } : {}) }] : [];
|
|
94
|
+
});
|
|
95
|
+
}
|
|
88
96
|
/** Semantic relation gate: the designer only offers published business fields. */
|
|
89
|
-
async function assertRelationOptionsFields(session, schemaCode, propertyType, relativeCode, options) {
|
|
97
|
+
async function assertRelationOptionsFields(session, schemaCode, propertyType, relativeCode, options, pendingOwnFields = []) {
|
|
90
98
|
const type = typeof propertyType === "number" ? propertyType : FIELD_PROPERTY_TYPES[String(propertyType ?? "")];
|
|
91
99
|
if (type !== FIELD_PROPERTY_TYPES.WORK_SHEET && type !== FIELD_PROPERTY_TYPES.MULT_WORK_SHEET)
|
|
92
100
|
return;
|
|
93
101
|
const target = String(relativeCode ?? options.schemaCode ?? "").trim();
|
|
94
102
|
if (!target)
|
|
95
103
|
return;
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
// One published-face read per schema, shared by target/own/main (a self
|
|
105
|
+
// relation names the same schema twice; a missing side must not fail the
|
|
106
|
+
// whole gate — see the empty-face note below).
|
|
107
|
+
const rowCache = new Map();
|
|
108
|
+
const rowsOf = (code) => {
|
|
109
|
+
const cached = rowCache.get(code);
|
|
110
|
+
if (cached)
|
|
111
|
+
return cached;
|
|
112
|
+
const pending = wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: code, isPublish: "true" } })
|
|
113
|
+
.then((response) => wireRows(response.data))
|
|
114
|
+
.catch(() => []);
|
|
115
|
+
rowCache.set(code, pending);
|
|
116
|
+
return pending;
|
|
117
|
+
};
|
|
118
|
+
const targetRows = await rowsOf(target);
|
|
119
|
+
// 同包声明、尚未落库的本模型字段并进本模型读面(configure_model 的 P0 缝)。
|
|
120
|
+
const ownRows = [...(await rowsOf(schemaCode)), ...pendingOwnFieldRows(pendingOwnFields)];
|
|
121
|
+
// 设计器把「关联目标 = 某模型的子表」存成 options.mainTableCode(主表模型)
|
|
122
|
+
// + options.schemaCode(子表)。前端 getSourceDataItems(bundle
|
|
123
|
+
// admin/js/79850.2b085fc5.js@byte25582,mainTableCode 分支@25858)把主表字段与
|
|
124
|
+
// 子表字段(FlatMapSheetPropertiesDecorator 生成的 `子表code.字段code`,
|
|
125
|
+
// bundle main.33434673.js@byte1978673)并进同一份 source 候选;后端
|
|
126
|
+
// WorkSheetMappingServiceImpl.queryWorksheetData(2.1.5:322-340 / 8.6.26:358-376)
|
|
127
|
+
// 也按 `裸 code = 主表字段`(P___ 别名)、`子表code.字段code = 该子表字段` 解析。
|
|
128
|
+
// 所以 source 的合法集不是只有关联模型(子表)字段;但它也**不**包含本模型字段
|
|
129
|
+
// ——设计器 getSourceList(bundle 17170.93392489.js@byte3998)只从 sourceDataItems
|
|
130
|
+
// (关联侧)取 source,本模型字段只做 target。mainTableCode 本身是 options 一等键
|
|
131
|
+
// (BizPropertyUtil.java 2.1.5:74-79 / 8.6.26:80-85 随 schemaCode 一起改名)。
|
|
132
|
+
const mainTableCode = typeof options.mainTableCode === "string" ? options.mainTableCode.trim() : "";
|
|
133
|
+
const mainRows = mainTableCode === target
|
|
134
|
+
? targetRows
|
|
135
|
+
: mainTableCode === schemaCode
|
|
136
|
+
? ownRows
|
|
137
|
+
: mainTableCode
|
|
138
|
+
? await rowsOf(mainTableCode)
|
|
139
|
+
: [];
|
|
98
140
|
const business = (rows) => rows
|
|
99
141
|
.map((row) => ({ code: String(row.code ?? row.propertyCode ?? "").trim(), type: relationTypeOf(row) }))
|
|
100
142
|
.filter((row) => row.code && !SYSTEM_FIELD_CODES.has(row.code));
|
|
101
143
|
const targetFields = business(targetRows);
|
|
102
144
|
const ownFields = business(ownRows);
|
|
145
|
+
const mainFields = business(mainRows);
|
|
146
|
+
// 候选清单按 field.list 的业务字段口径(businessOnly)过滤:`parentId`/`sortKey`
|
|
147
|
+
// 是平台注入子表的系统列,业务字段面板不显示,提示里也不该出现(0.8.3 真机 §5.4)。
|
|
148
|
+
// **判定**仍用上面未过滤的字段集——系统列确实存在于模型,把它们从解析/存在性里
|
|
149
|
+
// 摘掉会把指向系统列的合法映射误判成「字段不存在」。
|
|
150
|
+
const listedFields = (fields) => fields.filter((row) => !isSystemFieldCode(row.code));
|
|
103
151
|
// A compatibility/fake transport may expose an empty field face even though
|
|
104
152
|
// the model exists. Empty metadata is not proof that a requested field is
|
|
105
153
|
// absent; preserve the existing relation write path rather than rejecting a
|
|
106
154
|
// valid payload on an unavailable read face.
|
|
107
155
|
if (targetRows.length === 0 || ownRows.length === 0)
|
|
108
156
|
return;
|
|
109
|
-
|
|
157
|
+
// 关联目标是子表时(fieldList 带回 parentId/sortKey),裸 source 按主表字段
|
|
158
|
+
// 解析、`子表code.字段code` 按子表字段解析——两种都是设计器下拉里的合法项。
|
|
159
|
+
const targetIsChildSheet = childSchemaCodes(targetRows);
|
|
160
|
+
const childSheetCodes = new Set();
|
|
161
|
+
for (const field of mainFields)
|
|
162
|
+
if (field.type === FIELD_PROPERTY_TYPES.CHILD_TABLE)
|
|
163
|
+
childSheetCodes.add(field.code);
|
|
164
|
+
// 运行期解析裸 source 的判据是**关联目标 schema 的 BizSchema.parentCode**,不是
|
|
165
|
+
// options.mainTableCode(WorkSheetMappingServiceImpl.getMappingWorkSheetValue
|
|
166
|
+
// 2.1.5:270-274 / 8.6.26:310-314 只读 querySchemaCode 的 parentCode;
|
|
167
|
+
// 该类全文无 mainTableCode 读取点)。父模型 code 走既有读面
|
|
168
|
+
// bizmodels/get_all(BizSchemaModel.parentCode;2.1.5 BizSchemaController.java:479-486 /
|
|
169
|
+
// 8.6.26 同文件:615-631)。只在 mainTableCode 缺失或裸 source 未命中时读一次,
|
|
170
|
+
// 保证设计器正常数据零额外 wire。
|
|
171
|
+
let parentLoaded = false;
|
|
172
|
+
let targetParentCode = "";
|
|
173
|
+
let targetParentFields = [];
|
|
174
|
+
const loadTargetParent = async () => {
|
|
175
|
+
if (parentLoaded)
|
|
176
|
+
return targetParentCode;
|
|
177
|
+
parentLoaded = true;
|
|
178
|
+
try {
|
|
179
|
+
const record = await readModelRecord(session, target);
|
|
180
|
+
targetParentCode = typeof record?.parentCode === "string" ? record.parentCode.trim() : "";
|
|
181
|
+
}
|
|
182
|
+
catch {
|
|
183
|
+
targetParentCode = "";
|
|
184
|
+
}
|
|
185
|
+
if (!targetParentCode || targetParentCode === target)
|
|
186
|
+
return targetParentCode;
|
|
187
|
+
if (targetParentCode === schemaCode)
|
|
188
|
+
targetParentFields = ownFields;
|
|
189
|
+
else if (targetParentCode === mainTableCode)
|
|
190
|
+
targetParentFields = mainFields;
|
|
191
|
+
else {
|
|
192
|
+
targetParentFields = business(await rowsOf(targetParentCode));
|
|
193
|
+
for (const field of targetParentFields)
|
|
194
|
+
if (field.type === FIELD_PROPERTY_TYPES.CHILD_TABLE)
|
|
195
|
+
childSheetCodes.add(field.code);
|
|
196
|
+
}
|
|
197
|
+
return targetParentCode;
|
|
198
|
+
};
|
|
199
|
+
/** Resolve a mapping source: bare code (linked model / its parent main table) or `sheet.column`. */
|
|
200
|
+
const resolveSource = async (source) => {
|
|
201
|
+
if (!source)
|
|
202
|
+
return undefined;
|
|
203
|
+
const dot = source.indexOf(".");
|
|
204
|
+
if (dot < 0) {
|
|
205
|
+
const hit = [...targetFields, ...mainFields].find((row) => row.code === source);
|
|
206
|
+
if (hit)
|
|
207
|
+
return hit;
|
|
208
|
+
await loadTargetParent();
|
|
209
|
+
return targetParentFields.find((row) => row.code === source);
|
|
210
|
+
}
|
|
211
|
+
const sheetCode = source.slice(0, dot);
|
|
212
|
+
const column = source.slice(dot + 1);
|
|
213
|
+
if (!column || column.includes("."))
|
|
214
|
+
return undefined;
|
|
215
|
+
if (!targetIsChildSheet && !mainTableCode)
|
|
216
|
+
await loadTargetParent();
|
|
217
|
+
// Only the child-sheet relation shape uses dots; `模型.字段` on a plain
|
|
218
|
+
// model target would be dropped at runtime (not fetched), so keep it refused.
|
|
219
|
+
if (!targetIsChildSheet && !mainTableCode && !targetParentCode)
|
|
220
|
+
return undefined;
|
|
221
|
+
const sheetRows = sheetCode === target ? targetRows : childSheetCodes.has(sheetCode) ? await rowsOf(sheetCode) : undefined;
|
|
222
|
+
if (!sheetRows || sheetRows.length === 0)
|
|
223
|
+
return undefined;
|
|
224
|
+
return business(sheetRows).find((row) => row.code === column);
|
|
225
|
+
};
|
|
226
|
+
const linkedCandidates = [...new Set(listedFields([...targetFields, ...mainFields]).map((row) => row.code))].sort();
|
|
110
227
|
const display = typeof options.displayField === "string" ? options.displayField.trim() : "";
|
|
111
228
|
if (display) {
|
|
112
|
-
|
|
229
|
+
// 子表目标下显示字段来自主表模型(前端 getRelativeDataItem(mainTableCode))。
|
|
230
|
+
const field = [...targetFields, ...mainFields].find((row) => row.code === display);
|
|
113
231
|
const declaredType = options.displayFieldType === undefined ? undefined : Number(options.displayFieldType);
|
|
114
232
|
if (!field || (declaredType !== undefined && Number.isInteger(declaredType) && field.type !== undefined && field.type !== declaredType)) {
|
|
115
|
-
throw new ToolRefusalError({ status: "refused", blocker: "relation-display-field-not-found", schemaCode, relationTarget: target, displayField: display, candidates, message: `关联显示字段 ${target}.${display}
|
|
233
|
+
throw new ToolRefusalError({ status: "refused", blocker: "relation-display-field-not-found", schemaCode, relationTarget: target, displayField: display, candidates: linkedCandidates, message: `关联显示字段 ${target}.${display} 不存在于发布面或类型不兼容;请从关联模型业务字段中选择。候选:${linkedCandidates.join("、") || "(无)"}` });
|
|
116
234
|
}
|
|
117
235
|
}
|
|
118
236
|
let mappings = options.mappings;
|
|
@@ -126,20 +244,36 @@ async function assertRelationOptionsFields(session, schemaCode, propertyType, re
|
|
|
126
244
|
}
|
|
127
245
|
if (!Array.isArray(mappings))
|
|
128
246
|
return;
|
|
129
|
-
const
|
|
130
|
-
const targetCandidates = ownFields.map((row) => row.code).sort();
|
|
247
|
+
const targetCandidates = listedFields(ownFields).map((row) => row.code).sort();
|
|
131
248
|
for (const [index, row] of mappings.entries()) {
|
|
132
249
|
const source = row && typeof row === "object" ? String(row.source ?? "").trim() : "";
|
|
133
250
|
const mappedTarget = row && typeof row === "object" ? String(row.target ?? "").trim() : "";
|
|
134
|
-
|
|
135
|
-
|
|
251
|
+
const sourceField = await resolveSource(source);
|
|
252
|
+
const targetField = ownFields.find((entry) => entry.code === mappedTarget);
|
|
253
|
+
if (!sourceField || !targetField) {
|
|
254
|
+
// Diagnosis must be actionable: name the linked side(s) actually consulted.
|
|
255
|
+
if (!sourceField)
|
|
256
|
+
await loadTargetParent();
|
|
257
|
+
const linkedCodes = [...new Set(listedFields([...targetFields, ...mainFields, ...targetParentFields]).map((entry) => entry.code))].sort();
|
|
258
|
+
const side = !sourceField && !targetField ? "both" : !sourceField ? "source" : "target";
|
|
259
|
+
const linkedHint = mainTableCode
|
|
260
|
+
? `关联模型 ${target} / 主表 ${mainTableCode}`
|
|
261
|
+
: targetParentCode
|
|
262
|
+
? `关联模型 ${target} / 其父模型 ${targetParentCode}(bizmodels/get_all.parentCode)`
|
|
263
|
+
: `关联模型 ${target}(bizmodels/get_all 未回 parentCode:它没有父模型,裸 source 只能在 ${target} 自身字段里)`;
|
|
264
|
+
const detail = side === "source"
|
|
265
|
+
? `source=${source || "(空)"} 既不是${linkedHint}的发布面字段(关联目标为子表时:主表字段用裸 code、子表字段写成 子表code.字段code)。关联侧候选:${linkedCodes.join("、") || "(无)"};本模型 target 候选:${targetCandidates.join("、") || "(无)"}`
|
|
266
|
+
: side === "target"
|
|
267
|
+
? `target=${mappedTarget || "(空)"} 不是本模型 ${schemaCode} 的发布面字段(target 只用本模型字段 code,不带前缀)。本模型候选:${targetCandidates.join("、") || "(无)"}`
|
|
268
|
+
: `source=${source || "(空)"} 不在${linkedHint}的发布面字段里;target=${mappedTarget || "(空)"} 不在本模型 ${schemaCode} 的发布面字段里。关联侧候选:${linkedCodes.join("、") || "(无)"};本模型候选:${targetCandidates.join("、") || "(无)"}`;
|
|
269
|
+
throw new ToolRefusalError({ status: "refused", blocker: "relation-mapping-field-not-found", side, schemaCode, relationTarget: target, ...(mainTableCode ? { mainTableCode } : {}), ...(targetParentCode ? { relationParentCode: targetParentCode } : {}), mappingIndex: index, source, targetField: mappedTarget, sourceCandidates: linkedCodes, targetCandidates, message: `关联映射第 ${index + 1} 行字段不存在:${detail}。请使用发布面业务字段 code;确认关联面用 omc call field.list --args '{"schemaCode":"<模型code>","published":true}'。` });
|
|
136
270
|
}
|
|
137
271
|
// r52:类型兼容门。设计器 filterCondition(admin/js/17170.93392489.js)是产品承认的
|
|
138
272
|
// 可映射不变量,但它只活在下拉框里——保存、导入、field.create 全都绕过;平台后端
|
|
139
273
|
// checkOptions 的 if 链缺 WORK_SHEET 分支,运行期 assignChildData 直接 put 零转换。
|
|
140
274
|
// 所以错配要么运行期 50000,要么静默变 null/false/悬空 id。这里按设计器口径拦。
|
|
141
|
-
const sourceType =
|
|
142
|
-
const targetType =
|
|
275
|
+
const sourceType = sourceField.type;
|
|
276
|
+
const targetType = targetField.type;
|
|
143
277
|
if (sourceType !== undefined && targetType !== undefined && !mappingTypesCompatible(targetType, sourceType)) {
|
|
144
278
|
throw new ToolRefusalError({ status: "refused", blocker: "mapping-type-incompatible", schemaCode, relationTarget: target, mappingIndex: index, source, sourceType: propertyTypeName(sourceType), targetField: mappedTarget, targetType: propertyTypeName(targetType), allowedSourceTypes: mappingCompatibleSourceTypes(targetType).map(propertyTypeName), message: `关联映射第 ${index + 1} 行类型不兼容:${propertyTypeName(sourceType)} → ${propertyTypeName(targetType)}。设计器只允许 ${propertyTypeName(targetType)} 接收 ${mappingCompatibleSourceTypes(targetType).map(propertyTypeName).join("/")}。平台后端不校验这条,硬写会在运行期 50000 或静默丢值(真机 r52 2026-11-10)。` });
|
|
145
279
|
}
|
|
@@ -242,6 +376,23 @@ function isSystemFieldCode(code) {
|
|
|
242
376
|
const value = String(code ?? "");
|
|
243
377
|
return SYSTEM_FIELD_CODES.has(value) || value === "parentId" || value === "sortKey";
|
|
244
378
|
}
|
|
379
|
+
/**
|
|
380
|
+
* 子表 schema(`bizmodels/get_all.parentCode` 非空)没有独立表单槽位:表单/在线 JS
|
|
381
|
+
* 都挂在父模型的 `bizsheet` 上。把子表 code 当 `form.get` 的入参只会固定回 50000
|
|
382
|
+
* 「服务异常」——那是噪音,不是「表单里没有这个字段」(0.8.3 真机 §5.6)。
|
|
383
|
+
* 判据读一次模型记录(与关联语义门同一个 parentCode 面);读不到就按「不是子表」
|
|
384
|
+
* 继续既有扫描,不因判定面不可用而扩大跳过范围。
|
|
385
|
+
*/
|
|
386
|
+
async function schemaIsChildTable(session, schemaCode) {
|
|
387
|
+
try {
|
|
388
|
+
const record = await readModelRecord(session, schemaCode);
|
|
389
|
+
const parentCode = typeof record?.parentCode === "string" ? record.parentCode.trim() : "";
|
|
390
|
+
return parentCode !== "" && parentCode !== schemaCode;
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
245
396
|
/**
|
|
246
397
|
* 线上 #40 第 8 条(2026-11-17):field.list 只有 code/type/typeName/name,
|
|
247
398
|
* 无法判断字段何时被删除/改名(探针只能用业务数据的时间反推)。
|
|
@@ -275,7 +426,7 @@ function pickFieldTimestamps(row) {
|
|
|
275
426
|
* from an external model without a read. The create path already reads the
|
|
276
427
|
* published field list, so resolve it here for free and refuse before the write.
|
|
277
428
|
*/
|
|
278
|
-
function assertNoSelfSchemaAggregation(args, published) {
|
|
429
|
+
function assertNoSelfSchemaAggregation(args, published, pendingOwnFields = []) {
|
|
279
430
|
const raw = args.propertyType;
|
|
280
431
|
const propertyType = typeof raw === "number" ? raw : FIELD_PROPERTY_TYPES[String(raw)];
|
|
281
432
|
if (propertyType !== FIELD_PROPERTY_TYPES.FORMULA)
|
|
@@ -288,9 +439,14 @@ function assertNoSelfSchemaAggregation(args, published) {
|
|
|
288
439
|
const target = typeof agg?.schemaCode === "string" ? agg.schemaCode.trim() : "";
|
|
289
440
|
if (!target)
|
|
290
441
|
return;
|
|
291
|
-
const childCodes =
|
|
292
|
-
|
|
293
|
-
|
|
442
|
+
const childCodes = [
|
|
443
|
+
...published
|
|
444
|
+
.filter((row) => Number(row.type ?? row.propertyType) === FIELD_PROPERTY_TYPES.CHILD_TABLE)
|
|
445
|
+
.map((row) => String(row.code ?? row.propertyCode ?? "")),
|
|
446
|
+
...pendingOwnFieldRows(pendingOwnFields)
|
|
447
|
+
.filter((row) => row.type === FIELD_PROPERTY_TYPES.CHILD_TABLE)
|
|
448
|
+
.map((row) => String(row.code)),
|
|
449
|
+
];
|
|
294
450
|
const resolvesToSelf = aggregationTargetsOwnSchema(args.schemaCode, target) || childCodes.includes(stripAggregationPrefix(target));
|
|
295
451
|
if (!resolvesToSelf)
|
|
296
452
|
return;
|
|
@@ -340,6 +496,32 @@ async function assertNoChildSchemaAggregation(session, schemaCode, propertyType,
|
|
|
340
496
|
`(门户计算规则 / 写入方维护),再用 AGGREGATION 聚合该标量。配方:omc describe field.create --example formula-aggregation-cross-model。`,
|
|
341
497
|
});
|
|
342
498
|
}
|
|
499
|
+
/**
|
|
500
|
+
* `field.create` 的**唯一**写前语义门(0.8.4 P0,2.1.5/8.6.26 双侧证据见
|
|
501
|
+
* assertRelationOptionsFields / assertNoSelfSchemaAggregation 的注释):
|
|
502
|
+
*
|
|
503
|
+
* 1. 聚合自引用/本模型子表(305003 死循环);
|
|
504
|
+
* 2. 聚合目标是子表 schema(目标模型从此不可写 40000);
|
|
505
|
+
* 3. 关联目标模型不存在(发布 300010 毒模型);
|
|
506
|
+
* 4. 关联映射的 source/target 合法性(运行期 50000 / 静默丢值)。
|
|
507
|
+
*
|
|
508
|
+
* `field.create` 与 `configure_model` 的 `fields[]` 都调这一个函数:编排(写锁、
|
|
509
|
+
* 顺序、续跑)留在各自 lane,判定只在这里。**不要**在别处再内联其中任何一道。
|
|
510
|
+
*/
|
|
511
|
+
export async function lintFieldCreateWrite(session, input, options = {}) {
|
|
512
|
+
const published = options.publishedRows
|
|
513
|
+
?? wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: input.schemaCode, isPublish: "true" } })).data);
|
|
514
|
+
const pendingOwnFields = options.pendingOwnFields ?? [];
|
|
515
|
+
assertNoSelfSchemaAggregation({ schemaCode: input.schemaCode, propertyType: input.propertyType, options: input.options }, published, pendingOwnFields);
|
|
516
|
+
await assertNoChildSchemaAggregation(session, input.schemaCode, input.propertyType, input.options ?? {});
|
|
517
|
+
assertRelationTargetExists({ ...input }, options.relationCandidates ?? await modelSchemaCodes(session));
|
|
518
|
+
// 目标版本决定 optionsSet 形状:8.2 以下要补 optionStructure/treeSelect
|
|
519
|
+
// (cpdocs issue #8:缺键让设计器选项弹窗硬崩)。
|
|
520
|
+
const targetVersion = input.targetVersion ?? session.detectedVersion();
|
|
521
|
+
const prepared = prepareFieldChange({ ...input, ...(targetVersion ? { targetVersion } : {}) });
|
|
522
|
+
await assertRelationOptionsFields(session, input.schemaCode, prepared.propertyType, input.relativeCode, prepared.options, pendingOwnFields);
|
|
523
|
+
return prepared;
|
|
524
|
+
}
|
|
343
525
|
export function registerFieldLane(tools) {
|
|
344
526
|
tools.push(defineTool({
|
|
345
527
|
name: "field.list",
|
|
@@ -596,15 +778,10 @@ export function registerFieldLane(tools) {
|
|
|
596
778
|
}
|
|
597
779
|
// One seam owns field-change normalization, every reproduced gate, and the
|
|
598
780
|
// wire body (src/field-change.ts), so configure_model and intent share it.
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
const models = await modelSchemaCodes(session);
|
|
602
|
-
assertRelationTargetExists({ ...args }, models);
|
|
603
|
-
// 目标版本决定 optionsSet 形状:8.2 以下要补 optionStructure/treeSelect
|
|
604
|
-
// (cpdocs issue #8:缺键让设计器选项弹窗硬崩)。
|
|
781
|
+
// 0.8.4 P0: the three semantic gates live in lintFieldCreateWrite, which
|
|
782
|
+
// configure_model calls too — never inline a subset here again.
|
|
605
783
|
const targetVersion = session.detectedVersion();
|
|
606
|
-
const prepared =
|
|
607
|
-
await assertRelationOptionsFields(session, args.schemaCode, prepared.propertyType, args.relativeCode, prepared.options);
|
|
784
|
+
const prepared = await lintFieldCreateWrite(session, { ...args, ...(targetVersion ? { targetVersion } : {}) }, { publishedRows: published });
|
|
608
785
|
let performed;
|
|
609
786
|
try {
|
|
610
787
|
performed = await wireCall(session, { path: ENDPOINTS.fieldCreate, method: "POST", body: fieldChangeWireBody(args, prepared) });
|
|
@@ -711,6 +888,16 @@ export function registerFieldLane(tools) {
|
|
|
711
888
|
},
|
|
712
889
|
preflight: (args) => assertNameI18nArg(args.name_i18n),
|
|
713
890
|
dryRunPayload: fieldUpdateDryRun,
|
|
891
|
+
// 0.8.4 P0:真写与 dry-run 同门。此前 field.update 只有 dryRunPayload——
|
|
892
|
+
// 关联映射/显示字段的发布面语义门只在预览路径,真写把非法 mappings 原样
|
|
893
|
+
// 写进平台(2.1.5 真机:dry-run refused relation-mapping-field-not-found,
|
|
894
|
+
// 真写 ok/DELIVERED)。writeLint 在 lease 内、任何写 wire 之前跑
|
|
895
|
+
// lintFieldUpdateWrite(与 dry-run 同一个函数),拒绝即零 wire。
|
|
896
|
+
writeLint: async (session, args) => {
|
|
897
|
+
await lintFieldUpdateWrite(session, args);
|
|
898
|
+
},
|
|
899
|
+
lintScope: "partial",
|
|
900
|
+
lintUnchecked: ["sync-dictionary-binding", "platform-side-validation", "post-write-readback"],
|
|
714
901
|
rollback: fieldRollbackSpec("field.update"),
|
|
715
902
|
});
|
|
716
903
|
writeTool({
|
|
@@ -774,7 +961,7 @@ export function registerFieldLane(tools) {
|
|
|
774
961
|
const impact = await collectFieldDeleteImpact(session, args, { full: true });
|
|
775
962
|
return { wouldChange: true, impact, schemaCode: args.schemaCode, code: args.code };
|
|
776
963
|
},
|
|
777
|
-
lintScope: "
|
|
964
|
+
lintScope: "partial",
|
|
778
965
|
lintUnchecked: ["platform-side-validation", "post-write-readback"],
|
|
779
966
|
rollback: fieldRollbackSpec("field.delete"),
|
|
780
967
|
});
|
|
@@ -925,6 +1112,11 @@ async function countModelDataRows(session, schemaCode) {
|
|
|
925
1112
|
const MUTABLE_FIELD_OPTION_KEYS = new Set([
|
|
926
1113
|
"dictionaryData", "optionsSet", "mappings", "schemaCode", "queryCode", "displayField", "displayFieldType", "displayFieldFormat",
|
|
927
1114
|
"relativePropertyMatchCode", "relativePropertyCode", "linkMode", "showStyle", "searchFormula", "conditions",
|
|
1115
|
+
// Relation target = a child sheet: the designer stores the parent model here
|
|
1116
|
+
// and resolves bare mapping sources against it (WorkSheetMappingServiceImpl
|
|
1117
|
+
// queryWorksheetData). Without this key a nested-target relation's mappings
|
|
1118
|
+
// cannot be maintained through field.update.
|
|
1119
|
+
"mainTableCode",
|
|
928
1120
|
"requiredFormula", "readonlyCondition", "displayFormula", "readonlyFormula", "scale",
|
|
929
1121
|
// r64b (live 2026-11-14): the numeric DISPLAY FORMAT. The designer writes it
|
|
930
1122
|
// to this very row (数据项 Edit → Default Format → bizproperty/update
|
|
@@ -947,10 +1139,17 @@ function assertNoImmutableOptionChanges(schemaCode, code, changedOptionKeys) {
|
|
|
947
1139
|
});
|
|
948
1140
|
}
|
|
949
1141
|
/**
|
|
950
|
-
*
|
|
951
|
-
*
|
|
1142
|
+
* `field.update` 的唯一写前门(R75-B 同门缝)。
|
|
1143
|
+
*
|
|
1144
|
+
* 0.8.4 P0(2026-11-26,2.1.5 真机):关联映射语义门只在 `dryRunPayload` 里,
|
|
1145
|
+
* 真写 `runFieldUpdate` 没跑它——同一份 args `--dry-run` 回
|
|
1146
|
+
* `relation-mapping-field-not-found`,真写却 ok/DELIVERED 并把
|
|
1147
|
+
* `{"source":"no_such_field","target":"bm"}` 写进平台。本函数把「读字段行 →
|
|
1148
|
+
* 聚合自引用门 → prepareFieldUpdate → 关联映射/显示字段发布面门」收成一个
|
|
1149
|
+
* 只读函数,dry-run、`writeLint`(真写路径,lease 内、写 wire 之前)与
|
|
1150
|
+
* `runFieldUpdate` 都调它,不复制判定。
|
|
952
1151
|
*/
|
|
953
|
-
async function
|
|
1152
|
+
async function lintFieldUpdateWrite(session, args) {
|
|
954
1153
|
const record = await loadFieldRowForUpdate(session, args.schemaCode, args.code);
|
|
955
1154
|
if (args.options !== undefined) {
|
|
956
1155
|
const publishedRows = await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: args.schemaCode, isPublish: "true" } })
|
|
@@ -974,7 +1173,40 @@ async function fieldUpdateDryRun(session, args) {
|
|
|
974
1173
|
...(args.propertyEmpty !== undefined ? { propertyEmpty: args.propertyEmpty } : {}),
|
|
975
1174
|
};
|
|
976
1175
|
const prepared = prepareFieldUpdate(update);
|
|
1176
|
+
await assertFieldUpdateRelationTarget(session, record, prepared, args);
|
|
977
1177
|
await assertRelationOptionsFields(session, args.schemaCode, prepared.propertyType, args.relativeCode ?? record.relativeCode, prepared.options);
|
|
1178
|
+
return { record, prepared };
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* 审计 #2(W17):`field.update` 也能把关联列指向**不存在的模型**——`field.create`
|
|
1182
|
+
* 有 `assertRelationTargetExists`,update 的 dry-run 与真写两条路都没有。
|
|
1183
|
+
*
|
|
1184
|
+
* 只在调用方**改变了**关联目标(relativeCode / options.schemaCode 与存量不同)时
|
|
1185
|
+
* 校验。纯改名、只改别的 options 键不校验:目标模型已被平台删除后字段行仍在,
|
|
1186
|
+
* 若连改名都要求目标存在,这些历史字段就再也维护不了。判定复用 field.create 的
|
|
1187
|
+
* 同一个 assertRelationTargetExists(候选 = 租户模型 code 清单)。
|
|
1188
|
+
*/
|
|
1189
|
+
async function assertFieldUpdateRelationTarget(session, record, prepared, args) {
|
|
1190
|
+
const type = typeof prepared.propertyType === "number" ? prepared.propertyType : FIELD_PROPERTY_TYPES[String(prepared.propertyType ?? "")];
|
|
1191
|
+
if (type !== FIELD_PROPERTY_TYPES.WORK_SHEET && type !== FIELD_PROPERTY_TYPES.MULT_WORK_SHEET)
|
|
1192
|
+
return;
|
|
1193
|
+
const requestedCandidate = typeof args.relativeCode === "string" ? args.relativeCode : prepared.options.schemaCode;
|
|
1194
|
+
const requested = typeof requestedCandidate === "string" ? requestedCandidate.trim() : "";
|
|
1195
|
+
if (!requested)
|
|
1196
|
+
return;
|
|
1197
|
+
const previousCandidate = record.relativeCode ?? optionsObjectOf(record.options).schemaCode;
|
|
1198
|
+
const previous = typeof previousCandidate === "string" ? previousCandidate.trim() : "";
|
|
1199
|
+
if (requested === previous)
|
|
1200
|
+
return;
|
|
1201
|
+
assertRelationTargetExists({ propertyType: type, options: prepared.options, relativeCode: args.relativeCode }, await modelSchemaCodes(session));
|
|
1202
|
+
}
|
|
1203
|
+
/**
|
|
1204
|
+
* Session-aware dry-run for field.update: structured from→to changes (only real
|
|
1205
|
+
* diffs), plus an honest dataImpact note when storage-shape keys move.
|
|
1206
|
+
*/
|
|
1207
|
+
async function fieldUpdateDryRun(session, args) {
|
|
1208
|
+
// Same gate as the real write (writeLint → lintFieldUpdateWrite).
|
|
1209
|
+
const { record, prepared } = await lintFieldUpdateWrite(session, args);
|
|
978
1210
|
const currentOptions = decodeJsonObjectColumn(record.options, { invalid: "throw", array: "accept", object: "accept" }) ?? {};
|
|
979
1211
|
const changes = [];
|
|
980
1212
|
const pushChange = (field, from, to) => {
|
|
@@ -1114,76 +1346,85 @@ async function scanFieldRuleReferences(session, schemaCode, code) {
|
|
|
1114
1346
|
}
|
|
1115
1347
|
return { references };
|
|
1116
1348
|
}
|
|
1117
|
-
async function scanFieldFormListviewOnlineJs(session, schemaCode, code) {
|
|
1349
|
+
async function scanFieldFormListviewOnlineJs(session, schemaCode, code, options = {}) {
|
|
1118
1350
|
const references = [];
|
|
1119
1351
|
const dependentUpdates = {};
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
present:
|
|
1133
|
-
inDraft,
|
|
1134
|
-
inPublished,
|
|
1135
|
-
note: inDraft || inPublished
|
|
1136
|
-
? "删除字段后表单控件会残留;需 form.draft(rebuild)/form.publish 清理"
|
|
1137
|
-
: "默认表单控件码未引用该字段",
|
|
1138
|
-
};
|
|
1139
|
-
if (inDraft || inPublished) {
|
|
1140
|
-
references.push({
|
|
1141
|
-
kind: "form",
|
|
1142
|
-
code: schemaCode,
|
|
1143
|
-
name: String(sheet.name ?? schemaCode),
|
|
1144
|
-
via: inDraft && inPublished ? "draft+published controls" : inDraft ? "draft controls" : "published controls",
|
|
1145
|
-
schemaCode,
|
|
1146
|
-
});
|
|
1352
|
+
const childSchema = options.childSchema === true;
|
|
1353
|
+
// 子表 code 没有独立表单面(表单/在线 JS 挂在父模型上):不把子表 code 当
|
|
1354
|
+
// form.get 的入参,否则每次影响面扫描都固定回一条 50000 噪音(0.8.3 真机 §5.6)。
|
|
1355
|
+
if (childSchema) {
|
|
1356
|
+
dependentUpdates.form = { skipped: true, note: "子表 code 没有独立表单面(表单/在线 JS 在父模型上),未调用 form.get" };
|
|
1357
|
+
dependentUpdates.onlineJs = { skipped: true, note: "随表单面跳过:子表 code 没有独立表单/在线 JS 槽位" };
|
|
1358
|
+
}
|
|
1359
|
+
else {
|
|
1360
|
+
// form.get 面:控件码清单
|
|
1361
|
+
try {
|
|
1362
|
+
const sheet = (await wireCall(session, { path: ENDPOINTS.sheetGet, query: { schemaCode, sheetCode: schemaCode } })).data;
|
|
1363
|
+
if (!sheet) {
|
|
1364
|
+
dependentUpdates.form = { present: false, note: "默认表单不存在(sheetGet 空)" };
|
|
1147
1365
|
}
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1366
|
+
else {
|
|
1367
|
+
const draftControls = formControlCodes(sheet.draftAttributesJson);
|
|
1368
|
+
const publishedControls = formControlCodes(sheet.publishedAttributesJson);
|
|
1369
|
+
const inDraft = draftControls.includes(code);
|
|
1370
|
+
const inPublished = publishedControls.includes(code);
|
|
1371
|
+
dependentUpdates.form = {
|
|
1372
|
+
present: true,
|
|
1373
|
+
inDraft,
|
|
1374
|
+
inPublished,
|
|
1375
|
+
note: inDraft || inPublished
|
|
1376
|
+
? "删除字段后表单控件会残留;需 form.draft(rebuild)/form.publish 清理"
|
|
1377
|
+
: "默认表单控件码未引用该字段",
|
|
1378
|
+
};
|
|
1379
|
+
if (inDraft || inPublished) {
|
|
1380
|
+
references.push({
|
|
1381
|
+
kind: "form",
|
|
1382
|
+
code: schemaCode,
|
|
1383
|
+
name: String(sheet.name ?? schemaCode),
|
|
1384
|
+
via: inDraft && inPublished ? "draft+published controls" : inDraft ? "draft controls" : "published controls",
|
|
1385
|
+
schemaCode,
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
// online JS:扫 customScript 原文是否提及字段 code
|
|
1389
|
+
const scripts = [];
|
|
1390
|
+
for (const face of [sheet.draftHtmlJson, sheet.publishedHtmlJson]) {
|
|
1391
|
+
if (typeof face !== "string" || !face.trim())
|
|
1156
1392
|
continue;
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1393
|
+
try {
|
|
1394
|
+
const parsed = JSON.parse(face);
|
|
1395
|
+
if (!Array.isArray(parsed))
|
|
1396
|
+
continue;
|
|
1397
|
+
const custom = parsed.find((element) => element?.id === "customScript");
|
|
1398
|
+
if (typeof custom?.innerHTML === "string" && custom.innerHTML.trim())
|
|
1399
|
+
scripts.push(custom.innerHTML);
|
|
1400
|
+
}
|
|
1401
|
+
catch {
|
|
1402
|
+
// ignore malformed html face
|
|
1403
|
+
}
|
|
1160
1404
|
}
|
|
1161
|
-
|
|
1162
|
-
|
|
1405
|
+
const mentioned = scripts.some((script) => scriptMentionsField(script, code));
|
|
1406
|
+
dependentUpdates.onlineJs = {
|
|
1407
|
+
scanned: true,
|
|
1408
|
+
mentioned,
|
|
1409
|
+
note: mentioned
|
|
1410
|
+
? "在线 JS 原文仍包含该字段 code;删除后脚本引用会静默残留,需 onlinejs.compose 清理"
|
|
1411
|
+
: "在线 JS 原文未匹配到该字段 code(按词边界扫描,不含间接引用)",
|
|
1412
|
+
};
|
|
1413
|
+
if (mentioned) {
|
|
1414
|
+
references.push({
|
|
1415
|
+
kind: "onlineJs",
|
|
1416
|
+
code: schemaCode,
|
|
1417
|
+
name: String(sheet.name ?? schemaCode),
|
|
1418
|
+
via: "customScript.innerHTML",
|
|
1419
|
+
schemaCode,
|
|
1420
|
+
});
|
|
1163
1421
|
}
|
|
1164
1422
|
}
|
|
1165
|
-
const mentioned = scripts.some((script) => scriptMentionsField(script, code));
|
|
1166
|
-
dependentUpdates.onlineJs = {
|
|
1167
|
-
scanned: true,
|
|
1168
|
-
mentioned,
|
|
1169
|
-
note: mentioned
|
|
1170
|
-
? "在线 JS 原文仍包含该字段 code;删除后脚本引用会静默残留,需 onlinejs.compose 清理"
|
|
1171
|
-
: "在线 JS 原文未匹配到该字段 code(按词边界扫描,不含间接引用)",
|
|
1172
|
-
};
|
|
1173
|
-
if (mentioned) {
|
|
1174
|
-
references.push({
|
|
1175
|
-
kind: "onlineJs",
|
|
1176
|
-
code: schemaCode,
|
|
1177
|
-
name: String(sheet.name ?? schemaCode),
|
|
1178
|
-
via: "customScript.innerHTML",
|
|
1179
|
-
schemaCode,
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
1423
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1424
|
+
catch (error) {
|
|
1425
|
+
dependentUpdates.form = { unknown: true, note: `form.get 不可用:${error instanceof Error ? error.message : String(error)}` };
|
|
1426
|
+
dependentUpdates.onlineJs = { unknown: true, note: `onlinejs 扫描跳过:form 面读取失败` };
|
|
1427
|
+
}
|
|
1187
1428
|
}
|
|
1188
1429
|
// listview.get 面:列/条件
|
|
1189
1430
|
try {
|
|
@@ -1239,22 +1480,39 @@ async function collectFieldDeleteImpact(session, args, options) {
|
|
|
1239
1480
|
else {
|
|
1240
1481
|
unknowns.push("真写回执未扫业务规则引用(成本高);完整引用面请先 --dry-run");
|
|
1241
1482
|
}
|
|
1242
|
-
const
|
|
1483
|
+
const childSchema = await schemaIsChildTable(session, args.schemaCode);
|
|
1484
|
+
const surfaces = await scanFieldFormListviewOnlineJs(session, args.schemaCode, args.code, { childSchema });
|
|
1243
1485
|
references.push(...surfaces.references);
|
|
1244
1486
|
for (const key of ["form", "listview", "onlineJs"]) {
|
|
1245
1487
|
const face = surfaces.dependentUpdates[key];
|
|
1246
1488
|
if (face?.unknown === true && typeof face.note === "string")
|
|
1247
1489
|
unknowns.push(face.note);
|
|
1248
1490
|
}
|
|
1491
|
+
// 子表 code 无独立表单面:整面对不上就不算「扫过」,归入 notScanned 并说明原因。
|
|
1492
|
+
const skipped = new Set();
|
|
1493
|
+
if (surfaces.dependentUpdates.form?.skipped === true)
|
|
1494
|
+
skipped.add("form");
|
|
1495
|
+
if (surfaces.dependentUpdates.onlineJs?.skipped === true)
|
|
1496
|
+
skipped.add("onlinejs");
|
|
1497
|
+
const scanned = (options.full
|
|
1498
|
+
? ["businessrule", "form", "listview", "onlinejs", "data"]
|
|
1499
|
+
: ["form", "listview", "onlinejs", "data"]).filter((key) => !skipped.has(key));
|
|
1500
|
+
const notScanned = [
|
|
1501
|
+
...(options.full
|
|
1502
|
+
? ["workflow.permissions", "workflow.bindings", "rule.conditions"]
|
|
1503
|
+
: ["businessrule", "workflow.permissions", "workflow.bindings", "rule.conditions"]),
|
|
1504
|
+
...(skipped.has("form") ? ["form(子表 code 无独立表单面,未调用 form.get)"] : []),
|
|
1505
|
+
...(skipped.has("onlinejs") ? ["onlinejs(随表单面跳过:子表 code 无独立槽位)"] : []),
|
|
1506
|
+
];
|
|
1249
1507
|
return {
|
|
1250
1508
|
dataRows: counted.dataRows,
|
|
1251
1509
|
...(counted.note ? { dataRowsNote: counted.note } : counted.dataRows === "unknown" ? { dataRowsNote: "拿不到行数:data.list total 不可用" } : {}),
|
|
1252
1510
|
references,
|
|
1253
1511
|
dependentUpdates: surfaces.dependentUpdates,
|
|
1254
1512
|
coverage: {
|
|
1255
|
-
scanned
|
|
1256
|
-
notScanned
|
|
1257
|
-
coveredSurfaces:
|
|
1513
|
+
scanned,
|
|
1514
|
+
notScanned,
|
|
1515
|
+
coveredSurfaces: scanned,
|
|
1258
1516
|
},
|
|
1259
1517
|
...(unknowns.length > 0 ? { unknown: unknowns } : {}),
|
|
1260
1518
|
note: options.full
|
|
@@ -1325,6 +1583,14 @@ async function runFieldUpdate(session, args) {
|
|
|
1325
1583
|
...(args.propertyEmpty !== undefined ? { propertyEmpty: args.propertyEmpty } : {}),
|
|
1326
1584
|
};
|
|
1327
1585
|
const prepared = prepareFieldUpdate(update);
|
|
1586
|
+
// 0.8.4 P0:真写自己的这道门(与 writeLint/dry-run 同一个 assertRelationOptionsFields)。
|
|
1587
|
+
// writeLint 已经在前置跑过一遍;这里保留 execute 内的同函数调用,保证
|
|
1588
|
+
// runFieldUpdate 被任何未经过 writeLint 的入口复用时也不会把非法 mappings
|
|
1589
|
+
// 写进平台。propertyType/relativeCode 取 prepareFieldUpdate 的归一结果 +
|
|
1590
|
+
// 存量行回退,与 dry-run 逐字一致。
|
|
1591
|
+
await assertRelationOptionsFields(session, args.schemaCode, prepared.propertyType, args.relativeCode ?? record.relativeCode, prepared.options);
|
|
1592
|
+
// 审计 #2:目标变更时校验关联目标存在(与 dry-run/writeLint 同一个函数)。
|
|
1593
|
+
await assertFieldUpdateRelationTarget(session, record, prepared, args);
|
|
1328
1594
|
const currentOptions = decodeJsonObjectColumn(record.options, { invalid: "throw", array: "accept", object: "accept" }) ?? {};
|
|
1329
1595
|
const requestedChanges = [];
|
|
1330
1596
|
const same = (left, right) => JSON.stringify(left) === JSON.stringify(right);
|