@aiquants/daily-report 0.7.0 → 0.9.0

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 (67) hide show
  1. package/README.md +13 -6
  2. package/dist/client.d.mts +438 -26
  3. package/dist/client.d.ts +438 -26
  4. package/dist/client.js +5 -4
  5. package/dist/client.js.map +1 -1
  6. package/dist/client.mjs +5 -4
  7. package/dist/client.mjs.map +1 -1
  8. package/dist/index.d.mts +115 -3
  9. package/dist/index.d.ts +115 -3
  10. package/dist/index.js +1 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +1 -1
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/server.d.mts +15 -0
  15. package/dist/server.d.ts +15 -0
  16. package/dist/server.js +9 -6
  17. package/dist/server.js.map +1 -1
  18. package/dist/server.mjs +9 -6
  19. package/dist/server.mjs.map +1 -1
  20. package/dist/{sse-schema-Df49KA7B.d.mts → sse-schema-BiUnufrI.d.mts} +12 -0
  21. package/dist/{sse-schema-RHckD7TS.d.ts → sse-schema-YZh7Pz7i.d.ts} +12 -0
  22. package/dist/styles/daily-report.standalone.css +1 -1
  23. package/package.json +3 -3
  24. package/src/client/components/daily-report-comment-item.tsx +6 -1
  25. package/src/client/components/daily-report-detail-list.tsx +65 -34
  26. package/src/client/components/daily-report-edit-form.tsx +6 -0
  27. package/src/client/components/daily-report-ids-stream-status.spec.tsx +93 -0
  28. package/src/client/components/daily-report-ids-stream-status.tsx +67 -0
  29. package/src/client/components/daily-report-list.tsx +88 -55
  30. package/src/client/components/daily-report-page.spec.tsx +119 -0
  31. package/src/client/components/daily-report-page.tsx +62 -69
  32. package/src/client/components/daily-report-resolved-content.tsx +36 -10
  33. package/src/client/components/report-views.spec.tsx +37 -2
  34. package/src/client/config-context.tsx +18 -0
  35. package/src/client/contexts/daily-report-action-context.spec.tsx +278 -0
  36. package/src/client/contexts/daily-report-action-context.tsx +203 -65
  37. package/src/client/contexts/daily-report-error-context.spec.tsx +66 -0
  38. package/src/client/contexts/daily-report-error-context.tsx +98 -0
  39. package/src/client/hooks/use-animated-number.spec.ts +103 -0
  40. package/src/client/hooks/use-animated-number.ts +69 -0
  41. package/src/client/hooks/use-daily-report.spec.ts +50 -2
  42. package/src/client/hooks/use-daily-report.ts +30 -1
  43. package/src/client/route-helpers.spec.ts +100 -0
  44. package/src/client/route-helpers.ts +20 -41
  45. package/src/client/streaming/daily-report-ids-stream-client.spec.ts +704 -0
  46. package/src/client/streaming/daily-report-ids-stream-client.ts +677 -0
  47. package/src/client/streaming/daily-report-ids-stream-session.spec.ts +360 -0
  48. package/src/client/streaming/daily-report-ids-stream-session.ts +280 -0
  49. package/src/client.ts +5 -0
  50. package/src/index.ts +1 -0
  51. package/src/server/handlers.action.spec.ts +44 -0
  52. package/src/server/handlers.ids-stream.spec.ts +414 -0
  53. package/src/server/handlers.ts +324 -8
  54. package/src/server/service.spec.ts +83 -7
  55. package/src/server/service.ts +100 -3
  56. package/src/server/test-helpers/handlers-config.ts +48 -1
  57. package/src/server.spec.ts +49 -0
  58. package/src/server.ts +7 -0
  59. package/src/shared/business-date.spec.ts +22 -1
  60. package/src/shared/business-date.ts +20 -0
  61. package/src/shared/comment-adapter.spec.ts +38 -0
  62. package/src/shared/comment-adapter.ts +9 -7
  63. package/src/shared/ids-stream.spec.ts +65 -0
  64. package/src/shared/ids-stream.ts +139 -0
  65. package/src/shared/sse-schema.ts +5 -0
  66. package/src/shared/text-utils.spec.ts +42 -0
  67. package/src/shared/text-utils.ts +8 -0
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
- export { D as DailyReportSseMessage, U as UIComment, c as commentAddMessageSchema, a as commentDeleteMessageSchema, b as connectedMessageSchema, d as dailyReportAttachmentItemSchema, e as dailyReportCommentItemSchema, f as dailyReportCommentSchema, g as dailyReportDetailSchema, h as dailyReportInterviewerSchema, i as dailyReportLabelDefSchema, j as dailyReportSseMessageSchema, m as mergeComments, r as reportCreateMessageSchema, k as reportDeleteMessageSchema, l as reportPublishMessageSchema, n as reportUpdateMessageSchema, o as resolveCommentColorClass, s as statusUpdateMessageSchema } from './sse-schema-Df49KA7B.mjs';
1
+ export { D as DailyReportSseMessage, U as UIComment, c as commentAddMessageSchema, a as commentDeleteMessageSchema, b as connectedMessageSchema, d as dailyReportAttachmentItemSchema, e as dailyReportCommentItemSchema, f as dailyReportCommentSchema, g as dailyReportDetailSchema, h as dailyReportInterviewerSchema, i as dailyReportLabelDefSchema, j as dailyReportSseMessageSchema, m as mergeComments, r as reportCreateMessageSchema, k as reportDeleteMessageSchema, l as reportPublishMessageSchema, n as reportUpdateMessageSchema, o as resolveCommentColorClass, s as statusUpdateMessageSchema } from './sse-schema-BiUnufrI.mjs';
2
+ import { a as DailyReportItem } from './types-Ct1ggzy-.mjs';
3
+ export { d as DailyReportAttachmentState, D as DailyReportAttachmentSummary, e as DailyReportComment, f as DailyReportCommentItem, b as DailyReportDetail, g as DailyReportInterviewer, h as DailyReportLabelDef, c as DailyReportUser } from './types-Ct1ggzy-.mjs';
2
4
  export { D as DailyReportLogger, L as LogLevel, c as createLogger } from './logger-D3krZrNK.mjs';
3
- export { d as DailyReportAttachmentState, D as DailyReportAttachmentSummary, e as DailyReportComment, f as DailyReportCommentItem, b as DailyReportDetail, g as DailyReportInterviewer, a as DailyReportItem, h as DailyReportLabelDef, c as DailyReportUser } from './types-Ct1ggzy-.mjs';
4
5
  import 'zod';
5
6
 
6
7
  /**
@@ -8,6 +9,19 @@ import 'zod';
8
9
  * 営業日の正規化とフォーマットを支援するユーティリティ群。
9
10
  */
10
11
  type BusinessDateInput = string | Date | null | undefined;
12
+ /**
13
+ * Returns today's business-date key (YYYY-MM-DD) in the local calendar.
14
+ * ローカルカレンダー上の「本日」の営業日キー (YYYY-MM-DD) を返す。
15
+ *
16
+ * `new Date().toISOString()` の日付部は UTC 日付になり、UTC より東のタイムゾーン
17
+ * (JST など) では深夜〜午前帯に前日へずれる。営業日はブラウザのローカル暦日で判定する
18
+ * ため、ローカル getter から直接組む。タイムゾーンはパッケージに固定しない (消費側の
19
+ * 実行環境が決める) 方針に沿う。
20
+ *
21
+ * @param now Clock injection for tests (defaults to the current time). テスト用の時刻注入 (既定は現在時刻)。
22
+ * @returns Local calendar day as YYYY-MM-DD. ローカル暦日の YYYY-MM-DD。
23
+ */
24
+ declare const resolveTodayBusinessDateKey: (now?: Date) => string;
11
25
  /**
12
26
  * Normalizes business date input into YYYY-MM-DD format string.
13
27
  * 営業日を YYYY-MM-DD 形式の文字列へ正規化する。
@@ -24,6 +38,104 @@ declare const formatBusinessDateDisplay: (value: BusinessDateInput) => string |
24
38
  */
25
39
  declare const parseBusinessDateKeyToDate: (value: BusinessDateInput) => Date | null;
26
40
 
41
+ /**
42
+ * Wire contract and ordering helpers for the daily-report ids NDJSON stream.
43
+ * 日報 ID 一覧 NDJSON ストリームのワイヤ契約と並び順ヘルパー。
44
+ *
45
+ * サーバーは `GET {apiBasePath}/ids-stream` で 1 行 1 JSON の NDJSON を返す。
46
+ * 行は原則 {@link DailyReportIdsStreamChunkLine} で、送出中に予期しない失敗が
47
+ * 起きた場合のみ {@link DailyReportIdsStreamErrorLine} を 1 行流して正常クローズする
48
+ * (クライアントは「isLast 無しで終端」を再開シグナルとして扱う)。
49
+ *
50
+ * 並び順は SQL の `ORDER BY business_date DESC, id DESC` (MSSQL の DESC は NULL を
51
+ * 末尾に置く) と完全一致させる。カーソル再開はこの全順序に対する「厳密に後」の
52
+ * 位置からのスライスとして定義する。
53
+ */
54
+
55
+ /** ストリーム再開カーソル。直前チャンク末尾アイテムの並び順キー。 */
56
+ type DailyReportIdsStreamCursor = {
57
+ /** 営業日 (YYYY-MM-DD)。null は「営業日なし領域」(並び順の末尾) を表す。 */
58
+ businessDate: string | null;
59
+ /** 日報 Hub ID。 */
60
+ reportHubId: number;
61
+ };
62
+ /** データを運ぶ NDJSON 行。 */
63
+ type DailyReportIdsStreamChunkLine = {
64
+ /** このチャンクのアイテム群 (並び順どおり)。 */
65
+ items: DailyReportItem[];
66
+ /** 次チャンクの再開カーソル。最終チャンクでは null。 */
67
+ nextCursor: DailyReportIdsStreamCursor | null;
68
+ /** これが最終チャンクかどうか。 */
69
+ isLast: boolean;
70
+ /** 全体件数。接続ごとの先頭行にのみ載る。 */
71
+ total?: number;
72
+ };
73
+ /** サーバー側の予期しない失敗を伝える NDJSON 行 (内部情報は含めない)。 */
74
+ type DailyReportIdsStreamErrorLine = {
75
+ error: string;
76
+ };
77
+ /** NDJSON 1 行のユニオン。 */
78
+ type DailyReportIdsStreamLine = DailyReportIdsStreamChunkLine | DailyReportIdsStreamErrorLine;
79
+ /**
80
+ * Type guard for chunk lines (anything else is treated as an error line).
81
+ * チャンク行の型ガード (それ以外はエラー行として扱う)。
82
+ *
83
+ * @param line Parsed NDJSON line. パース済みの NDJSON 行。
84
+ * @returns True when the line carries items. アイテムを運ぶ行なら true。
85
+ */
86
+ declare const isIdsStreamChunkLine: (line: unknown) => line is DailyReportIdsStreamChunkLine;
87
+ /**
88
+ * Total order of the ids stream: businessDate DESC (NULL last), then id DESC.
89
+ * ids ストリームの全順序。営業日降順 (NULL は末尾)、同日内は ID 降順。
90
+ *
91
+ * MSSQL の `ORDER BY business_date DESC, id DESC` と一致させることが唯一の存在理由。
92
+ * 営業日は正規化済みの `YYYY-MM-DD` 文字列なので辞書順比較 = 時系列比較になる。
93
+ *
94
+ * @param a Left key. 左辺キー。
95
+ * @param b Right key. 右辺キー。
96
+ * @returns Negative when `a` streams before `b`. `a` が先に流れるなら負値。
97
+ */
98
+ declare const compareIdsStreamOrder: (a: DailyReportIdsStreamCursor, b: DailyReportIdsStreamCursor) => number;
99
+ /**
100
+ * Checks whether items already follow the ids-stream total order.
101
+ * アイテム配列が ids ストリームの全順序に既に従っているかを検査する処理。
102
+ *
103
+ * ストリームはソート順どおりに届いて末尾へ追記されるため通常は整列済みで、
104
+ * この O(n) 検査で全件ソート (O(n log n)) を省略できる。
105
+ *
106
+ * @param items Items to probe. 検査対象のアイテム配列。
107
+ * @returns True when already ordered. 整列済みなら true。
108
+ */
109
+ declare const isIdsStreamOrdered: (items: readonly DailyReportItem[]) => boolean;
110
+ /**
111
+ * Returns a copy with the item upserted at its ids-stream-ordered position.
112
+ * アイテムを ids ストリーム順の正しい位置へ upsert した複製配列を返す処理。
113
+ *
114
+ * 前提: `items` は ids ストリーム順に整列済み (このモジュールの比較器を使う全書き込み元が
115
+ * 維持する不変条件)。既存の同 ID は除去してから二分探索で挿入位置を求めるため、
116
+ * 全件ソート無しの O(n) で並び順を保てる (以前は SSE 1 件ごとに 20 万件超を
117
+ * localeCompare で全ソートしていた)。
118
+ *
119
+ * @param items Ordered items. 整列済みアイテム配列。
120
+ * @param item Item to upsert. upsert するアイテム。
121
+ * @returns New ordered array. 新しい整列済み配列。
122
+ */
123
+ declare const upsertInIdsStreamOrder: (items: readonly DailyReportItem[], item: DailyReportItem) => DailyReportItem[];
124
+ /**
125
+ * Finds the first index that streams strictly after the cursor.
126
+ * カーソルより厳密に後ろへ並ぶ最初のインデックスを求める処理。
127
+ *
128
+ * 配列は必ずストリーム順 (SQL の ORDER BY) で渡されるが、比較器とのズレが
129
+ * あっても壊れない線形走査で決定する (件数は高々数万・再開時のみの実行)。
130
+ * 該当なし (カーソルが末尾以降) は `items.length` を返し、空チャンク +
131
+ * `isLast: true` の正常終端に落ちる。
132
+ *
133
+ * @param items Stream-ordered items. ストリーム順のアイテム配列。
134
+ * @param cursor Resume cursor. 再開カーソル。
135
+ * @returns Index to resume emission from. 送出を再開するインデックス。
136
+ */
137
+ declare const findIdsStreamResumeIndex: (items: readonly DailyReportItem[], cursor: DailyReportIdsStreamCursor) => number;
138
+
27
139
  /**
28
140
  * Shared text helpers for daily report view components.
29
141
  * 日報ビューコンポーネント向けの共通テキストヘルパー。
@@ -39,4 +151,4 @@ declare const fallbackText: (value: string | null | undefined) => string;
39
151
  */
