tyc-cli 0.3.8 → 0.3.10
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/CHANGELOG.md +11 -0
- package/README.md +7 -1
- package/dist/catalog.json +332 -170
- package/dist/commands/capabilities.js +1 -2
- package/dist/commands/category.js +2 -3
- package/dist/commands/init.js +1 -3
- package/dist/commands/login.js +85 -88
- package/dist/commands/output.js +6 -7
- package/dist/config.js +1 -2
- package/dist/coreClient.js +3 -2
- package/dist/index.js +10 -2
- package/dist/oauth.js +35 -25
- package/dist/registry.js +1 -1
- package/dist/utils/history.js +69 -0
- package/dist/utils/identifierDetails.js +40 -0
- package/dist/utils/jsonToMarkdown.js +141 -28
- package/dist/utils/losslessJson.js +114 -0
- package/dist/utils/personnelChanges.js +75 -0
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { identifierDetails } from "./identifierDetails.js";
|
|
2
|
+
import { stringifyLosslessJSON, LosslessNumber } from "./losslessJson.js";
|
|
1
3
|
/**
|
|
2
4
|
* JSON → Markdown 输出格式化
|
|
3
5
|
*
|
|
@@ -5,20 +7,13 @@
|
|
|
5
7
|
* - 顶层简单字段渲染为 key/value 表格
|
|
6
8
|
* - 项目元数据(_summary / _empty / _warnings)单独凸显
|
|
7
9
|
* - items 列表自动渲染为表格
|
|
8
|
-
* -
|
|
10
|
+
* - 嵌套对象/对象数组完整保留;显式截断由统一输出层负责
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
import { renderChangeRecords, splitChangeRecords } from "./personnelChanges.js";
|
|
13
|
+
import { renderHistoryGuide, splitHistoricalPersonnel } from "./history.js";
|
|
14
|
+
const META_KEYS = new Set(["_summary", "_empty", "_warnings", "_tip", "_truncated", "_pagination", "_riskOverview", "_dateSemantics", "_fieldSemantics", "_historyGuide", "_source"]);
|
|
11
15
|
function isPlainObject(v) {
|
|
12
|
-
return v !== null && typeof v === "object" && !Array.isArray(v);
|
|
13
|
-
}
|
|
14
|
-
function isEmptyValue(v) {
|
|
15
|
-
if (v === null || v === undefined || v === "")
|
|
16
|
-
return true;
|
|
17
|
-
if (Array.isArray(v) && v.length === 0)
|
|
18
|
-
return true;
|
|
19
|
-
if (isPlainObject(v) && Object.keys(v).length === 0)
|
|
20
|
-
return true;
|
|
21
|
-
return false;
|
|
16
|
+
return v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof LosslessNumber);
|
|
22
17
|
}
|
|
23
18
|
function formatPrimitive(v) {
|
|
24
19
|
if (v === null || v === undefined || v === "")
|
|
@@ -49,21 +44,16 @@ function formatArrayCell(arr) {
|
|
|
49
44
|
return arr.map(formatPrimitive).join(", ");
|
|
50
45
|
}
|
|
51
46
|
// 对象数组:紧凑 JSON
|
|
52
|
-
return
|
|
47
|
+
return stringifyLosslessJSON(arr);
|
|
53
48
|
}
|
|
54
49
|
function formatObjectInline(obj) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
else {
|
|
63
|
-
parts.push(`${k}=${formatPrimitive(v)}`);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return parts.join("; ") || "-";
|
|
50
|
+
return stringifyLosslessJSON(obj);
|
|
51
|
+
}
|
|
52
|
+
function renderJSONBlock(value) {
|
|
53
|
+
const text = stringifyLosslessJSON(value, null, 2);
|
|
54
|
+
const longestFence = Math.max(0, ...(text.match(/`+/g) || []).map((s) => s.length));
|
|
55
|
+
const fence = "`".repeat(Math.max(3, longestFence + 1));
|
|
56
|
+
return `${fence}json\n${text}\n${fence}\n`;
|
|
67
57
|
}
|
|
68
58
|
function renderItemsTable(items, title = "items") {
|
|
69
59
|
if (items.length === 0) {
|
|
@@ -75,6 +65,9 @@ function renderItemsTable(items, title = "items") {
|
|
|
75
65
|
items.forEach((v, i) => lines.push(`${i + 1}. ${formatPrimitive(v)}`));
|
|
76
66
|
return lines.join("\n") + "\n";
|
|
77
67
|
}
|
|
68
|
+
if (!items.every(isPlainObject)) {
|
|
69
|
+
return `\n### ${title}(${items.length} 条)\n\n${renderJSONBlock(items)}`;
|
|
70
|
+
}
|
|
78
71
|
// 对象数组 → Markdown 表格
|
|
79
72
|
const cols = getAllKeys(items);
|
|
80
73
|
if (cols.length === 0)
|
|
@@ -119,16 +112,71 @@ function renderTopFields(obj) {
|
|
|
119
112
|
return lines.join("\n") + "\n";
|
|
120
113
|
}
|
|
121
114
|
function renderMeta(obj) {
|
|
122
|
-
const lines =
|
|
115
|
+
const lines = renderHistoryGuide(obj._historyGuide);
|
|
116
|
+
const sourceNotes = (payload, prefix = "") => {
|
|
117
|
+
if (!isPlainObject(payload._source))
|
|
118
|
+
return;
|
|
119
|
+
const source = payload._source;
|
|
120
|
+
lines.push(`> ${prefix}数据来源:${escapeCell(formatPrimitive(source.api))};${escapeCell(formatPrimitive(source.meaning))}`);
|
|
121
|
+
lines.push(`> ${prefix}来源时间口径:${escapeCell(formatPrimitive(source.temporalNote))}`);
|
|
122
|
+
};
|
|
123
|
+
sourceNotes(obj);
|
|
124
|
+
if (isPlainObject(obj.sources)) {
|
|
125
|
+
for (const [scope, payload] of Object.entries(obj.sources)) {
|
|
126
|
+
if (isPlainObject(payload))
|
|
127
|
+
sourceNotes(payload, `${scope}:`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (isPlainObject(obj._fieldSemantics)) {
|
|
131
|
+
for (const key of Object.keys(obj._fieldSemantics).sort()) {
|
|
132
|
+
const note = obj._fieldSemantics[key];
|
|
133
|
+
if (typeof note === "string" && note)
|
|
134
|
+
lines.push(`> 字段口径:${escapeCell(note)}`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (isPlainObject(obj._dateSemantics)) {
|
|
138
|
+
for (const key of ["change_time", "ftShareholding", "changeTime", "createTime", "historicalTime", "firstAppointment"]) {
|
|
139
|
+
const note = obj._dateSemantics[key];
|
|
140
|
+
if (typeof note === "string" && note)
|
|
141
|
+
lines.push(`> 时间口径:${escapeCell(note)}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
123
144
|
if (obj._summary) {
|
|
124
145
|
lines.push(`> 📋 **摘要**:${formatPrimitive(obj._summary)}`);
|
|
125
146
|
}
|
|
126
147
|
if (obj._tip) {
|
|
127
148
|
lines.push(`> 💡 **提示**:${formatPrimitive(obj._tip)}`);
|
|
128
149
|
}
|
|
129
|
-
if (obj._empty === true) {
|
|
150
|
+
if (obj._empty === true && !isPlainObject(obj._riskOverview)) {
|
|
130
151
|
lines.push(`> ⚪ **空结果**:未发现该维度记录`);
|
|
131
152
|
}
|
|
153
|
+
if (isPlainObject(obj._pagination)) {
|
|
154
|
+
const p = obj._pagination;
|
|
155
|
+
const parts = [];
|
|
156
|
+
if (p.page !== undefined)
|
|
157
|
+
parts.push(`第${p.page}页`);
|
|
158
|
+
if (p.requested_page_size !== undefined)
|
|
159
|
+
parts.push(`请求每页${p.requested_page_size}条`);
|
|
160
|
+
if (p.effective_page_size !== undefined)
|
|
161
|
+
parts.push(`实际每页${p.effective_page_size}条`);
|
|
162
|
+
if (p.max_page_size !== undefined)
|
|
163
|
+
parts.push(`上游每页上限${p.max_page_size}条`);
|
|
164
|
+
parts.push(`本次返回${p.returned}条`);
|
|
165
|
+
parts.push(p.total === undefined ? "全量总数未知" : `共${p.total}条`);
|
|
166
|
+
if (p.has_more === true) {
|
|
167
|
+
parts.push(`还有下一页;沿用原命令和主体/筛选参数,传 --pageNum ${p.next_page} --pageSize ${p.effective_page_size}`);
|
|
168
|
+
}
|
|
169
|
+
else if (p.has_more === false) {
|
|
170
|
+
parts.push("已到末页");
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
parts.push("尚不能确定是否还有下一页");
|
|
174
|
+
}
|
|
175
|
+
lines.push(`> 分页:${parts.join(";")}。`);
|
|
176
|
+
}
|
|
177
|
+
else if (obj._truncated === true) {
|
|
178
|
+
lines.push("> 当前返回不是全量;请根据工具分页参数继续查询。");
|
|
179
|
+
}
|
|
132
180
|
if (obj._warnings && isPlainObject(obj._warnings) && Object.keys(obj._warnings).length > 0) {
|
|
133
181
|
lines.push(`> ⚠️ **警告**:`);
|
|
134
182
|
for (const [path, msg] of Object.entries(obj._warnings)) {
|
|
@@ -137,6 +185,55 @@ function renderMeta(obj) {
|
|
|
137
185
|
}
|
|
138
186
|
return lines.length > 0 ? lines.join("\n") + "\n" : "";
|
|
139
187
|
}
|
|
188
|
+
function renderRiskOverview(obj) {
|
|
189
|
+
const parts = [];
|
|
190
|
+
const meta = obj._riskOverview;
|
|
191
|
+
if (isPlainObject(meta)) {
|
|
192
|
+
// State and counts come from Shared Core; never derive them from local rows.
|
|
193
|
+
parts.push(`> 数据状态:${formatPrimitive(meta.dataStatus)};摘要及诊断行数:${formatPrimitive(meta.displayRowCount)};风险事件总数:未确认。`);
|
|
194
|
+
parts.push(`> 计数口径:${formatPrimitive(meta.countMeaning)}`);
|
|
195
|
+
if (meta.reportedTotal !== undefined) {
|
|
196
|
+
parts.push(`> 上游报告总数:${formatPrimitive(meta.reportedTotal)}(保留原始口径,未经事件去重核实)。`);
|
|
197
|
+
}
|
|
198
|
+
if (Array.isArray(meta.reportedCounts) && meta.reportedCounts.length > 0) {
|
|
199
|
+
parts.push(renderItemsTable(meta.reportedCounts, "上游计数来源"));
|
|
200
|
+
}
|
|
201
|
+
if (Array.isArray(meta.issues)) {
|
|
202
|
+
parts.push(...meta.issues.map((issue) => `> 数据说明:${escapeCell(formatPrimitive(issue))}`));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
const sections = [
|
|
206
|
+
["toolRisks", "可用专项工具获取详情"],
|
|
207
|
+
["detailRisks", "需通过风险 ID 获取详情"],
|
|
208
|
+
["relationRiskNotes", "周边风险提示"],
|
|
209
|
+
["warningRisks", "预警提醒"],
|
|
210
|
+
["unclassifiedRisks", "未分类风险及诊断信息"],
|
|
211
|
+
];
|
|
212
|
+
const sectionKeys = new Set(sections.map(([key]) => key));
|
|
213
|
+
const otherFields = Object.fromEntries(Object.entries(obj).filter(([key]) => !META_KEYS.has(key) && !sectionKeys.has(key) && key !== "name" && !(key === "total" && isPlainObject(meta))));
|
|
214
|
+
if (Object.keys(otherFields).length > 0)
|
|
215
|
+
parts.push(renderTopFields(otherFields));
|
|
216
|
+
for (const [key, title] of sections) {
|
|
217
|
+
const rows = obj[key];
|
|
218
|
+
if (!Array.isArray(rows) || rows.length === 0)
|
|
219
|
+
continue;
|
|
220
|
+
if (key === "detailRisks") {
|
|
221
|
+
parts.push("使用 get_risk_detail,将 riskId 作为 id 参数、同一行 type 作为 type 参数。");
|
|
222
|
+
}
|
|
223
|
+
parts.push(renderItemsTable(rows.map((row) => {
|
|
224
|
+
if (!isPlainObject(row) || !Array.isArray(row.examples))
|
|
225
|
+
return row;
|
|
226
|
+
const { examples, ...rest } = row;
|
|
227
|
+
return rest;
|
|
228
|
+
}), title));
|
|
229
|
+
for (const row of rows) {
|
|
230
|
+
if (isPlainObject(row) && Array.isArray(row.examples) && row.examples.length > 0) {
|
|
231
|
+
parts.push(renderItemsTable(row.examples, `${title} / ${formatPrimitive(row.riskType)}:关联主体与原始风险示例`));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return parts.join("\n\n");
|
|
236
|
+
}
|
|
140
237
|
function renderNestedObjects(obj) {
|
|
141
238
|
const lines = [];
|
|
142
239
|
for (const [k, v] of Object.entries(obj)) {
|
|
@@ -171,7 +268,7 @@ function renderNestedObjects(obj) {
|
|
|
171
268
|
* @param value 工具返回的 JSON(已 parse 为对象)
|
|
172
269
|
* @param toolName 工具名(可选,用作标题)
|
|
173
270
|
*/
|
|
174
|
-
|
|
271
|
+
function renderMarkdownValue(value, toolName) {
|
|
175
272
|
if (value === null || value === undefined) {
|
|
176
273
|
return "_(空)_\n";
|
|
177
274
|
}
|
|
@@ -181,6 +278,15 @@ export function jsonToMarkdown(value, toolName) {
|
|
|
181
278
|
return "```\n" + formatPrimitive(value) + "\n```\n";
|
|
182
279
|
}
|
|
183
280
|
const obj = value;
|
|
281
|
+
const historical = splitHistoricalPersonnel(obj, toolName);
|
|
282
|
+
if (historical)
|
|
283
|
+
return renderMarkdownValue(historical.rest, toolName) + "\n" + historical.markdown;
|
|
284
|
+
const changes = splitChangeRecords(obj, toolName);
|
|
285
|
+
if (changes) {
|
|
286
|
+
// The recursive call receives a copy without the extracted list. Keep raw
|
|
287
|
+
// code blocks verbatim: the generic newline compaction must not touch them.
|
|
288
|
+
return renderMarkdownValue(changes.rest, toolName) + "\n" + renderChangeRecords(changes.records, changes.title);
|
|
289
|
+
}
|
|
184
290
|
const parts = [];
|
|
185
291
|
// 标题
|
|
186
292
|
if (toolName) {
|
|
@@ -193,6 +299,10 @@ export function jsonToMarkdown(value, toolName) {
|
|
|
193
299
|
const meta = renderMeta(obj);
|
|
194
300
|
if (meta)
|
|
195
301
|
parts.push(meta);
|
|
302
|
+
if (toolName === "get_risk_overview" || isPlainObject(obj._riskOverview)) {
|
|
303
|
+
parts.push(renderRiskOverview(obj));
|
|
304
|
+
return parts.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
305
|
+
}
|
|
196
306
|
// 顶层字段
|
|
197
307
|
const topFields = renderTopFields(obj);
|
|
198
308
|
parts.push(topFields);
|
|
@@ -206,3 +316,6 @@ export function jsonToMarkdown(value, toolName) {
|
|
|
206
316
|
parts.push(nested);
|
|
207
317
|
return parts.join("\n").replace(/\n{3,}/g, "\n\n");
|
|
208
318
|
}
|
|
319
|
+
export function jsonToMarkdown(value, toolName) {
|
|
320
|
+
return renderMarkdownValue(value, toolName) + identifierDetails(value);
|
|
321
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** JSON numbers whose original token cannot survive native Number serialisation.
|
|
2
|
+
* Keep the token numeric in JSON; String(value) is exact in Markdown. Node 18+.
|
|
3
|
+
*/
|
|
4
|
+
export class LosslessNumber {
|
|
5
|
+
token;
|
|
6
|
+
constructor(token) {
|
|
7
|
+
this.token = token;
|
|
8
|
+
}
|
|
9
|
+
toString() { return this.token; }
|
|
10
|
+
}
|
|
11
|
+
export function parseLosslessJSON(text) {
|
|
12
|
+
let offset = 0;
|
|
13
|
+
const fail = () => { throw new SyntaxError(`Invalid JSON at ${offset}`); };
|
|
14
|
+
const whitespace = () => { while (/[\t\n\r ]/.test(text[offset] ?? "x"))
|
|
15
|
+
offset++; };
|
|
16
|
+
const string = () => {
|
|
17
|
+
const start = offset++;
|
|
18
|
+
while (offset < text.length) {
|
|
19
|
+
const ch = text[offset++];
|
|
20
|
+
if (ch === "\\")
|
|
21
|
+
offset++;
|
|
22
|
+
else if (ch === '"')
|
|
23
|
+
return JSON.parse(text.slice(start, offset));
|
|
24
|
+
}
|
|
25
|
+
return fail();
|
|
26
|
+
};
|
|
27
|
+
const value = () => {
|
|
28
|
+
whitespace();
|
|
29
|
+
const ch = text[offset];
|
|
30
|
+
if (ch === '"')
|
|
31
|
+
return string();
|
|
32
|
+
if (ch === "{" || ch === "[") {
|
|
33
|
+
const object = ch === "{";
|
|
34
|
+
offset++;
|
|
35
|
+
const result = object ? {} : [];
|
|
36
|
+
const end = object ? "}" : "]";
|
|
37
|
+
whitespace();
|
|
38
|
+
if (text[offset] === end) {
|
|
39
|
+
offset++;
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
while (offset < text.length) {
|
|
43
|
+
whitespace();
|
|
44
|
+
let key = "";
|
|
45
|
+
if (object) {
|
|
46
|
+
if (text[offset] !== '"')
|
|
47
|
+
fail();
|
|
48
|
+
key = string();
|
|
49
|
+
whitespace();
|
|
50
|
+
if (text[offset++] !== ":")
|
|
51
|
+
fail();
|
|
52
|
+
}
|
|
53
|
+
const item = value();
|
|
54
|
+
if (object)
|
|
55
|
+
Object.defineProperty(result, key, { value: item, enumerable: true, writable: true, configurable: true });
|
|
56
|
+
else
|
|
57
|
+
result.push(item);
|
|
58
|
+
whitespace();
|
|
59
|
+
if (text[offset] === end) {
|
|
60
|
+
offset++;
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
if (text[offset++] !== ",")
|
|
64
|
+
fail();
|
|
65
|
+
}
|
|
66
|
+
return fail();
|
|
67
|
+
}
|
|
68
|
+
for (const [token, item] of [["true", true], ["false", false], ["null", null]]) {
|
|
69
|
+
if (text.startsWith(token, offset)) {
|
|
70
|
+
offset += token.length;
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const match = /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?/.exec(text.slice(offset));
|
|
75
|
+
if (!match)
|
|
76
|
+
return fail();
|
|
77
|
+
const token = match[0];
|
|
78
|
+
offset += token.length;
|
|
79
|
+
const number = Number(token);
|
|
80
|
+
return JSON.stringify(number) === token && (Number.isSafeInteger(number) || !Number.isInteger(number))
|
|
81
|
+
? number : new LosslessNumber(token);
|
|
82
|
+
};
|
|
83
|
+
const result = value();
|
|
84
|
+
whitespace();
|
|
85
|
+
if (offset !== text.length)
|
|
86
|
+
fail();
|
|
87
|
+
return result;
|
|
88
|
+
}
|
|
89
|
+
export function stringifyLosslessJSON(value, _replacer = null, space = 0) {
|
|
90
|
+
const indent = " ".repeat(Math.min(10, Math.max(0, space)));
|
|
91
|
+
const ancestors = new Set();
|
|
92
|
+
const encode = (item, depth) => {
|
|
93
|
+
if (item instanceof LosslessNumber)
|
|
94
|
+
return item.token;
|
|
95
|
+
if (item === null || typeof item !== "object")
|
|
96
|
+
return JSON.stringify(item);
|
|
97
|
+
if (ancestors.has(item))
|
|
98
|
+
throw new TypeError("Circular JSON value");
|
|
99
|
+
ancestors.add(item);
|
|
100
|
+
const array = Array.isArray(item);
|
|
101
|
+
const entries = array ? item.map((v) => encode(v, depth + 1) ?? "null")
|
|
102
|
+
: Object.entries(item).flatMap(([key, v]) => {
|
|
103
|
+
const text = encode(v, depth + 1);
|
|
104
|
+
return text === undefined ? [] : [JSON.stringify(key) + (indent ? ": " : ":") + text];
|
|
105
|
+
});
|
|
106
|
+
ancestors.delete(item);
|
|
107
|
+
const [open, close] = array ? ["[", "]"] : ["{", "}"];
|
|
108
|
+
if (!entries.length)
|
|
109
|
+
return open + close;
|
|
110
|
+
return indent ? open + "\n" + entries.map((entry) => indent.repeat(depth + 1) + entry).join(",\n")
|
|
111
|
+
+ "\n" + indent.repeat(depth) + close : open + entries.join(",") + close;
|
|
112
|
+
};
|
|
113
|
+
return encode(value, 0);
|
|
114
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { stringifyLosslessJSON, LosslessNumber } from "./losslessJson.js";
|
|
2
|
+
// Presentation only: all personnel extraction and statuses come from Shared Core.
|
|
3
|
+
import { changeRecordsForDisplay } from "./history.js";
|
|
4
|
+
const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v) && !(v instanceof LosslessNumber);
|
|
5
|
+
const text = (v) => typeof v === "string" ? v : stringifyLosslessJSON(v) ?? "null";
|
|
6
|
+
const cell = (v) => (v === undefined || v === "" ? "-" : text(v)).replace(/\|/g, "\\|").replace(/\r?\n/g, " ");
|
|
7
|
+
function block(value) {
|
|
8
|
+
const raw = text(value);
|
|
9
|
+
const longest = Math.max(0, ...(raw.match(/`+/g) ?? []).map((s) => s.length));
|
|
10
|
+
const fence = "`".repeat(Math.max(3, longest + 1));
|
|
11
|
+
return `${fence}text\n${raw}\n${fence}\n`;
|
|
12
|
+
}
|
|
13
|
+
export function splitChangeRecords(obj, toolName) {
|
|
14
|
+
if (toolName === "get_change_records" && Array.isArray(obj.items)) {
|
|
15
|
+
const rest = { ...obj };
|
|
16
|
+
delete rest.items;
|
|
17
|
+
return { rest, records: obj.items, title: "变更记录" };
|
|
18
|
+
}
|
|
19
|
+
if (toolName === "get_historical_registration" && object(obj.sources) && object(obj.sources.cb) && Array.isArray(obj.sources.cb.changeList)) {
|
|
20
|
+
const cb = { ...obj.sources.cb };
|
|
21
|
+
delete cb.changeList;
|
|
22
|
+
return { rest: { ...obj, sources: { ...obj.sources, cb } }, records: obj.sources.cb.changeList, title: "工商信息 / 变更记录" };
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
function renderSide(title, side) {
|
|
27
|
+
if (!object(side))
|
|
28
|
+
return "";
|
|
29
|
+
const out = [`#### ${title}\n`, `解析状态:${cell(side.status)}\n`];
|
|
30
|
+
const people = Array.isArray(side.people) ? side.people : [];
|
|
31
|
+
if (people.length) {
|
|
32
|
+
out.push("| 姓名 | 职务原值 | 法定代表人标志原值 | 显式变更标记 | 其他登记字段 |", "|---|---|---|---|---|");
|
|
33
|
+
for (const person of people) {
|
|
34
|
+
if (!object(person)) {
|
|
35
|
+
out.push(block(person));
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const fields = Array.isArray(person.fields) ? person.fields : [];
|
|
39
|
+
const other = fields.filter((field) => !object(field) || !["姓名", "职务", "法定代表人标志"].includes(String(field.key)));
|
|
40
|
+
out.push(`| ${[person.name, person.position, person.legalRepresentativeFlag, person.marker, other].map(cell).join(" | ")} |`);
|
|
41
|
+
}
|
|
42
|
+
out.push("");
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(side.warnings))
|
|
45
|
+
for (const warning of side.warnings)
|
|
46
|
+
out.push(`> 解析说明:${cell(warning)}\n`);
|
|
47
|
+
if (Array.isArray(side.unparsedFragments))
|
|
48
|
+
for (const fragment of side.unparsedFragments)
|
|
49
|
+
out.push("未解析片段:\n", block(fragment));
|
|
50
|
+
return out.join("\n");
|
|
51
|
+
}
|
|
52
|
+
export function renderChangeRecords(records, title) {
|
|
53
|
+
const out = [`## ${title}(${records.length} 条)\n`, "> 本次返回记录按变更日期倒序展示;同日维持来源顺序,日期未知置后,不代表全量历程。\n"];
|
|
54
|
+
changeRecordsForDisplay(records).forEach((value, index) => {
|
|
55
|
+
if (!object(value)) {
|
|
56
|
+
out.push(block(value));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
out.push(`### 第 ${index + 1} 条 · ${cell(value.changeTime)} · ${cell(value.changeItem)}\n`);
|
|
60
|
+
const parsed = object(value._parsed) && value._parsed.version === 1 ? value._parsed : undefined;
|
|
61
|
+
for (const [key, v] of Object.entries(value)) {
|
|
62
|
+
if (["changeTime", "changeItem", "contentBefore", "contentAfter"].includes(key) || (key === "_parsed" && parsed))
|
|
63
|
+
continue;
|
|
64
|
+
out.push(`${key === "createTime" ? "记录创建日期" : key}:${cell(v)}\n`);
|
|
65
|
+
}
|
|
66
|
+
if (parsed) {
|
|
67
|
+
out.push(`> 解析版本:${cell(parsed.version)};原文完整性:${cell(parsed.sourceCompleteness)}(未确认)。解析结果不是完整任职快照,标志原值未转换。\n`);
|
|
68
|
+
out.push(renderSide("变更前人员", parsed.before), renderSide("变更后人员", parsed.after));
|
|
69
|
+
}
|
|
70
|
+
for (const [key, name] of [["contentBefore", "变更前原文"], ["contentAfter", "变更后原文"]]) {
|
|
71
|
+
out.push(`#### ${name}\n`, key in value ? block(value[key]) : "_(原字段未返回)_\n");
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return out.join("\n");
|
|
75
|
+
}
|