@stalfh233/omc-cli 0.8.1 → 0.8.3

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.
@@ -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. */
@@ -93,26 +94,130 @@ async function assertRelationOptionsFields(session, schemaCode, propertyType, re
93
94
  const target = String(relativeCode ?? options.schemaCode ?? "").trim();
94
95
  if (!target)
95
96
  return;
96
- const targetRows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: target, isPublish: "true" } })).data);
97
- const ownRows = wireRows((await wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode, isPublish: "true" } })).data);
97
+ // One published-face read per schema, shared by target/own/main (a self
98
+ // relation names the same schema twice; a missing side must not fail the
99
+ // whole gate — see the empty-face note below).
100
+ const rowCache = new Map();
101
+ const rowsOf = (code) => {
102
+ const cached = rowCache.get(code);
103
+ if (cached)
104
+ return cached;
105
+ const pending = wireCall(session, { path: ENDPOINTS.fieldList, query: { schemaCode: code, isPublish: "true" } })
106
+ .then((response) => wireRows(response.data))
107
+ .catch(() => []);
108
+ rowCache.set(code, pending);
109
+ return pending;
110
+ };
111
+ const targetRows = await rowsOf(target);
112
+ const ownRows = await rowsOf(schemaCode);
113
+ // 设计器把「关联目标 = 某模型的子表」存成 options.mainTableCode(主表模型)
114
+ // + options.schemaCode(子表)。前端 getSourceDataItems(bundle
115
+ // admin/js/79850.2b085fc5.js@byte25582,mainTableCode 分支@25858)把主表字段与
116
+ // 子表字段(FlatMapSheetPropertiesDecorator 生成的 `子表code.字段code`,
117
+ // bundle main.33434673.js@byte1978673)并进同一份 source 候选;后端
118
+ // WorkSheetMappingServiceImpl.queryWorksheetData(2.1.5:322-340 / 8.6.26:358-376)
119
+ // 也按 `裸 code = 主表字段`(P___ 别名)、`子表code.字段code = 该子表字段` 解析。
120
+ // 所以 source 的合法集不是只有关联模型(子表)字段;但它也**不**包含本模型字段
121
+ // ——设计器 getSourceList(bundle 17170.93392489.js@byte3998)只从 sourceDataItems
122
+ // (关联侧)取 source,本模型字段只做 target。mainTableCode 本身是 options 一等键
123
+ // (BizPropertyUtil.java 2.1.5:74-79 / 8.6.26:80-85 随 schemaCode 一起改名)。
124
+ const mainTableCode = typeof options.mainTableCode === "string" ? options.mainTableCode.trim() : "";
125
+ const mainRows = mainTableCode === target
126
+ ? targetRows
127
+ : mainTableCode === schemaCode
128
+ ? ownRows
129
+ : mainTableCode
130
+ ? await rowsOf(mainTableCode)
131
+ : [];
98
132
  const business = (rows) => rows
99
133
  .map((row) => ({ code: String(row.code ?? row.propertyCode ?? "").trim(), type: relationTypeOf(row) }))
100
134
  .filter((row) => row.code && !SYSTEM_FIELD_CODES.has(row.code));
101
135
  const targetFields = business(targetRows);
102
136
  const ownFields = business(ownRows);
137
+ const mainFields = business(mainRows);
103
138
  // A compatibility/fake transport may expose an empty field face even though
104
139
  // the model exists. Empty metadata is not proof that a requested field is
105
140
  // absent; preserve the existing relation write path rather than rejecting a
106
141
  // valid payload on an unavailable read face.
107
142
  if (targetRows.length === 0 || ownRows.length === 0)
108
143
  return;