40
152
  declare const formatToIsoDate: (value: unknown) => string;
41
153
 
42
- export { fallbackText, formatBusinessDateDisplay, formatToIsoDate, normalizeBusinessDateKey, parseBusinessDateKeyToDate };
154
+ export { type DailyReportIdsStreamChunkLine, type DailyReportIdsStreamCursor, type DailyReportIdsStreamErrorLine, type DailyReportIdsStreamLine, DailyReportItem, compareIdsStreamOrder, fallbackText, findIdsStreamResumeIndex, formatBusinessDateDisplay, formatToIsoDate, isIdsStreamChunkLine, isIdsStreamOrdered, normalizeBusinessDateKey, parseBusinessDateKeyToDate, resolveTodayBusinessDateKey, upsertInIdsStreamOrder };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export { D as DailyReportSseMessage, U as UIComment, c as commentAddMessageSchema, a as commentDeleteMessageSchema, b as connectedMessageSchema, d as dailyReportAttachmentItemSchema, e as dailyReportCommentItemSchema, f as dailyReportCommentSchema, g as dailyReportDetailSchema, h as dailyReportInterviewerSchema, i as dailyReportLabelDefSchema, j as dailyReportSseMessageSchema, m as mergeComments, r as reportCreateMessageSchema, k as reportDeleteMessageSchema, l as reportPublishMessageSchema, n as reportUpdateMessageSchema, o as resolveCommentColorClass, s as statusUpdateMessageSchema } from './sse-schema-RHckD7TS.js';
1
+ export { D as DailyReportSseMessage, U as UIComment, c as commentAddMessageSchema, a as commentDeleteMessageSchema, b as connectedMessageSchema, d as dailyReportAttachmentItemSchema, e as dailyReportCommentItemSchema, f as dailyReportCommentSchema, g as dailyReportDetailSchema, h as dailyReportInterviewerSchema, i as dailyReportLabelDefSchema, j as dailyReportSseMessageSchema, m as mergeComments, r as reportCreateMessageSchema, k as reportDeleteMessageSchema, l as reportPublishMessageSchema, n as reportUpdateMessageSchema, o as resolveCommentColorClass, s as statusUpdateMessageSchema } from './sse-schema-YZh7Pz7i.js';
2
+ import { a as DailyReportItem } from './types-Ct1ggzy-.js';
3
+ export { d as DailyReportAttachmentState, D as DailyReportAttachmentSummary, e as DailyReportComment, f as DailyReportCommentItem, b as DailyReportDetail, g as DailyReportInterviewer, h as DailyReportLabelDef, c as DailyReportUser } from './types-Ct1ggzy-.js';
2
4
  export { D as DailyReportLogger, L as LogLevel, c as createLogger } from './logger-D3krZrNK.js';
3
- export { d as DailyReportAttachmentState, D as DailyReportAttachmentSummary, e as DailyReportComment, f as DailyReportCommentItem, b as DailyReportDetail, g as DailyReportInterviewer, a as DailyReportItem, h as DailyReportLabelDef, c as DailyReportUser } from './types-Ct1ggzy-.js';
4
5
  import 'zod';
5
6
 
6
7
  /**
@@ -8,6 +9,19 @@ import 'zod';
8
9
  * 営業日の正規化とフォーマットを支援するユーティリティ群。
9
10
  */
10
11
  type BusinessDateInput = string | Date | null | undefined;
12
+ /**
13
+ * Returns today's business-date key (YYYY-MM-DD) in the local calendar.
14
+ * ローカルカレンダー上の「本日」の営業日キー (YYYY-MM-DD) を返す。
15
+ *
16
+ * `new Date().toISOString()` の日付部は UTC 日付になり、UTC より東のタイムゾーン
17
+ * (JST など) では深夜〜午前帯に前日へずれる。営業日はブラウザのローカル暦日で判定する
18
+ * ため、ローカル getter から直接組む。タイムゾーンはパッケージに固定しない (消費側の
19
+ * 実行環境が決める) 方針に沿う。
20
+ *
21
+ * @param now Clock injection for tests (defaults to the current time). テスト用の時刻注入 (既定は現在時刻)。
22
+ * @returns Local calendar day as YYYY-MM-DD. ローカル暦日の YYYY-MM-DD。
23
+ */
24
+ declare const resolveTodayBusinessDateKey: (now?: Date) => string;
11
25
  /**
12
26
  * Normalizes business date input into YYYY-MM-DD format string.
13
27
  * 営業日を YYYY-MM-DD 形式の文字列へ正規化する。
@@ -24,6 +38,104 @@ declare const formatBusinessDateDisplay: (value: BusinessDateInput) => string |
24
38
  */
25
39
  declare const parseBusinessDateKeyToDate: (value: BusinessDateInput) => Date | null;
26
40
 
41
+ /**
42
+ * Wire contract and ordering helpers for the daily-report ids NDJSON stream.
43
+ * 日報 ID 一覧 NDJSON ストリームのワイヤ契約と並び順ヘルパー。
44
+ *
45
+ * サーバーは `GET {apiBasePath}/ids-stream` で 1 行 1 JSON の NDJSON を返す。
46
+ * 行は原則 {@link DailyReportIdsStreamChunkLine} で、送出中に予期しない失敗が
47
+ * 起きた場合のみ {@link DailyReportIdsStreamErrorLine} を 1 行流して正常クローズする
48
+ * (クライアントは「isLast 無しで終端」を再開シグナルとして扱う)。
49
+ *
50
+ * 並び順は SQL の `ORDER BY business_date DESC, id DESC` (MSSQL の DESC は NULL を
51
+ * 末尾に置く) と完全一致させる。カーソル再開はこの全順序に対する「厳密に後」の
52
+ * 位置からのスライスとして定義する。
53
+ */
54
+
55
+ /** ストリーム再開カーソル。直前チャンク末尾アイテムの並び順キー。 */
56
+ type DailyReportIdsStreamCursor = {
57
+ /** 営業日 (YYYY-MM-DD)。null は「営業日なし領域」(並び順の末尾) を表す。 */
58
+ businessDate: string | null;
59
+ /** 日報 Hub ID。 */
60
+ reportHubId: number;
61
+ };
62
+ /** データを運ぶ NDJSON 行。 */
63
+ type DailyReportIdsStreamChunkLine = {
64
+ /** このチャンクのアイテム群 (並び順どおり)。 */
65
+ items: DailyReportItem[];
66
+ /** 次チャンクの再開カーソル。最終チャンクでは null。 */
67
+ nextCursor: DailyReportIdsStreamCursor | null;
68
+ /** これが最終チャンクかどうか。 */
69
+ isLast: boolean;
70
+ /** 全体件数。接続ごとの先頭行にのみ載る。 */
71
+ total?: number;
72
+ };
73
+ /** サーバー側の予期しない失敗を伝える NDJSON 行 (内部情報は含めない)。 */
74
+ type DailyReportIdsStreamErrorLine = {
75
+ error: string;
76
+ };
77
+ /** NDJSON 1 行のユニオン。 */
78
+ type DailyReportIdsStreamLine = DailyReportIdsStreamChunkLine | DailyReportIdsStreamErrorLine;
79
+ /**
80
+ * Type guard for chunk lines (anything else is treated as an error line).
81
+ * チャンク行の型ガード (それ以外はエラー行として扱う)。
82
+ *
83
+ * @param line Parsed NDJSON line. パース済みの NDJSON 行。
84
+ * @returns True when the line carries items. アイテムを運ぶ行なら true。
85
+ */
86
+ declare const isIdsStreamChunkLine: (line: unknown) => line is DailyReportIdsStreamChunkLine;
87
+ /**
88
+ * Total order of the ids stream: businessDate DESC (NULL last), then id DESC.
89
+ * ids ストリームの全順序。営業日降順 (NULL は末尾)、同日内は ID 降順。
90
+ *
91
+ * MSSQL の `ORDER BY business_date DESC, id DESC` と一致させることが唯一の存在理由。
92
+ * 営業日は正規化済みの `YYYY-MM-DD` 文字列なので辞書順比較 = 時系列比較になる。
93
+ *
94
+ * @param a Left key. 左辺キー。
95
+ * @param b Right key. 右辺キー。
96
+ * @returns Negative when `a` streams before `b`. `a` が先に流れるなら負値。
97
+ */
98
+ declare const compareIdsStreamOrder: (a: DailyReportIdsStreamCursor, b: DailyReportIdsStreamCursor) => number;
99
+ /**
100
+ * Checks whether items already follow the ids-stream total order.
101
+ * アイテム配列が ids ストリームの全順序に既に従っているかを検査する処理。
102
+ *
103
+ * ストリームはソート順どおりに届いて末尾へ追記されるため通常は整列済みで、
104
+ * この O(n) 検査で全件ソート (O(n log n)) を省略できる。
105
+ *
106
+ * @param items Items to probe. 検査対象のアイテム配列。
107
+ * @returns True when already ordered. 整列済みなら true。
108
+ */
109
+ declare const isIdsStreamOrdered: (items: readonly DailyReportItem[]) => boolean;
110
+ /**
111
+ * Returns a copy with the item upserted at its ids-stream-ordered position.
112
+ * アイテムを ids ストリーム順の正しい位置へ upsert した複製配列を返す処理。
113
+ *
114
+ * 前提: `items` は ids ストリーム順に整列済み (このモジュールの比較器を使う全書き込み元が
115
+ * 維持する不変条件)。既存の同 ID は除去してから二分探索で挿入位置を求めるため、
116
+ * 全件ソート無しの O(n) で並び順を保てる (以前は SSE 1 件ごとに 20 万件超を
117
+ * localeCompare で全ソートしていた)。
118
+ *
119
+ * @param items Ordered items. 整列済みアイテム配列。
120
+ * @param item Item to upsert. upsert するアイテム。
121
+ * @returns New ordered array. 新しい整列済み配列。
122
+ */
123
+ declare const upsertInIdsStreamOrder: (items: readonly DailyReportItem[], item: DailyReportItem) => DailyReportItem[];
124
+ /**
125
+ * Finds the first index that streams strictly after the cursor.
126
+ * カーソルより厳密に後ろへ並ぶ最初のインデックスを求める処理。
127
+ *
128
+ * 配列は必ずストリーム順 (SQL の ORDER BY) で渡されるが、比較器とのズレが
129
+ * あっても壊れない線形走査で決定する (件数は高々数万・再開時のみの実行)。
130
+ * 該当なし (カーソルが末尾以降) は `items.length` を返し、空チャンク +
131
+ * `isLast: true` の正常終端に落ちる。
132
+ *
133
+ * @param items Stream-ordered items. ストリーム順のアイテム配列。
134
+ * @param cursor Resume cursor. 再開カーソル。
135
+ * @returns Index to resume emission from. 送出を再開するインデックス。
136
+ */
137
+ declare const findIdsStreamResumeIndex: (items: readonly DailyReportItem[], cursor: DailyReportIdsStreamCursor) => number;
138
+
27
139
  /**
28
140
  * Shared text helpers for daily report view components.
29
141
  * 日報ビューコンポーネント向けの共通テキストヘルパー。
@@ -39,4 +151,4 @@ declare const fallbackText: (value: string | null | undefined) => string;
39
151
  */
40
152
  declare const formatToIsoDate: (value: unknown) => string;
41
153
 
