@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.
Files changed (53) hide show
  1. package/dist/arg-vocabulary.js +223 -0
  2. package/dist/artifact-cmd.js +443 -0
  3. package/dist/batch-call.js +56 -3
  4. package/dist/call-command.js +70 -0
  5. package/dist/call-execute.js +228 -0
  6. package/dist/call-input.js +557 -0
  7. package/dist/call-output.js +240 -0
  8. package/dist/cli.js +23 -1360
  9. package/dist/command-transport.js +4 -1
  10. package/dist/field-add.js +2 -1
  11. package/dist/form-support.js +17 -4
  12. package/dist/intent/plan-apply.js +14 -24
  13. package/dist/lanes/datarule.js +21 -0
  14. package/dist/lanes/field.js +31 -0
  15. package/dist/lanes/list-view-shapes.js +8 -1
  16. package/dist/lanes/list-view.js +64 -2
  17. package/dist/lanes/runtime-data/aggregate-support.js +209 -0
  18. package/dist/lanes/runtime-data/aggregate.js +679 -0
  19. package/dist/lanes/runtime-data/field-options.js +52 -0
  20. package/dist/lanes/runtime-data/lane.js +4 -0
  21. package/dist/lanes/runtime-data/record-delete.js +419 -0
  22. package/dist/lanes/runtime-data/record-read.js +984 -0
  23. package/dist/lanes/runtime-data/record-write.js +562 -0
  24. package/dist/lanes/runtime-data/registration.js +22 -0
  25. package/dist/lanes/runtime-data/shapes.js +594 -0
  26. package/dist/lanes/runtime-data/submission.js +1293 -0
  27. package/dist/lanes/runtime-data/write-support.js +875 -0
  28. package/dist/lanes/runtime-data-contract.js +1 -1
  29. package/dist/lanes/runtime-data.js +10 -5556
  30. package/dist/lanes/workflow/approval-ops.js +983 -0
  31. package/dist/lanes/workflow/instance-read.js +284 -0
  32. package/dist/lanes/workflow/lifecycle-write.js +1499 -0
  33. package/dist/lanes/workflow/permissions.js +571 -0
  34. package/dist/lanes/workflow/recovery.js +361 -0
  35. package/dist/lanes/workflow/registration.js +14 -0
  36. package/dist/lanes/workflow/shapes.js +811 -0
  37. package/dist/lanes/workflow/template-fetch.js +197 -0
  38. package/dist/lanes/workflow/template-merge.js +1351 -0
  39. package/dist/lanes/workflow/template-read.js +327 -0
  40. package/dist/lanes/workflow.js +11 -6312
  41. package/dist/model-scaffold.js +3 -1
  42. package/dist/path-projection.js +27 -6
  43. package/dist/read-projection.js +442 -0
  44. package/dist/read.js +40 -335
  45. package/dist/rollback.js +17 -23
  46. package/dist/runtime-support.js +1 -1
  47. package/dist/verification.js +39 -0
  48. package/dist/write-coordinator.js +152 -0
  49. package/dist/write-outcome.js +295 -0
  50. package/dist/write.js +34 -115
  51. package/package.json +3 -3
  52. package/skills/omc-refusals.md +1 -1
  53. package/skills/omc-start-here.md +3 -3
