@takagaki/cortex-decisions-viewer 0.12.297 → 0.12.298

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/change-log.js +49 -4
  2. package/package.json +1 -1
@@ -56,9 +56,23 @@ exports.CHANGE_LOG_MAX_ROWS = 50;
56
56
  const WHY_MAX = 3;
57
57
  /**
58
58
  * 載る記録のパスか(4 区画の記録。README・雛形・入れ子は載らない)。自分の正規表現を持たず、engine の種類の表
59
- * `RECORD_KINDS`(束 `dist/engine/record-kinds.js`)の「履歴を取る」に聞く(cortex-engine #3271 便 E0)
59
+ * `RECORD_KINDS`(束 `dist/engine/record-kinds.js`)の「履歴を取る」に聞く(cortex-engine #3271 便 E0)。
60
+ * 聞くのは 4 区画の行(形 flat-md)だけ。engine の表にはスキルの行(形 folder・履歴を取る・cortex-engine #3273 便 E2)も入るが、
61
+ * スキルの行をビルドの画面用の更新履歴に渡すのは別の便(W2)なので、ここでは載せない(engine の番人の `E0_FOUR` と同じ切り方)
60
62
  */
61
- const isHistoryRecordPath = (p) => (0, record_kinds_1.recordKindOf)(p, memory_dir_1.MEMORY_DIRS, record_kinds_1.RECORD_KINDS)?.can.history === true;
63
+ const FOUR_KINDS = record_kinds_1.RECORD_KINDS.filter((k) => k.shape === record_kinds_1.FLAT_MD);
64
+ const isHistoryRecordPath = (p) => (0, record_kinds_1.recordKindOf)(p, memory_dir_1.MEMORY_DIRS, FOUR_KINDS)?.can.history === true;
65
+ /**
66
+ * 1 本がフォルダの行(スキル・鍵のファイル `keyFile` を持つ)。engine の表にスキルの行が入る前(今の engine main)は空。
67
+ * 空の間は、`skill` の持ち主を「4 区画の記録でないこと」だけで見る(配る順で、ビューアの束の表がまだスキルを知らないうちに
68
+ * engine が `skill` 付きの帳簿を書くため。表に聞いて弾くと 4 区画の更新履歴ごと画面から消える)
69
+ */
70
+ const FOLDER_KINDS = record_kinds_1.RECORD_KINDS.filter((k) => k.shape !== record_kinds_1.FLAT_MD && typeof k.keyFile === "string");
71
+ /** フォルダの 1 本の鍵のパス(`<dir>/<名前>/<keyFile>`)か。engine の `folderKeyOf(path) === path` と同じ判じを、表の行の欄から引く */
72
+ const isFolderKeyPath = (p) => {
73
+ const k = (0, record_kinds_1.recordKindOf)(p, memory_dir_1.MEMORY_DIRS, FOLDER_KINDS);
74
+ return !!k && p === `${k.dir}/${p.slice(k.dir.length + 1).split("/")[0]}/${k.keyFile}`;
75
+ };
62
76
  const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
63
77
  /** メールの形(URL の部分を除いて見る) */
64
78
  // engine `change-log.mjs` の定義と同じ(緩めると、URL の後ろのメールや非 ASCII のローカル部が通る)
@@ -101,6 +115,31 @@ function jstDay(at) {
101
115
  const ROW_KEYS = ["at", "by", "what", "why", "commit"];
102
116
  const BY_KINDS = ["member", "night", "unknown"];
103
117
  const norm = (p) => p.normalize("NFC");
118
+ const isDateOrNull = (v) => v === null || (typeof v === "string" && Number.isFinite(Date.parse(v)));
119
+ /**
120
+ * スキルの 1 本の事実の形(engine `change-log.mjs` の `skillFactsProblems` と同じ基準・cortex-engine #3273 便 E2)。
121
+ * 欄はちょうど `createdAt`・`lastModifiedAt`・`creator`。作った人は null か人(member)の行の形
122
+ */
123
+ function isSkillFacts(f) {
124
+ if (!isObj(f))
125
+ return false;
126
+ const keys = Object.keys(f);
127
+ if (keys.length !== 3 || !["createdAt", "lastModifiedAt", "creator"].every((k) => keys.includes(k)))
128
+ return false;
129
+ if (!isDateOrNull(f.createdAt) || !isDateOrNull(f.lastModifiedAt))
130
+ return false;
131
+ const c = f.creator;
132
+ if (c === null)
133
+ return true;
134
+ if (!isObj(c) || Object.keys(c).some((k) => k !== "at" && k !== "by" && k !== "commit"))
135
+ return false;
136
+ if (typeof c.at !== "string" || !Number.isFinite(Date.parse(c.at)))
137
+ return false;
138
+ if (!/^[0-9a-f]{7,64}$/.test(String(c.commit ?? "")))
139
+ return false;
140
+ const by = c.by;
141
+ return isObj(by) && by.kind === "member" && typeof by.member === "string" && !!by.member && Object.keys(by).every((k) => k === "kind" || k === "member");
142
+ }
104
143
  /** 中身を読む(投げない)。契約に 1 つでも反すれば `null` */
105
144
  function parseChangeLog(text) {
106
145
  let value;
@@ -128,11 +167,17 @@ function parseChangeLog(text) {
128
167
  for (const rec of Object.values(value.records)) {
129
168
  if (!isObj(rec))
130
169
  return null;
131
- if (Object.keys(rec).some((k) => k !== "path" && k !== "rows"))
170
+ if (Object.keys(rec).some((k) => k !== "path" && k !== "rows" && k !== "skill"))
132
171
  return null;
133
172
  if (typeof rec.path !== "string" || !rec.path || !Array.isArray(rec.rows))
134
173
  return null;
135
174
  const recPath = norm(rec.path);
175
+ // スキルの 1 本の事実 `skill`(cortex-engine #3273 便 E2)は形だけ検めて読み捨てる(使うのは別の便)。4 区画の記録が持てば弾く。
176
+ // 表がスキルの行を知っていれば、engine と同じく「スキルの 1 本の鍵の記録だけが持ち、必ず持つ」も見る(知らない間は上の FOLDER_KINDS の訳)
177
+ if ("skill" in rec && (isHistoryRecordPath(recPath) || !isSkillFacts(rec.skill)))
178
+ return null;
179
+ if (FOLDER_KINDS.length > 0 && ("skill" in rec) !== isFolderKeyPath(recPath))
180
+ return null;
136
181
  const out = [];
137
182
  for (const r of rec.rows) {
138
183
  if (!isObj(r))
@@ -181,7 +226,7 @@ function parseChangeLog(text) {
181
226
  (rows[recPath] ||= []).push(...out);
182
227
  }
183
228
  // メール・Operated-By は行の中のどこにも持たない(URL の部分を除いたメールの形も)
184
- const rowsText = JSON.stringify([value.window, ...Object.values(value.records).map((r) => (isObj(r) ? r.rows : null))]);
229
+ const rowsText = JSON.stringify([value.window, ...Object.values(value.records).map((r) => (isObj(r) ? [r.rows, r.skill ?? null] : null))]);
185
230
  if (hasEmailShape(rowsText) || /operated-by/i.test(rowsText))
186
231
  return null;
187
232
  const result = { windowDays: w.days, rows: {} };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takagaki/cortex-decisions-viewer",
3
- "version": "0.12.297",
3
+ "version": "0.12.298",
4
4
  "description": "Cortexの意思決定記録(Decisions/*.md)を静的サイトにビルドして閲覧する。各レコードに「Edit on GitHub」リンクを付与する。",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,