42
- export { fallbackText, formatBusinessDateDisplay, formatToIsoDate, normalizeBusinessDateKey, parseBusinessDateKeyToDate };
154
+ export { type DailyReportIdsStreamChunkLine, type DailyReportIdsStreamCursor, type DailyReportIdsStreamErrorLine, type DailyReportIdsStreamLine, DailyReportItem, compareIdsStreamOrder, fallbackText, findIdsStreamResumeIndex, formatBusinessDateDisplay, formatToIsoDate, isIdsStreamChunkLine, isIdsStreamOrdered, normalizeBusinessDateKey, parseBusinessDateKeyToDate, resolveTodayBusinessDateKey, upsertInIdsStreamOrder };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var l=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var U=Object.prototype.hasOwnProperty;var z=(n,t)=>{for(var o in t)l(n,o,{get:t[o],enumerable:!0})},B=(n,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of j(t))!U.call(n,s)&&s!==o&&l(n,s,{get:()=>t[s],enumerable:!(i=$(t,s))||i.enumerable});return n};var H=n=>B(l({},"__esModule",{value:!0}),n);var q={};z(q,{LogLevel:()=>g,commentAddMessageSchema:()=>x,commentDeleteMessageSchema:()=>S,connectedMessageSchema:()=>D,createLogger:()=>K,dailyReportAttachmentItemSchema:()=>h,dailyReportCommentItemSchema:()=>u,dailyReportCommentSchema:()=>f,dailyReportDetailSchema:()=>a,dailyReportInterviewerSchema:()=>y,dailyReportLabelDefSchema:()=>b,dailyReportSseMessageSchema:()=>W,fallbackText:()=>Y,formatBusinessDateDisplay:()=>P,formatToIsoDate:()=>N,mergeComments:()=>F,normalizeBusinessDateKey:()=>m,parseBusinessDateKeyToDate:()=>O,reportCreateMessageSchema:()=>w,reportDeleteMessageSchema:()=>T,reportPublishMessageSchema:()=>C,reportUpdateMessageSchema:()=>R,resolveCommentColorClass:()=>G,statusUpdateMessageSchema:()=>I});module.exports=H(q);var _=/^\d{4}-\d{2}-\d{2}$/,E=/^\d{4}\/\d{2}\/\d{2}$/,p=n=>n<10?`0${n}`:`${n}`,d=n=>{if(Number.isNaN(n.getTime()))return null;let t=n.getFullYear(),o=p(n.getMonth()+1),i=p(n.getDate());return`${t}-${o}-${i}`},m=n=>{if(n==null)return null;if(n instanceof Date)return d(n);let t=n.trim();if(t==="")return null;if(_.test(t))return t;if(E.test(t))return t.replaceAll("/","-");let o=new Date(t);return d(o)},P=n=>{let t=m(n);return t||null},O=n=>{let t=m(n);if(!t)return null;let[o,i,s]=t.split("-").map(r=>Number.parseInt(r,10));return[o,i,s].some(r=>Number.isNaN(r))?null:new Date(o,i-1,s)};var F=(n,t,o)=>{let i=n.map((r,c)=>({id:`legacy-${c}`,authorName:r.name||"Unknown",content:r.text||"",isMine:!1,color:r.color||void 0,isLegacy:!0})),s=t.map(r=>({id:r.id,authorName:r.userName??"",content:r.content??"",createdAt:r.createdAt??"",isMine:o?r.userId===o:r.isMine,isLegacy:!1}));return[...i,...s]},G=n=>{if(!n)return"text-gray-700";let t=n.toLowerCase();return t.includes("red")||t.includes("\u8D64")?"text-red-600":t.includes("green")||t.includes("\u7DD1")?"text-green-600":t.includes("blue")||t.includes("\u9752")?"text-blue-600":t.includes("yellow")||t.includes("\u9EC4")?"text-yellow-600":t.includes("orange")||t.includes("\u6A59")?"text-orange-500":"text-gray-700"};var g=(r=>(r[r.DEBUG=0]="DEBUG",r[r.INFO=1]="INFO",r[r.WARN=2]="WARN",r[r.ERROR=3]="ERROR",r[r.NONE=4]="NONE",r))(g||{}),K=(n,t,o=console)=>{let i=s=>typeof s=="string"?[`${t} ${s}`]:[t,s];return{debug:(s,...r)=>{n<=0&&o.debug(...i(s),...r)},info:(s,...r)=>{n<=1&&o.info(...i(s),...r)},warn:(s,...r)=>{n<=2&&o.warn(...i(s),...r)},error:(s,...r)=>{n<=3&&o.error(...i(s),...r)}}};var e=require("zod"),y=e.z.object({name:e.z.string().nullish(),affiliation:e.z.string().nullish()}),f=e.z.object({name:e.z.string().nullish(),text:e.z.string().nullish(),color:e.z.string().nullish()}),b=e.z.object({id:e.z.number(),name:e.z.string().nullish(),color:e.z.string().nullish()}),u=e.z.object({id:e.z.number(),userId:e.z.string().nullish(),userName:e.z.string().nullish(),content:e.z.string().nullish(),createdAt:e.z.string().nullish(),isMine:e.z.boolean()}),h=e.z.object({id:e.z.string(),fileName:e.z.string(),fileType:e.z.string().nullable(),fileSize:e.z.number().nullable(),createdAt:e.z.string().nullable(),state:e.z.enum(["present","absent","unknown"])}),a=e.z.object({reportHubId:e.z.number(),date:e.z.string().nullish(),createdAt:e.z.string().nullish(),author:e.z.string().nullish(),userId:e.z.string().nullish(),sourceType:e.z.string().nullish(),employeeName:e.z.string().nullish(),updatedBy:e.z.string().nullish(),updatedAt:e.z.string().nullish(),category:e.z.string().nullish(),creationCategory:e.z.string().nullish(),visitTimeFrom:e.z.string().nullish(),visitTimeTo:e.z.string().nullish(),customerName:e.z.string().nullish(),interviewers:e.z.array(y),subject:e.z.string().nullish(),content:e.z.string().nullish(),comments:e.z.array(f),isRead:e.z.boolean(),isStarred:e.z.boolean(),labels:e.z.array(b),commentItems:e.z.array(u),attachments:e.z.array(h).default([])}),D=e.z.object({type:e.z.literal("connected")}),I=e.z.object({type:e.z.literal("status-update"),reportHubId:e.z.number(),statusType:e.z.enum(["star","read"]),value:e.z.boolean(),clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),x=e.z.object({type:e.z.literal("comment-add"),reportHubId:e.z.number(),comment:u,clientTempId:e.z.string()}),S=e.z.object({type:e.z.literal("comment-delete"),reportHubId:e.z.number(),commentId:e.z.number(),clientTempId:e.z.string()}),w=e.z.object({type:e.z.literal("report-create"),reportHubId:e.z.number(),report:a,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),R=e.z.object({type:e.z.literal("report-update"),reportHubId:e.z.number(),report:a,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),C=e.z.object({type:e.z.literal("report-publish"),reportHubId:e.z.number(),report:a,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),T=e.z.object({type:e.z.literal("report-delete"),reportHubId:e.z.number(),clientTempId:e.z.string()}),W=e.z.discriminatedUnion("type",[D,I,x,S,w,R,C,T]);var Y=n=>{if(!n)return"-";let t=n.trim();return t===""?"-":t},N=n=>{if(!n)return"-";if(typeof n!="string")return n instanceof Date?N(n.toISOString()):String(n);let t=n.trim();if(t==="")return"-";let o=new Date(t);if(Number.isNaN(o.getTime()))return t;let i=o.getFullYear(),s=String(o.getMonth()+1).padStart(2,"0"),r=String(o.getDate()).padStart(2,"0");if(t.includes(":")||t.includes("T")){let k=String(o.getHours()).padStart(2,"0"),A=String(o.getMinutes()).padStart(2,"0"),M=String(o.getSeconds()).padStart(2,"0");return`${i}-${s}-${r}T${k}:${A}:${M}`}return`${i}-${s}-${r}`};0&&(module.exports={LogLevel,commentAddMessageSchema,commentDeleteMessageSchema,connectedMessageSchema,createLogger,dailyReportAttachmentItemSchema,dailyReportCommentItemSchema,dailyReportCommentSchema,dailyReportDetailSchema,dailyReportInterviewerSchema,dailyReportLabelDefSchema,dailyReportSseMessageSchema,fallbackText,formatBusinessDateDisplay,formatToIsoDate,mergeComments,normalizeBusinessDateKey,parseBusinessDateKeyToDate,reportCreateMessageSchema,reportDeleteMessageSchema,reportPublishMessageSchema,reportUpdateMessageSchema,resolveCommentColorClass,statusUpdateMessageSchema});
1
+ "use strict";var p=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var B=(t,r)=>{for(var o in r)p(t,o,{get:r[o],enumerable:!0})},E=(t,r,o,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of j(r))!z.call(t,i)&&i!==o&&p(t,i,{get:()=>r[i],enumerable:!(s=U(r,i))||s.enumerable});return t};var O=t=>E(p({},"__esModule",{value:!0}),t);var Z={};B(Z,{LogLevel:()=>b,commentAddMessageSchema:()=>S,commentDeleteMessageSchema:()=>w,compareIdsStreamOrder:()=>u,connectedMessageSchema:()=>x,createLogger:()=>Q,dailyReportAttachmentItemSchema:()=>h,dailyReportCommentItemSchema:()=>c,dailyReportCommentSchema:()=>D,dailyReportDetailSchema:()=>m,dailyReportInterviewerSchema:()=>f,dailyReportLabelDefSchema:()=>I,dailyReportSseMessageSchema:()=>V,fallbackText:()=>X,findIdsStreamResumeIndex:()=>J,formatBusinessDateDisplay:()=>P,formatToIsoDate:()=>$,isIdsStreamChunkLine:()=>G,isIdsStreamOrdered:()=>W,mergeComments:()=>K,normalizeBusinessDateKey:()=>d,parseBusinessDateKeyToDate:()=>F,reportCreateMessageSchema:()=>C,reportDeleteMessageSchema:()=>N,reportPublishMessageSchema:()=>T,reportUpdateMessageSchema:()=>k,resolveCommentColorClass:()=>Y,resolveTodayBusinessDateKey:()=>y,statusUpdateMessageSchema:()=>R,upsertInIdsStreamOrder:()=>q});module.exports=O(Z);var _=/^\d{4}-\d{2}-\d{2}$/,L=/^\d{4}\/\d{2}\/\d{2}$/,l=t=>t<10?`0${t}`:`${t}`,g=t=>{if(Number.isNaN(t.getTime()))return null;let r=t.getFullYear(),o=l(t.getMonth()+1),s=l(t.getDate());return`${r}-${o}-${s}`},y=(t=new Date)=>Number.isNaN(t.getTime())?y(new Date):`${t.getFullYear()}-${l(t.getMonth()+1)}-${l(t.getDate())}`,d=t=>{if(t==null)return null;if(t instanceof Date)return g(t);let r=t.trim();if(r==="")return null;if(_.test(r))return r;if(L.test(r))return r.replaceAll("/","-");let o=new Date(r);return g(o)},P=t=>{let r=d(t);return r||null},F=t=>{let r=d(t);if(!r)return null;let[o,s,i]=r.split("-").map(n=>Number.parseInt(n,10));return[o,s,i].some(n=>Number.isNaN(n))?null:new Date(o,s-1,i)};var K=(t,r,o)=>{let s=t.map((n,a)=>({id:`legacy-${a}`,authorName:n.name||"Unknown",content:n.text||"",isMine:!1,color:n.color||void 0,isLegacy:!0})),i=r.map(n=>({id:n.id,authorName:n.userName??"",content:n.content??"",createdAt:n.createdAt??"",isMine:o?n.userId===o:n.isMine,isLegacy:!1}));return[...s,...i]},Y=t=>{if(!t)return"text-gray-700 dark:text-gray-300";let r=t.toLowerCase();return r.includes("red")||r.includes("\u8D64")?"text-red-600 dark:text-red-400":r.includes("green")||r.includes("\u7DD1")?"text-green-600 dark:text-green-400":r.includes("blue")||r.includes("\u9752")?"text-blue-600 dark:text-blue-400":r.includes("yellow")||r.includes("\u9EC4")?"text-yellow-600 dark:text-yellow-400":r.includes("orange")||r.includes("\u6A59")?"text-orange-500 dark:text-orange-400":"text-gray-700 dark:text-gray-300"};var G=t=>typeof t=="object"&&t!==null&&Array.isArray(t.items),u=(t,r)=>t.businessDate!==r.businessDate?t.businessDate===null?1:r.businessDate===null||t.businessDate>r.businessDate?-1:1:r.reportHubId-t.reportHubId,W=t=>{for(let r=1;r<t.length;r++)if(u(t[r-1],t[r])>0)return!1;return!0},q=(t,r)=>{let o=t.filter(n=>n.reportHubId!==r.reportHubId),s=0,i=o.length;for(;s<i;){let n=s+i>>1;u(o[n],r)<=0?s=n+1:i=n}return o.splice(s,0,r),o},J=(t,r)=>{let o=t.findIndex(s=>u({businessDate:s.businessDate,reportHubId:s.reportHubId},r)>0);return o===-1?t.length:o};var b=(n=>(n[n.DEBUG=0]="DEBUG",n[n.INFO=1]="INFO",n[n.WARN=2]="WARN",n[n.ERROR=3]="ERROR",n[n.NONE=4]="NONE",n))(b||{}),Q=(t,r,o=console)=>{let s=i=>typeof i=="string"?[`${r} ${i}`]:[r,i];return{debug:(i,...n)=>{t<=0&&o.debug(...s(i),...n)},info:(i,...n)=>{t<=1&&o.info(...s(i),...n)},warn:(i,...n)=>{t<=2&&o.warn(...s(i),...n)},error:(i,...n)=>{t<=3&&o.error(...s(i),...n)}}};var e=require("zod"),f=e.z.object({name:e.z.string().nullish(),affiliation:e.z.string().nullish()}),D=e.z.object({name:e.z.string().nullish(),text:e.z.string().nullish(),color:e.z.string().nullish()}),I=e.z.object({id:e.z.number(),name:e.z.string().nullish(),color:e.z.string().nullish()}),c=e.z.object({id:e.z.number(),userId:e.z.string().nullish(),userName:e.z.string().nullish(),content:e.z.string().nullish(),createdAt:e.z.string().nullish(),isMine:e.z.boolean()}),h=e.z.object({id:e.z.string(),fileName:e.z.string(),fileType:e.z.string().nullable(),fileSize:e.z.number().nullable(),createdAt:e.z.string().nullable(),state:e.z.enum(["present","absent","unknown"])}),m=e.z.object({reportHubId:e.z.number(),date:e.z.string().nullish(),createdAt:e.z.string().nullish(),author:e.z.string().nullish(),userId:e.z.string().nullish(),sourceType:e.z.string().nullish(),employeeName:e.z.string().nullish(),updatedBy:e.z.string().nullish(),updatedAt:e.z.string().nullish(),category:e.z.string().nullish(),creationCategory:e.z.string().nullish(),visitTimeFrom:e.z.string().nullish(),visitTimeTo:e.z.string().nullish(),customerName:e.z.string().nullish(),interviewers:e.z.array(f),subject:e.z.string().nullish(),content:e.z.string().nullish(),comments:e.z.array(D),isRead:e.z.boolean(),isStarred:e.z.boolean(),labels:e.z.array(I),commentItems:e.z.array(c),attachments:e.z.array(h).default([])}),x=e.z.object({type:e.z.literal("connected")}),R=e.z.object({type:e.z.literal("status-update"),reportHubId:e.z.number(),statusType:e.z.enum(["star","read"]),value:e.z.boolean(),clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),S=e.z.object({type:e.z.literal("comment-add"),reportHubId:e.z.number(),comment:c,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),w=e.z.object({type:e.z.literal("comment-delete"),reportHubId:e.z.number(),commentId:e.z.number(),clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),C=e.z.object({type:e.z.literal("report-create"),reportHubId:e.z.number(),report:m,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),k=e.z.object({type:e.z.literal("report-update"),reportHubId:e.z.number(),report:m,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),T=e.z.object({type:e.z.literal("report-publish"),reportHubId:e.z.number(),report:m,clientTempId:e.z.string(),recipientRawUserId:e.z.number().optional()}),N=e.z.object({type:e.z.literal("report-delete"),reportHubId:e.z.number(),clientTempId:e.z.string()}),V=e.z.discriminatedUnion("type",[x,R,S,w,C,k,T,N]);var X=t=>{if(!t)return"-";let r=t.trim();return r===""?"-":r},$=t=>{if(!t)return"-";if(typeof t!="string")return t instanceof Date?$(t.toISOString()):String(t);let r=t.trim();if(r==="")return"-";let o=r.match(/^(\d{4})[-/](\d{2})[-/](\d{2})$/);if(o)return`${o[1]}-${o[2]}-${o[3]}`;let s=new Date(r);if(Number.isNaN(s.getTime()))return r;let i=s.getFullYear(),n=String(s.getMonth()+1).padStart(2,"0"),a=String(s.getDate()).padStart(2,"0");if(r.includes(":")||r.includes("T")){let A=String(s.getHours()).padStart(2,"0"),M=String(s.getMinutes()).padStart(2,"0"),H=String(s.getSeconds()).padStart(2,"0");return`${i}-${n}-${a}T${A}:${M}:${H}`}return`${i}-${n}-${a}`};0&&(module.exports={LogLevel,commentAddMessageSchema,commentDeleteMessageSchema,compareIdsStreamOrder,connectedMessageSchema,createLogger,dailyReportAttachmentItemSchema,dailyReportCommentItemSchema,dailyReportCommentSchema,dailyReportDetailSchema,dailyReportInterviewerSchema,dailyReportLabelDefSchema,dailyReportSseMessageSchema,fallbackText,findIdsStreamResumeIndex,formatBusinessDateDisplay,formatToIsoDate,isIdsStreamChunkLine,isIdsStreamOrdered,mergeComments,normalizeBusinessDateKey,parseBusinessDateKeyToDate,reportCreateMessageSchema,reportDeleteMessageSchema,reportPublishMessageSchema,reportUpdateMessageSchema,resolveCommentColorClass,resolveTodayBusinessDateKey,statusUpdateMessageSchema,upsertInIdsStreamOrder});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/shared/business-date.ts","../src/shared/comment-adapter.ts","../src/shared/logger.ts","../src/shared/sse-schema.ts","../src/shared/text-utils.ts"],"sourcesContent":["/**\n * Shared (isomorphic) entry of @aiquants/daily-report: types, SSE schemas, and pure utilities.\n * @aiquants/daily-report の共有 (isomorphic) エントリ。型・SSE スキーマ・純粋ユーティリティを公開。\n */\nexport * from \"./shared/business-date\"\nexport * from \"./shared/comment-adapter\"\nexport * from \"./shared/logger\"\nexport * from \"./shared/sse-schema\"\nexport * from \"./shared/text-utils\"\nexport * from \"./shared/types\"\n","/**\n * Business date normalization and formatting helper functions.\n * 営業日の正規化とフォーマットを支援するユーティリティ群。\n */\n\ntype BusinessDateInput = string | Date | null | undefined\n\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}$/\nconst SLASH_DATE_PATTERN = /^\\d{4}\\/\\d{2}\\/\\d{2}$/\n\nconst zeroPad = (value: number): string => {\n return value < 10 ? `0${value}` : `${value}`\n}\n\nconst normalizeFromDate = (value: Date): string | null => {\n if (Number.isNaN(value.getTime())) {\n return null\n }\n\n const year = value.getFullYear()\n const month = zeroPad(value.getMonth() + 1)\n const day = zeroPad(value.getDate())\n return `${year}-${month}-${day}`\n}\n\n/**\n * Normalizes business date input into YYYY-MM-DD format string.\n * 営業日を YYYY-MM-DD 形式の文字列へ正規化する。\n */\nexport const normalizeBusinessDateKey = (value: BusinessDateInput): string | null => {\n if (value === null || value === undefined) {\n return null\n }\n\n if (value instanceof Date) {\n return normalizeFromDate(value)\n }\n\n const trimmed = value.trim()\n if (trimmed === \"\") {\n return null\n }\n\n if (ISO_DATE_PATTERN.test(trimmed)) {\n return trimmed\n }\n\n if (SLASH_DATE_PATTERN.test(trimmed)) {\n return trimmed.replaceAll(\"/\", \"-\")\n }\n\n const parsed = new Date(trimmed)\n return normalizeFromDate(parsed)\n}\n\n/**\n * Converts normalized business date into display format YYYY-MM-DD.\n * 正規化済みの営業日を YYYY-MM-DD 形式の表示文字列へ変換する。\n */\nexport const formatBusinessDateDisplay = (value: BusinessDateInput): string | null => {\n const normalized = normalizeBusinessDateKey(value)\n if (!normalized) {\n return null\n }\n return normalized\n}\n\n/**\n * Parses normalized business date into Date object.\n * 正規化した営業日を Date オブジェクトへ変換する。\n */\nexport const parseBusinessDateKeyToDate = (value: BusinessDateInput): Date | null => {\n const normalized = normalizeBusinessDateKey(value)\n if (!normalized) {\n return null\n }\n\n const [year, month, day] = normalized.split(\"-\").map((part) => Number.parseInt(part, 10))\n if ([year, month, day].some((component) => Number.isNaN(component))) {\n return null\n }\n\n return new Date(year, month - 1, day)\n}\n","/**\n * Adapters merging legacy JSON comments and relational comments for the UI.\n * レガシー JSON コメントとリレーショナルコメントを UI 向けに統合するアダプタ群。\n */\nimport type { DailyReportComment, DailyReportCommentItem } from \"./types\"\n\nexport type UIComment = {\n id: string | number\n authorName: string\n content: string\n createdAt?: string\n isMine: boolean\n color?: string\n isLegacy: boolean\n}\n\n/**\n * Merges legacy JSON comments and modern relational comments into a unified UI format.\n * レガシーな JSON コメントとモダンなリレーショナルコメントを統合された UI 形式にマージする。\n */\nexport const mergeComments = (legacyComments: DailyReportComment[], modernComments: DailyReportCommentItem[], currentUserId?: string | null): UIComment[] => {\n // 1. Legacy コメントの変換\n const legacyUIComments: UIComment[] = legacyComments.map((c, index) => ({\n id: `legacy-${index}`,\n authorName: c.name || \"Unknown\",\n content: c.text || \"\",\n isMine: false,\n color: c.color || undefined,\n isLegacy: true,\n }))\n\n // 2. Modern コメントの変換\n const modernUIComments: UIComment[] = modernComments.map((c) => ({\n id: c.id,\n authorName: c.userName ?? \"\",\n content: c.content ?? \"\",\n createdAt: c.createdAt ?? \"\",\n isMine: currentUserId ? c.userId === currentUserId : c.isMine,\n isLegacy: false,\n }))\n\n // 3. 結合 (Legacy を先に表示)\n return [...legacyUIComments, ...modernUIComments]\n}\n\n/**\n * Resolves comment color tokens into Tailwind text classes.\n * コメント色のキーワードを Tailwind のテキストクラスに変換する関数。\n */\nexport const resolveCommentColorClass = (color: string | null | undefined): string => {\n if (!color) {\n return \"text-gray-700\"\n }\n\n const normalized = color.toLowerCase()\n\n if (normalized.includes(\"red\") || normalized.includes(\"赤\")) {\n return \"text-red-600\"\n }\n\n if (normalized.includes(\"green\") || normalized.includes(\"緑\")) {\n return \"text-green-600\"\n }\n\n if (normalized.includes(\"blue\") || normalized.includes(\"青\")) {\n return \"text-blue-600\"\n }\n\n if (normalized.includes(\"yellow\") || normalized.includes(\"黄\")) {\n return \"text-yellow-600\"\n }\n\n if (normalized.includes(\"orange\") || normalized.includes(\"橙\")) {\n return \"text-orange-500\"\n }\n\n return \"text-gray-700\"\n}\n","/**\n * Minimal level-filtered logger used internally by the daily-report package.\n * daily-report パッケージ内部で使う最小のレベルフィルタ付きロガー。\n *\n * 消費アプリのロガー実装 (console 互換の debug/info/warn/error) を注入でき、\n * 未注入時は console にフォールバックする。\n */\n\n/** 出力フィルタリング用のログレベル。 */\nexport enum LogLevel {\n DEBUG = 0,\n INFO = 1,\n WARN = 2,\n ERROR = 3,\n NONE = 4,\n}\n\n/** Console 互換のロガーインターフェース。 */\nexport interface DailyReportLogger {\n debug(message?: unknown, ...optionalParams: unknown[]): void\n info(message?: unknown, ...optionalParams: unknown[]): void\n warn(message?: unknown, ...optionalParams: unknown[]): void\n error(message?: unknown, ...optionalParams: unknown[]): void\n}\n\n/**\n * Creates a prefixed, level-filtered logger delegating to the given implementation.\n * 指定実装へ委譲するプレフィックス付き・レベルフィルタ付きロガーを生成する処理。\n */\nexport const createLogger = (level: LogLevel, prefix: string, impl: DailyReportLogger = console): DailyReportLogger => {\n // 文字列メッセージはプレフィックスを連結、それ以外は先頭引数として付加する\n const format = (message: unknown): unknown[] => (typeof message === \"string\" ? [`${prefix} ${message}`] : [prefix, message])\n return {\n debug: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.DEBUG) impl.debug(...format(message), ...rest)\n },\n info: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.INFO) impl.info(...format(message), ...rest)\n },\n warn: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.WARN) impl.warn(...format(message), ...rest)\n },\n error: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.ERROR) impl.error(...format(message), ...rest)\n },\n }\n}\n","/**\n * Zod schemas for daily-report SSE messages (client/server shared contract).\n * 日報 SSE メッセージの zod スキーマ (client / server 共有契約)。\n */\nimport { z } from \"zod\"\nimport type { DailyReportCommentItem as DeclaredComment, DailyReportDetail as DeclaredDetail } from \"./types\"\n\n// --- サブスキーマ(types.ts の型と構造的に一致させる) ---\n\nexport const dailyReportInterviewerSchema = z.object({\n name: z.string().nullish(),\n affiliation: z.string().nullish(),\n})\n\nexport const dailyReportCommentSchema = z.object({\n name: z.string().nullish(),\n text: z.string().nullish(),\n color: z.string().nullish(),\n})\n\nexport const dailyReportLabelDefSchema = z.object({\n id: z.number(),\n name: z.string().nullish(),\n color: z.string().nullish(),\n})\n\nexport const dailyReportCommentItemSchema = z.object({\n id: z.number(),\n userId: z.string().nullish(),\n userName: z.string().nullish(),\n content: z.string().nullish(),\n createdAt: z.string().nullish(),\n isMine: z.boolean(),\n})\n\n/**\n * 添付ファイル 1 件のスキーマ。\n *\n * 周囲のフィールドは `.nullish()` だが、ここは意図して `.nullable()` を使う。\n * `.nullish()` は推論キーを任意 (`?`) にするため、`types.ts` 側の必須 `fileType: string | null`\n * へ代入できず、ファイル末尾の `_AssertDetailCompat` が `never` に落ちてコンパイルエラーになる。\n * 既存の `.nullish()` フィールドはいずれも `types.ts` 側が `?` 付きの任意キーとペアになっており、\n * 「`.nullish()` ↔ 任意キー」「`.nullable()` ↔ 必須 `| null`」の対応で揃っている。\n * `| undefined` を混ぜないことは、詳細型を消費する DuckDB ステージ行の要請でもある。\n */\nexport const dailyReportAttachmentItemSchema = z.object({\n id: z.string(),\n fileName: z.string(),\n fileType: z.string().nullable(),\n fileSize: z.number().nullable(),\n createdAt: z.string().nullable(),\n state: z.enum([\"present\", \"absent\", \"unknown\"]),\n})\n\nexport const dailyReportDetailSchema = z.object({\n reportHubId: z.number(),\n date: z.string().nullish(),\n createdAt: z.string().nullish(),\n author: z.string().nullish(),\n userId: z.string().nullish(),\n sourceType: z.string().nullish(),\n employeeName: z.string().nullish(),\n updatedBy: z.string().nullish(),\n updatedAt: z.string().nullish(),\n category: z.string().nullish(),\n creationCategory: z.string().nullish(),\n visitTimeFrom: z.string().nullish(),\n visitTimeTo: z.string().nullish(),\n customerName: z.string().nullish(),\n interviewers: z.array(dailyReportInterviewerSchema),\n subject: z.string().nullish(),\n content: z.string().nullish(),\n comments: z.array(dailyReportCommentSchema),\n isRead: z.boolean(),\n isStarred: z.boolean(),\n labels: z.array(dailyReportLabelDefSchema),\n commentItems: z.array(dailyReportCommentItemSchema),\n // ❗ `.default([])` は必須。SSE の実体は永続 Redis Stream (MAXLEN 保持) であり、\n // 配備をまたいで**旧形式のエントリが残る**。共有リーダーはプロセス起動時に先頭から\n // 再生し、再接続クライアントの catch-up も同じエントリを読み直すため、\n // このキーを必須にすると添付機能を入れる前に publish された全エントリが\n // fail-closed で捨てられ、再接続タブへ更新が永久に届かなくなる。\n // 送信側の詰め忘れ検知は types.ts の必須フィールドと `_AssertDetailCompat`\n // (出力型は既定値適用後なので必須のまま) が担っており、ここを緩めても失われない。\n attachments: z.array(dailyReportAttachmentItemSchema).default([]),\n})\n\n// --- SSE メッセージスキーマ(8種) ---\n\nexport const connectedMessageSchema = z.object({\n type: z.literal(\"connected\"),\n})\n\nexport const statusUpdateMessageSchema = z.object({\n type: z.literal(\"status-update\"),\n reportHubId: z.number(),\n statusType: z.enum([\"star\", \"read\"]),\n value: z.boolean(),\n clientTempId: z.string(),\n // recipientRawUserId はサーバーサイドフィルタリング専用。\n // SSE ルートが raw JSON から取得してフィルタ後に除去する。\n // クライアントには到達しないが、サーバー側の publish で .parse() を通すため定義が必要。\n recipientRawUserId: z.number().optional(),\n})\n\nexport const commentAddMessageSchema = z.object({\n type: z.literal(\"comment-add\"),\n reportHubId: z.number(),\n comment: dailyReportCommentItemSchema,\n clientTempId: z.string(),\n})\n\nexport const commentDeleteMessageSchema = z.object({\n type: z.literal(\"comment-delete\"),\n reportHubId: z.number(),\n commentId: z.number(),\n clientTempId: z.string(),\n})\n\nexport const reportCreateMessageSchema = z.object({\n type: z.literal(\"report-create\"),\n reportHubId: z.number(),\n report: dailyReportDetailSchema,\n clientTempId: z.string(),\n recipientRawUserId: z.number().optional(),\n})\n\nexport const reportUpdateMessageSchema = z.object({\n type: z.literal(\"report-update\"),\n reportHubId: z.number(),\n report: dailyReportDetailSchema,\n clientTempId: z.string(),\n recipientRawUserId: z.number().optional(),\n})\n\nexport const reportPublishMessageSchema = z.object({\n type: z.literal(\"report-publish\"),\n reportHubId: z.number(),\n report: dailyReportDetailSchema,\n clientTempId: z.string(),\n recipientRawUserId: z.number().optional(),\n})\n\nexport const reportDeleteMessageSchema = z.object({\n type: z.literal(\"report-delete\"),\n reportHubId: z.number(),\n clientTempId: z.string(),\n})\n\n// --- Discriminated Union ---\n\nexport const dailyReportSseMessageSchema = z.discriminatedUnion(\"type\", [\n connectedMessageSchema,\n statusUpdateMessageSchema,\n commentAddMessageSchema,\n commentDeleteMessageSchema,\n reportCreateMessageSchema,\n reportUpdateMessageSchema,\n reportPublishMessageSchema,\n reportDeleteMessageSchema,\n])\n\n// --- 型エクスポート ---\n\nexport type DailyReportSseMessage = z.infer<typeof dailyReportSseMessageSchema>\n\n// --- コンパイル時の型互換チェック ---\n// Zod推論型が既存の型定義に代入可能であることを保証する。\n// ここでエラーが出たらスキーマと types.ts がずれている。\n\ntype _AssertDetailCompat = z.infer<typeof dailyReportDetailSchema> extends DeclaredDetail ? true : never\ntype _AssertCommentCompat = z.infer<typeof dailyReportCommentItemSchema> extends DeclaredComment ? true : never\nconst _detailCheck: _AssertDetailCompat = true\nconst _commentCheck: _AssertCommentCompat = true\nvoid _detailCheck\nvoid _commentCheck\n","/**\n * Shared text helpers for daily report view components.\n * 日報ビューコンポーネント向けの共通テキストヘルパー。\n */\n\n/**\n * Normalizes nullable text by trimming whitespace and applying fallback.\n * null 許容の文字列をトリムしつつフォールバック値を適用する関数。\n */\nexport const fallbackText = (value: string | null | undefined): string => {\n if (!value) {\n return \"-\"\n }\n const trimmed = value.trim()\n return trimmed === \"\" ? \"-\" : trimmed\n}\n\n/**\n * Formats a date string to ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss).\n * 日付文字列を ISO 8601 形式 (YYYY-MM-DD または YYYY-MM-DDTHH:mm:ss) に整形する関数。\n */\nexport const formatToIsoDate = (value: unknown): string => {\n if (!value) {\n return \"-\"\n }\n if (typeof value !== \"string\") {\n // If value is not a string (e.g. Date object), try to convert it to string or handle it\n if (value instanceof Date) {\n return formatToIsoDate(value.toISOString())\n }\n return String(value)\n }\n const trimmed = value.trim()\n if (trimmed === \"\") {\n return \"-\"\n }\n\n const date = new Date(trimmed)\n if (Number.isNaN(date.getTime())) {\n return trimmed\n }\n\n const year = date.getFullYear()\n const month = String(date.getMonth() + 1).padStart(2, \"0\")\n const day = String(date.getDate()).padStart(2, \"0\")\n\n const hasTime = trimmed.includes(\":\") || trimmed.includes(\"T\")\n\n if (hasTime) {\n const hours = String(date.getHours()).padStart(2, \"0\")\n const minutes = String(date.getMinutes()).padStart(2, \"0\")\n const seconds = String(date.getSeconds()).padStart(2, \"0\")\n return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`\n }\n\n return `${year}-${month}-${day}`\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,4BAAAC,EAAA,+BAAAC,EAAA,2BAAAC,EAAA,iBAAAC,EAAA,oCAAAC,EAAA,iCAAAC,EAAA,6BAAAC,EAAA,4BAAAC,EAAA,iCAAAC,EAAA,8BAAAC,EAAA,gCAAAC,EAAA,iBAAAC,EAAA,8BAAAC,EAAA,oBAAAC,EAAA,kBAAAC,EAAA,6BAAAC,EAAA,+BAAAC,EAAA,8BAAAC,EAAA,8BAAAC,EAAA,+BAAAC,EAAA,8BAAAC,EAAA,6BAAAC,EAAA,8BAAAC,IAAA,eAAAC,EAAA1B,GCOA,IAAM2B,EAAmB,sBACnBC,EAAqB,wBAErBC,EAAWC,GACNA,EAAQ,GAAK,IAAIA,CAAK,GAAK,GAAGA,CAAK,GAGxCC,EAAqBD,GAA+B,CACtD,GAAI,OAAO,MAAMA,EAAM,QAAQ,CAAC,EAC5B,OAAO,KAGX,IAAME,EAAOF,EAAM,YAAY,EACzBG,EAAQJ,EAAQC,EAAM,SAAS,EAAI,CAAC,EACpCI,EAAML,EAAQC,EAAM,QAAQ,CAAC,EACnC,MAAO,GAAGE,CAAI,IAAIC,CAAK,IAAIC,CAAG,EAClC,EAMaC,EAA4BL,GAA4C,CACjF,GAAIA,GAAU,KACV,OAAO,KAGX,GAAIA,aAAiB,KACjB,OAAOC,EAAkBD,CAAK,EAGlC,IAAMM,EAAUN,EAAM,KAAK,EAC3B,GAAIM,IAAY,GACZ,OAAO,KAGX,GAAIT,EAAiB,KAAKS,CAAO,EAC7B,OAAOA,EAGX,GAAIR,EAAmB,KAAKQ,CAAO,EAC/B,OAAOA,EAAQ,WAAW,IAAK,GAAG,EAGtC,IAAMC,EAAS,IAAI,KAAKD,CAAO,EAC/B,OAA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AIC,CAAK,IAAIC,CAAG,IAAIC,CAAK,IAAIC,CAAO,IAAIC,CAAO,EACjE,CAEA,MAAO,GAAGL,CAAI,IAAIC,CAAK,IAAIC,CAAG,EAClC","names":["index_exports","__export","LogLevel","commentAddMessageSchema","commentDeleteMessageSchema","connectedMessageSchema","createLogger","dailyReportAttachmentItemSchema","dailyReportCommentItemSchema","dailyReportCommentSchema","dailyReportDetailSchema","dailyReportInterviewerSchema","dailyReportLabelDefSchema","dailyReportSseMessageSchema","fallbackText","formatBusinessDateDisplay","formatToIsoDate","mergeComments","normalizeBusinessDateKey","parseBusinessDateKeyToDate","reportCreateMessageSchema","reportDeleteMessageSchema","reportPublishMessageSchema","reportUpdateMessageSchema","resolveCommentColorClass","statusUpdateMessageSchema","__toCommonJS","ISO_DATE_PATTERN","SLASH_DATE_PATTERN","zeroPad","value","normalizeFromDate","year","month","day","normalizeBusinessDateKey","trimmed","parsed","formatBusinessDateDisplay","normalized","parseBusinessDateKeyToDate","part","component","mergeComments","legacyComments","modernComments","currentUserId","legacyUIComments","c","index","modernUIComments","resolveCommentColorClass","color","normalized","LogLevel","createLogger","level","prefix","impl","format","message","rest","import_zod","dailyReportInterviewerSchema","dailyReportCommentSchema","dailyReportLabelDefSchema","dailyReportCommentItemSchema","dailyReportAttachmentItemSchema","dailyReportDetailSchema","connectedMessageSchema","statusUpdateMessageSchema","commentAddMessageSchema","commentDeleteMessageSchema","reportCreateMessageSchema","reportUpdateMessageSchema","reportPublishMessageSchema","reportDeleteMessageSchema","dailyReportSseMessageSchema","fallbackText","value","trimmed","formatToIsoDate","date","year","month","day","hours","minutes","seconds"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/shared/business-date.ts","../src/shared/comment-adapter.ts","../src/shared/ids-stream.ts","../src/shared/logger.ts","../src/shared/sse-schema.ts","../src/shared/text-utils.ts"],"sourcesContent":["/**\n * Shared (isomorphic) entry of @aiquants/daily-report: types, SSE schemas, and pure utilities.\n * @aiquants/daily-report の共有 (isomorphic) エントリ。型・SSE スキーマ・純粋ユーティリティを公開。\n */\nexport * from \"./shared/business-date\"\nexport * from \"./shared/comment-adapter\"\nexport * from \"./shared/ids-stream\"\nexport * from \"./shared/logger\"\nexport * from \"./shared/sse-schema\"\nexport * from \"./shared/text-utils\"\nexport * from \"./shared/types\"\n","/**\n * Business date normalization and formatting helper functions.\n * 営業日の正規化とフォーマットを支援するユーティリティ群。\n */\n\ntype BusinessDateInput = string | Date | null | undefined\n\nconst ISO_DATE_PATTERN = /^\\d{4}-\\d{2}-\\d{2}$/\nconst SLASH_DATE_PATTERN = /^\\d{4}\\/\\d{2}\\/\\d{2}$/\n\nconst zeroPad = (value: number): string => {\n return value < 10 ? `0${value}` : `${value}`\n}\n\nconst normalizeFromDate = (value: Date): string | null => {\n if (Number.isNaN(value.getTime())) {\n return null\n }\n\n const year = value.getFullYear()\n const month = zeroPad(value.getMonth() + 1)\n const day = zeroPad(value.getDate())\n return `${year}-${month}-${day}`\n}\n\n/**\n * Returns today's business-date key (YYYY-MM-DD) in the local calendar.\n * ローカルカレンダー上の「本日」の営業日キー (YYYY-MM-DD) を返す。\n *\n * `new Date().toISOString()` の日付部は UTC 日付になり、UTC より東のタイムゾーン\n * (JST など) では深夜〜午前帯に前日へずれる。営業日はブラウザのローカル暦日で判定する\n * ため、ローカル getter から直接組む。タイムゾーンはパッケージに固定しない (消費側の\n * 実行環境が決める) 方針に沿う。\n *\n * @param now Clock injection for tests (defaults to the current time). テスト用の時刻注入 (既定は現在時刻)。\n * @returns Local calendar day as YYYY-MM-DD. ローカル暦日の YYYY-MM-DD。\n */\nexport const resolveTodayBusinessDateKey = (now: Date = new Date()): string => {\n if (Number.isNaN(now.getTime())) {\n // 不正な Date が注入されたら現在時刻で解決する (空の営業日キーを返さない)\n return resolveTodayBusinessDateKey(new Date())\n }\n return `${now.getFullYear()}-${zeroPad(now.getMonth() + 1)}-${zeroPad(now.getDate())}`\n}\n\n/**\n * Normalizes business date input into YYYY-MM-DD format string.\n * 営業日を YYYY-MM-DD 形式の文字列へ正規化する。\n */\nexport const normalizeBusinessDateKey = (value: BusinessDateInput): string | null => {\n if (value === null || value === undefined) {\n return null\n }\n\n if (value instanceof Date) {\n return normalizeFromDate(value)\n }\n\n const trimmed = value.trim()\n if (trimmed === \"\") {\n return null\n }\n\n if (ISO_DATE_PATTERN.test(trimmed)) {\n return trimmed\n }\n\n if (SLASH_DATE_PATTERN.test(trimmed)) {\n return trimmed.replaceAll(\"/\", \"-\")\n }\n\n const parsed = new Date(trimmed)\n return normalizeFromDate(parsed)\n}\n\n/**\n * Converts normalized business date into display format YYYY-MM-DD.\n * 正規化済みの営業日を YYYY-MM-DD 形式の表示文字列へ変換する。\n */\nexport const formatBusinessDateDisplay = (value: BusinessDateInput): string | null => {\n const normalized = normalizeBusinessDateKey(value)\n if (!normalized) {\n return null\n }\n return normalized\n}\n\n/**\n * Parses normalized business date into Date object.\n * 正規化した営業日を Date オブジェクトへ変換する。\n */\nexport const parseBusinessDateKeyToDate = (value: BusinessDateInput): Date | null => {\n const normalized = normalizeBusinessDateKey(value)\n if (!normalized) {\n return null\n }\n\n const [year, month, day] = normalized.split(\"-\").map((part) => Number.parseInt(part, 10))\n if ([year, month, day].some((component) => Number.isNaN(component))) {\n return null\n }\n\n return new Date(year, month - 1, day)\n}\n","/**\n * Adapters merging legacy JSON comments and relational comments for the UI.\n * レガシー JSON コメントとリレーショナルコメントを UI 向けに統合するアダプタ群。\n */\nimport type { DailyReportComment, DailyReportCommentItem } from \"./types\"\n\nexport type UIComment = {\n id: string | number\n authorName: string\n content: string\n createdAt?: string\n isMine: boolean\n color?: string\n isLegacy: boolean\n}\n\n/**\n * Merges legacy JSON comments and modern relational comments into a unified UI format.\n * レガシーな JSON コメントとモダンなリレーショナルコメントを統合された UI 形式にマージする。\n */\nexport const mergeComments = (legacyComments: DailyReportComment[], modernComments: DailyReportCommentItem[], currentUserId?: string | null): UIComment[] => {\n // 1. Legacy コメントの変換\n const legacyUIComments: UIComment[] = legacyComments.map((c, index) => ({\n id: `legacy-${index}`,\n authorName: c.name || \"Unknown\",\n content: c.text || \"\",\n isMine: false,\n color: c.color || undefined,\n isLegacy: true,\n }))\n\n // 2. Modern コメントの変換\n const modernUIComments: UIComment[] = modernComments.map((c) => ({\n id: c.id,\n authorName: c.userName ?? \"\",\n content: c.content ?? \"\",\n createdAt: c.createdAt ?? \"\",\n isMine: currentUserId ? c.userId === currentUserId : c.isMine,\n isLegacy: false,\n }))\n\n // 3. 結合 (Legacy を先に表示)\n return [...legacyUIComments, ...modernUIComments]\n}\n\n/**\n * Resolves comment color tokens into Tailwind text classes.\n * コメント色のキーワードを Tailwind のテキストクラスに変換する関数。\n */\nexport const resolveCommentColorClass = (color: string | null | undefined): string => {\n // 各色にダークモードの明色対応を必ず添える。ダークカード上で暗色トークン\n // (text-gray-700 など) 単体だと文字が背景に沈んで読めない\n if (!color) {\n return \"text-gray-700 dark:text-gray-300\"\n }\n\n const normalized = color.toLowerCase()\n\n if (normalized.includes(\"red\") || normalized.includes(\"赤\")) {\n return \"text-red-600 dark:text-red-400\"\n }\n\n if (normalized.includes(\"green\") || normalized.includes(\"緑\")) {\n return \"text-green-600 dark:text-green-400\"\n }\n\n if (normalized.includes(\"blue\") || normalized.includes(\"青\")) {\n return \"text-blue-600 dark:text-blue-400\"\n }\n\n if (normalized.includes(\"yellow\") || normalized.includes(\"黄\")) {\n return \"text-yellow-600 dark:text-yellow-400\"\n }\n\n if (normalized.includes(\"orange\") || normalized.includes(\"橙\")) {\n return \"text-orange-500 dark:text-orange-400\"\n }\n\n return \"text-gray-700 dark:text-gray-300\"\n}\n","/**\n * Wire contract and ordering helpers for the daily-report ids NDJSON stream.\n * 日報 ID 一覧 NDJSON ストリームのワイヤ契約と並び順ヘルパー。\n *\n * サーバーは `GET {apiBasePath}/ids-stream` で 1 行 1 JSON の NDJSON を返す。\n * 行は原則 {@link DailyReportIdsStreamChunkLine} で、送出中に予期しない失敗が\n * 起きた場合のみ {@link DailyReportIdsStreamErrorLine} を 1 行流して正常クローズする\n * (クライアントは「isLast 無しで終端」を再開シグナルとして扱う)。\n *\n * 並び順は SQL の `ORDER BY business_date DESC, id DESC` (MSSQL の DESC は NULL を\n * 末尾に置く) と完全一致させる。カーソル再開はこの全順序に対する「厳密に後」の\n * 位置からのスライスとして定義する。\n */\nimport type { DailyReportItem } from \"./types\"\n\n/** ストリーム再開カーソル。直前チャンク末尾アイテムの並び順キー。 */\nexport type DailyReportIdsStreamCursor = {\n /** 営業日 (YYYY-MM-DD)。null は「営業日なし領域」(並び順の末尾) を表す。 */\n businessDate: string | null\n /** 日報 Hub ID。 */\n reportHubId: number\n}\n\n/** データを運ぶ NDJSON 行。 */\nexport type DailyReportIdsStreamChunkLine = {\n /** このチャンクのアイテム群 (並び順どおり)。 */\n items: DailyReportItem[]\n /** 次チャンクの再開カーソル。最終チャンクでは null。 */\n nextCursor: DailyReportIdsStreamCursor | null\n /** これが最終チャンクかどうか。 */\n isLast: boolean\n /** 全体件数。接続ごとの先頭行にのみ載る。 */\n total?: number\n}\n\n/** サーバー側の予期しない失敗を伝える NDJSON 行 (内部情報は含めない)。 */\nexport type DailyReportIdsStreamErrorLine = {\n error: string\n}\n\n/** NDJSON 1 行のユニオン。 */\nexport type DailyReportIdsStreamLine = DailyReportIdsStreamChunkLine | DailyReportIdsStreamErrorLine\n\n/**\n * Type guard for chunk lines (anything else is treated as an error line).\n * チャンク行の型ガード (それ以外はエラー行として扱う)。\n *\n * @param line Parsed NDJSON line. パース済みの NDJSON 行。\n * @returns True when the line carries items. アイテムを運ぶ行なら true。\n */\nexport const isIdsStreamChunkLine = (line: unknown): line is DailyReportIdsStreamChunkLine => {\n return typeof line === \"object\" && line !== null && Array.isArray((line as { items?: unknown }).items)\n}\n\n/**\n * Total order of the ids stream: businessDate DESC (NULL last), then id DESC.\n * ids ストリームの全順序。営業日降順 (NULL は末尾)、同日内は ID 降順。\n *\n * MSSQL の `ORDER BY business_date DESC, id DESC` と一致させることが唯一の存在理由。\n * 営業日は正規化済みの `YYYY-MM-DD` 文字列なので辞書順比較 = 時系列比較になる。\n *\n * @param a Left key. 左辺キー。\n * @param b Right key. 右辺キー。\n * @returns Negative when `a` streams before `b`. `a` が先に流れるなら負値。\n */\nexport const compareIdsStreamOrder = (a: DailyReportIdsStreamCursor, b: DailyReportIdsStreamCursor): number => {\n if (a.businessDate !== b.businessDate) {\n // null 営業日は並び順の末尾 (MSSQL DESC の NULL 末尾挙動へ揃える)\n if (a.businessDate === null) return 1\n if (b.businessDate === null) return -1\n return a.businessDate > b.businessDate ? -1 : 1\n }\n return b.reportHubId - a.reportHubId\n}\n\n/**\n * Checks whether items already follow the ids-stream total order.\n * アイテム配列が ids ストリームの全順序に既に従っているかを検査する処理。\n *\n * ストリームはソート順どおりに届いて末尾へ追記されるため通常は整列済みで、\n * この O(n) 検査で全件ソート (O(n log n)) を省略できる。\n *\n * @param items Items to probe. 検査対象のアイテム配列。\n * @returns True when already ordered. 整列済みなら true。\n */\nexport const isIdsStreamOrdered = (items: readonly DailyReportItem[]): boolean => {\n for (let i = 1; i < items.length; i++) {\n if (compareIdsStreamOrder(items[i - 1], items[i]) > 0) return false\n }\n return true\n}\n\n/**\n * Returns a copy with the item upserted at its ids-stream-ordered position.\n * アイテムを ids ストリーム順の正しい位置へ upsert した複製配列を返す処理。\n *\n * 前提: `items` は ids ストリーム順に整列済み (このモジュールの比較器を使う全書き込み元が\n * 維持する不変条件)。既存の同 ID は除去してから二分探索で挿入位置を求めるため、\n * 全件ソート無しの O(n) で並び順を保てる (以前は SSE 1 件ごとに 20 万件超を\n * localeCompare で全ソートしていた)。\n *\n * @param items Ordered items. 整列済みアイテム配列。\n * @param item Item to upsert. upsert するアイテム。\n * @returns New ordered array. 新しい整列済み配列。\n */\nexport const upsertInIdsStreamOrder = (items: readonly DailyReportItem[], item: DailyReportItem): DailyReportItem[] => {\n // 既存の同 ID を除いた複製 (位置移動を伴う更新もこれで単一経路になる)\n const next = items.filter((existing) => existing.reportHubId !== item.reportHubId)\n let low = 0\n let high = next.length\n while (low < high) {\n const mid = (low + high) >> 1\n if (compareIdsStreamOrder(next[mid], item) <= 0) {\n low = mid + 1\n } else {\n high = mid\n }\n }\n next.splice(low, 0, item)\n return next\n}\n\n/**\n * Finds the first index that streams strictly after the cursor.\n * カーソルより厳密に後ろへ並ぶ最初のインデックスを求める処理。\n *\n * 配列は必ずストリーム順 (SQL の ORDER BY) で渡されるが、比較器とのズレが\n * あっても壊れない線形走査で決定する (件数は高々数万・再開時のみの実行)。\n * 該当なし (カーソルが末尾以降) は `items.length` を返し、空チャンク +\n * `isLast: true` の正常終端に落ちる。\n *\n * @param items Stream-ordered items. ストリーム順のアイテム配列。\n * @param cursor Resume cursor. 再開カーソル。\n * @returns Index to resume emission from. 送出を再開するインデックス。\n */\nexport const findIdsStreamResumeIndex = (items: readonly DailyReportItem[], cursor: DailyReportIdsStreamCursor): number => {\n const index = items.findIndex((item) => compareIdsStreamOrder({ businessDate: item.businessDate, reportHubId: item.reportHubId }, cursor) > 0)\n return index === -1 ? items.length : index\n}\n","/**\n * Minimal level-filtered logger used internally by the daily-report package.\n * daily-report パッケージ内部で使う最小のレベルフィルタ付きロガー。\n *\n * 消費アプリのロガー実装 (console 互換の debug/info/warn/error) を注入でき、\n * 未注入時は console にフォールバックする。\n */\n\n/** 出力フィルタリング用のログレベル。 */\nexport enum LogLevel {\n DEBUG = 0,\n INFO = 1,\n WARN = 2,\n ERROR = 3,\n NONE = 4,\n}\n\n/** Console 互換のロガーインターフェース。 */\nexport interface DailyReportLogger {\n debug(message?: unknown, ...optionalParams: unknown[]): void\n info(message?: unknown, ...optionalParams: unknown[]): void\n warn(message?: unknown, ...optionalParams: unknown[]): void\n error(message?: unknown, ...optionalParams: unknown[]): void\n}\n\n/**\n * Creates a prefixed, level-filtered logger delegating to the given implementation.\n * 指定実装へ委譲するプレフィックス付き・レベルフィルタ付きロガーを生成する処理。\n */\nexport const createLogger = (level: LogLevel, prefix: string, impl: DailyReportLogger = console): DailyReportLogger => {\n // 文字列メッセージはプレフィックスを連結、それ以外は先頭引数として付加する\n const format = (message: unknown): unknown[] => (typeof message === \"string\" ? [`${prefix} ${message}`] : [prefix, message])\n return {\n debug: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.DEBUG) impl.debug(...format(message), ...rest)\n },\n info: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.INFO) impl.info(...format(message), ...rest)\n },\n warn: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.WARN) impl.warn(...format(message), ...rest)\n },\n error: (message?: unknown, ...rest: unknown[]) => {\n if (level <= LogLevel.ERROR) impl.error(...format(message), ...rest)\n },\n }\n}\n","/**\n * Zod schemas for daily-report SSE messages (client/server shared contract).\n * 日報 SSE メッセージの zod スキーマ (client / server 共有契約)。\n */\nimport { z } from \"zod\"\nimport type { DailyReportCommentItem as DeclaredComment, DailyReportDetail as DeclaredDetail } from \"./types\"\n\n// --- サブスキーマ(types.ts の型と構造的に一致させる) ---\n\nexport const dailyReportInterviewerSchema = z.object({\n name: z.string().nullish(),\n affiliation: z.string().nullish(),\n})\n\nexport const dailyReportCommentSchema = z.object({\n name: z.string().nullish(),\n text: z.string().nullish(),\n color: z.string().nullish(),\n})\n\nexport const dailyReportLabelDefSchema = z.object({\n id: z.number(),\n name: z.string().nullish(),\n color: z.string().nullish(),\n})\n\nexport const dailyReportCommentItemSchema = z.object({\n id: z.number(),\n userId: z.string().nullish(),\n userName: z.string().nullish(),\n content: z.string().nullish(),\n createdAt: z.string().nullish(),\n isMine: z.boolean(),\n})\n\n/**\n * 添付ファイル 1 件のスキーマ。\n *\n * 周囲のフィールドは `.nullish()` だが、ここは意図して `.nullable()` を使う。\n * `.nullish()` は推論キーを任意 (`?`) にするため、`types.ts` 側の必須 `fileType: string | null`\n * へ代入できず、ファイル末尾の `_AssertDetailCompat` が `never` に落ちてコンパイルエラーになる。\n * 既存の `.nullish()` フィールドはいずれも `types.ts` 側が `?` 付きの任意キーとペアになっており、\n * 「`.nullish()` ↔ 任意キー」「`.nullable()` ↔ 必須 `| null`」の対応で揃っている。\n * `| undefined` を混ぜないことは、詳細型を消費する DuckDB ステージ行の要請でもある。\n */\nexport const dailyReportAttachmentItemSchema = z.object({\n id: z.string(),\n fileName: z.string(),\n fileType: z.string().nullable(),\n fileSize: z.number().nullable(),\n createdAt: z.string().nullable(),\n state: z.enum([\"present\", \"absent\", \"unknown\"]),\n})\n\nexport const dailyReportDetailSchema = z.object({\n reportHubId: z.number(),\n date: z.string().nullish(),\n createdAt: z.string().nullish(),\n author: z.string().nullish(),\n userId: z.string().nullish(),\n sourceType: z.string().nullish(),\n employeeName: z.string().nullish(),\n updatedBy: z.string().nullish(),\n updatedAt: z.string().nullish(),\n category: z.string().nullish(),\n creationCategory: z.string().nullish(),\n visitTimeFrom: z.string().nullish(),\n visitTimeTo: z.string().nullish(),\n customerName: z.string().nullish(),\n interviewers: z.array(dailyReportInterviewerSchema),\n subject: z.string().nullish(),\n content: z.string().nullish(),\n comments: z.array(dailyReportCommentSchema),\n isRead: z.boolean(),\n isStarred: z.boolean(),\n labels: z.array(dailyReportLabelDefSchema),\n commentItems: z.array(dailyReportCommentItemSchema),\n // ❗ `.default([])` は必須。SSE の実体は永続 Redis Stream (MAXLEN 保持) であり、\n // 配備をまたいで**旧形式のエントリが残る**。共有リーダーはプロセス起動時に先頭から\n // 再生し、再接続クライアントの catch-up も同じエントリを読み直すため、\n // このキーを必須にすると添付機能を入れる前に publish された全エントリが\n // fail-closed で捨てられ、再接続タブへ更新が永久に届かなくなる。\n // 送信側の詰め忘れ検知は types.ts の必須フィールドと `_AssertDetailCompat`\n // (出力型は既定値適用後なので必須のまま) が担っており、ここを緩めても失われない。\n attachments: z.array(dailyReportAttachmentItemSchema).default([]),\n})\n\n// --- SSE メッセージスキーマ(8種) ---\n\nexport const connectedMessageSchema = z.object({\n type: z.literal(\"connected\"),\n})\n\nexport const statusUpdateMessageSchema = z.object({\n type: z.literal(\"status-update\"),\n reportHubId: z.number(),\n statusType: z.enum([\"star\", \"read\"]),\n value: z.boolean(),\n clientTempId: z.string(),\n // recipientRawUserId はサーバーサイドフィルタリング専用。\n // SSE ルートが raw JSON から取得してフィルタ後に除去する。\n // クライアントには到達しないが、サーバー側の publish で .parse() を通すため定義が必要。\n recipientRawUserId: z.number().optional(),\n})\n\nexport const commentAddMessageSchema = z.object({\n type: z.literal(\"comment-add\"),\n reportHubId: z.number(),\n comment: dailyReportCommentItemSchema,\n clientTempId: z.string(),\n // 下書き日報のコメントは所有者以外に見えてはならない (本文の全員配信を防ぐ)。\n // サーバーサイドフィルタ専用で、SSE ルートがフィルタ後に除去する\n recipientRawUserId: z.number().optional(),\n})\n\nexport const commentDeleteMessageSchema = z.object({\n type: z.literal(\"comment-delete\"),\n reportHubId: z.number(),\n commentId: z.number(),\n clientTempId: z.string(),\n // comment-add と同じ理由の宛先フィルタ\n recipientRawUserId: z.number().optional(),\n})\n\nexport const reportCreateMessageSchema = z.object({\n type: z.literal(\"report-create\"),\n reportHubId: z.number(),\n report: dailyReportDetailSchema,\n clientTempId: z.string(),\n recipientRawUserId: z.number().optional(),\n})\n\nexport const reportUpdateMessageSchema = z.object({\n type: z.literal(\"report-update\"),\n reportHubId: z.number(),\n report: dailyReportDetailSchema,\n clientTempId: z.string(),\n recipientRawUserId: z.number().optional(),\n})\n\nexport const reportPublishMessageSchema = z.object({\n type: z.literal(\"report-publish\"),\n reportHubId: z.number(),\n report: dailyReportDetailSchema,\n clientTempId: z.string(),\n recipientRawUserId: z.number().optional(),\n})\n\nexport const reportDeleteMessageSchema = z.object({\n type: z.literal(\"report-delete\"),\n reportHubId: z.number(),\n clientTempId: z.string(),\n})\n\n// --- Discriminated Union ---\n\nexport const dailyReportSseMessageSchema = z.discriminatedUnion(\"type\", [\n connectedMessageSchema,\n statusUpdateMessageSchema,\n commentAddMessageSchema,\n commentDeleteMessageSchema,\n reportCreateMessageSchema,\n reportUpdateMessageSchema,\n reportPublishMessageSchema,\n reportDeleteMessageSchema,\n])\n\n// --- 型エクスポート ---\n\nexport type DailyReportSseMessage = z.infer<typeof dailyReportSseMessageSchema>\n\n// --- コンパイル時の型互換チェック ---\n// Zod推論型が既存の型定義に代入可能であることを保証する。\n// ここでエラーが出たらスキーマと types.ts がずれている。\n\ntype _AssertDetailCompat = z.infer<typeof dailyReportDetailSchema> extends DeclaredDetail ? true : never\ntype _AssertCommentCompat = z.infer<typeof dailyReportCommentItemSchema> extends DeclaredComment ? true : never\nconst _detailCheck: _AssertDetailCompat = true\nconst _commentCheck: _AssertCommentCompat = true\nvoid _detailCheck\nvoid _commentCheck\n","/**\n * Shared text helpers for daily report view components.\n * 日報ビューコンポーネント向けの共通テキストヘルパー。\n */\n\n/**\n * Normalizes nullable text by trimming whitespace and applying fallback.\n * null 許容の文字列をトリムしつつフォールバック値を適用する関数。\n */\nexport const fallbackText = (value: string | null | undefined): string => {\n if (!value) {\n return \"-\"\n }\n const trimmed = value.trim()\n return trimmed === \"\" ? \"-\" : trimmed\n}\n\n/**\n * Formats a date string to ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss).\n * 日付文字列を ISO 8601 形式 (YYYY-MM-DD または YYYY-MM-DDTHH:mm:ss) に整形する関数。\n */\nexport const formatToIsoDate = (value: unknown): string => {\n if (!value) {\n return \"-\"\n }\n if (typeof value !== \"string\") {\n // If value is not a string (e.g. Date object), try to convert it to string or handle it\n if (value instanceof Date) {\n return formatToIsoDate(value.toISOString())\n }\n return String(value)\n }\n const trimmed = value.trim()\n if (trimmed === \"\") {\n return \"-\"\n }\n\n // 日付のみ (YYYY-MM-DD / YYYY/MM/DD) は Date を経由せず整形する。\n // `new Date(\"2026-08-08\")` は UTC 深夜と解釈され、ローカル getter で負オフセット圏\n // (米国など) では前日へずれるため。\n const dateOnly = trimmed.match(/^(\\d{4})[-/](\\d{2})[-/](\\d{2})$/)\n if (dateOnly) {\n return `${dateOnly[1]}-${dateOnly[2]}-${dateOnly[3]}`\n }\n\n const date = new Date(trimmed)\n if (Number.isNaN(date.getTime())) {\n return trimmed\n }\n\n const year = date.getFullYear()\n const month = String(date.getMonth() + 1).padStart(2, \"0\")\n const day = String(date.getDate()).padStart(2, \"0\")\n\n const hasTime = trimmed.includes(\":\") || trimmed.includes(\"T\")\n\n if (hasTime) {\n const hours = String(date.getHours()).padStart(2, \"0\")\n const minutes = String(date.getMinutes()).padStart(2, \"0\")\n const seconds = String(date.getSeconds()).padStart(2, \"0\")\n return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}`\n }\n\n return `${year}-${month}-${day}`\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,cAAAE,EAAA,4BAAAC,EAAA,+BAAAC,EAAA,0BAAAC,EAAA,2BAAAC,EAAA,iBAAAC,EAAA,oCAAAC,EAAA,iCAAAC,EAAA,6BAAAC,EAAA,4BAAAC,EAAA,iCAAAC,EAAA,8BAAAC,EAAA,gCAAAC,EAAA,iBAAAC,EAAA,6BAAAC,EAAA,8BAAAC,EAAA,oBAAAC,EAAA,yBAAAC,EAAA,uBAAAC,EAAA,kBAAAC,EAAA,6BAAAC,EAAA,+BAAAC,EAAA,8BAAAC,EAAA,8BAAAC,EAAA,+BAAAC,EAAA,8BAAAC,EAAA,6BAAAC,EAAA,gCAAAC,EAAA,8BAAAC,EAAA,2BAAAC,IAAA,eAAAC,EAAAhC,GCOA,IAAMiC,EAAmB,sBACnBC,EAAqB,wBAErBC,EAAWC,GACNA,EAAQ,GAAK,IAAIA,CAAK,GAAK,GAAGA,CAAK,GAGxCC,EAAqBD,GAA+B,CACtD,GAAI,OAAO,MAAMA,EAAM,QAAQ,CAAC,EAC5B,OAAO,KAGX,IAAME,EAAOF,EAAM,YAAY,EACzBG,EAAQJ,EAAQC,EAAM,SAAS,EAAI,CAAC,EACpCI,EAAML,EAAQC,EAAM,QAAQ,CAAC,EACnC,MAAO,GAAGE,CAAI,IAAIC,CAAK,IAA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AAMC,EAAO,IAAI,KAAKH,CAAO,EAC7B,GAAI,OAAO,MAAMG,EAAK,QAAQ,CAAC,EAC3B,OAAOH,EAGX,IAAMI,EAAOD,EAAK,YAAY,EACxBE,EAAQ,OAAOF,EAAK,SAAS,EAAI,CAAC,EAAE,SAAS,EAAG,GAAG,EACnDG,EAAM,OAAOH,EAAK,QAAQ,CAAC,EAAE,SAAS,EAAG,GAAG,EAIlD,GAFgBH,EAAQ,SAAS,GAAG,GAAKA,EAAQ,SAAS,GAAG,EAEhD,CACT,IAAMO,EAAQ,OAAOJ,EAAK,SAAS,CAAC,EAAE,SAAS,EAAG,GAAG,EAC/CK,EAAU,OAAOL,EAAK,WAAW,CAAC,EAAE,SAAS,EAAG,GAAG,EACnDM,EAAU,OAAON,EAAK,WAAW,CAAC,EAAE,SAAS,EAAG,GAAG,EACzD,MAAO,GAAGC,CAAI,IAAIC,CAAK,IAAIC,CAAG,IAAIC,CAAK,IAAIC,CAAO,IAAIC,CAAO,EACjE,CAEA,MAAO,GAAGL,CAAI,IAAIC,CAAK,IAAIC,CAAG,EAClC","names":["index_exports","__export","LogLevel","commentAddMessageSchema","commentDeleteMessageSchema","compareIdsStreamOrder","connectedMessageSchema","createLogger","dailyReportAttachmentItemSchema","dailyReportCommentItemSchema","dailyReportCommentSchema","dailyReportDetailSchema","dailyReportInterviewerSchema","dailyReportLabelDefSchema","dailyReportSseMessageSchema","fallbackText","findIdsStreamResumeIndex","formatBusinessDateDisplay","formatToIsoDate","isIdsStreamChunkLine","isIdsStreamOrdered","mergeComments","normalizeBusinessDateKey","parseBusinessDateKeyToDate","reportCreateMessageSchema","reportDeleteMessageSchema","reportPublishMessageSchema","reportUpdateMessageSchema","resolveCommentColorClass","resolveTodayBusinessDateKey","statusUpdateMessageSchema","upsertInIdsStreamOrder","__toCommonJS","ISO_DATE_PATTERN","SLASH_DATE_PATTERN","zeroPad","value","normalizeFromDate","year","month","day","resolveTodayBusinessDateKey","now","normalizeBusinessDateKey","trimmed","parsed","formatBusinessDateDisplay","normalized","parseBusinessDateKeyToDate","part","component","mergeComments","legacyComments","modernComments","currentUserId","legacyUIComments","c","index","modernUIComments","resolveCommentColorClass","color","normalized","isIdsStreamChunkLine","line","compareIdsStreamOrder","a","b","isIdsStreamOrdered","items","i","upsertInIdsStreamOrder","item","next","existing","low","high","mid","findIdsStreamResumeIndex","cursor","index","LogLevel","createLogger","level","prefix","impl","format","message","rest","import_zod","dailyReportInterviewerSchema","dailyReportCommentSchema","dailyReportLabelDefSchema","dailyReportCommentItemSchema","dailyReportAttachmentItemSchema","dailyReportDetailSchema","connectedMessageSchema","statusUpdateMessageSchema","commentAddMessageSchema","commentDeleteMessageSchema","reportCreateMessageSchema","reportUpdateMessageSchema","reportPublishMessageSchema","reportDeleteMessageSchema","dailyReportSseMessageSchema","fallbackText","value","trimmed","formatToIsoDate","dateOnly","date","year","month","day","hours","minutes","seconds"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- var f=/^\d{4}-\d{2}-\d{2}$/,b=/^\d{4}\/\d{2}\/\d{2}$/,m=n=>n<10?`0${n}`:`${n}`,u=n=>{if(Number.isNaN(n.getTime()))return null;let t=n.getFullYear(),o=m(n.getMonth()+1),i=m(n.getDate());return`${t}-${o}-${i}`},c=n=>{if(n==null)return null;if(n instanceof Date)return u(n);let t=n.trim();if(t==="")return null;if(f.test(t))return t;if(b.test(t))return t.replaceAll("/","-");let o=new Date(t);return u(o)},j=n=>{let t=c(n);return t||null},U=n=>{let t=c(n);if(!t)return null;let[o,i,s]=t.split("-").map(r=>Number.parseInt(r,10));return[o,i,s].some(r=>Number.isNaN(r))?null:new Date(o,i-1,s)};var B=(n,t,o)=>{let i=n.map((r,l)=>({id:`legacy-${l}`,authorName:r.name||"Unknown",content:r.text||"",isMine:!1,color:r.color||void 0,isLegacy:!0})),s=t.map(r=>({id:r.id,authorName:r.userName??"",content:r.content??"",createdAt:r.createdAt??"",isMine:o?r.userId===o:r.isMine,isLegacy:!1}));return[...i,...s]},H=n=>{if(!n)return"text-gray-700";let t=n.toLowerCase();return t.includes("red")||t.includes("\u8D64")?"text-red-600":t.includes("green")||t.includes("\u7DD1")?"text-green-600":t.includes("blue")||t.includes("\u9752")?"text-blue-600":t.includes("yellow")||t.includes("\u9EC4")?"text-yellow-600":t.includes("orange")||t.includes("\u6A59")?"text-orange-500":"text-gray-700"};var h=(r=>(r[r.DEBUG=0]="DEBUG",r[r.INFO=1]="INFO",r[r.WARN=2]="WARN",r[r.ERROR=3]="ERROR",r[r.NONE=4]="NONE",r))(h||{}),E=(n,t,o=console)=>{let i=s=>typeof s=="string"?[`${t} ${s}`]:[t,s];return{debug:(s,...r)=>{n<=0&&o.debug(...i(s),...r)},info:(s,...r)=>{n<=1&&o.info(...i(s),...r)},warn:(s,...r)=>{n<=2&&o.warn(...i(s),...r)},error:(s,...r)=>{n<=3&&o.error(...i(s),...r)}}};import{z as e}from"zod";var D=e.object({name:e.string().nullish(),affiliation:e.string().nullish()}),I=e.object({name:e.string().nullish(),text:e.string().nullish(),color:e.string().nullish()}),x=e.object({id:e.number(),name:e.string().nullish(),color:e.string().nullish()}),p=e.object({id:e.number(),userId:e.string().nullish(),userName:e.string().nullish(),content:e.string().nullish(),createdAt:e.string().nullish(),isMine:e.boolean()}),S=e.object({id:e.string(),fileName:e.string(),fileType:e.string().nullable(),fileSize:e.number().nullable(),createdAt:e.string().nullable(),state:e.enum(["present","absent","unknown"])}),a=e.object({reportHubId:e.number(),date:e.string().nullish(),createdAt:e.string().nullish(),author:e.string().nullish(),userId:e.string().nullish(),sourceType:e.string().nullish(),employeeName:e.string().nullish(),updatedBy:e.string().nullish(),updatedAt:e.string().nullish(),category:e.string().nullish(),creationCategory:e.string().nullish(),visitTimeFrom:e.string().nullish(),visitTimeTo:e.string().nullish(),customerName:e.string().nullish(),interviewers:e.array(D),subject:e.string().nullish(),content:e.string().nullish(),comments:e.array(I),isRead:e.boolean(),isStarred:e.boolean(),labels:e.array(x),commentItems:e.array(p),attachments:e.array(S).default([])}),w=e.object({type:e.literal("connected")}),R=e.object({type:e.literal("status-update"),reportHubId:e.number(),statusType:e.enum(["star","read"]),value:e.boolean(),clientTempId:e.string(),recipientRawUserId:e.number().optional()}),C=e.object({type:e.literal("comment-add"),reportHubId:e.number(),comment:p,clientTempId:e.string()}),T=e.object({type:e.literal("comment-delete"),reportHubId:e.number(),commentId:e.number(),clientTempId:e.string()}),N=e.object({type:e.literal("report-create"),reportHubId:e.number(),report:a,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),k=e.object({type:e.literal("report-update"),reportHubId:e.number(),report:a,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),A=e.object({type:e.literal("report-publish"),reportHubId:e.number(),report:a,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),M=e.object({type:e.literal("report-delete"),reportHubId:e.number(),clientTempId:e.string()}),F=e.discriminatedUnion("type",[w,R,C,T,N,k,A,M]);var K=n=>{if(!n)return"-";let t=n.trim();return t===""?"-":t},$=n=>{if(!n)return"-";if(typeof n!="string")return n instanceof Date?$(n.toISOString()):String(n);let t=n.trim();if(t==="")return"-";let o=new Date(t);if(Number.isNaN(o.getTime()))return t;let i=o.getFullYear(),s=String(o.getMonth()+1).padStart(2,"0"),r=String(o.getDate()).padStart(2,"0");if(t.includes(":")||t.includes("T")){let d=String(o.getHours()).padStart(2,"0"),g=String(o.getMinutes()).padStart(2,"0"),y=String(o.getSeconds()).padStart(2,"0");return`${i}-${s}-${r}T${d}:${g}:${y}`}return`${i}-${s}-${r}`};export{h as LogLevel,C as commentAddMessageSchema,T as commentDeleteMessageSchema,w as connectedMessageSchema,E as createLogger,S as dailyReportAttachmentItemSchema,p as dailyReportCommentItemSchema,I as dailyReportCommentSchema,a as dailyReportDetailSchema,D as dailyReportInterviewerSchema,x as dailyReportLabelDefSchema,F as dailyReportSseMessageSchema,K as fallbackText,j as formatBusinessDateDisplay,$ as formatToIsoDate,B as mergeComments,c as normalizeBusinessDateKey,U as parseBusinessDateKeyToDate,N as reportCreateMessageSchema,M as reportDeleteMessageSchema,A as reportPublishMessageSchema,k as reportUpdateMessageSchema,H as resolveCommentColorClass,R as statusUpdateMessageSchema};
1
+ var f=/^\d{4}-\d{2}-\d{2}$/,D=/^\d{4}\/\d{2}\/\d{2}$/,l=t=>t<10?`0${t}`:`${t}`,p=t=>{if(Number.isNaN(t.getTime()))return null;let r=t.getFullYear(),o=l(t.getMonth()+1),s=l(t.getDate());return`${r}-${o}-${s}`},I=(t=new Date)=>Number.isNaN(t.getTime())?I(new Date):`${t.getFullYear()}-${l(t.getMonth()+1)}-${l(t.getDate())}`,d=t=>{if(t==null)return null;if(t instanceof Date)return p(t);let r=t.trim();if(r==="")return null;if(f.test(r))return r;if(D.test(r))return r.replaceAll("/","-");let o=new Date(r);return p(o)},z=t=>{let r=d(t);return r||null},B=t=>{let r=d(t);if(!r)return null;let[o,s,i]=r.split("-").map(n=>Number.parseInt(n,10));return[o,s,i].some(n=>Number.isNaN(n))?null:new Date(o,s-1,i)};var O=(t,r,o)=>{let s=t.map((n,a)=>({id:`legacy-${a}`,authorName:n.name||"Unknown",content:n.text||"",isMine:!1,color:n.color||void 0,isLegacy:!0})),i=r.map(n=>({id:n.id,authorName:n.userName??"",content:n.content??"",createdAt:n.createdAt??"",isMine:o?n.userId===o:n.isMine,isLegacy:!1}));return[...s,...i]},_=t=>{if(!t)return"text-gray-700 dark:text-gray-300";let r=t.toLowerCase();return r.includes("red")||r.includes("\u8D64")?"text-red-600 dark:text-red-400":r.includes("green")||r.includes("\u7DD1")?"text-green-600 dark:text-green-400":r.includes("blue")||r.includes("\u9752")?"text-blue-600 dark:text-blue-400":r.includes("yellow")||r.includes("\u9EC4")?"text-yellow-600 dark:text-yellow-400":r.includes("orange")||r.includes("\u6A59")?"text-orange-500 dark:text-orange-400":"text-gray-700 dark:text-gray-300"};var P=t=>typeof t=="object"&&t!==null&&Array.isArray(t.items),u=(t,r)=>t.businessDate!==r.businessDate?t.businessDate===null?1:r.businessDate===null||t.businessDate>r.businessDate?-1:1:r.reportHubId-t.reportHubId,F=t=>{for(let r=1;r<t.length;r++)if(u(t[r-1],t[r])>0)return!1;return!0},K=(t,r)=>{let o=t.filter(n=>n.reportHubId!==r.reportHubId),s=0,i=o.length;for(;s<i;){let n=s+i>>1;u(o[n],r)<=0?s=n+1:i=n}return o.splice(s,0,r),o},Y=(t,r)=>{let o=t.findIndex(s=>u({businessDate:s.businessDate,reportHubId:s.reportHubId},r)>0);return o===-1?t.length:o};var h=(n=>(n[n.DEBUG=0]="DEBUG",n[n.INFO=1]="INFO",n[n.WARN=2]="WARN",n[n.ERROR=3]="ERROR",n[n.NONE=4]="NONE",n))(h||{}),W=(t,r,o=console)=>{let s=i=>typeof i=="string"?[`${r} ${i}`]:[r,i];return{debug:(i,...n)=>{t<=0&&o.debug(...s(i),...n)},info:(i,...n)=>{t<=1&&o.info(...s(i),...n)},warn:(i,...n)=>{t<=2&&o.warn(...s(i),...n)},error:(i,...n)=>{t<=3&&o.error(...s(i),...n)}}};import{z as e}from"zod";var x=e.object({name:e.string().nullish(),affiliation:e.string().nullish()}),R=e.object({name:e.string().nullish(),text:e.string().nullish(),color:e.string().nullish()}),S=e.object({id:e.number(),name:e.string().nullish(),color:e.string().nullish()}),c=e.object({id:e.number(),userId:e.string().nullish(),userName:e.string().nullish(),content:e.string().nullish(),createdAt:e.string().nullish(),isMine:e.boolean()}),w=e.object({id:e.string(),fileName:e.string(),fileType:e.string().nullable(),fileSize:e.number().nullable(),createdAt:e.string().nullable(),state:e.enum(["present","absent","unknown"])}),m=e.object({reportHubId:e.number(),date:e.string().nullish(),createdAt:e.string().nullish(),author:e.string().nullish(),userId:e.string().nullish(),sourceType:e.string().nullish(),employeeName:e.string().nullish(),updatedBy:e.string().nullish(),updatedAt:e.string().nullish(),category:e.string().nullish(),creationCategory:e.string().nullish(),visitTimeFrom:e.string().nullish(),visitTimeTo:e.string().nullish(),customerName:e.string().nullish(),interviewers:e.array(x),subject:e.string().nullish(),content:e.string().nullish(),comments:e.array(R),isRead:e.boolean(),isStarred:e.boolean(),labels:e.array(S),commentItems:e.array(c),attachments:e.array(w).default([])}),C=e.object({type:e.literal("connected")}),k=e.object({type:e.literal("status-update"),reportHubId:e.number(),statusType:e.enum(["star","read"]),value:e.boolean(),clientTempId:e.string(),recipientRawUserId:e.number().optional()}),T=e.object({type:e.literal("comment-add"),reportHubId:e.number(),comment:c,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),N=e.object({type:e.literal("comment-delete"),reportHubId:e.number(),commentId:e.number(),clientTempId:e.string(),recipientRawUserId:e.number().optional()}),$=e.object({type:e.literal("report-create"),reportHubId:e.number(),report:m,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),A=e.object({type:e.literal("report-update"),reportHubId:e.number(),report:m,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),M=e.object({type:e.literal("report-publish"),reportHubId:e.number(),report:m,clientTempId:e.string(),recipientRawUserId:e.number().optional()}),H=e.object({type:e.literal("report-delete"),reportHubId:e.number(),clientTempId:e.string()}),Q=e.discriminatedUnion("type",[C,k,T,N,$,A,M,H]);var X=t=>{if(!t)return"-";let r=t.trim();return r===""?"-":r},U=t=>{if(!t)return"-";if(typeof t!="string")return t instanceof Date?U(t.toISOString()):String(t);let r=t.trim();if(r==="")return"-";let o=r.match(/^(\d{4})[-/](\d{2})[-/](\d{2})$/);if(o)return`${o[1]}-${o[2]}-${o[3]}`;let s=new Date(r);if(Number.isNaN(s.getTime()))return r;let i=s.getFullYear(),n=String(s.getMonth()+1).padStart(2,"0"),a=String(s.getDate()).padStart(2,"0");if(r.includes(":")||r.includes("T")){let g=String(s.getHours()).padStart(2,"0"),y=String(s.getMinutes()).padStart(2,"0"),b=String(s.getSeconds()).padStart(2,"0");return`${i}-${n}-${a}T${g}:${y}:${b}`}return`${i}-${n}-${a}`};export{h as LogLevel,T as commentAddMessageSchema,N as commentDeleteMessageSchema,u as compareIdsStreamOrder,C as connectedMessageSchema,W as createLogger,w as dailyReportAttachmentItemSchema,c as dailyReportCommentItemSchema,R as dailyReportCommentSchema,m as dailyReportDetailSchema,x as dailyReportInterviewerSchema,S as dailyReportLabelDefSchema,Q as dailyReportSseMessageSchema,X as fallbackText,Y as findIdsStreamResumeIndex,z as formatBusinessDateDisplay,U as formatToIsoDate,P as isIdsStreamChunkLine,F as isIdsStreamOrdered,O as mergeComments,d as normalizeBusinessDateKey,B as parseBusinessDateKeyToDate,$ as reportCreateMessageSchema,H as reportDeleteMessageSchema,M as reportPublishMessageSchema,A as reportUpdateMessageSchema,_ as resolveCommentColorClass,I as resolveTodayBusinessDateKey,k as statusUpdateMessageSchema,K as upsertInIdsStreamOrder};
2
2
  //# sourceMappingURL=index.mjs.map