@@ -0,0 +1,594 @@
1
+ import { FIELD_PROPERTY_TYPES, SYSTEM_FIELD_CODES } from "../../field-families.js";
2
+ import { z } from "zod";
3
+ /** r29b F8: keep ids/itemsPreview through governedRead's compact diet. */
4
+ export const DATA_LIST_PREVIEW_LIMIT = 20;
5
+ export function dataListItemPreview(items) {
6
+ const ids = [];
7
+ const itemsPreview = [];
8
+ for (const item of items) {
9
+ const id = typeof item.id === "string" && item.id.trim() ? item.id : typeof item.fields?.id === "string" ? String(item.fields.id) : null;
10
+ if (!id)
11
+ continue;
12
+ ids.push(id);
13
+ if (itemsPreview.length < DATA_LIST_PREVIEW_LIMIT) {
14
+ const nameRaw = item.fields?.name;
15
+ itemsPreview.push({ id, name: typeof nameRaw === "string" && nameRaw.length > 0 ? nameRaw : null });
16
+ }
17
+ }
18
+ return { ids, itemsPreview };
19
+ }
20
+ /**
21
+ * r40a B:`data.list` 的大结果被外置后不能回 `items:[]`,否则调用方会把
22
+ * 「有数据但在 artifact」误读成「空结果」。保留一个明确的 items 外置指针,
23
+ * 让通用读门不会再补回空数组占位。
24
+ *
25
+ * **只在确实要丢弃 items 时才补 `ids`/`itemsPreview`**:这段只在 governedRead
26
+ * 判定 `large`(>2048B)后才会被调用。早期版本把 ids/preview 无条件塞进 handler
27
+ * 的回执,结果 25 行的小结果因为多了这一份副本被顶过 2048B → 反而触发外置、
28
+ * `items` 变成空数组(composers 的 `--all` 聚齐断言直接失败)。
29
+ *
30
+ * r31b F7:外置后同信封只给一份身份面——`ids` 全量;`itemsPreview` 仅
31
+ * `ids.slice(0,3)` 的引用(`{id}`,不再带 name),避免「同一批行给三份」。
32
+ */
33
+ export function dataListCompactProjection(result) {
34
+ const compact = {};
35
+ for (const [key, value] of Object.entries(result)) {
36
+ if (key === "items" && Array.isArray(value)) {
37
+ compact.itemsCount = value.length;
38
+ const preview = dataListItemPreview(value);
39
+ compact.ids = preview.ids;
40
+ // Reference face only — not a second copy of the rows.
41
+ compact.itemsPreview = preview.ids.slice(0, 3).map((id) => ({ id }));
42
+ if (value.length > 0)
43
+ compact.listArtifactHint =
44
+ "items 已外置:items 是指针而非空结果;完整行见 artifact(detailArtifactId / fetch)。ids=本页全部 id;itemsPreview=ids 前 3 个的引用(仅 {id},不是第二份行)。";
45
+ // The generic read gate adds [] for dropped array keys. Keep an explicit
46
+ // pointer under the original key so it cannot manufacture that false
47
+ // empty-result shape. The full rows remain in detailArtifactId.
48
+ compact.items = { externalized: true, count: value.length };
49
+ compact.truncatedKeys = ["items"];
50
+ compact.truncated = true;
51
+ compact.itemsExternalized = { count: value.length };
52
+ continue;
53
+ }
54
+ // 这两个键由本函数按 items 现算,handler 不再重复内联。
55
+ if (key === "ids" || key === "itemsPreview" || key === "listArtifactHint")
56
+ continue;
57
+ compact[key] = value;
58
+ }
59
+ return compact;
60
+ }
61
+ export function extractBizObjectPage(value) {
62
+ const root = value && typeof value === "object" ? value : {};
63
+ const candidate = root.bizObjectPage && typeof root.bizObjectPage === "object" ? root.bizObjectPage : root;
64
+ const content = Array.isArray(candidate.content) ? candidate.content.filter((row) => !!row && typeof row === "object") : [];
65
+ return {
66
+ total: typeof candidate.totalElements === "number" ? candidate.totalElements : 0,
67
+ totalKnown: typeof candidate.totalElements === "number",
68
+ totalPages: typeof candidate.totalPages === "number" ? candidate.totalPages : 0,
69
+ page: typeof candidate.page === "number" ? candidate.page : undefined,
70
+ size: typeof candidate.size === "number" ? candidate.size : undefined,
71
+ content,
72
+ };
73
+ }
74
+ /**
75
+ * Engine/system record keys that dominate a raw form/load payload but carry no
76
+ * business meaning for the caller: the `owner`/`creater`/`modifier` staff blobs
77
+ * and the owning-department objects. Each is a ~30-key object full of nulls
78
+ * (live 2026-09-25: a 23-key record was ~3 KB, of which these were ~2.5 KB).
79
+ * They stay reachable via `full:true` (raw record) and in the spilled artifact.
80
+ */
81
+ export const RUNTIME_ENGINE_RECORD_KEYS = new Set([
82
+ "owner", "creater", "modifier", "createdDeptId", "ownerDeptId", "ownerDeptQueryCode",
83
+ "createdBy", "modifiedBy",
84
+ ]);
85
+ // Same reserved catalogue as field.list, plus runtime identity/time aliases
86
+ // and staff/dept keys removed by compactRuntimeRecord. Flow internals end in _.
87
+ export const RUNTIME_SYSTEM_FIELD_CODES = new Set([
88
+ ...SYSTEM_FIELD_CODES, ...RUNTIME_ENGINE_RECORD_KEYS,
89
+ "bizObjectId", "schemaCode", "updatedTime", "creator", "updater", "parentId", "sortKey",
90
+ ]);
91
+ export const BUSINESS_NULL_WARNING_HINT = "模型可能未配置列表视图:data.list 只投影列表列,业务列会全为 null;核对写入结果请用 data.load,或用 listview.configure 给视图配列";
92
+ export const BUSINESS_MISSING_WARNING_HINT = "本次返回行没有任何业务字段(只有系统列):data.list 只回列表视图投影列,键缺席≠值为空;盘点字段值用 data.load,或把业务列加进视图(listview.configure)";
93
+ export function isBusinessProjectionCode(code) {
94
+ return code.length > 0 && !RUNTIME_SYSTEM_FIELD_CODES.has(code) && !code.endsWith("_") && !code.endsWith("_key");
95
+ }
96
+ export function projectionWarningOf(items, evidence, requestedFields,
97
+ /**
98
+ * 模型已发布业务列(可选)。业务键整个缺席时,光有视图证据分不清「视图漏配」
99
+ * 与「模型本来就没有业务列」——只有模型字段目录能判。传入空数组 = 纯系统模型,
100
+ * 静默(r53 的 system-only 行不是漏投影);undefined = 读不到,不编结论。
101
+ */
102
+ modelBusinessCodes) {
103
+ if (items.length === 0)
104
+ return undefined;
105
+ const businessKeys = new Set();
106
+ let hasBusinessValue = false;
107
+ for (const item of items) {
108
+ for (const [key, value] of Object.entries(item.fields)) {
109
+ if (!isBusinessProjectionCode(key))
110
+ continue;
111
+ businessKeys.add(key);
112
+ if (value !== null && value !== undefined)
113
+ hasBusinessValue = true;
114
+ }
115
+ }
116
+ const viewCodes = evidence?.viewColumnCodes;
117
+ const projectionKnown = viewCodes !== undefined;
118
+ if (businessKeys.size > 0 && hasBusinessValue)
119
+ return undefined;
120
+ // 显式窄投影:调用方自己只要了系统列(如 fields:["sequenceNo"]),业务列缺席
121
+ // 是请求本身的形状,不是视图漏配——不能反过来教「去配视图」。
122
+ if (businessKeys.size === 0
123
+ && requestedFields !== undefined
124
+ && requestedFields.length > 0
125
+ && requestedFields.every((code) => !isBusinessProjectionCode(code))) {
126
+ return {
127
+ reason: "caller-narrowed",
128
+ hint: "你显式只选了系统列,业务列不在本次投影里;业务值用 data.load 读单条,或把业务列加进 fields(只能选视图列)。",
129
+ projectionKnown,
130
+ ...(evidence?.viewColumnsCount !== undefined ? { viewColumnsCount: evidence.viewColumnsCount } : {}),
131
+ };
132
+ }
133
+ if (businessKeys.size === 0) {
134
+ const modelCodes = modelBusinessCodes?.filter(isBusinessProjectionCode);
135
+ // r53:模型自己没有业务列(纯系统模型)→ 系统-only 行是正常形状,不喊狼。
136
+ if (modelCodes !== undefined && modelCodes.length === 0)
137
+ return undefined;
138
+ // 有模型证据就点名「模型业务列里没回来的」;否则退回视图证据;都没有就不编字段名。
139
+ const unprojected = modelCodes !== undefined
140
+ ? modelCodes.filter((code) => !businessKeys.has(code))
141
+ : viewCodes === undefined
142
+ ? []
143
+ : viewCodes.filter((code) => isBusinessProjectionCode(code) && !businessKeys.has(code));
144
+ const detail = unprojected.length > 0
145
+ ? `${modelCodes !== undefined ? "模型的业务列" : "视图里的业务列"} ${unprojected.join("、")} 未出现在结果行`
146
+ : modelCodes === undefined && projectionKnown
147
+ ? "当前列表视图没有业务列"
148
+ : undefined;
149
+ return {
150
+ reason: "business-columns-missing",
151
+ hint: `${BUSINESS_MISSING_WARNING_HINT}${detail !== undefined ? `(${detail})` : ""}`,
152
+ projectionKnown,
153
+ ...(evidence?.viewColumnsCount !== undefined ? { viewColumnsCount: evidence.viewColumnsCount } : {}),
154
+ ...(unprojected.length > 0 ? { unprojected } : {}),
155
+ };
156
+ }
157
+ return {
158
+ reason: "business-columns-null",
159
+ hint: BUSINESS_NULL_WARNING_HINT,
160
+ projectionKnown,
161
+ ...(evidence?.viewColumnsCount !== undefined ? { viewColumnsCount: evidence.viewColumnsCount } : {}),
162
+ };
163
+ }
164
+ export const VIEW_PROJECTION_HINT = "该面仅回视图投影列;业务字段全 null 不代表未写入,真值用 data.load,或用 listview.configure 配列。";
165
+ export const PROJECTION_MISS_HINT = "这些字段没有出现在平台返回行里 ≠ 值为空;先查 listview.get 或用 data.load 复核";
166
+ /**
167
+ * Distinguish an omitted wire key from a present empty value. A field is a
168
+ * miss only when it is absent from every returned row; a partial omission is
169
+ * deliberately left alone because it may be row-specific data.
170
+ */
171
+ export function dataListProjectionMiss(rows, requestedFields) {
172
+ if (requestedFields === undefined || rows.length === 0)
173
+ return [];
174
+ return requestedFields.filter((field) => rows.every((row) => {
175
+ const data = row.data && typeof row.data === "object" ? row.data : {};
176
+ return !Object.prototype.hasOwnProperty.call(data, field);
177
+ }));
178
+ }
179
+ export function projectionHintWithMiss(hint, projectionMiss) {
180
+ if (projectionMiss.length === 0)
181
+ return hint;
182
+ return {
183
+ ...(hint ?? { projectionKnown: false }),
184
+ hint: `${hint?.hint ?? ""}${hint?.hint ? ";" : ""}${PROJECTION_MISS_HINT}`,
185
+ };
186
+ }
187
+ /** F5(w63,2026-11-26 真机 P1):columns 只收窄、不扩列;超出视图列的部分不可能有值。 */
188
+ export const DATA_LIST_COLUMNS_NARROWING_NOTE = "只能选视图列;扩列用 data.load 或加进视图。";
189
+ /**
190
+ * F5(w63,2026-11-26 真机 P1):`data.list` 的 `columns` 被调用方当成「任意
191
+ * 字段投影」用,但平台查询只取视图列——`display=false`(默认)时 SELECT 列集 =
192
+ * 视图 `queryColumns`(backend `BizObjectFacadeImpl.handleQueryColumn`:4155-4190,
193
+ * `display=true` 才 SELECT 全部属性;`getDisplayFields = completeSystemFields(
194
+ * columnList)`:2728-2729 只补系统列)。所以视图外的业务列在 wire 行里没有值,
195
+ * 本地裁剪再「保留」也补不回来。
196
+ *
197
+ * 判据(有证据才判,绝不拿 null 猜):
198
+ * - 请求的 code 不在**非空** `queryColumns` 清单里(listViewProjectionEvidence);
199
+ * - 或该 code 在整页 wire 行里键缺席(`projectionMiss`,与 0-F9 同源证据)。
200
+ *
201
+ * 空 `queryColumns` 不参与本判定:那种形状已由 `projectionHint` /
202
+ * `viewProjectionOnly`(全 null 业务列)覆盖,避免把「fake 默认无视图」误报成
203
+ * 「超列」。系统列由 completeSystemFields 恒投影,不判。
204
+ *
205
+ * F4b(0.8.32,真机 P2):**任一行该 code 有非 null 值** = 平台确实返回了它,
206
+ * 就不是「视图外」。子表列(CHILD_TABLE)是典型反例:视图 queryColumns 里没有
207
+ * 它,但行数据照常带子表数组(2.1.5 `BizObjectFacadeImpl.java:614` 的
208
+ * `assemblySubTableBizObject` → `SubBizObjectLoader.java:65,71-78` 遍历的是
209
+ * 模型的**全部已发布子表属性**、子列集来自子表 schema,与主表视图列集无关),
210
+ * 旧判据只看 `!view.has(code)` 于是把 `pb_repair_items` 报成「不会返回值」——
211
+ * 与同一行 `items[].fields.pb_repair_items` 的 2 行数据自相矛盾。用现有证据
212
+ * (不额外 wire),只有「无值且不在视图」才点名。
213
+ *
214
+ * 残余边界(未解,别当成已全解):
215
+ * - ① 子表 **0 行**时平台不返回该子表键(无值证据),该 code 仍可能被报
216
+ * 「视图外」——此时「不会返回值」在字面上成立,但不是「列不在视图」的意思。
217
+ * - ② 只看**本次读到的行**:`all:false` 只观测当前页,某 code 可能在别页有值;
218
+ * `all:true` 也只扫到 1000 行上限。跨页有值而本页为 null/缺键时仍可能误报。
219
+ */
220
+ export function columnsOutsideViewOf(requested, viewColumnCodes, projectionMiss, observedNonNullCodes) {
221
+ if (requested === undefined || requested.length === 0)
222
+ return [];
223
+ const view = viewColumnCodes !== undefined && viewColumnCodes.length > 0 ? new Set(viewColumnCodes) : undefined;
224
+ const missed = projectionMiss.length > 0 ? new Set(projectionMiss) : undefined;
225
+ if (view === undefined && missed === undefined)
226
+ return [];
227
+ return [...new Set(requested)].filter((code) => {
228
+ if (code.length === 0 || RUNTIME_SYSTEM_FIELD_CODES.has(code) || code.endsWith("_") || code.endsWith("_key"))
229
+ return false;
230
+ if (observedNonNullCodes?.has(code) === true)
231
+ return false;
232
+ if (missed?.has(code) === true)
233
+ return true;
234
+ return view !== undefined && !view.has(code);
235
+ });
236
+ }
237
+ /** 结果行里真的有非 null 值的 code(columnsOutsideViewOf 的「不是视图外」证据)。 */
238
+ export function observedNonNullCodesOf(items) {
239
+ const codes = new Set();
240
+ for (const item of items) {
241
+ for (const [code, value] of Object.entries(item.fields)) {
242
+ if (value !== null && value !== undefined)
243
+ codes.add(code);
244
+ }
245
+ }
246
+ return codes;
247
+ }
248
+ /**
249
+ * F10(w63,2026-11-26 真机):DATE 字段读回固定 `YYYY-MM-DD HH:mm:ss`
250
+ * (0.8.8 只在 describe 写了,探针仍在回执里按 `options.format` 断言而踩)。
251
+ * 平台证据:
252
+ * - 表单 load/写回序列化用全局 ObjectMapper 的 `yyyy-MM-dd HH:mm:ss`
253
+ * (backend `ObjectMapperUtils.java:75`);
254
+ * - 列表行 DATE 额外按视图列 `displayFormat` 格式化,0/2 或无视图列时仍是
255
+ * `yyyy-MM-dd HH:mm:ss`(backend `QueryRuntimeController.parseDate`:2066-2140)。
256
+ * - 门户显示才读字段 `options.format`(frontend portal-app bundle
257
+ * `30079.c1617b14.js` 的 formatDisplayField → getDateShowText(value, options.format))。
258
+ *
259
+ * 只在**结果里真的出现 DATE 形状的日期串且元数据确认该 code 是 DATE** 时给一句;
260
+ * 元数据读失败零提示。候选按值形状先筛(避免每次读都多一跳 field.list)。
261
+ */
262
+ export const DATE_READBACK_NOTE = "DATE 字段读回固定 `YYYY-MM-DD HH:mm:ss`(00:00:00 只是日期的零点);`options.format` 只影响门户显示,不是 API 读回格式——按前 10 位(YYYY-MM-DD)比较即可。";
263
+ export const DATE_READBACK_SHAPE = /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}$/u;
264
+ export function dateLikeCodes(fields) {
265
+ if (fields === null || fields === undefined || typeof fields !== "object")
266
+ return [];
267
+ return Object.entries(fields)
268
+ .filter(([, value]) => typeof value === "string" && DATE_READBACK_SHAPE.test(value))
269
+ .map(([code]) => code);
270
+ }
271
+ export function hasDateCode(codes, typeByCode) {
272
+ return codes.some((code) => typeByCode.get(code) === FIELD_PROPERTY_TYPES.DATE);
273
+ }
274
+ /**
275
+ * 从 items 里找「null 业务列」(跨行全 null;任何一行有值就算已投影有数据),
276
+ * 按视图列证据分类。无 null 业务列时返回 undefined(正常读取零噪音,与旧行为一致)。
277
+ */
278
+ export function projectionHintFace(items, evidence) {
279
+ const allNull = [];
280
+ const hasValue = new Set();
281
+ for (const item of items) {
282
+ for (const [key, value] of Object.entries(item.fields)) {
283
+ // `*_key` 是平台给单选/字典字段铸的孪生列(BizObject.SELECTION_KEY_SUFFIX
284
+ // ="_key":8.6.26 BizObject.java:83 / 2.1.5 BizObject.java:59,两版同形)——
285
+ // 它不在发布业务字段里,全 null 不代表「视图漏配了一列」。
286
+ if (RUNTIME_SYSTEM_FIELD_CODES.has(key) || key.endsWith("_") || key.endsWith("_key"))
287
+ continue;
288
+ if (value === null || value === undefined) {
289
+ if (!hasValue.has(key) && !allNull.includes(key))
290
+ allNull.push(key);
291
+ }
292
+ else {
293
+ hasValue.add(key);
294
+ }
295
+ }
296
+ }
297
+ const nullColumns = allNull.filter((key) => !hasValue.has(key));
298
+ if (items.length === 0 || nullColumns.length === 0)
299
+ return undefined;
300
+ const base = {
301
+ hint: "null 可能=未投影进视图列,判真值用 data.load --args {schemaCode,bizObjectId}",
302
+ projectionKnown: false,
303
+ ...(evidence !== undefined ? { viewColumnsCount: evidence.viewColumnsCount } : {}),
304
+ };
305
+ const codes = evidence?.viewColumnCodes;
306
+ if (codes === undefined)
307
+ return base;
308
+ const inView = new Set(codes);
309
+ const projectedFields = nullColumns.filter((code) => inView.has(code));
310
+ const unprojected = nullColumns.filter((code) => !inView.has(code));
311
+ return {
312
+ ...base,
313
+ projectionKnown: true,
314
+ ...(projectedFields.length > 0 ? { projectedFields } : {}),
315
+ ...(unprojected.length > 0
316
+ ? {
317
+ unprojected,
318
+ // 探针 V F5(0.8.30):大行集(>10)保持既有字节形状(读门预算),
319
+ // 小行集给口径说明;items[].unprojected 始终是行内全部缺席键。
320
+ ...(items.length <= 10
321
+ ? {
322
+ unprojectedScope: "view-columns",
323
+ unprojectedNote: "顶层只列视图列缺口;items[].unprojected 含系统列",
324
+ }
325
+ : {}),
326
+ }
327
+ : {}),
328
+ };
329
+ }
330
+ /**
331
+ * F8(w44,2026-11-26 真机):`data.list` 的行内 `fields` 对**未投影**列也回
332
+ * `null`(与真空值同形),顶层 `projectionHint.unprojected` 只在整列全 null 时
333
+ * 出现,脚本按行对账仍会把 null 当数据丢失。行级 `unprojected` 用**同一份**
334
+ * 视图列证据(queryColumns)逐行标注:值 null 且不在视图列 → 本行未投影。
335
+ *
336
+ * F5(w91,0.8.12 真机):**系统列同样按证据判**——视图只配 4 个业务列时
337
+ * `sequenceNo` 回 `null` 却不在 `unprojected`,与 `data.load`(sequenceNo=记录 id)
338
+ * 自相矛盾。平台证据:列表 SELECT 只取视图列(`BizObjectFacadeImpl.handleQueryColumn`
339
+ * 8.6.26:4155-4182 / 2.1.5:1830-1860,display 缺省 false),`completeSystemFields`
340
+ * 的系统列白名单**不含 sequenceNo**(8.6.26:4866-4875 / 2.1.5
341
+ * `QueryDisplayFieldResolver:38,78-89`);行对象仍为每个已发布属性建字段,没查出来
342
+ * 的值留 null(`BizObject.createBizObject` 8.6.26:151-170 / `toObjectMap`:309-316)。
343
+ * 所以有视图列证据时系统列与业务列同判;`*_key` 孪生列仍不算(投影证据只覆盖
344
+ * 主列),拿不到视图清单时只用 `projectionMiss`,绝不拿 null 猜。
345
+ */
346
+ export const isKeyTwinProjectionCode = (key) => key.endsWith("_") || key.endsWith("_key");
347
+ /**
348
+ * 平台 `completeSystemFields` 无条件补进 SELECT 的系统列(8.6.26
349
+ * `BizObjectFacadeImpl:4870`;2.1.5 `QueryDisplayFieldResolver.REQUIRED_SYSTEM_FIELDS:38`):
350
+ * 它们**不由视图列决定**,所以视图清单里没有也不代表「未投影」——此时 null 就是真值。
351
+ * 只有白名单外的系统列(典型 `sequenceNo`、`version`)才随视图列证据判。
352
+ */
353
+ /**
354
+ * 即便列在视图里,平台 `runtime/query/list` 也不回值、恒为 null 的系统列。
355
+ * `sequenceNo` 就是典型(`completeSystemFields` 白名单不含它:8.6.26
356
+ * `BizObjectFacadeImpl:4870` / 2.1.5 `QueryDisplayFieldResolver.REQUIRED_SYSTEM_FIELDS:38`),
357
+ * 而 `data.load` 同记录有值。null 因此不代表真空值——与未投影同判(省略键)。
358
+ */
359
+ export const RUNTIME_NEVER_VALUED_WHEN_NULL = new Set(["sequenceNo"]);
360
+ export const RUNTIME_ALWAYS_PROJECTED_FIELD_CODES = new Set([
361
+ "id", "name", "owner", "creater", "createdTime", "modifiedTime", "sequenceStatus",
362
+ "workflowInstanceId", "ownerDeptId", "ownerDeptQueryCode",
363
+ ]);
364
+ export function itemUnprojectedFields(fields, projectionMiss, viewColumnCodes) {
365
+ const missed = projectionMiss.length > 0 ? new Set(projectionMiss) : undefined;
366
+ if (viewColumnCodes === undefined && missed === undefined)
367
+ return [];
368
+ const inView = viewColumnCodes === undefined ? undefined : new Set(viewColumnCodes);
369
+ return Object.entries(fields)
370
+ .filter(([code, value]) => {
371
+ if (isKeyTwinProjectionCode(code))
372
+ return false;
373
+ if (value !== null && value !== undefined)
374
+ return false;
375
+ if (inView !== undefined) {
376
+ // 视图含 sequenceNo 也不代表平台会回值(completeSystemFields 白名单不含它)。
377
+ if (RUNTIME_NEVER_VALUED_WHEN_NULL.has(code))
378
+ return true;
379
+ if (RUNTIME_ALWAYS_PROJECTED_FIELD_CODES.has(code))
380
+ return false;
381
+ return !inView.has(code);
382
+ }
383
+ // 无视图证据:系统列保持旧口径(不猜),只认 projectionMiss 的业务列。
384
+ if (RUNTIME_SYSTEM_FIELD_CODES.has(code))
385
+ return false;
386
+ return missed.has(code);
387
+ })
388
+ .map(([code]) => code);
389
+ }
390
+ /** 行级 `unprojected` 只在有已判定未投影列时加键(空数组没有信息量,也会涨字节)。 */
391
+ export function attachItemUnprojected(items, projectionMiss, viewColumnCodes) {
392
+ // 键只在**该行真的**有已判定未投影列时出现:无标注的行不加 `unprojected: []`
393
+ // ——每行多 ~20B 会把 25 行的小结果顶过 compact 外置阈值(0.8.7 全量实测
394
+ // composers `data.list --all` 因 `items` 被外置而失败),且空数组没有信息量。
395
+ return items.map((item) => {
396
+ const unprojected = itemUnprojectedFields(item.fields, projectionMiss, viewColumnCodes);
397
+ return unprojected.length > 0 ? { ...item, unprojected } : { ...item };
398
+ });
399
+ }
400
+ /**
401
+ * F5(w53,2026-11-26 真机):已判定未投影的列**从 `items[].fields` 省略键**,
402
+ * 不再回 `null`——0.8.7 真机里 `faultDesc/repairDate/version:null` 与真实空值
403
+ * 同形,脚本会当成「值丢了」。`unprojected` 仍逐行点名同一批 code(键缺席 =
404
+ * 未投影/不适用;键在且 null 才是真空值)。
405
+ *
406
+ * 只删**该行 unprojected 点名的键**:无证据的 null(真空值)逐字保留;系统列 /
407
+ * `*_` / `*_key` 本来就不进 unprojected,也不会被误删。
408
+ */
409
+ export function omitUnprojectedFields(items) {
410
+ return items.map((item) => {
411
+ if (item.unprojected === undefined || item.unprojected.length === 0)
412
+ return item;
413
+ const fields = { ...item.fields };
414
+ for (const code of item.unprojected)
415
+ delete fields[code];
416
+ return { ...item, fields };
417
+ });
418
+ }
419
+ /**
420
+ * F5(w112 探针 H,P2):行级 `unprojected` 是权威点名,但 compact 会把大结果的
421
+ * `items` 外置——外置后行内证据只剩 artifact 里。顶层给一个**跨行并集计数**,
422
+ * 让人类摘要行在外置/内联两种形状下都能说「N 个未投影字段已省略」(仍是同一份
423
+ * `items[].unprojected` 证据,不新增判据)。
424
+ */
425
+ export function unprojectedFieldCodes(items) {
426
+ const seen = new Set();
427
+ for (const item of items)
428
+ for (const code of item.unprojected ?? [])
429
+ seen.add(code);
430
+ return [...seen];
431
+ }
432
+ /** 人类/脚本读 null 的唯一权威口径;与行级 `unprojected` 同时出现才完整。 */
433
+ export const DATA_LIST_NULL_SEMANTICS = "items[].fields.<code> 键缺席=字段不存在或该行已判定未投影(items[].unprojected 已省略该键;有视图列证据时系统列如 sequenceNo 与业务列同判);键在且值为 null 才是真空值;判真值用 data.load。";
434
+ /**
435
+ * B2(issue 2026-11-25,真机 `milestone_ledger`):`data.list` 对关联字段静默回
436
+ * null,而同一条记录 `data.load` 有真实值(`{id, displayCode, <显示字段>}`)。
437
+ *
438
+ * 平台事实(两棵树同形,见 B2 证据表):
439
+ * - 列表 SELECT 只取视图列:`BizFilter.toFilter` 只把 displayFields 里
440
+ * `hasRealColumn()` 的列放进 SELECT(8.6.26 `BizFilter.java:62-74` /
441
+ * 2.1.5 `BizFilter.java:60-72`);`display` 缺省 false → 列集 = 视图
442
+ * queryColumns(`BizObjectFacadeImpl.java:4697` → `handleQueryColumn:4155-4185`;
443
+ * 2.1.5 `:2216` → `:1830-1860`;`QueryDataModel.display` 默认 false,`:70/:98-103`)。
444
+ * - 行对象为**每个已发布属性**建 BizField(8.6.26 `BizObject.createBizObject:158-170` /
445
+ * 2.1.5 `:127-145`),关联字段只 setOriginDbValue;没查出来的列 originDbValue=null,
446
+ * 值留在 null → wire 上是「键在、值 null」,**不是键缺席**
447
+ * (`WorkSheetBizField.contentFromRelatedObject:55-73` 只在 originDbValue 非空时由
448
+ * `WorkSheetFieldFiller` 填充:8.6.26 `:77-121` / 2.1.5 `:61-106`)。
449
+ * `BizObject.toObjectMap` 遍历整个 dataMap(8.6.26 `:309-316` / 2.1.5 `:280-288`)。
450
+ *
451
+ * 因此「关联列 null」有两种互斥含义,必须能区分:
452
+ * - 视图列里没有该列 → 平台根本没查 → **未投影**(本回执点名 + 给 data.load);
453
+ * - 视图列里有该列而值为 null → 关联确实没值 → 保留 null,**不算**未投影。
454
+ * 判据只用 queryColumns 清单(或请求列在 wire 行里缺席),不拿 null 猜。
455
+ */
456
+ export const RELATION_PROPERTY_TYPES = new Set([
457
+ FIELD_PROPERTY_TYPES.WORK_SHEET,
458
+ FIELD_PROPERTY_TYPES.MULT_WORK_SHEET,
459
+ FIELD_PROPERTY_TYPES.RELEVANCE_DATA,
460
+ ]);
461
+ /**
462
+ * 全 null 且判为「未投影」的列:请求列在 wire 行里整列缺席(键缺席 = 平台没返回),
463
+ * 或(有 queryColumns 证据时)不在视图列清单里。两路证据都没有 → 不列(null 不猜)。
464
+ */
465
+ export function unprojectedNullColumns(items, projectionMiss, viewColumnCodes) {
466
+ if (items.length === 0)
467
+ return [];
468
+ const codes = new Set();
469
+ for (const item of items)
470
+ for (const code of Object.keys(item.fields))
471
+ codes.add(code);
472
+ const inView = viewColumnCodes === undefined ? undefined : new Set(viewColumnCodes);
473
+ const missed = new Set(projectionMiss);
474
+ return [...codes].filter((code) => {
475
+ if (!items.every((item) => item.fields[code] === null))
476
+ return false;
477
+ if (missed.has(code))
478
+ return true;
479
+ return inView !== undefined && !inView.has(code);
480
+ });
481
+ }
482
+ /** 未投影列里只保留关联/引用类字段,并给出可复制的 data.load 复核命令。 */
483
+ export function relationColumnsNotProjected(codes, relationCodes, schemaCode, sampleId) {
484
+ const id = typeof sampleId === "string" && sampleId.trim() !== "" ? sampleId : "<bizObjectId>";
485
+ return codes
486
+ .filter((code) => relationCodes.has(code))
487
+ .map((code) => ({
488
+ code,
489
+ reason: "relation-column-not-projected",
490
+ nextCommand: `omc call data.load --env <env> --args '{"schemaCode":"${schemaCode}","bizObjectId":"${id}"}'`,
491
+ }));
492
+ }
493
+ /**
494
+ * Default-compact a runtime record: drop only KNOWN engine noise — `*_` keys are
495
+ * flow-engine internals (`activityName_`, `participants_`, …) and the staff/dept
496
+ * blobs above. Every business value is kept verbatim, INCLUDING null/empty (a
497
+ * null business field is a real, readable state; dropping it would make it
498
+ * indistinguishable from an absent field). `full:true` returns the untouched
499
+ * record.
500
+ *
501
+ * Round 13: the filter now recurses. A child-table field comes back as an array
502
+ * of row objects, and each row carries its own owner/creater/dept blobs and
503
+ * `*_` internals — the first version only stripped the top level, so a record
504
+ * with a child table still shipped the noise one level down. The keys are
505
+ * platform-reserved (`SYSTEM_FIELD_CODES` / engine internals), so a business
506
+ * field cannot collide with them and recursion cannot eat authored data.
507
+ */
508
+ export function compactRuntimeValue(value) {
509
+ if (Array.isArray(value))
510
+ return value.map(compactRuntimeValue);
511
+ if (value !== null && typeof value === "object")
512
+ return compactRuntimeRecord(value);
513
+ return value;
514
+ }
515
+ export function compactRuntimeRecord(record) {
516
+ const compact = {};
517
+ for (const [key, value] of Object.entries(record)) {
518
+ if (key.endsWith("_"))
519
+ continue;
520
+ // 探针 R F13(0.8.26):`*_key` 是平台给单选/字典字段铸的孪生列,值为 null
521
+ // 时既不在模型字段里也没有来源说明,读回会让人误判「漏配字段」;非 null 保留
522
+ // (它携带真实字典 key)。只丢 null/undefined 的伴生键。
523
+ if (key.endsWith("_key") && (value === null || value === undefined))
524
+ continue;
525
+ if (RUNTIME_ENGINE_RECORD_KEYS.has(key))
526
+ continue;
527
+ compact[key] = compactRuntimeValue(value);
528
+ }
529
+ return compact;
530
+ }
531
+ /**
532
+ * F6 工单 05b(2026-11-21):`data.list` 内联子表行后,agent 不知道有
533
+ * `data.aggregate child`,只能拉全量子行、再也不会想到计数/合计可以一次服务端
534
+ * 完成。检测「值是对象数组」的字段(子表字段 code 就是 childSchemaCode——与
535
+ * data.aggregate 的 child.childSchemaCode 同义),给出按需读取数面的指路。
536
+ * 只探测、不加 wire;每次回执至多一句。
537
+ */
538
+ export function inlineChildRowsOf(fields, bizObjectId) {
539
+ const id = String(bizObjectId ?? "").trim();
540
+ if (id === "")
541
+ return undefined;
542
+ for (const [key, value] of Object.entries(fields)) {
543
+ if (key === "" || !Array.isArray(value) || value.length === 0)
544
+ continue;
545
+ // 0.8.19(探针 M F2):`data.load full` 的系统人员列也序列化成对象数组
546
+ // (owner/modifier/creater/createdDeptId/ownerDeptId…),旧实现取「第一个数组键」
547
+ // → childRowsHint 给 `childSchemaCode:"modifier"`,照抄必错。只认业务键。
548
+ if (!isBusinessProjectionCode(key))
549
+ continue;
550
+ if (!value.every((entry) => entry !== null && typeof entry === "object" && !Array.isArray(entry)))
551
+ continue;
552
+ return { childSchemaCode: key, bizObjectId: id };
553
+ }
554
+ return undefined;
555
+ }
556
+ export function childRowsAggregateHint(hit, schemaCode, lead) {
557
+ return `${lead};只要子表**计数/合计**:omc call data.aggregate --args '{"schemaCode":"${schemaCode}","metric":"count","child":{"childSchemaCode":"${hit.childSchemaCode}","bizObjectId":"${hit.bizObjectId}"}}'(服务端计数零行内联,数值只拉目标列)`;
558
+ }
559
+ /**
560
+ * Round 3 (issue §D5): the write readback inlined the whole `authoritative`
561
+ * record (owner/creater objects included), ~4 KB a row. Default is now the
562
+ * compact projection (business fields + identity); `summary:true` keeps
563
+ * identity/status keys, `fields:[...]` keeps exactly the named keys, and
564
+ * `full:true` returns the untouched record.
565
+ */
566
+ export function projectReadbackRecord(record, args) {
567
+ if (record === null || typeof record !== "object" || Array.isArray(record))
568
+ return record;
569
+ const source = record;
570
+ if (Array.isArray(args.fields) && args.fields.length > 0) {
571
+ const projected = {};
572
+ for (const field of args.fields)
573
+ if (field in source)
574
+ projected[field] = source[field];
575
+ return projected;
576
+ }
577
+ if (args.summary === true) {
578
+ const projected = {};
579
+ for (const key of ["id", "bizObjectId", "schemaCode", "name", "sequenceStatus"])
580
+ if (key in source)
581
+ projected[key] = source[key];
582
+ return projected;
583
+ }
584
+ if (args.full === true)
585
+ return record;
586
+ return compactRuntimeRecord(source);
587
+ }
588
+ /** Shared optional schema fields for the write readback projection. */
589
+ export const readbackProjectionArgs = {
590
+ summary: z.boolean().optional().describe("只回身份/状态字段,裁剪 readback.authoritative(默认关闭,读回为业务字段+身份的精简记录)"),
591
+ fields: z.array(z.string().min(1)).optional().describe("只保留 readback.authoritative 中列出的字段(比 summary 更精确)"),
592
+ full: z.boolean().optional().describe("返回未裁剪的原始记录(含 owner/creater 等系统字段与 *_ 引擎内部字段;默认已裁剪)"),
593
+ };
594
+ //# sourceMappingURL=shapes.js.map