109
- const candidates = targetFields.map((row) => row.code).sort();
144
+ // 关联目标是子表时(fieldList 带回 parentId/sortKey),裸 source 按主表字段
145
+ // 解析、`子表code.字段code` 按子表字段解析——两种都是设计器下拉里的合法项。
146
+ const targetIsChildSheet = childSchemaCodes(targetRows);
147
+ const childSheetCodes = new Set();
148
+ for (const field of mainFields)
149
+ if (field.type === FIELD_PROPERTY_TYPES.CHILD_TABLE)
150
+ childSheetCodes.add(field.code);
151
+ // 运行期解析裸 source 的判据是**关联目标 schema 的 BizSchema.parentCode**,不是
152
+ // options.mainTableCode(WorkSheetMappingServiceImpl.getMappingWorkSheetValue
153
+ // 2.1.5:270-274 / 8.6.26:310-314 只读 querySchemaCode 的 parentCode;
154
+ // 该类全文无 mainTableCode 读取点)。父模型 code 走既有读面
155
+ // bizmodels/get_all(BizSchemaModel.parentCode;2.1.5 BizSchemaController.java:479-486 /
156
+ // 8.6.26 同文件:615-631)。只在 mainTableCode 缺失或裸 source 未命中时读一次,
157
+ // 保证设计器正常数据零额外 wire。
158
+ let parentLoaded = false;
159
+ let targetParentCode = "";
160
+ let targetParentFields = [];
161
+ const loadTargetParent = async () => {
162
+ if (parentLoaded)
163
+ return targetParentCode;
164
+ parentLoaded = true;
165
+ try {
166
+ const record = await readModelRecord(session, target);
167
+ targetParentCode = typeof record?.parentCode === "string" ? record.parentCode.trim() : "";
168
+ }
169
+ catch {
170
+ targetParentCode = "";
171
+ }
172
+ if (!targetParentCode || targetParentCode === target)
173
+ return targetParentCode;
174
+ if (targetParentCode === schemaCode)
175
+ targetParentFields = ownFields;
176
+ else if (targetParentCode === mainTableCode)
177
+ targetParentFields = mainFields;
178
+ else {
179
+ targetParentFields = business(await rowsOf(targetParentCode));
180
+ for (const field of targetParentFields)
181
+ if (field.type === FIELD_PROPERTY_TYPES.CHILD_TABLE)
182
+ childSheetCodes.add(field.code);
183
+ }
184
+ return targetParentCode;
185
+ };
186
+ /** Resolve a mapping source: bare code (linked model / its parent main table) or `sheet.column`. */
187
+ const resolveSource = async (source) => {
188
+ if (!source)
189
+ return undefined;
190
+ const dot = source.indexOf(".");
191
+ if (dot < 0) {
192
+ const hit = [...targetFields, ...mainFields].find((row) => row.code === source);
193
+ if (hit)
194
+ return hit;
195
+ await loadTargetParent();
196
+ return targetParentFields.find((row) => row.code === source);
197
+ }
198
+ const sheetCode = source.slice(0, dot);
199
+ const column = source.slice(dot + 1);
200
+ if (!column || column.includes("."))
201
+ return undefined;
202
+ if (!targetIsChildSheet && !mainTableCode)
203
+ await loadTargetParent();
204
+ // Only the child-sheet relation shape uses dots; `模型.字段` on a plain
205
+ // model target would be dropped at runtime (not fetched), so keep it refused.
206
+ if (!targetIsChildSheet && !mainTableCode && !targetParentCode)
207
+ return undefined;
208
+ const sheetRows = sheetCode === target ? targetRows : childSheetCodes.has(sheetCode) ? await rowsOf(sheetCode) : undefined;
209
+ if (!sheetRows || sheetRows.length === 0)
210
+ return undefined;
211
+ return business(sheetRows).find((row) => row.code === column);
212
+ };
213
+ const linkedCandidates = [...new Set([...targetFields, ...mainFields].map((row) => row.code))].sort();
110
214
  const display = typeof options.displayField === "string" ? options.displayField.trim() : "";
