@stalfh233/omc-cli 0.6.86 → 0.6.87
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/batch-executor.js +236 -0
- package/dist/capability-overview.js +2 -2
- package/dist/cli.js +21 -3
- package/dist/discovery.js +50 -1
- package/dist/endpoints.js +16 -0
- package/dist/goal-plan.js +12 -0
- package/dist/goal-routes.js +20 -1
- package/dist/intent/capabilities/bizservice.js +368 -58
- package/dist/intent/compiler.js +11 -5
- package/dist/intent/plan-apply.js +22 -5
- package/dist/intent/plan-file.js +1 -0
- package/dist/intent/readback.js +78 -1
- package/dist/intent/schema.js +1 -1
- package/dist/lanes/apply-changes.js +134 -252
- package/dist/lanes/b2-registration.js +61 -5
- package/dist/lanes/businessrule.js +8 -3
- package/dist/lanes/config-diff.js +9 -0
- package/dist/lanes/rule-lifecycle.js +37 -4
- package/dist/lanes/runtime-data-contract.js +2 -1
- package/dist/lanes/runtime-data.js +301 -99
- package/dist/lanes/runtime-paging.js +100 -0
- package/dist/package.js +8 -2
- package/dist/read-shapes.js +29 -10
- package/dist/rollback.js +71 -20
- package/dist/rule-support.js +43 -1
- package/dist/service-support.js +57 -0
- package/dist/surface-ref.js +37 -0
- package/dist/write.js +5 -1
- package/package.json +3 -3
- package/skills/omc-capabilities.md +1 -1
|
@@ -14,6 +14,8 @@ import { closestMatch } from "../closest-match.js";
|
|
|
14
14
|
import { getInstanceBaseInfo, getReplayToken, listInstanceActivities, searchWorkItems, wireString } from "../workflow-support.js";
|
|
15
15
|
import { PLATFORM_ADMIN_START_BYPASS, resolvePermissionActor } from "../identity.js";
|
|
16
16
|
import { ENGINE_OWNED_KEYS, RUNTIME_DATA_LANE_CONTRACT, RUNTIME_DATA_WIRE, runtimeFormDataArg, } from "./runtime-data-contract.js";
|
|
17
|
+
import { scanPages } from "./runtime-paging.js";
|
|
18
|
+
import { decodeJsonColumn, JSON_COLUMN_NULL_COALESCE } from "../json-column.js";
|
|
17
19
|
import { SYSTEM_FIELD_CODES, familyName } from "../field-families.js";
|
|
18
20
|
import { applicationResolutionOf, resolveApplicationScope } from "../support.js";
|
|
19
21
|
/** r29b F8: keep ids/itemsPreview through governedRead's compact diet. */
|
|
@@ -172,6 +174,7 @@ export function extractBizObjectPage(value) {
|
|
|
172
174
|
const content = Array.isArray(candidate.content) ? candidate.content.filter((row) => !!row && typeof row === "object") : [];
|
|
173
175
|
return {
|
|
174
176
|
total: typeof candidate.totalElements === "number" ? candidate.totalElements : 0,
|
|
177
|
+
totalKnown: typeof candidate.totalElements === "number",
|
|
175
178
|
totalPages: typeof candidate.totalPages === "number" ? candidate.totalPages : 0,
|
|
176
179
|
page: typeof candidate.page === "number" ? candidate.page : undefined,
|
|
177
180
|
size: typeof candidate.size === "number" ? candidate.size : undefined,
|
|
@@ -1065,6 +1068,126 @@ async function diagnoseDbException(session, schemaCode, error) {
|
|
|
1065
1068
|
/** `data.aggregate` caps: server-total counts are exact; the local-scan fallback shares data.list's row cap. */
|
|
1066
1069
|
const AGGREGATE_CAP = 1000;
|
|
1067
1070
|
const AGGREGATE_PAGE_SIZE = 200;
|
|
1071
|
+
/**
|
|
1072
|
+
* 0.6.87 D2:策略标记不靠调用方猜 `complete`。
|
|
1073
|
+
* - `server-total`:count 走服务端 totalElements(精确);
|
|
1074
|
+
* - `paged-local-scan`:本地扫描真的翻了页(pagesConsumed>1);
|
|
1075
|
+
* - `local-scan`:本地扫描一页取齐(无分页发生)。
|
|
1076
|
+
* `/sum` 命中时另用 `server-aggregate`(D5)。
|
|
1077
|
+
*/
|
|
1078
|
+
function localScanMode(pagesConsumed) {
|
|
1079
|
+
return pagesConsumed > 1 ? "paged-local-scan" : "local-scan";
|
|
1080
|
+
}
|
|
1081
|
+
/**
|
|
1082
|
+
* 0.6.87 D5:`/sum` 的 GET_LIST 守卫(平台证据:
|
|
1083
|
+
* `DomainServiceImpl.query` 只在 CODING → SourceCodeLauncher、BIZ_SERVICE →
|
|
1084
|
+
* integration 时偏离 DB;默认 GET_LIST 仍 `queryFromDb`;`BizObjectRuleUtils
|
|
1085
|
+
* .isOperateDbForQuery` 是同一判据;`/sum` 直接 `aggregateBizObjects` →
|
|
1086
|
+
* `executeScalar`,**不经过** `DomainServiceImpl.query`,所以只有「可执行
|
|
1087
|
+
* GET_LIST 规则仍读 DB」时两边才是同一真相)。
|
|
1088
|
+
*
|
|
1089
|
+
* 可证明路径:DRAFT 行的 enabled/status/developmentMode 决定 getExecutable 是否
|
|
1090
|
+
* 返回规则;DEFAULT 时执行的是 latest PUBLISH 行,故还要读 runtime 面的
|
|
1091
|
+
* PUBLISH 行并核对它的 GET_LIST 节点 dataSourceType。任一步读不到/解析不了 →
|
|
1092
|
+
* `isDatabase:false`(不能证明 → 本地扫描),fail closed。
|
|
1093
|
+
*/
|
|
1094
|
+
const GET_LIST_RULE_CODE = "getlist";
|
|
1095
|
+
function developmentModeName(value) {
|
|
1096
|
+
if (typeof value === "number")
|
|
1097
|
+
return value === 0 ? "DEFAULT" : value === 1 ? "CODING" : value === 2 ? "DECISION" : String(value);
|
|
1098
|
+
return String(value ?? "").toUpperCase();
|
|
1099
|
+
}
|
|
1100
|
+
function getListRuleRow(rows) {
|
|
1101
|
+
return rows.find((row) => String(row.code ?? "").toLowerCase() === GET_LIST_RULE_CODE);
|
|
1102
|
+
}
|
|
1103
|
+
function ruleNodesOf(row) {
|
|
1104
|
+
if (row === undefined)
|
|
1105
|
+
return undefined;
|
|
1106
|
+
const nodes = decodeJsonColumn(row.node, JSON_COLUMN_NULL_COALESCE);
|
|
1107
|
+
return Array.isArray(nodes) ? nodes : undefined;
|
|
1108
|
+
}
|
|
1109
|
+
async function probeGetListReadsDatabase(session, schemaCode) {
|
|
1110
|
+
let wireCalls = 0;
|
|
1111
|
+
try {
|
|
1112
|
+
// app 面 list 投影 DRAFT 行(getExecutable 的 enabled/status 判据在 DRAFT 上)。
|
|
1113
|
+
const drafts = wireRows((await wireCall(session, { path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } })).data);
|
|
1114
|
+
wireCalls += 1;
|
|
1115
|
+
const draft = getListRuleRow(drafts);
|
|
1116
|
+
if (draft === undefined)
|
|
1117
|
+
return { isDatabase: true, wireCalls, reason: "no-get-list-rule" };
|
|
1118
|
+
if (draft.enabled === undefined)
|
|
1119
|
+
return { isDatabase: false, wireCalls, reason: "get-list-enabled-unknown" };
|
|
1120
|
+
if (draft.enabled !== true)
|
|
1121
|
+
return { isDatabase: true, wireCalls, reason: "get-list-disabled" };
|
|
1122
|
+
if (String(draft.status ?? "").toUpperCase() === "DISABLED")
|
|
1123
|
+
return { isDatabase: true, wireCalls, reason: "get-list-disabled" };
|
|
1124
|
+
const draftMode = developmentModeName(draft.developmentMode);
|
|
1125
|
+
if (draftMode !== "DEFAULT")
|
|
1126
|
+
return { isDatabase: false, wireCalls, reason: `get-list-development-mode-${draftMode || "unknown"}` };
|
|
1127
|
+
// DEFAULT 时真正执行的是 latest PUBLISH 行,节点以它为准。
|
|
1128
|
+
const published = getListRuleRow(wireRows((await wireCall(session, { path: ENDPOINTS.runtimeBusinessRuleListBySchemaCode, query: { schemaCode } })).data));
|
|
1129
|
+
wireCalls += 1;
|
|
1130
|
+
if (published === undefined)
|
|
1131
|
+
return { isDatabase: false, wireCalls, reason: "no-published-get-list" };
|
|
1132
|
+
const publishedMode = published.developmentMode === undefined ? "DEFAULT" : developmentModeName(published.developmentMode);
|
|
1133
|
+
if (publishedMode !== "DEFAULT")
|
|
1134
|
+
return { isDatabase: false, wireCalls, reason: `published-development-mode-${publishedMode || "unknown"}` };
|
|
1135
|
+
let nodes = ruleNodesOf(published);
|
|
1136
|
+
if (nodes === undefined) {
|
|
1137
|
+
const id = typeof published.id === "string" && published.id !== "" ? published.id : undefined;
|
|
1138
|
+
if (id === undefined)
|
|
1139
|
+
return { isDatabase: false, wireCalls, reason: "get-list-node-unreadable" };
|
|
1140
|
+
wireCalls += 1;
|
|
1141
|
+
const detail = (await wireCall(session, { path: ENDPOINTS.businessRuleGet, query: { id } })).data;
|
|
1142
|
+
nodes = ruleNodesOf(detail && typeof detail === "object" ? detail : undefined);
|
|
1143
|
+
}
|
|
1144
|
+
if (nodes === undefined)
|
|
1145
|
+
return { isDatabase: false, wireCalls, reason: "get-list-node-unreadable" };
|
|
1146
|
+
const getList = nodes.find((node) => !!node && typeof node === "object" && String(node.nodeType ?? "") === "GET_LIST");
|
|
1147
|
+
if (getList === undefined)
|
|
1148
|
+
return { isDatabase: false, wireCalls, reason: "get-list-node-missing" };
|
|
1149
|
+
const dataSource = getList.dataSourceType;
|
|
1150
|
+
const dataSourceName = dataSource === undefined || dataSource === null ? "GET_LIST" : String(dataSource).toUpperCase();
|
|
1151
|
+
return { isDatabase: dataSourceName === "GET_LIST", wireCalls, reason: dataSourceName === "GET_LIST" ? "get-list-db" : `get-list-datasource-${dataSourceName}` };
|
|
1152
|
+
}
|
|
1153
|
+
catch (error) {
|
|
1154
|
+
const detail = error instanceof WireError ? (error.errcode !== undefined ? `errcode ${error.errcode}` : error.kind) : "transport";
|
|
1155
|
+
return { isDatabase: false, wireCalls, reason: `get-list-probe-failed:${detail}` };
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* D5:调用平台 `/sum` ALL_DATA 并做**运行时键校验**。后端固定回
|
|
1160
|
+
* `{COUNT,SUM,MAX,MIN,AVG}`(`BizObjectFacadeImpl.executeAggregateQueries`,
|
|
1161
|
+
* decompiled 5667-5674);键缺失/非数 → 视为形状不符,回退本地扫描而不是猜。
|
|
1162
|
+
*/
|
|
1163
|
+
async function tryServerSum(session, body, field, metric) {
|
|
1164
|
+
try {
|
|
1165
|
+
const response = await wireCall(session, {
|
|
1166
|
+
path: ENDPOINTS.runtimeQuerySum,
|
|
1167
|
+
method: "POST",
|
|
1168
|
+
body: { ...body, sumItemList: [{ propertyCode: field, sumDataType: "ALL_DATA" }] },
|
|
1169
|
+
});
|
|
1170
|
+
const payload = response.data;
|
|
1171
|
+
const row = payload && typeof payload === "object" && !Array.isArray(payload) ? payload[field] : undefined;
|
|
1172
|
+
if (!row || typeof row !== "object" || Array.isArray(row))
|
|
1173
|
+
return { ok: false, reason: "sum-shape-invalid", detail: "missing-field-map" };
|
|
1174
|
+
const record = row;
|
|
1175
|
+
const count = aggregateNumeric(record.COUNT);
|
|
1176
|
+
if (count === null)
|
|
1177
|
+
return { ok: false, reason: "sum-shape-invalid", detail: "COUNT" };
|
|
1178
|
+
if (count === 0)
|
|
1179
|
+
return { ok: true, value: null, nonNullCount: 0 };
|
|
1180
|
+
const key = metric === "sum" ? "SUM" : metric === "avg" ? "AVG" : metric === "min" ? "MIN" : "MAX";
|
|
1181
|
+
const raw = aggregateNumeric(record[key]);
|
|
1182
|
+
if (raw === null)
|
|
1183
|
+
return { ok: false, reason: "sum-shape-invalid", detail: key };
|
|
1184
|
+
return { ok: true, value: metric === "sum" || metric === "avg" ? aggregateTidy(raw) : raw, nonNullCount: count };
|
|
1185
|
+
}
|
|
1186
|
+
catch (error) {
|
|
1187
|
+
const detail = error instanceof WireError ? (error.errcode !== undefined ? `errcode ${error.errcode}` : error.kind) : "transport";
|
|
1188
|
+
return { ok: false, reason: "sum-failed", detail };
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1068
1191
|
/** 数值聚合的字段拒绝面:publishedFields 只列前 N 个(与 data.list 的过滤目录同口径)。 */
|
|
1069
1192
|
const AGGREGATE_FIELD_SAMPLE_LIMIT = 20;
|
|
1070
1193
|
/**
|
|
@@ -1457,28 +1580,29 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1457
1580
|
const firstBody = { ...body, page: 0, size: pageSize };
|
|
1458
1581
|
const first = await wireCall(session, { path: ENDPOINTS.runtimeQueryList, method: "POST", body: firstBody });
|
|
1459
1582
|
const firstPage = extractBizObjectPage(first.data);
|
|
1460
|
-
|
|
1461
|
-
|
|
1583
|
+
// 0.6.87 D1:翻页语义统一进 scanPages(首页 total 唯一基准 / 页码序消费 /
|
|
1584
|
+
// 空页停止 / 超 total 尾页裁剪 / total 缺失不得当全集)。这里只保留
|
|
1585
|
+
// 「真空模型」早退(total 已知为 0),其余路径(含 total 缺失、首页空但
|
|
1586
|
+
// total>0 的漂移)走共享扫描并如实上报 total/totalUnknown。
|
|
1587
|
+
if (firstPage.totalKnown && firstPage.total === 0)
|
|
1462
1588
|
return { schemaCode: args.schemaCode, ...application, total: 0, page: "all", size: 0, pagesFetched: 0, items: [], itemsCount: 0, itemsReturned: 0, resultTruncated: false, itemsExternalized: false, ...(choiceFilterFields.length > 0 ? { filterValueHint: choiceFilterValueHint(choiceFilterFields) } : {}) };
|
|
1463
|
-
const
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
}
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
const
|
|
1477
|
-
// GitLab #18 P1-2:`capped = rows.length > CAP`
|
|
1478
|
-
//
|
|
1479
|
-
|
|
1480
|
-
// 读成"数据就这么多")。真正的截断判据是「拿到的比总量少」。
|
|
1481
|
-
const truncatedByCap = collected.length < total;
|
|
1589
|
+
const scan = await scanPages({
|
|
1590
|
+
cap: CAP,
|
|
1591
|
+
pageSize,
|
|
1592
|
+
fetchPage: async (pageIndex) => {
|
|
1593
|
+
if (pageIndex === 0)
|
|
1594
|
+
return { totalKnown: firstPage.totalKnown, total: firstPage.total, content: firstPage.content };
|
|
1595
|
+
const next = await wireCall(session, { path: ENDPOINTS.runtimeQueryList, method: "POST", body: { ...body, page: pageIndex, size: pageSize } });
|
|
1596
|
+
const nextPage = extractBizObjectPage(next.data);
|
|
1597
|
+
return { totalKnown: nextPage.totalKnown, total: nextPage.total, content: nextPage.content };
|
|
1598
|
+
},
|
|
1599
|
+
});
|
|
1600
|
+
const total = scan.total;
|
|
1601
|
+
const collected = scan.rows;
|
|
1602
|
+
const pageIndex = scan.pagesConsumed;
|
|
1603
|
+
// GitLab #18 P1-2:`capped = rows.length > CAP` 是死代码——真正的截断判据
|
|
1604
|
+
// 是「拿到的比总量少」(total 缺失时 = 停在 cap,见 scanPages.truncatedByCap)。
|
|
1605
|
+
const truncatedByCap = scan.truncatedByCap;
|
|
1482
1606
|
const items = collected.map((row0) => {
|
|
1483
1607
|
const row = row0;
|
|
1484
1608
|
const rawData = row.data && typeof row.data === "object" ? row.data : {};
|
|
@@ -1531,8 +1655,17 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1531
1655
|
truncated: true,
|
|
1532
1656
|
capped: true,
|
|
1533
1657
|
cap: CAP,
|
|
1534
|
-
|
|
1535
|
-
|
|
1658
|
+
...(total !== null
|
|
1659
|
+
? {
|
|
1660
|
+
missingCount: total - collected.length,
|
|
1661
|
+
capNotice: `已取前 ${collected.length} 条 / 共 ${total} 条(安全上限 ${CAP})——还差 ${total - collected.length} 条没返回。不要把它当全集:加 filters 分片(如按日期/业务键)分别拉取,或去掉 all 用 page/size 手动翻页。`,
|
|
1662
|
+
}
|
|
1663
|
+
: {
|
|
1664
|
+
// D1:total 缺失(showTotal:false / 面未回 totalElements)——
|
|
1665
|
+
// 缺口不可算,但截断事实(停在 cap)必须说清,不得当全集。
|
|
1666
|
+
totalUnknown: true,
|
|
1667
|
+
capNotice: `首页未回 totalElements(showTotal:false 或该面不回 total):已按安全上限 ${CAP} 扫描并取回 ${collected.length} 条,total 未知、缺多少条不可算——不要当全集。要精确计数用 size:1 + filter 读 total,或去掉 all 用 page/size 手动翻页。`,
|
|
1668
|
+
}),
|
|
1536
1669
|
}
|
|
1537
1670
|
: {}),
|
|
1538
1671
|
...(nullProjection ? { projectionHint: { hint: "null 可能=未投影进视图列,判真值用 data.load --args {schemaCode,bizObjectId}", ...(viewColumnsCount !== undefined ? { viewColumnsCount } : {}) } } : {}),
|
|
@@ -1938,63 +2071,110 @@ export function registerRuntimeDataLane(tools) {
|
|
|
1938
2071
|
const overall = emptyAcc();
|
|
1939
2072
|
const nullBucket = emptyAcc();
|
|
1940
2073
|
const buckets = new Map();
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
const
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
}
|
|
1968
|
-
|
|
2074
|
+
const numericMetric = metric;
|
|
2075
|
+
// D5:首页探针同时给出 total(是否值得走 /sum)和本地扫描的首页行
|
|
2076
|
+
// (回退零额外读)。只有「无 groupBy + total 已知且 > 一页」才考虑 /sum。
|
|
2077
|
+
const probe = await wireCall(session, { path: ENDPOINTS.runtimeQueryList, method: "POST", body: queryBody(AGGREGATE_PAGE_SIZE, 0) });
|
|
2078
|
+
const probePage = extractBizObjectPage(probe.data);
|
|
2079
|
+
let strategyFallback;
|
|
2080
|
+
let guardCalls = 0;
|
|
2081
|
+
let sumAttempts = 0;
|
|
2082
|
+
if (groupBy === undefined && probePage.totalKnown && probePage.total > AGGREGATE_PAGE_SIZE) {
|
|
2083
|
+
const path = await probeGetListReadsDatabase(session, args.schemaCode);
|
|
2084
|
+
guardCalls = path.wireCalls;
|
|
2085
|
+
if (path.isDatabase) {
|
|
2086
|
+
sumAttempts = 1;
|
|
2087
|
+
const sum = await tryServerSum(session, queryBody(1, 0), target, numericMetric);
|
|
2088
|
+
if (sum.ok) {
|
|
2089
|
+
const total = probePage.total;
|
|
2090
|
+
const nonNullCount = sum.nonNullCount;
|
|
2091
|
+
return {
|
|
2092
|
+
schemaCode: args.schemaCode,
|
|
2093
|
+
metric,
|
|
2094
|
+
field: target,
|
|
2095
|
+
value: sum.value,
|
|
2096
|
+
count: total,
|
|
2097
|
+
nonNullCount,
|
|
2098
|
+
nullCount: Math.max(0, total - nonNullCount),
|
|
2099
|
+
...(sum.value === null ? { note: "no numeric values in matched rows" } : {}),
|
|
2100
|
+
coverage: { mode: "server-aggregate", rowsScanned: 0, cap: null, complete: true },
|
|
2101
|
+
filter: draftFilter,
|
|
2102
|
+
wire: {
|
|
2103
|
+
calls: metaCalls + 1 + path.wireCalls + 1,
|
|
2104
|
+
plan: `1 metadata + 1 probe + ${path.wireCalls} guard + 1 /sum ALL_DATA`,
|
|
2105
|
+
strategy: "server-sum",
|
|
2106
|
+
},
|
|
2107
|
+
};
|
|
1969
2108
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2109
|
+
strategyFallback = { strategy: "server-sum", reason: sum.reason, detail: sum.detail, guardCalls: path.wireCalls };
|
|
2110
|
+
}
|
|
2111
|
+
else {
|
|
2112
|
+
strategyFallback = { strategy: "server-sum", reason: path.reason, guardCalls: path.wireCalls };
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2115
|
+
// 0.6.87 D1:翻页语义统一走 scanPages(首页 total 唯一基准 / 页码序消费 /
|
|
2116
|
+
// 空页停止 / 超 total 尾页裁剪 / total 缺失不当全集)。本路径只负责折叠。
|
|
2117
|
+
const scan = await scanPages({
|
|
2118
|
+
cap: AGGREGATE_CAP,
|
|
2119
|
+
pageSize: AGGREGATE_PAGE_SIZE,
|
|
2120
|
+
fetchPage: async (pageIndex) => {
|
|
2121
|
+
if (pageIndex === 0)
|
|
2122
|
+
return { totalKnown: probePage.totalKnown, total: probePage.total, content: probePage.content };
|
|
2123
|
+
const response = await wireCall(session, { path: ENDPOINTS.runtimeQueryList, method: "POST", body: queryBody(AGGREGATE_PAGE_SIZE, pageIndex) });
|
|
2124
|
+
const pageData = extractBizObjectPage(response.data);
|
|
2125
|
+
return { totalKnown: pageData.totalKnown, total: pageData.total, content: pageData.content };
|
|
2126
|
+
},
|
|
2127
|
+
});
|
|
2128
|
+
for (const row of scan.rows) {
|
|
2129
|
+
// 平台 query/list 无服务端列投影面:投影在本地做(只读这两列,其余不落内存)。
|
|
2130
|
+
const data = row.data && typeof row.data === "object" ? row.data : row;
|
|
2131
|
+
const value = aggregateNumeric(data[target]);
|
|
2132
|
+
let bucket;
|
|
2133
|
+
if (groupBy !== undefined) {
|
|
2134
|
+
const raw = data[groupBy];
|
|
2135
|
+
if (raw === null || raw === undefined)
|
|
2136
|
+
bucket = nullBucket;
|
|
2137
|
+
else {
|
|
2138
|
+
const key = String(raw);
|
|
2139
|
+
bucket = buckets.get(key);
|
|
2140
|
+
if (bucket === undefined) {
|
|
2141
|
+
bucket = emptyAcc();
|
|
2142
|
+
buckets.set(key, bucket);
|
|
2143
|
+
}
|
|
1980
2144
|
}
|
|
1981
2145
|
}
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
2146
|
+
for (const acc of bucket === undefined ? [overall] : [overall, bucket]) {
|
|
2147
|
+
acc.count += 1;
|
|
2148
|
+
if (value === null)
|
|
2149
|
+
continue;
|
|
2150
|
+
acc.nonNullCount += 1;
|
|
2151
|
+
acc.sum += value;
|
|
2152
|
+
if (value < acc.min)
|
|
2153
|
+
acc.min = value;
|
|
2154
|
+
if (value > acc.max)
|
|
2155
|
+
acc.max = value;
|
|
2156
|
+
}
|
|
1985
2157
|
}
|
|
1986
|
-
const
|
|
1987
|
-
const
|
|
2158
|
+
const rowsScanned = scan.rows.length;
|
|
2159
|
+
const total = scan.total;
|
|
2160
|
+
const complete = scan.complete;
|
|
1988
2161
|
const scanValue = (acc) => aggregateValue(numericMetric, acc.sum, acc.nonNullCount, acc.min, acc.max);
|
|
1989
2162
|
const coverage = {
|
|
1990
|
-
mode:
|
|
2163
|
+
mode: localScanMode(scan.pagesConsumed),
|
|
1991
2164
|
rowsScanned,
|
|
1992
2165
|
cap: AGGREGATE_CAP,
|
|
1993
2166
|
complete,
|
|
1994
|
-
...(complete ? {} : { missingCount: Math.max(0, total - rowsScanned) }),
|
|
2167
|
+
...(complete || total === null ? {} : { missingCount: Math.max(0, total - rowsScanned) }),
|
|
2168
|
+
};
|
|
2169
|
+
const capNotice = total !== null
|
|
2170
|
+
? `数值列本地折叠:已扫前 ${rowsScanned}/${total} 行,${metric} 只覆盖已扫部分(complete:false,非全集)。要全集:filters 按日期/业务键 gte/lt 分片重跑,或 page/size 手动翻页。`
|
|
2171
|
+
: `数值列本地折叠:首页未回 totalElements(showTotal:false 或该面不回 total),已按安全上限 ${AGGREGATE_CAP} 扫到 ${rowsScanned} 行;total 未知、缺口不可算,不要当全集。要全集:filters 按日期/业务键 gte/lt 分片重跑,或 page/size 手动翻页。`;
|
|
2172
|
+
const strategyNote = guardCalls + sumAttempts > 0 ? `${guardCalls} guard + ${sumAttempts} /sum + ` : "";
|
|
2173
|
+
const wire = {
|
|
2174
|
+
calls: metaCalls + scan.wireCalls + guardCalls + sumAttempts,
|
|
2175
|
+
plan: `1 metadata + ${strategyNote}${scan.wireCalls} pages`,
|
|
2176
|
+
...(scan.concurrency !== undefined ? { concurrency: scan.concurrency } : {}),
|
|
1995
2177
|
};
|
|
1996
|
-
const capNotice = `数值列本地折叠:已扫前 ${rowsScanned}/${total} 行,${metric} 只覆盖已扫部分(complete:false,非全集)。要全集:filters 按日期/业务键 gte/lt 分片重跑,或 page/size 手动翻页。`;
|
|
1997
|
-
const wire = { calls: metaCalls + pages, plan: `1 metadata + ${pages} pages` };
|
|
1998
2178
|
if (groupBy === undefined) {
|
|
1999
2179
|
const value = scanValue(overall);
|
|
2000
2180
|
return {
|
|
@@ -2009,6 +2189,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2009
2189
|
coverage,
|
|
2010
2190
|
filter: draftFilter,
|
|
2011
2191
|
...(complete ? {} : { capNotice }),
|
|
2192
|
+
...(strategyFallback !== undefined ? { strategyFallback } : {}),
|
|
2012
2193
|
wire,
|
|
2013
2194
|
};
|
|
2014
2195
|
}
|
|
@@ -2035,6 +2216,7 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2035
2216
|
coverage,
|
|
2036
2217
|
filter: draftFilter,
|
|
2037
2218
|
...(complete ? {} : { capNotice }),
|
|
2219
|
+
...(strategyFallback !== undefined ? { strategyFallback } : {}),
|
|
2038
2220
|
wire,
|
|
2039
2221
|
};
|
|
2040
2222
|
}
|
|
@@ -2053,7 +2235,13 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2053
2235
|
// 2/3) groupBy:值域可枚举 → 值域×count;否则 1 列投影本地扫描。
|
|
2054
2236
|
const meta = await fieldMeta();
|
|
2055
2237
|
const groupField = meta?.get(args.groupBy);
|
|
2056
|
-
const
|
|
2238
|
+
const rawCodes = groupField?.choiceCodes ?? [];
|
|
2239
|
+
// 0.6.87 D4:重复 choiceCodes 会让同一值域被 count 两次,U+null 之和超过
|
|
2240
|
+
// base total(负 unaccounted)。按输入序去重并显式告警,不静默重复计。
|
|
2241
|
+
const codes = [...new Set(rawCodes)];
|
|
2242
|
+
const shapeWarnings = [];
|
|
2243
|
+
if (codes.length !== rawCodes.length)
|
|
2244
|
+
shapeWarnings.push(`choiceCodes-duplicate: groupBy ${args.groupBy} 的选项/字典码有 ${rawCodes.length - codes.length} 个重复(${rawCodes.length}→${codes.length}),已去重;否则同一值域会被重复计数`);
|
|
2057
2245
|
if (groupField && Number.isInteger(groupField.type) && codes.length > 0) {
|
|
2058
2246
|
// R88 S1:值域×count 扇出(base + 每值域 Eq + IsNull)彼此独立,走有界
|
|
2059
2247
|
// 并发(窗口 4)。fieldMeta() 已在前一行完成,绝不进并发窗口(metaCalls
|
|
@@ -2094,6 +2282,10 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2094
2282
|
const nullCount = values[units.length - 1];
|
|
2095
2283
|
const sums = buckets.reduce((sum, bucket) => sum + bucket.count, 0);
|
|
2096
2284
|
const unaccounted = baseTotal - sums - nullCount;
|
|
2285
|
+
// D4:负 unaccounted 不得静默丢(旧代码只在 >0 时给键,负值连信号都没有)。
|
|
2286
|
+
// 归零 + 显式 warning:桶计数是平台 COUNT 结果,不在这里改写数字本身。
|
|
2287
|
+
if (unaccounted < 0)
|
|
2288
|
+
shapeWarnings.push(`unaccounted-negative: 桶和 ${sums} + null ${nullCount} > base total ${baseTotal}(差 ${unaccounted}),已归零;通常是重复 choiceCodes 或平台 COUNT 漂移——不要把分桶当精确闭环`);
|
|
2097
2289
|
buckets.sort((left, right) => right.count - left.count || left.key.localeCompare(right.key));
|
|
2098
2290
|
const shown = buckets.slice(0, topN);
|
|
2099
2291
|
return {
|
|
@@ -2105,7 +2297,8 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2105
2297
|
nullBucket: { count: nullCount },
|
|
2106
2298
|
truncatedBuckets: buckets.length > shown.length,
|
|
2107
2299
|
bucketsTruncatedCount: buckets.length - shown.length,
|
|
2108
|
-
...(unaccounted > 0 ? { unaccountedCount: unaccounted } : {}),
|
|
2300
|
+
...(unaccounted > 0 ? { unaccountedCount: unaccounted } : unaccounted < 0 ? { unaccountedCount: 0 } : {}),
|
|
2301
|
+
...(shapeWarnings.length > 0 ? { shapeWarnings } : {}),
|
|
2109
2302
|
coverage: { mode: "server-total", rowsScanned: 0, cap: AGGREGATE_CAP, complete: true },
|
|
2110
2303
|
filter: draftFilter,
|
|
2111
2304
|
wire: {
|
|
@@ -2118,34 +2311,31 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2118
2311
|
// 自由文本/高基数:翻页取前 cap 行,只投影 groupBy 列本地计数;绝不按扫描比例外推。
|
|
2119
2312
|
const counts = new Map();
|
|
2120
2313
|
let nullCount = 0;
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
2140
|
-
}
|
|
2314
|
+
// 0.6.87 D1:与数值路径共用 scanPages 的翻页/裁剪/空页/total 语义。
|
|
2315
|
+
const scan = await scanPages({
|
|
2316
|
+
cap: AGGREGATE_CAP,
|
|
2317
|
+
pageSize: AGGREGATE_PAGE_SIZE,
|
|
2318
|
+
fetchPage: async (pageIndex) => {
|
|
2319
|
+
const response = await wireCall(session, { path: ENDPOINTS.runtimeQueryList, method: "POST", body: queryBody(AGGREGATE_PAGE_SIZE, pageIndex) });
|
|
2320
|
+
const pageData = extractBizObjectPage(response.data);
|
|
2321
|
+
return { totalKnown: pageData.totalKnown, total: pageData.total, content: pageData.content };
|
|
2322
|
+
},
|
|
2323
|
+
});
|
|
2324
|
+
for (const row of scan.rows) {
|
|
2325
|
+
const data = row.data && typeof row.data === "object" ? row.data : row;
|
|
2326
|
+
const raw = data[args.groupBy];
|
|
2327
|
+
if (raw === null || raw === undefined)
|
|
2328
|
+
nullCount += 1;
|
|
2329
|
+
else {
|
|
2330
|
+
const key = String(raw);
|
|
2331
|
+
counts.set(key, (counts.get(key) ?? 0) + 1);
|
|
2141
2332
|
}
|
|
2142
|
-
rowsScanned += pageData.content.length;
|
|
2143
|
-
if (rowsScanned >= total)
|
|
2144
|
-
break;
|
|
2145
2333
|
}
|
|
2334
|
+
const rowsScanned = scan.rows.length;
|
|
2335
|
+
const total = scan.total;
|
|
2336
|
+
const complete = scan.complete;
|
|
2146
2337
|
const allBuckets = [...counts].map(([key, count]) => ({ key, count })).sort((left, right) => right.count - left.count || left.key.localeCompare(right.key));
|
|
2147
2338
|
const shown = allBuckets.slice(0, topN);
|
|
2148
|
-
const complete = rowsScanned >= total;
|
|
2149
2339
|
return {
|
|
2150
2340
|
schemaCode: args.schemaCode,
|
|
2151
2341
|
metric: "count",
|
|
@@ -2155,12 +2345,24 @@ export function registerRuntimeDataLane(tools) {
|
|
|
2155
2345
|
nullBucket: { count: nullCount },
|
|
2156
2346
|
truncatedBuckets: allBuckets.length > shown.length,
|
|
2157
2347
|
bucketsTruncatedCount: allBuckets.length - shown.length,
|
|
2158
|
-
coverage: {
|
|
2348
|
+
coverage: {
|
|
2349
|
+
mode: localScanMode(scan.pagesConsumed),
|
|
2350
|
+
rowsScanned,
|
|
2351
|
+
cap: AGGREGATE_CAP,
|
|
2352
|
+
complete,
|
|
2353
|
+
...(total === null ? {} : { missingCount: Math.max(0, total - rowsScanned) }),
|
|
2354
|
+
},
|
|
2159
2355
|
filter: draftFilter,
|
|
2160
2356
|
...(complete ? {} : {
|
|
2161
|
-
capNotice:
|
|
2357
|
+
capNotice: total !== null
|
|
2358
|
+
? `值域非可枚举:已扫前 ${rowsScanned}/${total} 行,桶只覆盖已扫部分(complete:false,非全集)。要全集:filters 按日期/业务键 gte/lt 分片重跑,或 page/size 手动翻页。`
|
|
2359
|
+
: `值域非可枚举:首页未回 totalElements(showTotal:false 或该面不回 total),已按安全上限 ${AGGREGATE_CAP} 扫到 ${rowsScanned} 行;total 未知、缺口不可算,不要当全集。要全集:filters 按日期/业务键 gte/lt 分片重跑,或 page/size 手动翻页。`,
|
|
2162
2360
|
}),
|
|
2163
|
-
wire: {
|
|
2361
|
+
wire: {
|
|
2362
|
+
calls: metaCalls + scan.wireCalls,
|
|
2363
|
+
plan: `${metaCalls > 0 ? "1 metadata + " : ""}${scan.wireCalls} pages`,
|
|
2364
|
+
...(scan.concurrency !== undefined ? { concurrency: scan.concurrency } : {}),
|
|
2365
|
+
},
|
|
2164
2366
|
};
|
|
2165
2367
|
}, { target: `data.aggregate:${JSON.stringify({ schemaCode: args.schemaCode, metric: args.metric, field: args.field, filter: args.filter, filters: args.filters, filterGroup: args.filterGroup, groupBy: args.groupBy, topN: args.topN ?? 10, includeDrafts: args.includeDrafts ?? null })}` });
|
|
2166
2368
|
},
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 0.6.87 D1/D3(批次计划 r89-batch PLAN.md D1/D3;T2 trace §2/§3/§7 M1):runtime 读面共享翻页扫描。
|
|
3
|
+
*
|
|
4
|
+
* 统一 `data.list all:true` 与 `data.aggregate` 数值/本地扫描的翻页语义:
|
|
5
|
+
* - 首页 total 是**唯一基准**(后续页的 total 不采信——平台每页独立 COUNT,
|
|
6
|
+
* `PageVO.java:50-57` / `BizObjectRepository.java:132-155`,无跨请求快照);
|
|
7
|
+
* - 页码序消费:行按 page 0,1,2… 顺序折叠,绝不按完成序;
|
|
8
|
+
* - 空页停止:某页 0 行即停止,不再**消费**其后页(D3 的预取可能已经发出,
|
|
9
|
+
* 但断点之后的行一律丢弃);
|
|
10
|
+
* - 超 total 尾页裁剪:rowCeiling = min(total, cap),越界行丢弃;
|
|
11
|
+
* - total 缺失(面没回 totalElements,如 showTotal:false)→ `total:null`,
|
|
12
|
+
* 扫描只能按 cap/空页停止,`complete` 恒 false——「total 缺失必须 complete:false」,
|
|
13
|
+
* 不得把 0 当 total 静默当全集。
|
|
14
|
+
*
|
|
15
|
+
* D3 分页并发(T2-S2):首页串行取 total 后才预取余页(窗口
|
|
16
|
+
* `DEFAULT_SCAN_CONCURRENCY`);**只按页码序折叠、只消费断点前页**。
|
|
17
|
+
* `rowsScanned` 由调用方按返回的 rows 计算(预取但未消费的页不会进来);
|
|
18
|
+
* `wireCalls` 仍是**逻辑翻页请求数**(含预取越界页,不含限流退避/串行重放——
|
|
19
|
+
* 与 S1 的 wire.calls 口径一致,重试只进 `concurrency.retries`)。
|
|
20
|
+
* 失败语义沿用 S1:非限流直接抛;断点处限流失败串行重放一次,仍失败抛该页;
|
|
21
|
+
* 断点之后的失败一律忽略(串行基线根本不会读到那一页)。
|
|
22
|
+
*
|
|
23
|
+
* 调用方保留各自回执容器:list 仍回 items/itemsCount/pagesFetched/…;aggregate 仍回
|
|
24
|
+
* value/buckets/coverage——本模块只统一翻页/裁剪/覆盖判定,不碰投影。
|
|
25
|
+
*/
|
|
26
|
+
import { DEFAULT_SCAN_CONCURRENCY, isThrottleClassError, mapWithConcurrency } from "../concurrency.js";
|
|
27
|
+
/**
|
|
28
|
+
* 共享翻页扫描(D1/D3 语义,见文件头)。首页串行取 total;计划页数 = ceil(min(total,
|
|
29
|
+
* cap)/pageSize);余页有界并发预取,然后严格按页码序折叠到 rowCeiling / 空页 / 计划耗尽。
|
|
30
|
+
*/
|
|
31
|
+
export async function scanPages(options) {
|
|
32
|
+
const { cap, pageSize, fetchPage } = options;
|
|
33
|
+
const first = await fetchPage(0);
|
|
34
|
+
const total = first.totalKnown ? first.total : null;
|
|
35
|
+
if (first.content.length === 0) {
|
|
36
|
+
return {
|
|
37
|
+
rows: [],
|
|
38
|
+
total,
|
|
39
|
+
pagesConsumed: 0,
|
|
40
|
+
wireCalls: 1,
|
|
41
|
+
stopReason: total === 0 ? "no-data" : "empty-page",
|
|
42
|
+
complete: total === 0,
|
|
43
|
+
truncatedByCap: false,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const rowCeiling = Math.min(total ?? Number.POSITIVE_INFINITY, cap);
|
|
47
|
+
const plannedPages = Math.max(1, Math.ceil(rowCeiling / pageSize));
|
|
48
|
+
const prefetchPages = Array.from({ length: Math.max(0, plannedPages - 1) }, (_unused, index) => index + 1);
|
|
49
|
+
// D3:首页已串行确认 total,余页彼此独立,可有界并发;折叠绝不按完成序。
|
|
50
|
+
const prefetch = prefetchPages.length > 0
|
|
51
|
+
? await mapWithConcurrency(prefetchPages, DEFAULT_SCAN_CONCURRENCY, (page) => fetchPage(page))
|
|
52
|
+
: undefined;
|
|
53
|
+
const rows = [...first.content];
|
|
54
|
+
let pagesConsumed = 1;
|
|
55
|
+
let brokeOnEmpty = false;
|
|
56
|
+
for (let index = 0; index < prefetchPages.length; index += 1) {
|
|
57
|
+
// 只消费断点前页:已到 rowCeiling 就丢弃其余预取结果。
|
|
58
|
+
if (rows.length >= rowCeiling)
|
|
59
|
+
break;
|
|
60
|
+
const outcome = prefetch.outcomes[index];
|
|
61
|
+
let shape;
|
|
62
|
+
if (outcome.ok) {
|
|
63
|
+
shape = outcome.value;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// S1 失败语义:非限流(业务拒绝等)直接抛断点处错误;限流类在窗口内已
|
|
67
|
+
// 退避重试一次,仍失败则串行重放一次(突发限流串行往往能过),再失败抛。
|
|
68
|
+
if (!isThrottleClassError(outcome.error))
|
|
69
|
+
throw outcome.error;
|
|
70
|
+
shape = await fetchPage(prefetchPages[index]);
|
|
71
|
+
}
|
|
72
|
+
if (shape.content.length === 0) {
|
|
73
|
+
brokeOnEmpty = true;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
rows.push(...shape.content);
|
|
77
|
+
pagesConsumed += 1;
|
|
78
|
+
}
|
|
79
|
+
const clipped = rows.length > rowCeiling ? rows.slice(0, rowCeiling) : rows;
|
|
80
|
+
const complete = total !== null && clipped.length >= total;
|
|
81
|
+
const stopReason = complete
|
|
82
|
+
? "complete"
|
|
83
|
+
: brokeOnEmpty
|
|
84
|
+
? "empty-page"
|
|
85
|
+
: clipped.length >= cap
|
|
86
|
+
? "cap"
|
|
87
|
+
: "short-read";
|
|
88
|
+
return {
|
|
89
|
+
rows: clipped,
|
|
90
|
+
total,
|
|
91
|
+
pagesConsumed,
|
|
92
|
+
// 预取的每一页都真实发过请求(即使断点后没消费)。
|
|
93
|
+
wireCalls: 1 + prefetchPages.length,
|
|
94
|
+
stopReason,
|
|
95
|
+
complete,
|
|
96
|
+
truncatedByCap: total !== null ? clipped.length < total : clipped.length >= cap,
|
|
97
|
+
...(prefetch !== undefined && prefetchPages.length > 1 ? { concurrency: prefetch.stats } : {}),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=runtime-paging.js.map
|