@tama-create/sf-tools 1.4.0-dev.2 → 1.4.0-dev.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.
- package/config/changeset-types.txt +350 -0
- package/config/install/gitmessage +6 -0
- package/config/install/release/README.md +26 -0
- package/config/install/release/deploy-target.txt +368 -0
- package/config/install/release/remove-target.txt +279 -0
- package/config/metadata-capability.txt +118 -0
- package/config/metadata-dirs.txt +79 -0
- package/config/metasync-detect.txt +52 -0
- package/config/metasync-extra.txt +30 -0
- package/config/metasync-fingerprint.txt +90 -0
- package/lib/apexlog.js +819 -0
- package/lib/metasync.js +1364 -0
- package/lib/package.json +4 -0
- package/lib/typecheck.js +547 -0
- package/package.json +8 -2
- package/templates/.forceignore +12 -0
- package/templates/.gitattributes +58 -0
- package/templates/.github/workflows/wf-metasync.yml +177 -0
- package/templates/.github/workflows/wf-release.yml +454 -0
- package/templates/.github/workflows/wf-sequence.yml +292 -0
- package/templates/.github/workflows/wf-validate.yml +389 -0
- package/templates/.prettierignore +11 -0
- package/templates/.prettierrc +17 -0
- package/templates/.vscode/extensions.json +9 -0
- package/templates/.vscode/launch.json +16 -0
- package/templates/.vscode/settings.json +39 -0
- package/templates/AGENTS.md +3 -0
- package/templates/CLAUDE.md +4 -0
- package/templates/README.md +11 -0
- package/templates/config/project-scratch-def.json +13 -0
- package/templates/eslint.config.js +55 -0
- package/templates/force-app/main/default/.gitkeep +0 -0
- package/templates/gitignore.template +61 -0
- package/templates/jest.config.js +6 -0
- package/templates/package.json +29 -0
- package/templates/scripts/apex/hello.apex +10 -0
- package/templates/scripts/soql/account.soql +6 -0
- package/templates/sf-tools/config/branches.txt +24 -0
- package/templates/sf-tools/config/metadata.txt +576 -0
- package/templates/sfdx-project.json +12 -0
package/lib/apexlog.js
ADDED
|
@@ -0,0 +1,819 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// ==============================================================================
|
|
3
|
+
// apexlog.js - デバッグログの一覧の検査・AI 向けの要約・日時の計算(bin/sf-log.sh から呼ぶ)
|
|
4
|
+
// ==============================================================================
|
|
5
|
+
// Node の標準ライブラリだけを使う(追加パッケージなし。sf CLI が npm 版のため、Node は前提)。
|
|
6
|
+
// 境界は、この 1 ファイルだけ。シェル側(bin/sf-log.sh)が、組織への問い合わせ・手元の状態・ファイルの保存・終了コードを受け持つ。
|
|
7
|
+
// 設計: doc/sf-log-design.md(6 章 要約・8.3 一覧・6.4 実装の言語)
|
|
8
|
+
//
|
|
9
|
+
// 【使い方】
|
|
10
|
+
// node lib/apexlog.js summarize --list F [--now ISO] [--note TEXT]... [--base DIR] [--local-offset MIN]
|
|
11
|
+
// # 要約(Markdown)を標準出力に書く(6 章)
|
|
12
|
+
// node lib/apexlog.js list --user ID # 標準入力の ApexLog の一覧(sf data query --json の応答)を検査し、表(TSV)にする(8.3)
|
|
13
|
+
// node lib/apexlog.js time now [--plus-sec N] # 今(UTC。YYYY-MM-DDTHH:MM:SSZ)。N 秒後も出せる
|
|
14
|
+
// node lib/apexlog.js time norm ISO # 日時を YYYY-MM-DDTHH:MM:SSZ(UTC)に直す(Salesforce の …000+0000 も読む)
|
|
15
|
+
// node lib/apexlog.js time cmp A B # A < B なら -1、同じなら 0、A > B なら 1
|
|
16
|
+
// node lib/apexlog.js time min A B # 早いほう(YYYY-MM-DDTHH:MM:SSZ)
|
|
17
|
+
// node lib/apexlog.js time add ISO --sec N # ISO の N 秒後(N は負でもよい)
|
|
18
|
+
// node lib/apexlog.js time local ISO [--local-offset MIN] # PC のタイムゾーンの「YYYYMMDD<TAB>HHMMSS」(保存するログの名前。9.1)
|
|
19
|
+
// node lib/apexlog.js tflist [--now ISO] # 標準入力の TraceFlag の検索の応答を検査し、表(TSV)にする(4.2・8.2)
|
|
20
|
+
//
|
|
21
|
+
// 【オプション】
|
|
22
|
+
// --list F : (summarize)要約に入れるログの一覧(TSV。1 行に 1 本。古い順)。列:
|
|
23
|
+
// 1 ファイルのパス(要約に、そのまま書く)・2 ログの ID・3 開始時刻(UTC。YYYY-MM-DDTHH:MM:SSZ)・
|
|
24
|
+
// 4 操作(Operation)・5 状態(Status)・6 長さ(バイト)・7 所要(ミリ秒)
|
|
25
|
+
// --now ISO : (summarize)作成時刻(UTC。テスト用。省略時は今)
|
|
26
|
+
// --note TEXT : (summarize)要約の先頭に書く注意(取得役の状態・入れなかったログ・取り込みの残りなど。何度でも)
|
|
27
|
+
// --base DIR : (summarize)一覧のパスが相対のとき、ファイルを読む基準のフォルダ(省略時は今のフォルダ)
|
|
28
|
+
// --local-offset MIN : (summarize)作成時刻・ログの開始時刻を表示する時差(分。-720〜840。例: 540 = 日本時間)。
|
|
29
|
+
// 省略時は PC のタイムゾーン。テスト用(どの OS でも同じ表示にするため。環境変数 TZ は、Windows の Node で効かないことがある)
|
|
30
|
+
// --user ID : (list)自分のユーザー ID(英数字 15 か 18 文字)
|
|
31
|
+
// --plus-sec N・--sec N : (time)秒数(整数)
|
|
32
|
+
//
|
|
33
|
+
// 【処理の流れ】(summarize)
|
|
34
|
+
// 1. 一覧の各行を検査する(列の数・ID・日時・数値の形)。形が違えば、終了コード 1(要約を作らない)
|
|
35
|
+
// 2. ログを 1 本ずつ読む。行の形(doc/sf-log-design.md 6.3):
|
|
36
|
+
// 1 行目 = API の版と詳しさ。`Execute Anonymous: ` の行は、匿名 Apex のコード(飛ばす)
|
|
37
|
+
// `<時刻> (<ナノ秒>)|<種類>[|<項目>…]` = イベント。時刻で始まらない行は、直前のイベントの続き(複数行のイベント)
|
|
38
|
+
// 最初のイベントより前の、上のどれでもない行 = 読み取れなかった行(推測で読まない)
|
|
39
|
+
// ファイルがない・読めない → そのログを「読めなかったログ」に入れて、続ける
|
|
40
|
+
// 3. 区分ごとに集める: エラー(保存を止めたもの。EXCEPTION_THROWN・FATAL_ERROR・FLOW_ELEMENT_ERROR・
|
|
41
|
+
// フローのカスタムエラー(要素の種類が FlowCustomError の FLOW_ELEMENT_BEGIN。文言はログに出ない)・
|
|
42
|
+
// 入力規則の停止(VALIDATION_FAIL・VALIDATION_ERROR。直前の VALIDATION_RULE の名前を添える))・
|
|
43
|
+
// デバッグ出力(USER_DEBUG)・流れ(CODE_UNIT_STARTED / FINISHED)・
|
|
44
|
+
// 制限(LIMIT_USAGE_FOR_NS の (default) の「Number of … : a out of b」)・件数(SOQL_EXECUTE_BEGIN・DML_BEGIN)・
|
|
45
|
+
// フロー(6.3。FLOW_CREATE_INTERVIEW_END・FLOW_START_INTERVIEW_BEGIN で、実行の ID とフローの名前を結ぶ。FLOW_ELEMENT_BEGIN で
|
|
46
|
+
// 実行した要素。FLOW_INTERVIEW_FINISHED で完了(カスタムエラーで止めた実行にも出る)。FLOW_ELEMENT_ERROR は実行の ID を持たないため、
|
|
47
|
+
// 同じ要素(種類と名前)を最後に始めた実行のフローに結ぶ。FLOW_START_INTERVIEW_END まで進み、完了もエラーもない実行は「画面待ち」
|
|
48
|
+
// (画面フローは、画面を出すたびに止まり、完了の行が出ない。2026-11-26 に実機で確認)。このログの中で名前に結べない実行の ID の要素
|
|
49
|
+
// (画面フローの続きの要求)は、4 で、全部のログの実行の ID と結び、「続き」と数える)・入力規則の評価(VALIDATION_RULE ごとの、VALIDATION_PASS / VALIDATION_FAIL の数)・
|
|
50
|
+
// 重複ルール(6.3。DUPLICATE_DETECTION_RULE_INVOCATION の DuplicateRuleName ごとに、その後の MATCH_INVOCATION_DETAILS(動作・
|
|
51
|
+
// 重複したレコードの ID)と MATCH_INVOCATION_SUMMARY(保存しようとした件数・重複ありの件数)を結ぶ。DML_BEGIN〜DML_END の中は
|
|
52
|
+
// 「保存の中」、外は「保存の後」(保存のあとの、記録のための検出)として分けて数える。2026-11-24 に実機で確認)・
|
|
53
|
+
// ログの中の経過(行の (<ナノ秒>) のいちばん大きい値。処理の始まりからの経過)
|
|
54
|
+
// 4. Markdown を組み立てる(エラーが先・正常な情報が後。6.1・6.2):
|
|
55
|
+
// 見出し(作成時刻・本数・エラーの数)→ 注意(--note・読めなかったログ・読み取れなかった行・切り詰め・タイムゾーン不明)→
|
|
56
|
+
// 1 エラー(保存を止めたもの。フローのエラー・カスタムエラー・入力規則の停止を含む。同じ種類と文言は 1 つにまとめ、件数を書く)→
|
|
57
|
+
// 2 ログの一覧(操作に、最初の CODE_UNIT と、ログの中のフロー・入力規則・重複ルールの名前を添える。所要は一覧の値のまま。
|
|
58
|
+
// ログの中の経過より 1 時間以上長ければ、ログの中の経過と ※ を添え、表の下に注意を書く)→ 3 System.debug(新しい順・最大 50 件)→
|
|
59
|
+
// 4 フロー・入力規則・重複ルール(フローごとの開始・完了・エラー(うちカスタムエラー)・画面待ち・続きの数と実行した要素
|
|
60
|
+
// (画面待ち・続きは、あるときだけ書き、一覧の下に説明の行を 1 つ書く)・
|
|
61
|
+
// 入力規則ごとの評価・通過・停止の数・重複ルールごとの、保存の中と保存の後の回数・重複ありの件数・見つかった重複・動作)→
|
|
62
|
+
// 5 制限の使用量(50% を超えたもの)→ 6 切り詰め・出なかった区分・読み取れなかった行
|
|
63
|
+
// 5. 各区分の件数に上限を付け、超えた分は件数だけを書く(全体の目安は 200 行)
|
|
64
|
+
//
|
|
65
|
+
// 【補足】
|
|
66
|
+
// - 行の時刻は、ログのユーザーのタイムゾーン(6.3)。表示するだけで、UTC に直さない。USER_INFO の行がない・読めないログは、
|
|
67
|
+
// 「タイムゾーン不明」と添える。ログの開始時刻は、一覧の開始時刻(UTC)を、PC のタイムゾーンで表示する
|
|
68
|
+
// - 本文への参照は `<ファイルのパス>:<行番号>`(行番号は 1 から)
|
|
69
|
+
// - 20MB(20,971,520 バイト)以上のログは、Salesforce が古い行から削っている(8.6)。「切り詰めあり」と書く
|
|
70
|
+
// - list は、応答の内容を、標準出力の表にだけ書く(ファイル・記録に残さない。他の人のログの見出しを含むため。10.3)。
|
|
71
|
+
// 表の列: ID・自分か(1 / 0)・開始時刻(UTC)・長さ・所要・操作・状態。応答の形が違えば、終了コード 1(推測で進めない)
|
|
72
|
+
// - tflist の表の列: ID・種類(LogType)・開始(UTC。空なら -)・期限(UTC)・状態(active / expired / future)・DebugLevel の名前(なければ -)。
|
|
73
|
+
// 状態は、開始が今より後 = future、期限が今以前 = expired、それ以外 = active(開始が空か今以前、かつ期限が今より後)
|
|
74
|
+
// ==============================================================================
|
|
75
|
+
|
|
76
|
+
const fs = require('fs');
|
|
77
|
+
const path = require('path');
|
|
78
|
+
|
|
79
|
+
// ------------------------------------------------------------------------------
|
|
80
|
+
// 共通
|
|
81
|
+
// ------------------------------------------------------------------------------
|
|
82
|
+
const ID_RE = /^[A-Za-z0-9]{15}(?:[A-Za-z0-9]{3})?$/;
|
|
83
|
+
const ISO_Z_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/;
|
|
84
|
+
const TRUNCATE_BYTES = 20 * 1024 * 1024;
|
|
85
|
+
|
|
86
|
+
function fail(msg) {
|
|
87
|
+
process.stderr.write(`apexlog.js: ${msg}\n`);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// 引数を読む。値を取るオプションは、繰り返してよい(--note)
|
|
92
|
+
function parseArgs(argv) {
|
|
93
|
+
const opts = { _: [], note: [] };
|
|
94
|
+
for (let i = 0; i < argv.length; i++) {
|
|
95
|
+
const a = argv[i];
|
|
96
|
+
if (a.startsWith('--')) {
|
|
97
|
+
const k = a.slice(2);
|
|
98
|
+
if (i + 1 >= argv.length) fail(`${a} の値がありません。`);
|
|
99
|
+
const v = argv[++i];
|
|
100
|
+
if (k === 'note') opts.note.push(v);
|
|
101
|
+
else opts[k] = v;
|
|
102
|
+
} else {
|
|
103
|
+
opts._.push(a);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return opts;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// 日時を読む(UTC のミリ秒)。YYYY-MM-DDTHH:MM:SS[.sss](Z|+HHMM|+HH:MM) だけを受け付ける。
|
|
110
|
+
// Salesforce は「…000+0000」(コロンなし)で返す。JavaScript の標準の形ではないため、Date.parse に頼らない
|
|
111
|
+
function parseTime(s) {
|
|
112
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,9}))?(Z|[+-]\d{2}:?\d{2})$/.exec(String(s));
|
|
113
|
+
if (!m) return null;
|
|
114
|
+
const [, y, mo, d, h, mi, se, , tz] = m;
|
|
115
|
+
let ms = Date.UTC(+y, +mo - 1, +d, +h, +mi, +se);
|
|
116
|
+
if (Number.isNaN(ms)) return null;
|
|
117
|
+
// 日付として正しいか(2 月 30 日などを弾く)
|
|
118
|
+
const chk = new Date(ms);
|
|
119
|
+
if (chk.getUTCFullYear() !== +y || chk.getUTCMonth() !== +mo - 1 || chk.getUTCDate() !== +d) return null;
|
|
120
|
+
if (tz !== 'Z') {
|
|
121
|
+
const t = tz.replace(':', '');
|
|
122
|
+
const sign = t[0] === '-' ? -1 : 1;
|
|
123
|
+
const off = (+t.slice(1, 3)) * 60 + (+t.slice(3, 5));
|
|
124
|
+
ms -= sign * off * 60 * 1000;
|
|
125
|
+
}
|
|
126
|
+
return ms;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// UTC のミリ秒 → YYYY-MM-DDTHH:MM:SSZ(ミリ秒は切り捨て)
|
|
130
|
+
function fmtZ(ms) {
|
|
131
|
+
return new Date(Math.floor(ms / 1000) * 1000).toISOString().replace(/\.\d{3}Z$/, 'Z');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 表示の時差(分)。null = PC のタイムゾーン。summarize の --local-offset で決める(テスト用)
|
|
135
|
+
let LOCAL_OFFSET_MIN = null;
|
|
136
|
+
|
|
137
|
+
// PC のタイムゾーン(--local-offset があれば、その時差)での表示(YYYY-MM-DD HH:MM:SS)
|
|
138
|
+
// テストで TZ を使わないのは、GitHub Actions の Windows で、Node が環境変数 TZ を効かせなかったため(2026-11-23。手元の WSL では効いた)
|
|
139
|
+
function fmtLocal(ms) {
|
|
140
|
+
const p = n => String(n).padStart(2, '0');
|
|
141
|
+
if (LOCAL_OFFSET_MIN !== null) {
|
|
142
|
+
const d = new Date(ms + LOCAL_OFFSET_MIN * 60 * 1000);
|
|
143
|
+
return `${d.getUTCFullYear()}-${p(d.getUTCMonth() + 1)}-${p(d.getUTCDate())} ${p(d.getUTCHours())}:${p(d.getUTCMinutes())}:${p(d.getUTCSeconds())}`;
|
|
144
|
+
}
|
|
145
|
+
const d = new Date(ms);
|
|
146
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function needInt(v, name) {
|
|
150
|
+
if (v === undefined || !/^-?\d+$/.test(String(v))) fail(`${name} は整数で指定してください: ${v}`);
|
|
151
|
+
return parseInt(v, 10);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 表の 1 つのマスに入れる文字(改行・タブ・| を除く)
|
|
155
|
+
function cell(s) {
|
|
156
|
+
return String(s == null ? '' : s).replace(/[\r\n\t]+/g, ' ').replace(/\|/g, '|').trim();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function sizeText(n) {
|
|
160
|
+
if (n >= 1024 * 1024) return `${(n / 1024 / 1024).toFixed(1)}MB`;
|
|
161
|
+
if (n >= 1024) return `${(n / 1024).toFixed(1)}KB`;
|
|
162
|
+
return `${n}B`;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// ------------------------------------------------------------------------------
|
|
166
|
+
// time
|
|
167
|
+
// ------------------------------------------------------------------------------
|
|
168
|
+
function cmdTime(opts) {
|
|
169
|
+
const [sub, a, b] = opts._.slice(1);
|
|
170
|
+
const need = (s) => { const t = parseTime(s); if (t === null) fail(`日時の形が正しくありません: ${s}`); return t; };
|
|
171
|
+
switch (sub) {
|
|
172
|
+
case 'now': {
|
|
173
|
+
const plus = opts['plus-sec'] === undefined ? 0 : needInt(opts['plus-sec'], '--plus-sec');
|
|
174
|
+
process.stdout.write(fmtZ(Date.now() + plus * 1000) + '\n');
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case 'norm':
|
|
178
|
+
process.stdout.write(fmtZ(need(a)) + '\n');
|
|
179
|
+
break;
|
|
180
|
+
case 'cmp': {
|
|
181
|
+
const x = need(a), y = need(b);
|
|
182
|
+
process.stdout.write((x < y ? '-1' : x > y ? '1' : '0') + '\n');
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
case 'min': {
|
|
186
|
+
const x = need(a), y = need(b);
|
|
187
|
+
process.stdout.write(fmtZ(Math.min(x, y)) + '\n');
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case 'add': {
|
|
191
|
+
const x = need(a);
|
|
192
|
+
const sec = needInt(opts.sec, '--sec');
|
|
193
|
+
process.stdout.write(fmtZ(x + sec * 1000) + '\n');
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
case 'local': {
|
|
197
|
+
// 保存するログのファイル名に使う、PC のタイムゾーン(--local-offset があれば、その時差)の日付と時刻(9.1)
|
|
198
|
+
setLocalOffset(opts);
|
|
199
|
+
const s = fmtLocal(need(a)); // YYYY-MM-DD HH:MM:SS
|
|
200
|
+
process.stdout.write(`${s.slice(0, 10).replace(/-/g, '')}\t${s.slice(11).replace(/:/g, '')}\n`);
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
default:
|
|
204
|
+
fail(`time のサブコマンドが正しくありません: ${sub || '(なし)'}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// --local-offset を読む(summarize・time local)
|
|
209
|
+
function setLocalOffset(opts) {
|
|
210
|
+
if (opts['local-offset'] === undefined) return;
|
|
211
|
+
const off = needInt(opts['local-offset'], '--local-offset');
|
|
212
|
+
if (off < -720 || off > 840) fail(`--local-offset は -720〜840(分)で指定してください: ${off}`);
|
|
213
|
+
LOCAL_OFFSET_MIN = off;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// 標準入力の sf の --json の応答を読み、result.records を返す。形が違えば終了コード 1
|
|
217
|
+
// 応答の中身(他の人のログの見出しなど)は、エラーの文言に入れない
|
|
218
|
+
function readSfRecords() {
|
|
219
|
+
let s = '';
|
|
220
|
+
try { s = fs.readFileSync(0, 'utf8'); } catch (e) { fail('標準入力を読めません。'); }
|
|
221
|
+
let o;
|
|
222
|
+
try { o = JSON.parse(s); }
|
|
223
|
+
catch (e) {
|
|
224
|
+
// sf の更新のお知らせなどが前に付いたときのため、最初の { から最後の } までを読む(lib/common.sh の json_get と同じ)
|
|
225
|
+
try { o = JSON.parse(s.slice(s.indexOf('{'), s.lastIndexOf('}') + 1)); }
|
|
226
|
+
catch (e2) { fail('応答が JSON ではありません。'); }
|
|
227
|
+
}
|
|
228
|
+
if (!o || o.status !== 0 || !o.result) fail('応答の status が 0 ではありません。');
|
|
229
|
+
const recs = o.result.records;
|
|
230
|
+
if (!Array.isArray(recs)) fail('応答の result.records が配列ではありません。');
|
|
231
|
+
return recs;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// ------------------------------------------------------------------------------
|
|
235
|
+
// tflist(4.2・8.2): 標準入力の TraceFlag の検索の応答を検査し、TSV にする
|
|
236
|
+
// 列: ID・種類(LogType)・開始(UTC。空なら -)・期限(UTC)・状態(active / expired / future)・DebugLevel の名前(なければ -)
|
|
237
|
+
// 状態: future = 開始が今より後/expired = 期限が今以前/active = それ以外(開始が空か今以前、かつ期限が今より後)
|
|
238
|
+
// ------------------------------------------------------------------------------
|
|
239
|
+
function cmdTflist(opts) {
|
|
240
|
+
const now = opts.now === undefined ? Date.now() : parseTime(opts.now);
|
|
241
|
+
if (now === null) fail(`--now の形が正しくありません: ${opts.now}`);
|
|
242
|
+
const recs = readSfRecords();
|
|
243
|
+
const out = [];
|
|
244
|
+
recs.forEach((r, i) => {
|
|
245
|
+
if (!r || typeof r !== 'object') fail(`${i + 1} 件目の形が正しくありません。`);
|
|
246
|
+
if (typeof r.Id !== 'string' || !ID_RE.test(r.Id)) fail(`${i + 1} 件目の Id の形が正しくありません。`);
|
|
247
|
+
if (typeof r.LogType !== 'string' || !/^[A-Z_]+$/.test(r.LogType)) fail(`${i + 1} 件目の LogType の形が正しくありません。`);
|
|
248
|
+
const exp = parseTime(r.ExpirationDate);
|
|
249
|
+
if (exp === null) fail(`${i + 1} 件目の ExpirationDate の形が正しくありません。`);
|
|
250
|
+
let start = null;
|
|
251
|
+
if (r.StartDate !== null && r.StartDate !== undefined) {
|
|
252
|
+
start = parseTime(r.StartDate);
|
|
253
|
+
if (start === null) fail(`${i + 1} 件目の StartDate の形が正しくありません。`);
|
|
254
|
+
}
|
|
255
|
+
const state = start !== null && start > now ? 'future' : (exp <= now ? 'expired' : 'active');
|
|
256
|
+
const dl = r.DebugLevel && typeof r.DebugLevel.DeveloperName === 'string' ? cell(r.DebugLevel.DeveloperName) : '-';
|
|
257
|
+
out.push([r.Id, r.LogType, start === null ? '-' : fmtZ(start), fmtZ(exp), state, dl || '-'].join('\t'));
|
|
258
|
+
});
|
|
259
|
+
process.stdout.write(out.length ? out.join('\n') + '\n' : '');
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ------------------------------------------------------------------------------
|
|
263
|
+
// list(8.3): 標準入力の sf data query --json の応答を検査し、TSV にする
|
|
264
|
+
// ------------------------------------------------------------------------------
|
|
265
|
+
function cmdList(opts) {
|
|
266
|
+
const user = opts.user;
|
|
267
|
+
if (!user || !ID_RE.test(user)) fail('--user に、ユーザー ID(英数字 15 か 18 文字)を指定してください。');
|
|
268
|
+
const recs = readSfRecords();
|
|
269
|
+
const me = user.slice(0, 15);
|
|
270
|
+
const out = [];
|
|
271
|
+
recs.forEach((r, i) => {
|
|
272
|
+
if (!r || typeof r !== 'object') fail(`${i + 1} 件目の形が正しくありません。`);
|
|
273
|
+
if (typeof r.Id !== 'string' || !ID_RE.test(r.Id)) fail(`${i + 1} 件目の Id の形が正しくありません。`);
|
|
274
|
+
if (typeof r.LogUserId !== 'string' || !ID_RE.test(r.LogUserId)) fail(`${i + 1} 件目の LogUserId の形が正しくありません。`);
|
|
275
|
+
const t = parseTime(r.StartTime);
|
|
276
|
+
if (t === null) fail(`${i + 1} 件目の StartTime の形が正しくありません。`);
|
|
277
|
+
const len = Number.isInteger(r.LogLength) && r.LogLength >= 0 ? r.LogLength : null;
|
|
278
|
+
if (len === null) fail(`${i + 1} 件目の LogLength の形が正しくありません。`);
|
|
279
|
+
const dur = Number.isInteger(r.DurationMilliseconds) && r.DurationMilliseconds >= 0 ? r.DurationMilliseconds : 0;
|
|
280
|
+
const mine = r.LogUserId.slice(0, 15) === me ? '1' : '0';
|
|
281
|
+
out.push([r.Id, mine, fmtZ(t), len, dur, cell(r.Operation), cell(r.Status)].join('\t'));
|
|
282
|
+
});
|
|
283
|
+
process.stdout.write(out.length ? out.join('\n') + '\n' : '');
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ------------------------------------------------------------------------------
|
|
287
|
+
// summarize(6 章)
|
|
288
|
+
// ------------------------------------------------------------------------------
|
|
289
|
+
const EVENT_RE = /^(\d{1,2}:\d{2}:\d{2}\.\d+) \((\d+)\)\|([A-Z][A-Z0-9_]*)(?:\|(.*))?$/;
|
|
290
|
+
const ERROR_TYPES = new Set(['EXCEPTION_THROWN', 'FATAL_ERROR', 'FLOW_ELEMENT_ERROR']);
|
|
291
|
+
// 入力規則で保存を止めた行(1 のエラーに入れる。保存を止めたものは、すべて 1 に集める。6.2)
|
|
292
|
+
const VALIDATION_TYPES = new Set(['VALIDATION_FAIL', 'VALIDATION_ERROR']);
|
|
293
|
+
// フローのカスタムエラーの要素の種類。実行すると、保存を止めて、もとの変更を巻き戻す(公式の Custom Error Element)。
|
|
294
|
+
// ログには FLOW_ELEMENT_BEGIN|<実行の ID>|FlowCustomError|<要素の名前> しか出ず、文言は出ない(2026-11-25 に実機で確認。6.3)
|
|
295
|
+
const CUSTOM_ERROR_TYPE = 'FlowCustomError';
|
|
296
|
+
// 区分の有無(6 の「該当する行なし」)は、ログの行の種類ごとの数(res.counts)で見る。
|
|
297
|
+
// CUSTOM_ERROR_TYPE は行の種類ではないが、カスタムエラーの要素を実行した数を、この名前で数える(1 に出たのに、6 で「エラーの行なし」と書かないため)
|
|
298
|
+
const CATEGORIES = [
|
|
299
|
+
['エラー', ['EXCEPTION_THROWN', 'FATAL_ERROR', 'FLOW_ELEMENT_ERROR', 'VALIDATION_FAIL', 'VALIDATION_ERROR', CUSTOM_ERROR_TYPE]],
|
|
300
|
+
['入力規則', ['VALIDATION_FAIL', 'VALIDATION_RULE', 'VALIDATION_ERROR']],
|
|
301
|
+
['フロー', ['FLOW_START_INTERVIEW_BEGIN', 'FLOW_ELEMENT_BEGIN', 'FLOW_ELEMENT_ERROR']],
|
|
302
|
+
['重複ルール', ['DUPLICATE_DETECTION_RULE_INVOCATION']],
|
|
303
|
+
['デバッグ出力', ['USER_DEBUG']],
|
|
304
|
+
['流れ', ['CODE_UNIT_STARTED', 'CODE_UNIT_FINISHED']],
|
|
305
|
+
['制限', ['LIMIT_USAGE_FOR_NS', 'CUMULATIVE_LIMIT_USAGE']],
|
|
306
|
+
['件数', ['SOQL_EXECUTE_BEGIN', 'DML_BEGIN']],
|
|
307
|
+
];
|
|
308
|
+
// 所要の印(2 の一覧の ※)を付ける差(ミリ秒。1 時間)
|
|
309
|
+
const DUR_ODD_MS = 60 * 60 * 1000;
|
|
310
|
+
const MAX = { errors: 30, debug: 50, limits: 20, unreadable: 10, logs: 100, flows: 20, rules: 20, elements: 10, names: 3, dups: 20, dupIds: 5 };
|
|
311
|
+
// フローの要素の種類(FlowRecordUpdate・FlowDecision など。6.3)。FLOW_ELEMENT_ERROR の項目の並びを見分ける
|
|
312
|
+
const FLOW_ELEMENT_TYPE_RE = /^Flow[A-Z][A-Za-z]*$/;
|
|
313
|
+
|
|
314
|
+
// フローのエラーの文言にある HTML のリンク(<a href=…>…</a>)を、中の文字だけにする(実機の文言に混じる。6.3)。
|
|
315
|
+
// ほかの < > は残す(System.debug の List<String> などを壊さないため、対象はこのリンクだけ)
|
|
316
|
+
function stripLinks(s) {
|
|
317
|
+
return s.replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gi, '$1');
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// 重複ルールの動作(ActionTaken)を言い換える。実機で見た形は「Allow_[Alert,Report]」(2026-11-24)。
|
|
321
|
+
// 知らない語は、そのまま残す(推測で言い換えない)
|
|
322
|
+
const DUP_WORDS = { Allow: '許可', Alert: '警告', Report: '記録' };
|
|
323
|
+
function dupAction(a) {
|
|
324
|
+
const m = /^([A-Za-z]+)(?:_\[([A-Za-z,]*)\])?$/.exec(a || '');
|
|
325
|
+
if (!m || !DUP_WORDS[m[1]]) return a || '';
|
|
326
|
+
const flags = (m[2] || '').split(',').filter(Boolean);
|
|
327
|
+
if (flags.some(f => !DUP_WORDS[f])) return a;
|
|
328
|
+
return DUP_WORDS[m[1]] + (flags.length ? `(${flags.map(f => DUP_WORDS[f]).join('・')})` : '');
|
|
329
|
+
}
|
|
330
|
+
// 「キー:値」の項目を読む(DuplicateRuleName:… など)
|
|
331
|
+
function kvFields(fields) {
|
|
332
|
+
const o = {};
|
|
333
|
+
fields.forEach(f => { const i = f.indexOf(':'); if (i > 0) o[f.slice(0, i)] = f.slice(i + 1); });
|
|
334
|
+
return o;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// 一覧(TSV)を読む
|
|
338
|
+
function readList(file) {
|
|
339
|
+
let text;
|
|
340
|
+
try { text = fs.readFileSync(file, 'utf8'); } catch (e) { fail(`一覧を読めません: ${file}`); }
|
|
341
|
+
const rows = [];
|
|
342
|
+
text.split(/\r?\n/).forEach((line, i) => {
|
|
343
|
+
if (line === '') return;
|
|
344
|
+
const c = line.split('\t');
|
|
345
|
+
const where = `一覧の ${i + 1} 行目`;
|
|
346
|
+
if (c.length !== 7) fail(`${where}: 列の数が 7 ではありません。`);
|
|
347
|
+
const [p, id, st, op, status, len, dur] = c;
|
|
348
|
+
if (p === '') fail(`${where}: ファイルのパスが空です。`);
|
|
349
|
+
if (!ID_RE.test(id)) fail(`${where}: ID の形が正しくありません。`);
|
|
350
|
+
if (!ISO_Z_RE.test(st) || parseTime(st) === null) fail(`${where}: 開始時刻の形が正しくありません。`);
|
|
351
|
+
if (!/^\d+$/.test(len)) fail(`${where}: 長さが整数ではありません。`);
|
|
352
|
+
if (!/^\d+$/.test(dur)) fail(`${where}: 所要が整数ではありません。`);
|
|
353
|
+
rows.push({ path: p, id, start: parseTime(st), op, status, len: parseInt(len, 10), dur: parseInt(dur, 10) });
|
|
354
|
+
});
|
|
355
|
+
return rows;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// 1 本のログを読む
|
|
359
|
+
function parseLog(text) {
|
|
360
|
+
const lines = text.split(/\r?\n/);
|
|
361
|
+
if (lines.length && lines[lines.length - 1] === '') lines.pop();
|
|
362
|
+
const events = [];
|
|
363
|
+
const unreadable = [];
|
|
364
|
+
let tzKnown = false;
|
|
365
|
+
let cur = null;
|
|
366
|
+
lines.forEach((line, idx) => {
|
|
367
|
+
const no = idx + 1;
|
|
368
|
+
if (no === 1 && /^\d+\.\d+ /.test(line)) return; // API の版と詳しさ
|
|
369
|
+
if (line.startsWith('Execute Anonymous: ')) return; // 匿名 Apex のコード
|
|
370
|
+
const m = EVENT_RE.exec(line);
|
|
371
|
+
if (m) {
|
|
372
|
+
cur = { line: no, time: m[1], ns: Number(m[2]), type: m[3], fields: m[4] === undefined ? [] : m[4].split('|'), more: [] };
|
|
373
|
+
events.push(cur);
|
|
374
|
+
if (cur.type === 'USER_INFO' && cur.fields.some(f => /\([A-Za-z_]+\/[A-Za-z_]+\)/.test(f) || /^GMT[+-]\d{2}:\d{2}$/.test(f))) tzKnown = true;
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
if (cur) { cur.more.push(line); return; } // 直前のイベントの続き
|
|
378
|
+
if (line.trim() !== '') unreadable.push(no); // 最初のイベントより前の、知らない形の行
|
|
379
|
+
});
|
|
380
|
+
return { events, unreadable, tzKnown };
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
// 行の中の位置([42] など)
|
|
384
|
+
function lineRef(f) {
|
|
385
|
+
const m = /^\[(\d+)\]$/.exec(f || '');
|
|
386
|
+
return m ? `行 ${m[1]}` : '';
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function analyze(row, base) {
|
|
390
|
+
const file = path.isAbsolute(row.path) ? row.path : path.join(base, row.path);
|
|
391
|
+
let text;
|
|
392
|
+
try { text = fs.readFileSync(file, 'utf8'); }
|
|
393
|
+
catch (e) { return { row, missing: true }; }
|
|
394
|
+
const { events, unreadable, tzKnown } = parseLog(text);
|
|
395
|
+
const res = {
|
|
396
|
+
row, missing: false, unreadable, tzKnown, errors: [], debug: [], limits: [],
|
|
397
|
+
soql: null, dml: null, firstUnit: '', counts: {},
|
|
398
|
+
// ログの中の経過(ミリ秒): 行の (<ナノ秒>) は、処理の始まりからの経過。いちばん大きい値を使う(行がなければ null)。
|
|
399
|
+
// 一覧の所要(Salesforce の DurationMilliseconds)が、これより極端に長いときに印を付けるため(2 の一覧)
|
|
400
|
+
// (Math.max(...) は、行の多いログで引数の数の上限を超えるため、reduce で求める)
|
|
401
|
+
elapsed: events.length ? Math.floor(events.reduce((a, e) => (e.ns > a ? e.ns : a), 0) / 1e6) : null,
|
|
402
|
+
flows: new Map(), // フローの名前 → { ref(最初の開始), started, finished, errors(うち customErrors), elements: Map(「名前(種類)」→ 1) }
|
|
403
|
+
rules: new Map(), // 入力規則の名前 → { ref(最初の評価), evaluated, passed, failed }
|
|
404
|
+
dups: new Map(), // 重複ルールの名前 → { ref, objects, dml, actions(Set), ids(Set), inSave / after: { runs, toSave, withDup } }
|
|
405
|
+
};
|
|
406
|
+
const stack = [];
|
|
407
|
+
let lastRule = '';
|
|
408
|
+
let lastDup = ''; // 直前の DUPLICATE_DETECTION_RULE_INVOCATION のルール(DUPLICATE_DETECTION_END で空に戻す)
|
|
409
|
+
let inDml = 0; // DML_BEGIN〜DML_END の中か(重複ルールの「保存の中」と「保存の後」を分ける)
|
|
410
|
+
const dupOf = (name, ref) => {
|
|
411
|
+
if (!res.dups.has(name)) res.dups.set(name, { ref, objects: new Set(), dml: new Set(), actions: new Set(), ids: new Set(),
|
|
412
|
+
inSave: { runs: 0, toSave: 0, withDup: 0 }, after: { runs: 0, toSave: 0, withDup: 0 } });
|
|
413
|
+
return res.dups.get(name);
|
|
414
|
+
};
|
|
415
|
+
const interviews = new Map(); // 実行の ID → フローの名前(4 で、全部のログをまたいで結ぶため、res にも残す)
|
|
416
|
+
res.interviews = interviews;
|
|
417
|
+
// 実行の ID が、このログの中でフローの名前に結べない要素(画面フローの続き。前の画面の要求のログで開始した実行)。
|
|
418
|
+
// 4 で、ほかのログの実行の ID と結ぶ(2026-11-26 に実機で確認: 返却の画面フローの「次へ」の要求に、開始の行がなかった)
|
|
419
|
+
res.orphanElements = []; // { iid, key(「名前(種類)」), ref(その行)}
|
|
420
|
+
const ivState = new Map(); // 実行の ID → { started, ended(START_INTERVIEW_END), finished, errored }(画面待ちを数えるため)
|
|
421
|
+
const ivOf = (iid) => {
|
|
422
|
+
if (!ivState.has(iid)) ivState.set(iid, { started: false, ended: false, finished: false, errored: false });
|
|
423
|
+
return ivState.get(iid);
|
|
424
|
+
};
|
|
425
|
+
const lastElement = new Map(); // 「種類|名前」→ その要素を最後に始めた実行の ID(FLOW_ELEMENT_ERROR を結ぶため)
|
|
426
|
+
const flowOf = (name, ref) => {
|
|
427
|
+
if (!res.flows.has(name)) res.flows.set(name, { ref, started: 0, finished: 0, errors: 0, customErrors: 0, paused: 0, elements: new Map() });
|
|
428
|
+
return res.flows.get(name);
|
|
429
|
+
};
|
|
430
|
+
events.forEach(ev => {
|
|
431
|
+
res.counts[ev.type] = (res.counts[ev.type] || 0) + 1;
|
|
432
|
+
const ref = `${row.path}:${ev.line}`;
|
|
433
|
+
switch (ev.type) {
|
|
434
|
+
case 'CODE_UNIT_STARTED': {
|
|
435
|
+
const name = ev.fields[ev.fields.length - 1] || '';
|
|
436
|
+
if (!res.firstUnit) res.firstUnit = name;
|
|
437
|
+
stack.push(name);
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
case 'CODE_UNIT_FINISHED':
|
|
441
|
+
stack.pop();
|
|
442
|
+
break;
|
|
443
|
+
case 'USER_DEBUG': {
|
|
444
|
+
const msg = ev.fields.slice(2).join('|');
|
|
445
|
+
res.debug.push({ ref, time: ev.time, where: lineRef(ev.fields[0]), level: ev.fields[1] || '', msg, more: ev.more.length });
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
case 'VALIDATION_RULE':
|
|
449
|
+
lastRule = ev.fields[ev.fields.length - 1] || '';
|
|
450
|
+
if (lastRule) {
|
|
451
|
+
if (!res.rules.has(lastRule)) res.rules.set(lastRule, { ref, evaluated: 0, passed: 0, failed: 0 });
|
|
452
|
+
res.rules.get(lastRule).evaluated++;
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
case 'DML_BEGIN':
|
|
456
|
+
inDml++;
|
|
457
|
+
break;
|
|
458
|
+
case 'DML_END':
|
|
459
|
+
if (inDml > 0) inDml--;
|
|
460
|
+
break;
|
|
461
|
+
// 重複ルール(項目は「キー:値」。6.3)
|
|
462
|
+
case 'DUPLICATE_DETECTION_RULE_INVOCATION': {
|
|
463
|
+
const kv = kvFields(ev.fields);
|
|
464
|
+
lastDup = kv.DuplicateRuleName || '';
|
|
465
|
+
if (!lastDup) break;
|
|
466
|
+
const d = dupOf(lastDup, ref);
|
|
467
|
+
(inDml > 0 ? d.inSave : d.after).runs++;
|
|
468
|
+
if (kv.DmlType) d.dml.add(kv.DmlType);
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
case 'DUPLICATE_DETECTION_MATCH_INVOCATION_DETAILS': {
|
|
472
|
+
if (!lastDup || !res.dups.has(lastDup)) break;
|
|
473
|
+
const kv = kvFields(ev.fields), d = res.dups.get(lastDup);
|
|
474
|
+
if (kv.EntityType) d.objects.add(kv.EntityType);
|
|
475
|
+
if (kv.ActionTaken) d.actions.add(kv.ActionTaken);
|
|
476
|
+
(kv.DuplicateRecordIds || '').split(',').map(x => x.trim()).filter(Boolean).forEach(x => d.ids.add(x));
|
|
477
|
+
break;
|
|
478
|
+
}
|
|
479
|
+
case 'DUPLICATE_DETECTION_MATCH_INVOCATION_SUMMARY': {
|
|
480
|
+
if (!lastDup || !res.dups.has(lastDup)) break;
|
|
481
|
+
const kv = kvFields(ev.fields), d = res.dups.get(lastDup), ph = inDml > 0 ? d.inSave : d.after;
|
|
482
|
+
if (kv.EntityType) d.objects.add(kv.EntityType);
|
|
483
|
+
ph.toSave += Number(kv.NumRecordsToBeSaved) || 0;
|
|
484
|
+
ph.withDup += Number(kv.NumRecordsToBeSavedWithDuplicates) || 0;
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
case 'DUPLICATE_DETECTION_END':
|
|
488
|
+
lastDup = '';
|
|
489
|
+
break;
|
|
490
|
+
case 'VALIDATION_PASS':
|
|
491
|
+
if (lastRule && res.rules.has(lastRule)) res.rules.get(lastRule).passed++;
|
|
492
|
+
break;
|
|
493
|
+
case 'VALIDATION_FAIL':
|
|
494
|
+
if (lastRule && res.rules.has(lastRule)) res.rules.get(lastRule).failed++;
|
|
495
|
+
break;
|
|
496
|
+
// フロー(項目: CREATE_INTERVIEW_END・START_INTERVIEW_BEGIN・INTERVIEW_FINISHED = 実行の ID|フローの名前。
|
|
497
|
+
// ELEMENT_BEGIN = 実行の ID|要素の種類|要素の名前。2026-11-24 に実機で確認。6.3)
|
|
498
|
+
case 'FLOW_CREATE_INTERVIEW_END':
|
|
499
|
+
case 'FLOW_START_INTERVIEW_BEGIN':
|
|
500
|
+
case 'FLOW_START_INTERVIEW_END':
|
|
501
|
+
case 'FLOW_INTERVIEW_FINISHED': {
|
|
502
|
+
const [iid, name] = ev.fields;
|
|
503
|
+
if (!iid || !name) break;
|
|
504
|
+
interviews.set(iid, name);
|
|
505
|
+
if (ev.type === 'FLOW_START_INTERVIEW_BEGIN') { flowOf(name, ref).started++; ivOf(iid).started = true; }
|
|
506
|
+
if (ev.type === 'FLOW_START_INTERVIEW_END') ivOf(iid).ended = true;
|
|
507
|
+
if (ev.type === 'FLOW_INTERVIEW_FINISHED') { flowOf(name, ref).finished++; ivOf(iid).finished = true; }
|
|
508
|
+
break;
|
|
509
|
+
}
|
|
510
|
+
case 'FLOW_ELEMENT_BEGIN': {
|
|
511
|
+
const [iid, etype, ename] = ev.fields;
|
|
512
|
+
if (!iid || !etype || !ename) break;
|
|
513
|
+
lastElement.set(`${etype}|${ename}`, iid);
|
|
514
|
+
const name = interviews.get(iid);
|
|
515
|
+
if (name) flowOf(name, ref).elements.set(`${ename}(${etype})`, 1);
|
|
516
|
+
else res.orphanElements.push({ iid, key: `${ename}(${etype})`, ref });
|
|
517
|
+
if (etype === CUSTOM_ERROR_TYPE) ivOf(iid).errored = true;
|
|
518
|
+
// カスタムエラーの要素を実行した = 保存を止めた(文言はログに出ない)。1 のエラーに入れ、フローのエラーに数える。
|
|
519
|
+
// このあとも FLOW_INTERVIEW_FINISHED は出る(完了の数に入る)ため、4 では「うちカスタムエラー」と添える
|
|
520
|
+
if (etype === CUSTOM_ERROR_TYPE) {
|
|
521
|
+
res.counts[CUSTOM_ERROR_TYPE] = (res.counts[CUSTOM_ERROR_TYPE] || 0) + 1;
|
|
522
|
+
if (name) { flowOf(name, ref).errors++; flowOf(name, ref).customErrors++; }
|
|
523
|
+
const fname = name || '(不明)';
|
|
524
|
+
res.errors.push({
|
|
525
|
+
ref, type: CUSTOM_ERROR_TYPE,
|
|
526
|
+
// 文言に、フローと要素の名前を入れる(エラーは、種類と文言でまとめるため。別の要素を 1 つにまとめない)
|
|
527
|
+
msg: `フローのカスタムエラーで停止(${fname} の ${ename}。文言はログに出ません。フローの定義の、この要素を見てください)`,
|
|
528
|
+
where: `フロー ${fname} の要素 ${ename}(${etype})`,
|
|
529
|
+
unit: stack[stack.length - 1] || '',
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
case 'LIMIT_USAGE_FOR_NS': {
|
|
535
|
+
if (ev.fields[0] !== '(default)') break;
|
|
536
|
+
ev.more.forEach(l => {
|
|
537
|
+
const m = /^\s*(.+?):\s*(\d+)\s+out of\s+(\d+)\s*$/.exec(l);
|
|
538
|
+
if (!m) return;
|
|
539
|
+
const used = +m[2], max = +m[3];
|
|
540
|
+
if (m[1] === 'Number of SOQL queries') res.soql = `${used}/${max}`;
|
|
541
|
+
if (m[1] === 'Number of DML statements') res.dml = `${used}/${max}`;
|
|
542
|
+
if (max > 0 && used / max > 0.5) res.limits.push({ ref, name: m[1], used, max });
|
|
543
|
+
});
|
|
544
|
+
break;
|
|
545
|
+
}
|
|
546
|
+
default:
|
|
547
|
+
break;
|
|
548
|
+
}
|
|
549
|
+
if (ERROR_TYPES.has(ev.type)) {
|
|
550
|
+
let msg, where;
|
|
551
|
+
if (ev.type === 'FATAL_ERROR') {
|
|
552
|
+
msg = ev.fields.join('|');
|
|
553
|
+
where = ev.more.map(s => s.trim()).find(s => s !== '') || '';
|
|
554
|
+
} else if (ev.type === 'EXCEPTION_THROWN') {
|
|
555
|
+
msg = ev.fields.slice(1).join('|');
|
|
556
|
+
where = lineRef(ev.fields[0]);
|
|
557
|
+
} else {
|
|
558
|
+
// FLOW_ELEMENT_ERROR: 実機の並びは「文言|要素の種類|要素の名前」(文言に | が入っても、後ろの 2 つで見分ける)。
|
|
559
|
+
// この並びでなければ、推測で読まず、項目をそのまま並べる
|
|
560
|
+
const n = ev.fields.length;
|
|
561
|
+
if (n >= 3 && FLOW_ELEMENT_TYPE_RE.test(ev.fields[n - 2])) {
|
|
562
|
+
const etype = ev.fields[n - 2], ename = ev.fields[n - 1];
|
|
563
|
+
msg = stripLinks(ev.fields.slice(0, n - 2).join('|'));
|
|
564
|
+
const eiid = lastElement.get(`${etype}|${ename}`);
|
|
565
|
+
const name = interviews.get(eiid);
|
|
566
|
+
if (name) flowOf(name, ref).errors++;
|
|
567
|
+
if (eiid) ivOf(eiid).errored = true;
|
|
568
|
+
where = `フロー ${name || '(不明)'} の要素 ${ename}(${etype})`;
|
|
569
|
+
} else {
|
|
570
|
+
msg = stripLinks(ev.fields.join(' / '));
|
|
571
|
+
where = '';
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
res.errors.push({ ref, type: ev.type, msg, where, unit: stack[stack.length - 1] || '' });
|
|
575
|
+
}
|
|
576
|
+
// 入力規則で止めた行も、1 のエラーに入れる(保存を止めたものは、すべて 1 に集める)。
|
|
577
|
+
// VALIDATION_FAIL には文言がない(項目なし。2026-11-24 に実機で確認)ため、規則の名前で書く。
|
|
578
|
+
// 文言に規則の名前を入れる(エラーは、種類と文言でまとめるため。別の規則を 1 つにまとめない)
|
|
579
|
+
if (VALIDATION_TYPES.has(ev.type)) {
|
|
580
|
+
const rule = lastRule ? `(規則: ${lastRule})` : '';
|
|
581
|
+
const msg = ev.type === 'VALIDATION_FAIL'
|
|
582
|
+
? `入力規則${lastRule ? ` ${lastRule}` : ''} で停止(文言はログに出ません。入力規則の定義を見てください)`
|
|
583
|
+
: `${ev.fields.join(' / ')}${rule}`;
|
|
584
|
+
res.errors.push({ ref, type: ev.type, msg, where: '', unit: stack[stack.length - 1] || '' });
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
// 画面待ち: 開始の終わり(START_INTERVIEW_END)まで進み、完了もエラーもない実行。画面フローは、画面を出すたびに止まり、
|
|
588
|
+
// 完了の行(FLOW_INTERVIEW_FINISHED)がログに出ない(最後の画面の「完了」の要求にも出ない。2026-11-26 に実機で確認)。
|
|
589
|
+
// 開始の終わりがない実行(ログの終わりで切れたなど)は、数えない
|
|
590
|
+
ivState.forEach((s, iid) => {
|
|
591
|
+
const name = interviews.get(iid);
|
|
592
|
+
if (name && s.started && s.ended && !s.finished && !s.errored && res.flows.has(name)) res.flows.get(name).paused++; // 開始したフローは、必ず res.flows にある
|
|
593
|
+
});
|
|
594
|
+
return res;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
function cmdSummarize(opts) {
|
|
598
|
+
if (!opts.list) fail('--list を指定してください。');
|
|
599
|
+
const now = opts.now === undefined ? Date.now() : parseTime(opts.now);
|
|
600
|
+
if (now === null) fail(`--now の形が正しくありません: ${opts.now}`);
|
|
601
|
+
setLocalOffset(opts);
|
|
602
|
+
const base = opts.base || process.cwd();
|
|
603
|
+
const rows = readList(opts.list);
|
|
604
|
+
const results = rows.map(r => analyze(r, base));
|
|
605
|
+
const ok = results.filter(r => !r.missing);
|
|
606
|
+
const missing = results.filter(r => r.missing);
|
|
607
|
+
|
|
608
|
+
// エラーを、種類と文言でまとめる(最初に出た場所を残す)
|
|
609
|
+
const errMap = new Map();
|
|
610
|
+
ok.forEach(r => r.errors.forEach(e => {
|
|
611
|
+
const k = `${e.type}\u0000${e.msg}`;
|
|
612
|
+
if (errMap.has(k)) errMap.get(k).count++;
|
|
613
|
+
else errMap.set(k, Object.assign({ count: 1 }, e));
|
|
614
|
+
}));
|
|
615
|
+
const errors = [...errMap.values()];
|
|
616
|
+
const errorTotal = ok.reduce((n, r) => n + r.errors.length, 0);
|
|
617
|
+
|
|
618
|
+
const out = [];
|
|
619
|
+
out.push(`# デバッグログの要約(${fmtLocal(now)} 作成・${rows.length} 本・エラー ${errorTotal})`);
|
|
620
|
+
out.push('');
|
|
621
|
+
|
|
622
|
+
// 注意(取れていないものを隠さない。6.1)
|
|
623
|
+
const notes = opts.note.slice();
|
|
624
|
+
if (missing.length) notes.push(`読めなかったログ: ${missing.length} 本(${missing.slice(0, 5).map(r => r.row.path).join('、')}${missing.length > 5 ? ' ほか' : ''})`);
|
|
625
|
+
const unread = ok.filter(r => r.unreadable.length);
|
|
626
|
+
if (unread.length) notes.push(`読み取れなかった行: ${unread.reduce((n, r) => n + r.unreadable.length, 0)} 行(想定と違う形。推測で読んでいません。下の 6)`);
|
|
627
|
+
const trunc = ok.filter(r => r.row.len >= TRUNCATE_BYTES);
|
|
628
|
+
if (trunc.length) notes.push(`20MB で切り詰められたログ: ${trunc.length} 本(古い行が削られています。下の 6)`);
|
|
629
|
+
const noTz = ok.filter(r => !r.tzKnown);
|
|
630
|
+
if (noTz.length) notes.push(`タイムゾーン不明のログ: ${noTz.length} 本(USER_INFO の行がありません。行の時刻は、ログのまま)`);
|
|
631
|
+
if (rows.length === 0) notes.push('対象のログはありません。');
|
|
632
|
+
notes.forEach(n => out.push(`> ${cell(n)}`));
|
|
633
|
+
if (notes.length) out.push('');
|
|
634
|
+
|
|
635
|
+
// 1. エラー
|
|
636
|
+
out.push('## 1. エラー');
|
|
637
|
+
if (errors.length === 0) {
|
|
638
|
+
out.push('- なし(エラーの行は、ありませんでした。出なかった区分は、下の 6 を見てください)');
|
|
639
|
+
} else {
|
|
640
|
+
errors.slice(0, MAX.errors).forEach(e => {
|
|
641
|
+
out.push(`- [${e.ref}] ${e.type} ${cell(e.msg)}${e.count > 1 ? `(同じものが ${e.count} 件)` : ''}`);
|
|
642
|
+
// 場所: 行(例外の行・スタックトレースの 1 行目)と、そのとき動いていた CODE_UNIT(入れ子のいちばん内側)
|
|
643
|
+
const unit = e.unit ? `直前の CODE_UNIT: ${cell(e.unit)}` : '';
|
|
644
|
+
const loc = e.where && unit ? `${cell(e.where)}(${unit})` : (cell(e.where) || unit);
|
|
645
|
+
if (loc) out.push(` - 場所: ${loc}`);
|
|
646
|
+
});
|
|
647
|
+
if (errors.length > MAX.errors) out.push(`- ほか ${errors.length - MAX.errors} 種類(省略)`);
|
|
648
|
+
}
|
|
649
|
+
out.push('');
|
|
650
|
+
|
|
651
|
+
// 2. ログの一覧
|
|
652
|
+
out.push('## 2. ログの一覧');
|
|
653
|
+
out.push('| 開始 | 操作 | 状態 | 長さ | 所要 | SOQL | DML | ファイル |');
|
|
654
|
+
out.push('|---|---|---|---|---|---|---|---|');
|
|
655
|
+
const listed = results.slice(-MAX.logs);
|
|
656
|
+
// 名前を、最大 MAX.names 個まで「・」でつなぐ(超えたら「ほか N」)
|
|
657
|
+
const names = (m) => { const a = [...m.keys()]; return a.slice(0, MAX.names).join('・') + (a.length > MAX.names ? ` ほか ${a.length - MAX.names}` : ''); };
|
|
658
|
+
// 所要は、Salesforce の値(DurationMilliseconds)をそのまま書く。ログの中の経過より DUR_ODD_MS 以上長いときは、
|
|
659
|
+
// 値が不自然なことを ※ で示す(2026-11-25 に、ログの中が約 10 秒で、Salesforce の値が約 96 時間のログを実機で見た。
|
|
660
|
+
// 普通のログは、Salesforce の値がログの中の経過の数倍で、差は大きくても数十秒だった)
|
|
661
|
+
let durOdd = false;
|
|
662
|
+
const durText = (r) => {
|
|
663
|
+
if (r.missing || r.elapsed === null || r.row.dur - r.elapsed < DUR_ODD_MS) return `${r.row.dur}ms`;
|
|
664
|
+
durOdd = true;
|
|
665
|
+
return `${r.row.dur}ms(ログの中は ${r.elapsed}ms ※)`;
|
|
666
|
+
};
|
|
667
|
+
listed.forEach(r => {
|
|
668
|
+
// 操作の括弧: 最初の CODE_UNIT と、ログの中のフロー・入力規則の名前(1 回の保存が、何本かのログに分かれるため。
|
|
669
|
+
// 最初の CODE_UNIT だけでは、フローを含むログが「Validation:Account:new」と見える。6.3)
|
|
670
|
+
const inner = [];
|
|
671
|
+
if (r.firstUnit) inner.push(cell(r.firstUnit));
|
|
672
|
+
if (r.flows && r.flows.size) inner.push(`フロー: ${cell(names(r.flows))}`);
|
|
673
|
+
if (r.rules && r.rules.size) inner.push(`入力規則: ${cell(names(r.rules))}`);
|
|
674
|
+
if (r.dups && r.dups.size) inner.push(`重複: ${cell(names(r.dups))}`);
|
|
675
|
+
const op = cell(r.row.op) + (inner.length ? `(${inner.join('/')})` : '');
|
|
676
|
+
out.push(`| ${fmtLocal(r.row.start)} | ${op} | ${cell(r.row.status)} | ${sizeText(r.row.len)} | ${durText(r)} | ${r.soql || '-'} | ${r.dml || '-'} | ${r.row.path}${r.missing ? '(読めません)' : ''} |`);
|
|
677
|
+
});
|
|
678
|
+
if (results.length > MAX.logs) out.push(`| … | ほか ${results.length - MAX.logs} 本(古いもの。省略) | | | | | | |`);
|
|
679
|
+
out.push('');
|
|
680
|
+
if (durOdd) {
|
|
681
|
+
out.push(`- ※ 所要は、Salesforce が返した値(ApexLog の DurationMilliseconds)です。※ の付いたログは、ログの中の経過(行の時刻の、処理の始まりからの経過)より 1 時間以上長く、実際の所要ではない可能性があります`);
|
|
682
|
+
out.push('');
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// 3. System.debug(新しい順)
|
|
686
|
+
out.push('## 3. System.debug の出力(新しい順・最大 50 件)');
|
|
687
|
+
const debug = [];
|
|
688
|
+
ok.forEach(r => r.debug.forEach(d => debug.push(d)));
|
|
689
|
+
debug.reverse();
|
|
690
|
+
if (debug.length === 0) out.push('- なし');
|
|
691
|
+
debug.slice(0, MAX.debug).forEach(d => {
|
|
692
|
+
out.push(`- [${d.ref}] ${d.time} ${d.level}${d.where ? ` ${d.where}` : ''}: ${cell(d.msg)}${d.more ? `(続き ${d.more} 行は本文を見てください)` : ''}`);
|
|
693
|
+
});
|
|
694
|
+
if (debug.length > MAX.debug) out.push(`- ほか ${debug.length - MAX.debug} 件(古いもの。省略)`);
|
|
695
|
+
out.push('');
|
|
696
|
+
|
|
697
|
+
// 4. フロー・入力規則・重複ルール(どれが動いたか。全部のログを、名前でまとめる。最初に出た場所を残す)
|
|
698
|
+
out.push('## 4. フロー・入力規則・重複ルール');
|
|
699
|
+
const flows = new Map(), rules = new Map();
|
|
700
|
+
const newFlow = (ref) => ({ ref, started: 0, finished: 0, errors: 0, customErrors: 0, paused: 0, resumed: 0, elements: new Map() });
|
|
701
|
+
// 実行の ID → フローの名前を、全部のログから集める(画面フローの続きの要素を、開始したログのフローに結ぶため)
|
|
702
|
+
const allInterviews = new Map();
|
|
703
|
+
ok.forEach(r => (r.interviews || new Map()).forEach((name, iid) => allInterviews.set(iid, name)));
|
|
704
|
+
ok.forEach(r => {
|
|
705
|
+
r.flows.forEach((f, name) => {
|
|
706
|
+
if (!flows.has(name)) flows.set(name, newFlow(f.ref));
|
|
707
|
+
const t = flows.get(name);
|
|
708
|
+
t.started += f.started; t.finished += f.finished; t.errors += f.errors; t.customErrors += f.customErrors; t.paused += f.paused || 0;
|
|
709
|
+
f.elements.forEach((v, k) => t.elements.set(k, 1));
|
|
710
|
+
});
|
|
711
|
+
// 続き: このログでは名前に結べなかった実行の要素を、ほかのログの実行の ID で結ぶ(ログ 1 本・実行 1 つにつき、続き 1)
|
|
712
|
+
const seen = new Set();
|
|
713
|
+
(r.orphanElements || []).forEach(o => {
|
|
714
|
+
const name = allInterviews.get(o.iid);
|
|
715
|
+
if (!name) return;
|
|
716
|
+
if (!flows.has(name)) flows.set(name, newFlow(o.ref));
|
|
717
|
+
const t = flows.get(name);
|
|
718
|
+
t.elements.set(o.key, 1);
|
|
719
|
+
if (!seen.has(o.iid)) { seen.add(o.iid); t.resumed++; }
|
|
720
|
+
});
|
|
721
|
+
r.rules.forEach((v, name) => {
|
|
722
|
+
if (!rules.has(name)) rules.set(name, { ref: v.ref, evaluated: 0, passed: 0, failed: 0 });
|
|
723
|
+
const t = rules.get(name);
|
|
724
|
+
t.evaluated += v.evaluated; t.passed += v.passed; t.failed += v.failed;
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
// 完了の行がない実行(エラーで止まった・ログの終わりで切れた)もあるため、成功の数は書かず、行の数だけを書く
|
|
728
|
+
if (flows.size === 0) out.push('- フロー: なし');
|
|
729
|
+
[...flows].slice(0, MAX.flows).forEach(([name, f]) => {
|
|
730
|
+
const els = [...f.elements.keys()];
|
|
731
|
+
const elText = els.length ? `・要素: ${cell(els.slice(0, MAX.elements).join('、'))}${els.length > MAX.elements ? ` ほか ${els.length - MAX.elements}` : ''}` : '';
|
|
732
|
+
// カスタムエラーで止めた実行も、完了の行が出る(完了の数に入る)。止めたことが分かるように、内訳を添える
|
|
733
|
+
const custom = f.customErrors ? `(うちカスタムエラー ${f.customErrors})` : '';
|
|
734
|
+
// 画面待ち・続きは、あるときだけ書く(画面フロー。下の説明の行)
|
|
735
|
+
const screen = `${f.paused ? `・画面待ち ${f.paused}` : ''}${f.resumed ? `・続き ${f.resumed}` : ''}`;
|
|
736
|
+
out.push(`- [${f.ref}] フロー ${cell(name)}: 開始 ${f.started}・完了 ${f.finished}・エラー ${f.errors}${custom}${screen}${elText}`);
|
|
737
|
+
});
|
|
738
|
+
if (flows.size > MAX.flows) out.push(`- ほか ${flows.size - MAX.flows} 個のフロー(省略)`);
|
|
739
|
+
if ([...flows.values()].some(f => f.paused || f.resumed)) {
|
|
740
|
+
out.push('- 画面待ち・続き: 画面フローは、画面を出すたびに止まり、画面ごとに要求(ログ)が分かれます。完了の行はログに出ないため、正常に終わっても「完了」は数えられません。' +
|
|
741
|
+
'「画面待ち」は画面を出して止まった実行、「続き」は前の画面の続きとして動いた要求の数です(続きで動いた要素も、上の要素に入れています)');
|
|
742
|
+
}
|
|
743
|
+
if (rules.size === 0) out.push('- 入力規則: なし');
|
|
744
|
+
[...rules].slice(0, MAX.rules).forEach(([name, v]) => {
|
|
745
|
+
out.push(`- [${v.ref}] 入力規則 ${cell(name)}: 評価 ${v.evaluated}・通過 ${v.passed}・停止 ${v.failed}`);
|
|
746
|
+
});
|
|
747
|
+
if (rules.size > MAX.rules) out.push(`- ほか ${rules.size - MAX.rules} 個の入力規則(省略)`);
|
|
748
|
+
// 重複ルール(保存の中と、保存の後(記録のための検出)を分ける。足し合わせると、同じ保存を二重に数えるため)
|
|
749
|
+
const dups = new Map();
|
|
750
|
+
ok.forEach(r => (r.dups || new Map()).forEach((v, name) => {
|
|
751
|
+
if (!dups.has(name)) dups.set(name, { ref: v.ref, objects: new Set(), dml: new Set(), actions: new Set(), ids: new Set(),
|
|
752
|
+
inSave: { runs: 0, toSave: 0, withDup: 0 }, after: { runs: 0, toSave: 0, withDup: 0 } });
|
|
753
|
+
const t = dups.get(name);
|
|
754
|
+
['objects', 'dml', 'actions', 'ids'].forEach(k => v[k].forEach(x => t[k].add(x)));
|
|
755
|
+
['inSave', 'after'].forEach(k => { t[k].runs += v[k].runs; t[k].toSave += v[k].toSave; t[k].withDup += v[k].withDup; });
|
|
756
|
+
}));
|
|
757
|
+
if (dups.size === 0) out.push('- 重複ルール: なし');
|
|
758
|
+
let blockedHint = false;
|
|
759
|
+
[...dups].slice(0, MAX.dups).forEach(([name, d]) => {
|
|
760
|
+
const what = [...d.objects, ...d.dml].join('・');
|
|
761
|
+
const parts = [];
|
|
762
|
+
if (d.inSave.runs) parts.push(`保存の中で ${d.inSave.runs} 回(保存しようとした ${d.inSave.toSave} 件のうち、重複あり ${d.inSave.withDup} 件)`);
|
|
763
|
+
if (d.after.runs) parts.push(`保存の後で ${d.after.runs} 回(重複あり ${d.after.withDup} 件)`);
|
|
764
|
+
const ids = [...d.ids];
|
|
765
|
+
if (ids.length) parts.push(`見つかった重複: ${ids.slice(0, MAX.dupIds).join('、')}${ids.length > MAX.dupIds ? ` ほか ${ids.length - MAX.dupIds}` : ''}`);
|
|
766
|
+
if (d.actions.size) parts.push(`動作: ${[...d.actions].map(dupAction).join('・')}`);
|
|
767
|
+
out.push(`- [${d.ref}] 重複ルール ${cell(name)}${what ? `(${cell(what)})` : ''}: ${parts.join('・')}`);
|
|
768
|
+
if (d.inSave.withDup > 0) blockedHint = true;
|
|
769
|
+
});
|
|
770
|
+
if (dups.size > MAX.dups) out.push(`- ほか ${dups.size - MAX.dups} 個の重複ルール(省略)`);
|
|
771
|
+
if (blockedHint) {
|
|
772
|
+
// 2026-11-24 に実機で確認: 動作が「許可(警告・記録)」でも、Apex・API の保存は、許可の指定(allowSave)がないと止められる
|
|
773
|
+
out.push('- 保存の中で重複ありのとき、Apex・API の保存は、許可の指定(DuplicateRuleHeader.allowSave)がなければ止められます(DUPLICATES_DETECTED。動作が「許可」でも)。ふつうの保存は上の 1 のエラーに入ります。部分保存(Database.insert(…, false))は、ログに失敗の行が出ないため、ここで見てください');
|
|
774
|
+
}
|
|
775
|
+
out.push('- 保存を止めたもの(フローのエラー FLOW_ELEMENT_ERROR・フローのカスタムエラー FlowCustomError・入力規則の停止 VALIDATION_FAIL / VALIDATION_ERROR)は、上の 1 に入れています');
|
|
776
|
+
out.push('');
|
|
777
|
+
|
|
778
|
+
// 5. 制限の使用量
|
|
779
|
+
out.push('## 5. 制限の使用量(上限の 50% を超えたものだけ)');
|
|
780
|
+
const lim = [];
|
|
781
|
+
ok.forEach(r => r.limits.forEach(l => lim.push(l)));
|
|
782
|
+
if (lim.length === 0) out.push('- なし');
|
|
783
|
+
lim.slice(0, MAX.limits).forEach(l => out.push(`- [${l.ref}] ${l.name}: ${l.used} / ${l.max}(${Math.round(l.used / l.max * 100)}%)`));
|
|
784
|
+
if (lim.length > MAX.limits) out.push(`- ほか ${lim.length - MAX.limits} 件(省略)`);
|
|
785
|
+
out.push('');
|
|
786
|
+
|
|
787
|
+
// 6. 切り詰め・出なかった区分・読み取れなかった行
|
|
788
|
+
out.push('## 6. 切り詰め・出なかった区分・読み取れなかった行');
|
|
789
|
+
trunc.forEach(r => out.push(`- 切り詰めあり: ${r.row.path}(${sizeText(r.row.len)})`));
|
|
790
|
+
const empty = CATEGORIES.filter(([, types]) => !ok.some(r => types.some(t => r.counts[t])));
|
|
791
|
+
if (ok.length && empty.length) {
|
|
792
|
+
out.push(`- 該当する行なし(詳しさが足りずに出なかった可能性もある): ${empty.map(([n]) => n).join('・')}`);
|
|
793
|
+
}
|
|
794
|
+
unread.slice(0, MAX.unreadable).forEach(r => {
|
|
795
|
+
const ls = r.unreadable.slice(0, 5).map(n => `${r.row.path}:${n}`).join('、');
|
|
796
|
+
out.push(`- 読み取れなかった行: ${r.unreadable.length} 行(${ls}${r.unreadable.length > 5 ? ' ほか' : ''})`);
|
|
797
|
+
});
|
|
798
|
+
if (unread.length > MAX.unreadable) out.push(`- ほか ${unread.length - MAX.unreadable} 本のログに、読み取れなかった行があります(省略)`);
|
|
799
|
+
if (!trunc.length && !(ok.length && empty.length) && !unread.length) out.push('- なし');
|
|
800
|
+
|
|
801
|
+
process.stdout.write(out.join('\n') + '\n');
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// ------------------------------------------------------------------------------
|
|
805
|
+
// 入口
|
|
806
|
+
// ------------------------------------------------------------------------------
|
|
807
|
+
function main() {
|
|
808
|
+
const opts = parseArgs(process.argv.slice(2));
|
|
809
|
+
const cmd = opts._[0];
|
|
810
|
+
switch (cmd) {
|
|
811
|
+
case 'summarize': return cmdSummarize(opts);
|
|
812
|
+
case 'list': return cmdList(opts);
|
|
813
|
+
case 'tflist': return cmdTflist(opts);
|
|
814
|
+
case 'time': return cmdTime(opts);
|
|
815
|
+
default: fail(`サブコマンドが正しくありません: ${cmd || '(なし)'}(summarize / list / time)`);
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
main();
|