111
215
  if (display) {
112
- const field = targetFields.find((row) => row.code === display);
216
+ // 子表目标下显示字段来自主表模型(前端 getRelativeDataItem(mainTableCode))。
217
+ const field = [...targetFields, ...mainFields].find((row) => row.code === display);
113
218
  const declaredType = options.displayFieldType === undefined ? undefined : Number(options.displayFieldType);
114
219
  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} 不存在于发布面或类型不兼容;请从目标模型业务字段中选择。候选:${candidates.join("、") || "(无)"}` });
220
+ throw new ToolRefusalError({ status: "refused", blocker: "relation-display-field-not-found", schemaCode, relationTarget: target, displayField: display, candidates: linkedCandidates, message: `关联显示字段 ${target}.${display} 不存在于发布面或类型不兼容;请从关联模型业务字段中选择。候选:${linkedCandidates.join("、") || "(无)"}` });
116
221
  }
117
222
  }
118
223
  let mappings = options.mappings;
@@ -126,20 +231,36 @@ async function assertRelationOptionsFields(session, schemaCode, propertyType, re
126
231
  }
127
232
  if (!Array.isArray(mappings))
128
233
  return;
129
- const sourceCandidates = targetFields.map((row) => row.code).sort();
130
234
  const targetCandidates = ownFields.map((row) => row.code).sort();
131
235
  for (const [index, row] of mappings.entries()) {
132
236
  const source = row && typeof row === "object" ? String(row.source ?? "").trim() : "";
133
237
  const mappedTarget = row && typeof row === "object" ? String(row.target ?? "").trim() : "";
134
- if (!sourceCandidates.includes(source) || !targetCandidates.includes(mappedTarget)) {
135
- throw new ToolRefusalError({ status: "refused", blocker: "relation-mapping-field-not-found", schemaCode, relationTarget: target, mappingIndex: index, source, targetField: mappedTarget, sourceCandidates, targetCandidates, message: `关联映射第 ${index + 1} 行字段不存在:source=${source || "(空)"}(目标模型候选:${sourceCandidates.join("、") || "(无)"}),target=${mappedTarget || "(空)"}(本模型候选:${targetCandidates.join("、") || "(无)"})。请使用发布面业务字段 code。` });
238
+ const sourceField = await resolveSource(source);
239
+ const targetField = ownFields.find((entry) => entry.code === mappedTarget);
240
+ if (!sourceField || !targetField) {
241
+ // Diagnosis must be actionable: name the linked side(s) actually consulted.
242
+ if (!sourceField)
243
+ await loadTargetParent();
244
+ const linkedCodes = [...new Set([...targetFields, ...mainFields, ...targetParentFields].map((entry) => entry.code))].sort();
245
+ const side = !sourceField && !targetField ? "both" : !sourceField ? "source" : "target";
246
+ const linkedHint = mainTableCode
247
+ ? `关联模型 ${target} / 主表 ${mainTableCode}`
248
+ : targetParentCode
249
+ ? `关联模型 ${target} / 其父模型 ${targetParentCode}(bizmodels/get_all.parentCode)`
250
+ : `关联模型 ${target}(bizmodels/get_all 未回 parentCode:它没有父模型,裸 source 只能在 ${target} 自身字段里)`;
251
+ const detail = side === "source"
252
+ ? `source=${source || "(空)"} 既不是${linkedHint}的发布面字段(关联目标为子表时:主表字段用裸 code、子表字段写成 子表code.字段code)。关联侧候选:${linkedCodes.join("、") || "(无)"};本模型 target 候选:${targetCandidates.join("、") || "(无)"}`
253
+ : side === "target"
254
+ ? `target=${mappedTarget || "(空)"} 不是本模型 ${schemaCode} 的发布面字段(target 只用本模型字段 code,不带前缀)。本模型候选:${targetCandidates.join("、") || "(无)"}`
255
+ : `source=${source || "(空)"} 不在${linkedHint}的发布面字段里;target=${mappedTarget || "(空)"} 不在本模型 ${schemaCode} 的发布面字段里。关联侧候选:${linkedCodes.join("、") || "(无)"};本模型候选:${targetCandidates.join("、") || "(无)"}`;
256
+ 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
257
  }
137
258
  // r52:类型兼容门。设计器 filterCondition(admin/js/17170.93392489.js)是产品承认的
138
259
  // 可映射不变量,但它只活在下拉框里——保存、导入、field.create 全都绕过;平台后端
139
260
  // checkOptions 的 if 链缺 WORK_SHEET 分支,运行期 assignChildData 直接 put 零转换。
140
261
  // 所以错配要么运行期 50000,要么静默变 null/false/悬空 id。这里按设计器口径拦。
141
- const sourceType = targetFields.find((row) => row.code === source)?.type;
142
- const targetType = ownFields.find((row) => row.code === mappedTarget)?.type;
262
+ const sourceType = sourceField.type;
263
+ const targetType = targetField.type;
143
264
  if (sourceType !== undefined && targetType !== undefined && !mappingTypesCompatible(targetType, sourceType)) {
144
265
  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
266
  }
@@ -925,6 +1046,11 @@ async function countModelDataRows(session, schemaCode) {
925
1046
  const MUTABLE_FIELD_OPTION_KEYS = new Set([
926
1047
  "dictionaryData", "optionsSet", "mappings", "schemaCode", "queryCode", "displayField", "displayFieldType", "displayFieldFormat",
927
1048
  "relativePropertyMatchCode", "relativePropertyCode", "linkMode", "showStyle", "searchFormula", "conditions",
1049
+ // Relation target = a child sheet: the designer stores the parent model here
1050
+ // and resolves bare mapping sources against it (WorkSheetMappingServiceImpl
1051
+ // queryWorksheetData). Without this key a nested-target relation's mappings
1052
+ // cannot be maintained through field.update.
1053
+ "mainTableCode",
928
1054
  "requiredFormula", "readonlyCondition", "displayFormula", "readonlyFormula", "scale",
929
1055
  // r64b (live 2026-11-14): the numeric DISPLAY FORMAT. The designer writes it
930
1056
  // to this very row (数据项 Edit → Default Format → bizproperty/update
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { ENDPOINTS } from "../endpoints.js";
3
3
  import { decodeButtonScript } from "./list-view.js";
4
- import { executeFormDraftWrite, executeFormPublishWrite, executeFormRunButtonWrite, lintFormPublishReadOnly, readFormButtons, readFormOrNull, refuseEmptyCallerLayout, validateHtmlRender, customButtonJsonStoredShape, CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING } from "../form-support.js";
4
+ import { executeFormDraftWrite, executeFormPublishWrite, executeFormRunButtonWrite, lintFormPublishReadOnly, readFormButtons, readFormOrNull, refuseEmptyCallerLayout, validateHtmlRender, customButtonJsonStoredShape, CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING, FORM_FLAG_AUTHORITY_NOTE, resolveEffectiveFormFace } from "../form-support.js";
5
5
  import { capabilityArg, environmentArg } from "../args.js";
6
6
  import { governedRead } from "../read.js";
7
7
  import { writeTool } from "../write.js";
@@ -183,12 +183,22 @@ export function registerFormLane(tools) {
183
183
  const platformPublished = sheet.published === true;
184
184
  const platformDraft = sheet.existDraft === true;
185
185
  const flagMismatch = platformPublished !== publishedPresent || platformDraft !== draftPresent;
186
+ // B5(issue 2026-11-25):两套口径(旗标 vs faces)并列时调用方还得二次推理
187
+ // 「到底发布没发布」。给单一结论字段(规则与证据见 form-support 的
188
+ // resolveEffectiveFormFace),旗标矛盾时再补一句「以谁为准」。
189
+ const faceVerdict = resolveEffectiveFormFace({
190
+ draftPresent,
191
+ publishedPresent,
192
+ inSync: draftPresent && publishedPresent ? sheet.draftViewJson === sheet.publishedViewJson : null,
193
+ });
186
194
  const base = {
187
195
  schemaCode: args.schemaCode,
188
196
  sheetCode,
189
197
  present: true,
190
198
  published: platformPublished,
191
199
  existDraft: platformDraft,
200
+ effectiveFace: faceVerdict.effectiveFace,
201
+ effectiveFaceNote: faceVerdict.effectiveFaceNote,
192
202
  faces: {
193
203
  draft: { present: draftPresent, controlCount: draftCodes.length },
194
204
  published: { present: publishedPresent, controlCount: publishedCodes.length },
@@ -197,7 +207,8 @@ export function registerFormLane(tools) {
197
207
  ...(flagMismatch
198
208
  ? {
199
209
  flagMismatch: true,
200
- flagNote: "平台布尔与内容不一致:published/existDraft 来自 bizsheet/get 的标记位,faces 由 draft/published 两份布局内容推导。判「现在有几面」以 faces 为准;判「能否被运行时读到」以 published 为准(平台可能未刷新标记)。",
210
+ flagNote: "平台布尔与内容不一致:published/existDraft 来自 bizsheet/get 的标记位,faces 由 draft/published 两份布局内容推导。判「现在有几面」以 faces 为准;判「能否被运行时读到」以 published 为准(平台可能未刷新标记)。" +
211
+ FORM_FLAG_AUTHORITY_NOTE,
201
212
  }
202
213
  : {}),
203
214
  };
@@ -493,10 +504,13 @@ export function registerFormLane(tools) {
493
504
  const buttons = readFormButtons(record.options) ?? [];
494
505
  const publishedActions = parseActionEntries(record.publishedActionsJson);
495
506
  const flagMismatch = (record.published === true) !== publishedPresent || (record.existDraft === true) !== draftPresent;
507
+ const inSync = draftPresent && publishedPresent ? record.draftViewJson === record.publishedViewJson : null;
508
+ const faceVerdict = resolveEffectiveFormFace({ draftPresent, publishedPresent, inSync });
496
509
  detailed.push({
497
510
  ...publicSheet,
498
511
  present: true,
499
512
  existDraft: record.existDraft === true,
513
+ effectiveFace: faceVerdict.effectiveFace,
500
514
  controlCount: draftCodes.length,
501
515
  buttonCount: buttons.length,
502
516
  ...("parseError" in publishedActions ? { publishedActionParseError: true } : { publishedActionCount: publishedActions.count }),
@@ -504,12 +518,12 @@ export function registerFormLane(tools) {
504
518
  faces: {
505
519
  draft: { present: draftPresent, controlCount: draftCodes.length },
506
520
  published: { present: publishedPresent, controlCount: publishedCodes.length },
507
- inSync: draftPresent && publishedPresent ? record.draftViewJson === record.publishedViewJson : null,
521
+ inSync,
508
522
  },
509
523
  ...(flagMismatch
510
524
  ? {
511
525
  flagMismatch: true,
512
- flagNote: "平台旗标与内容不一致:published/existDraft 来自 bizsheet/get 的标记位,faces 由两份布局内容推导。判「现在有几面」以 faces 为准;判「运行时能否读到」以 published 为准",
526
+ flagNote: "平台旗标与内容不一致:published/existDraft 来自 bizsheet/get 的标记位,faces 由两份布局内容推导。判「现在有几面」以 faces 为准;判「运行时能否读到」以 published 为准。" + FORM_FLAG_AUTHORITY_NOTE,
513
527
  }
514
528
  : {}),
515
529
  });