tyc-cli 0.1.1 → 0.2.1

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.
@@ -1,133 +0,0 @@
1
- // Transformer (TS 版本)
2
- // 对齐 tools/t1_1/transformer/transformer.go:
3
- // 1. 按 sources 声明顺序做顶层 map 覆盖合并
4
- // 2. 时间戳字段值格式化为 Asia/Shanghai 字符串(key 不变)
5
- // 3. 注入 _summary / _warnings / _empty
6
- const TIMESTAMP_FIELDS = new Set([
7
- "estiblishTime", "approvedTime", "fromTime", "toTime", "updateTimes",
8
- "cancelDate", "revokeDate",
9
- "changeTime", "createTime", "subscriptionTime", "paidinTime", "ftShareholding",
10
- "publishDate", "publishTime", "judgeTime", "submitTime", "submittime",
11
- "caseRegTime", "caseCreateTime", "filingDate", "endCaseDate",
12
- "decisionDate", "startDate",
13
- "appDate", "regDate", "rtm", "eventTime", "pubDate",
14
- "applicationTime", "regtime", "publishtime",
15
- "releaseTime", "grantDate", "applicationPublishTime",
16
- "freezeStartDate", "freezeEndDate", "expiryDate", "issueDate",
17
- "recordDate", "establishDate", "joinDate",
18
- "investTime", "time", "pubTime",
19
- "reportDate", "listingDate", "validFrom", "validTo",
20
- "occurDate", "checkDate", "startdate", "bidWinDate",
21
- "noticePeriodStart", "noticePeriodEnd", "evaluationDate",
22
- "occurTime", "finishDate", "firstPublishDate", "ratingTime",
23
- "examineDate",
24
- ]);
25
- const DATETIME_FIELDS = new Set([
26
- "updateTimes", "rtm", "pubTime", "eventTime", "startTime",
27
- ]);
28
- function pad(n) {
29
- return n < 10 ? "0" + n : String(n);
30
- }
31
- function formatMs(ms, dateTime) {
32
- if (!ms || ms <= 0)
33
- return "";
34
- // 转换到 Asia/Shanghai(UTC+8)
35
- const shanghai = new Date(ms + 8 * 3600 * 1000);
36
- const y = shanghai.getUTCFullYear();
37
- const mo = pad(shanghai.getUTCMonth() + 1);
38
- const d = pad(shanghai.getUTCDate());
39
- if (!dateTime)
40
- return `${y}-${mo}-${d}`;
41
- const h = pad(shanghai.getUTCHours());
42
- const mi = pad(shanghai.getUTCMinutes());
43
- const s = pad(shanghai.getUTCSeconds());
44
- return `${y}-${mo}-${d} ${h}:${mi}:${s}`;
45
- }
46
- function formatTimestampsInPlace(v) {
47
- if (v === null || v === undefined)
48
- return;
49
- if (Array.isArray(v)) {
50
- for (const item of v)
51
- formatTimestampsInPlace(item);
52
- return;
53
- }
54
- if (typeof v === "object") {
55
- const obj = v;
56
- for (const [k, val] of Object.entries(obj)) {
57
- if (TIMESTAMP_FIELDS.has(k) && typeof val === "number" && val > 0) {
58
- obj[k] = formatMs(val, DATETIME_FIELDS.has(k));
59
- continue;
60
- }
61
- if (TIMESTAMP_FIELDS.has(k) && typeof val === "string" && /^\d{10,13}$/.test(val)) {
62
- const n = Number(val);
63
- obj[k] = formatMs(n, DATETIME_FIELDS.has(k));
64
- continue;
65
- }
66
- formatTimestampsInPlace(val);
67
- }
68
- }
69
- }
70
- function summaryCount(count, label) {
71
- return `该查询实体共有${count}条${label}记录。`;
72
- }
73
- function summaryCountTruncated(total, returned, label) {
74
- return `该查询实体共有${total}条${label}记录。已为您展示前${returned}条。`;
75
- }
76
- function summaryEmpty(label) {
77
- return `已全量扫描该主体${label}数据库,未发现任何记录。`;
78
- }
79
- function summaryEmptyRisk(name, label) {
80
- return `经天眼查底层数据库全量核查实体 ${name},当前未发现任何【${label}】记录。此项核心合规风控排查安全,允许进入下一步审计。`;
81
- }
82
- export function applyTransformer(tool, results, warnings) {
83
- const out = {};
84
- // 1. 按 sources 顺序合并
85
- const singleSource = tool.sources.length <= 1;
86
- for (const src of tool.sources) {
87
- const r = results[src.scope];
88
- if (!r)
89
- continue;
90
- if (singleSource || src.scope === "root") {
91
- for (const [k, v] of Object.entries(r))
92
- out[k] = v;
93
- }
94
- else {
95
- for (const [k, v] of Object.entries(r))
96
- out[k] = v;
97
- out["_" + src.scope] = r;
98
- }
99
- }
100
- // 2. 时间戳格式化
101
- formatTimestampsInPlace(out);
102
- // 3. 元数据
103
- if (Object.keys(warnings).length > 0)
104
- out._warnings = warnings;
105
- const items = Array.isArray(out.items) ? out.items : null;
106
- if (items && items.length === 0)
107
- out._empty = true;
108
- if (tool.summary) {
109
- const name = typeof out.name === "string" ? out.name : "";
110
- const count = items ? items.length : 0;
111
- const label = tool.summary.label;
112
- switch (tool.summary.template) {
113
- case "count":
114
- out._summary = count > 0 ? summaryCount(count, label) : summaryEmpty(label);
115
- break;
116
- case "count_truncated": {
117
- let total = count;
118
- if (typeof out.total === "number" && out.total > 0)
119
- total = out.total;
120
- out._summary = count > 0 ? summaryCountTruncated(total, count, label) : summaryEmpty(label);
121
- break;
122
- }
123
- case "empty_risk":
124
- out._summary = count > 0 ? summaryCount(count, label) : summaryEmptyRisk(name, label);
125
- break;
126
- case "empty_generic":
127
- default:
128
- out._summary = count > 0 ? summaryCount(count, label) : summaryEmpty(label);
129
- break;
130
- }
131
- }
132
- return out;
133
- }