@aiquants/daily-report 0.20.0 → 0.21.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 (116) hide show
  1. package/README.md +229 -8
  2. package/dist/client.d.mts +201 -739
  3. package/dist/client.d.ts +201 -739
  4. package/dist/client.js +5 -6
  5. package/dist/client.mjs +5 -6
  6. package/dist/index.d.mts +5 -197
  7. package/dist/index.d.ts +5 -197
  8. package/dist/index.js +1 -2
  9. package/dist/index.mjs +1 -2
  10. package/dist/logger-D3krZrNK.d.mts +0 -14
  11. package/dist/logger-D3krZrNK.d.ts +0 -14
  12. package/dist/server.d.mts +114 -744
  13. package/dist/server.d.ts +114 -744
  14. package/dist/server.js +1 -2
  15. package/dist/server.mjs +1 -2
  16. package/dist/{sse-schema-ChSFm-4q.d.mts → sse-schema-DCxpdETM.d.mts} +1106 -1090
  17. package/dist/{sse-schema-BdUGThiz.d.ts → sse-schema-DoQw8_om.d.ts} +1106 -1090
  18. package/dist/types-CqgYQgbH.d.mts +0 -34
  19. package/dist/types-CqgYQgbH.d.ts +0 -34
  20. package/package.json +9 -10
  21. package/dist/client.js.map +0 -1
  22. package/dist/client.mjs.map +0 -1
  23. package/dist/index.js.map +0 -1
  24. package/dist/index.mjs.map +0 -1
  25. package/dist/server.js.map +0 -1
  26. package/dist/server.mjs.map +0 -1
  27. package/src/client/components/business-day-thumb-overlay.tsx +0 -19
  28. package/src/client/components/daily-report-attachment-indicator.spec.tsx +0 -51
  29. package/src/client/components/daily-report-attachment-indicator.tsx +0 -45
  30. package/src/client/components/daily-report-attachment-list.spec.tsx +0 -94
  31. package/src/client/components/daily-report-attachment-list.tsx +0 -112
  32. package/src/client/components/daily-report-comment-item.tsx +0 -89
  33. package/src/client/components/daily-report-comment-section.tsx +0 -166
  34. package/src/client/components/daily-report-detail-list.tsx +0 -842
  35. package/src/client/components/daily-report-edit-form.tsx +0 -87
  36. package/src/client/components/daily-report-ids-stream-status.spec.tsx +0 -93
  37. package/src/client/components/daily-report-ids-stream-status.tsx +0 -67
  38. package/src/client/components/daily-report-list.tsx +0 -1232
  39. package/src/client/components/daily-report-page.spec.tsx +0 -119
  40. package/src/client/components/daily-report-page.tsx +0 -140
  41. package/src/client/components/daily-report-resize-panels.spec.tsx +0 -307
  42. package/src/client/components/daily-report-resolved-content.tsx +0 -207
  43. package/src/client/components/daily-report-scroll-restoration.spec.tsx +0 -422
  44. package/src/client/components/report-views.spec.tsx +0 -375
  45. package/src/client/components/unread-indicator.tsx +0 -13
  46. package/src/client/config-context.tsx +0 -184
  47. package/src/client/contexts/daily-report-action-context.spec.tsx +0 -433
  48. package/src/client/contexts/daily-report-action-context.tsx +0 -1147
  49. package/src/client/contexts/daily-report-error-context.spec.tsx +0 -66
  50. package/src/client/contexts/daily-report-error-context.tsx +0 -98
  51. package/src/client/hooks/use-animated-number.spec.ts +0 -103
  52. package/src/client/hooks/use-animated-number.ts +0 -69
  53. package/src/client/hooks/use-daily-report-comments.ts +0 -73
  54. package/src/client/hooks/use-daily-report-sse-connection.ts +0 -86
  55. package/src/client/hooks/use-daily-report.spec.ts +0 -546
  56. package/src/client/hooks/use-daily-report.ts +0 -549
  57. package/src/client/hooks/use-dynamic-viewport-height.ts +0 -127
  58. package/src/client/hooks/use-responsive-layout.spec.ts +0 -74
  59. package/src/client/hooks/use-responsive-layout.ts +0 -63
  60. package/src/client/route-helpers.spec.ts +0 -100
  61. package/src/client/route-helpers.ts +0 -61
  62. package/src/client/streaming/daily-report-ids-stream-client.spec.ts +0 -910
  63. package/src/client/streaming/daily-report-ids-stream-client.ts +0 -730
  64. package/src/client/streaming/daily-report-ids-stream-session.spec.ts +0 -401
  65. package/src/client/streaming/daily-report-ids-stream-session.ts +0 -319
  66. package/src/client/ui/button.tsx +0 -42
  67. package/src/client/ui/cn.ts +0 -14
  68. package/src/client/ui/input.tsx +0 -21
  69. package/src/client/ui/label.tsx +0 -16
  70. package/src/client/ui/switch.tsx +0 -19
  71. package/src/client/ui/tabs.tsx +0 -40
  72. package/src/client/ui/textarea.tsx +0 -19
  73. package/src/client/utils/constants.spec.ts +0 -96
  74. package/src/client/utils/constants.ts +0 -84
  75. package/src/client.ts +0 -28
  76. package/src/index.ts +0 -11
  77. package/src/lucide-icons.d.ts +0 -6
  78. package/src/server/authz.spec.ts +0 -57
  79. package/src/server/authz.ts +0 -99
  80. package/src/server/cache.spec.ts +0 -556
  81. package/src/server/cache.ts +0 -303
  82. package/src/server/etag.ts +0 -18
  83. package/src/server/external-source.ts +0 -60
  84. package/src/server/handlers.action.spec.ts +0 -44
  85. package/src/server/handlers.attachment.spec.ts +0 -470
  86. package/src/server/handlers.ids-stream.spec.ts +0 -618
  87. package/src/server/handlers.ts +0 -1638
  88. package/src/server/handlers.unauthorized-cookie.spec.ts +0 -187
  89. package/src/server/handlers.visibility.spec.ts +0 -774
  90. package/src/server/ports.ts +0 -222
  91. package/src/server/response.ts +0 -37
  92. package/src/server/schema.spec.ts +0 -30
  93. package/src/server/schema.ts +0 -344
  94. package/src/server/service.spec.ts +0 -1130
  95. package/src/server/service.ts +0 -2045
  96. package/src/server/sse-reader.spec.ts +0 -302
  97. package/src/server/sse-reader.ts +0 -267
  98. package/src/server/test-helpers/handlers-config.ts +0 -321
  99. package/src/server/transaction-retry.spec.ts +0 -63
  100. package/src/server/visibility.spec.ts +0 -403
  101. package/src/server/visibility.ts +0 -373
  102. package/src/server.spec.ts +0 -160
  103. package/src/server.ts +0 -131
  104. package/src/shared/business-date.spec.ts +0 -82
  105. package/src/shared/business-date.ts +0 -104
  106. package/src/shared/comment-adapter.spec.ts +0 -38
  107. package/src/shared/comment-adapter.ts +0 -80
  108. package/src/shared/ids-stream.spec.ts +0 -154
  109. package/src/shared/ids-stream.ts +0 -279
  110. package/src/shared/logger.ts +0 -47
  111. package/src/shared/sse-schema.spec.ts +0 -50
  112. package/src/shared/sse-schema.ts +0 -198
  113. package/src/shared/text-utils.spec.ts +0 -42
  114. package/src/shared/text-utils.ts +0 -65
  115. package/src/shared/types.ts +0 -109
  116. package/src/styles/standalone.entry.css +0 -51
@@ -1,74 +0,0 @@
1
- /**
2
- * Tests for the shared responsive-layout hooks.
3
- * 共有のレスポンシブ判定フックのテスト。
4
- *
5
- * 閾値は 1 箇所でだけ定義する。各ビューが独自に `matchMedia` を持つと、片方だけ変更されて
6
- * レイアウト分岐が食い違う。
7
- *
8
- * ❗ スクロール操作の可否はここで決めない (画面幅では「主入力がマウスのタッチ対応ノート」を
9
- * 取りこぼす)。ドラッグはポインタ種別ごとに `pointerDragInputs` で制御する。
10
- */
11
- import { act, renderHook } from "@testing-library/react"
12
- import { afterEach, describe, expect, it, vi } from "vitest"
13
- import { MOBILE_LAYOUT_MEDIA_QUERY, useIsMobileLayout } from "./use-responsive-layout"
14
-
15
- /** 購読中のリスナー。`change` を発火させて再評価させるために保持する。 */
16
- type Listener = () => void
17
-
18
- /**
19
- * Installs a `matchMedia` stub whose result is driven by the given query set.
20
- * 指定したクエリ集合で結果が決まる `matchMedia` スタブを差し込む処理。
21
- *
22
- * @param matching Queries that should report a match. 一致させるクエリ群。
23
- * @returns A setter to change the matching set and re-notify. 一致集合を差し替えて再通知するための関数。
24
- */
25
- const stubMatchMedia = (matching: string[]) => {
26
- let current = new Set(matching)
27
- const listeners: Listener[] = []
28
-
29
- vi.stubGlobal("matchMedia", (query: string) => ({
30
- get matches() {
31
- return current.has(query)
32
- },
33
- media: query,
34
- addEventListener: (_type: string, listener: Listener) => listeners.push(listener),
35
- removeEventListener: (_type: string, listener: Listener) => {
36
- const index = listeners.indexOf(listener)
37
- if (index >= 0) listeners.splice(index, 1)
38
- },
39
- }))
40
-
41
- return {
42
- set: (next: string[]) => {
43
- current = new Set(next)
44
- act(() => {
45
- for (const listener of [...listeners]) listener()
46
- })
47
- },
48
- listenerCount: () => listeners.length,
49
- }
50
- }
51
-
52
- afterEach(() => {
53
- vi.unstubAllGlobals()
54
- })
55
-
56
- describe("useIsMobileLayout", () => {
57
- it("ビューポートが閾値以下ならモバイルレイアウトと判定する", () => {
58
- stubMatchMedia([MOBILE_LAYOUT_MEDIA_QUERY])
59
- expect(renderHook(() => useIsMobileLayout()).result.current).toBe(true)
60
- })
61
-
62
- it("閾値を超えるならデスクトップレイアウトと判定する", () => {
63
- stubMatchMedia([])
64
- expect(renderHook(() => useIsMobileLayout()).result.current).toBe(false)
65
- })
66
-
67
- it("リサイズ (change) に追随する", () => {
68
- const media = stubMatchMedia([])
69
- const { result } = renderHook(() => useIsMobileLayout())
70
- expect(result.current).toBe(false)
71
- media.set([MOBILE_LAYOUT_MEDIA_QUERY])
72
- expect(result.current).toBe(true)
73
- })
74
- })
@@ -1,63 +0,0 @@
1
- /**
2
- * Responsive layout detection shared by the daily-report views.
3
- * 日報ビューが共有するレスポンシブ判定。
4
- *
5
- * 閾値を 1 箇所に集約する。各ビューが独自に `matchMedia` を持つと、片方だけ変更されて
6
- * レイアウト分岐が食い違う。
7
- *
8
- * ❗ **スクロール操作の可否をここで決めてはならない。** 画面幅で判定すると
9
- * 「主入力がマウスのタッチ対応ノート」のような端末を取りこぼす。ドラッグスクロールは
10
- * `ScrollPane` の `pointerDragInputs` で**イベントのポインタ種別ごとに**制御する
11
- * (`CONTENT_DRAG_POINTER_INPUTS` 参照)。
12
- */
13
- import { useSyncExternalStore } from "react"
14
-
15
- /**
16
- * Viewport width at which the daily-report views switch to the mobile layout.
17
- * 日報ビューがモバイルレイアウトへ切り替わるビューポート幅。
18
- *
19
- * Tailwind の `sm` (640px) の直下に合わせてある。リスト + サイドペインの 2 カラムを
20
- * 畳んでオーバーレイ表示にする閾値であり、**この値は 1 箇所でだけ定義する**。
21
- */
22
- export const MOBILE_LAYOUT_MEDIA_QUERY = "(max-width: 639px)"
23
-
24
- /**
25
- * Subscribes to media query changes.
26
- * メディアクエリの変更通知を購読する処理。
27
- *
28
- * @param callback - Function invoked on media query change. 変更時に呼び出されるコールバック。
29
- * @returns Cleanup function to remove event listener. イベントリスナーを解除するクリーンアップ関数。
30
- */
31
- const subscribe = (callback: () => void): (() => void) => {
32
- if (typeof window === "undefined" || typeof window.matchMedia !== "function") return () => {}
33
- const query = window.matchMedia(MOBILE_LAYOUT_MEDIA_QUERY)
34
- query.addEventListener("change", callback)
35
- return () => query.removeEventListener("change", callback)
36
- }
37
-
38
- /**
39
- * Reads the current matching state of the media query on the client.
40
- * クライアント環境における現在のメディアクエリ適合状態を取得する処理。
41
- *
42
- * @returns True if current viewport matches mobile layout. モバイル幅に適合している場合は true。
43
- */
44
- const getSnapshot = (): boolean => (typeof window !== "undefined" && typeof window.matchMedia === "function" ? window.matchMedia(MOBILE_LAYOUT_MEDIA_QUERY).matches : false)
45
-
46
- /**
47
- * Returns the fallback state for server-side rendering.
48
- * サーバーサイドレンダリング時のフォールバック状態を取得する処理。
49
- *
50
- * @returns False on server environment. サーバー環境では false。
51
- */
52
- const getServerSnapshot = (): boolean => false
53
-
54
- /**
55
- * Reports whether the viewport is narrow enough for the mobile layout.
56
- * ビューポートがモバイルレイアウトの幅かどうかを返す処理。
57
- *
58
- * Synchronizes with window.matchMedia via useSyncExternalStore without hydration delay.
59
- * useSyncExternalStore を介してハイドレーション遅延なく window.matchMedia と同期する。
60
- *
61
- * @returns True on the mobile layout. モバイルレイアウトなら true。
62
- */
63
- export const useIsMobileLayout = (): boolean => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot)
@@ -1,100 +0,0 @@
1
- /**
2
- * Bootstrap-ordering tests for the daily-report clientLoader factory.
3
- * 日報 clientLoader 工場の起動順序テスト。
4
- *
5
- * ここで固定する不変条件のうち、特に重要なもの:
6
- *
7
- * - **prime は serverLoader の解決を待たずに先行する** (再訪の再検証前倒し)。
8
- * - **ローダー時点でセッションを bootstrap する** (コールドロードの最重要最適化 —
9
- * ページマウントの effect まで生成を遅らせると、ストリーム開始がハイドレーション
10
- * 完了の後ろに直列化される)。
11
- * - **`hydrate = true`** (初期ハイドレーションでも実行される契約)。
12
- */
13
- import { describe, expect, it, vi } from "vitest"
14
-
15
- const calls: string[] = []
16
- const bootstrapMock = vi.fn((options: { apiBasePath?: string; userKey: string | null }) => {
17
- calls.push(`bootstrap:${options.userKey}`)
18
- })
19
- const primeMock = vi.fn(() => {
20
- calls.push("prime")
21
- })
22
-
23
- vi.mock("./streaming/daily-report-ids-stream-session", () => ({
24
- bootstrapDailyReportIdsStreamSession: (options: { apiBasePath?: string; userKey: string | null }) => bootstrapMock(options),
25
- primeDailyReportIdsStreamSession: () => primeMock(),
26
- }))
27
-
28
- import { createDailyReportClientLoader, dailyReportShouldRevalidate } from "./route-helpers"
29
-
30
- describe("createDailyReportClientLoader", () => {
31
- it("prime → serverLoader → bootstrap(userKey) の順で起動し、serverData を素通しする", async () => {
32
- calls.length = 0
33
- const clientLoader = createDailyReportClientLoader<{ userId: string | null; extra: number }>()
34
- const serverLoader = vi.fn(async () => {
35
- calls.push("serverLoader")
36
- return { userId: "ENC8", extra: 42 }
37
- })
38
-
39
- const result = await clientLoader({ serverLoader })
40
-
41
- expect(calls).toEqual(["prime", "serverLoader", "bootstrap:ENC8"])
42
- expect(result).toEqual({ userId: "ENC8", extra: 42 })
43
- })
44
-
45
- it("userId が文字列でない serverData は userKey null で起動する", async () => {
46
- bootstrapMock.mockClear()
47
- const clientLoader = createDailyReportClientLoader()
48
- await clientLoader({ serverLoader: async () => ({ userId: null }) })
49
- expect(bootstrapMock).toHaveBeenCalledWith({ apiBasePath: undefined, userKey: null })
50
-
51
- await clientLoader({ serverLoader: async () => ({}) })
52
- expect(bootstrapMock).toHaveBeenLastCalledWith({ apiBasePath: undefined, userKey: null })
53
- })
54
-
55
- it("factory の apiBasePath オプションは bootstrap へ透過する", async () => {
56
- bootstrapMock.mockClear()
57
- const clientLoader = createDailyReportClientLoader({ apiBasePath: "/custom/api" })
58
- await clientLoader({ serverLoader: async () => ({ userId: "ENC9" }) })
59
- expect(bootstrapMock).toHaveBeenCalledWith({ apiBasePath: "/custom/api", userKey: "ENC9" })
60
- })
61
-
62
- it("hydrate フラグが立っている (初期ハイドレーションでも実行される契約)", () => {
63
- const clientLoader = createDailyReportClientLoader()
64
- expect(clientLoader.hydrate).toBe(true)
65
- })
66
- })
67
-
68
- describe("dailyReportShouldRevalidate", () => {
69
- /** 最小限の引数組み立て。 */
70
- const makeArgs = (over: Record<string, unknown> = {}) =>
71
- ({
72
- defaultShouldRevalidate: true,
73
- currentUrl: new URL("http://localhost/daily_report"),
74
- nextUrl: new URL("http://localhost/daily_report"),
75
- actionResult: undefined,
76
- actionStatus: undefined,
77
- formAction: undefined,
78
- formData: undefined,
79
- formEncType: undefined,
80
- formMethod: undefined,
81
- json: undefined,
82
- text: undefined,
83
- ...over,
84
- // biome-ignore lint/suspicious/noExplicitAny: ShouldRevalidateFunctionArgs の完全構築はテストに不要
85
- }) as any
86
-
87
- it("同一 URL かつ送信シグナル無しは再検証しない", () => {
88
- expect(dailyReportShouldRevalidate(makeArgs())).toBe(false)
89
- })
90
-
91
- it("URL が変われば既定に従う", () => {
92
- expect(dailyReportShouldRevalidate(makeArgs({ nextUrl: new URL("http://localhost/daily_report?businessDate=2026-08-01") }))).toBe(true)
93
- })
94
-
95
- it("ミューテーション intent は再検証しない (SSE が伝搬を担う)", () => {
96
- const formData = new FormData()
97
- formData.set("intent", "toggleRead")
98
- expect(dailyReportShouldRevalidate(makeArgs({ formData }))).toBe(false)
99
- })
100
- })
@@ -1,61 +0,0 @@
1
- /**
2
- * React Router route helpers for the daily-report page (revalidation policy / client loader).
3
- * 日報ページ向け React Router ルートヘルパー (再検証ポリシー / クライアントローダー)。
4
- */
5
- import type { ShouldRevalidateFunction, ShouldRevalidateFunctionArgs } from "react-router"
6
- import { bootstrapDailyReportIdsStreamSession, primeDailyReportIdsStreamSession } from "./streaming/daily-report-ids-stream-session"
7
-
8
- /**
9
- * Prevents loader revalidation when POP navigations keep identical URL state.
10
- * URL 状態が同一の POP ナビゲーション時にローダー再検証を抑止。
11
- */
12
- export const dailyReportShouldRevalidate: ShouldRevalidateFunction = ({ actionResult, actionStatus, currentUrl, defaultShouldRevalidate, formAction, formData, formEncType, formMethod, json, nextUrl, text }: ShouldRevalidateFunctionArgs) => {
13
- if (!defaultShouldRevalidate) {
14
- return false
15
- }
16
-
17
- const isSameUrl = currentUrl.pathname === nextUrl.pathname && currentUrl.search === nextUrl.search && currentUrl.hash === nextUrl.hash
18
- if (!isSameUrl) {
19
- return defaultShouldRevalidate
20
- }
21
-
22
- if (formData) {
23
- const intent = formData.get("intent")
24
- if (intent === "toggleRead" || intent === "toggleStar" || intent === "addComment" || intent === "deleteComment" || intent === "create" || intent === "update" || intent === "publish" || intent === "delete") {
25
- return false
26
- }
27
- }
28
-
29
- const hasSubmission = actionResult !== undefined || actionStatus !== undefined || formAction !== undefined || formData !== undefined || formEncType !== undefined || formMethod !== undefined || json !== undefined || text !== undefined
30
- return hasSubmission ? defaultShouldRevalidate : false
31
- }
32
-
33
- /**
34
- * Creates a React Router clientLoader that bootstraps the ids stream session.
35
- * ID ストリームセッションを起動する React Router clientLoader を生成する処理。
36
- *
37
- * ID 一覧は Promise で返さず、モジュール常駐のストリームセッションが供給する
38
- * (ページ側は `useDailyReportIdsStream` で購読する)。ローダー時点でセッションを
39
- * 生成することが**コールドロードの最重要最適化** — ページマウントの effect まで
40
- * 遅らせると、ストリームの開始が「ハイドレーション完了 + effect flush」の後ろに
41
- * 直列化される。再訪 (セッション既存) は serverLoader を待たずに鮮度確認を先行させる。
42
- *
43
- * `config.apiBasePath` を上書きするアプリは同じ値を `options.apiBasePath` にも渡すこと
44
- * (渡し忘れは初回 1 回だけ誤パス生成 → ページマウントの ensure が自己修復する)。
45
- *
46
- * 返す関数へ `hydrate = true as const` を付与済み (初期ハイドレーションでも実行される)。
47
- */
48
- export const createDailyReportClientLoader = <TServerData extends Record<string, unknown>>(options?: { apiBasePath?: string }) => {
49
- const clientLoader = async (args: { serverLoader: () => Promise<unknown> }): Promise<TServerData> => {
50
- // 再訪の主経路: 既存セッションの鮮度確認を serverLoader より先に始める
51
- primeDailyReportIdsStreamSession()
52
- const serverData = (await args.serverLoader()) as TServerData
53
- // 不在なら生成 (コールドロードでハイドレーションと並行してフェッチを開始)、
54
- // 既存なら userKey 照合 (別ユーザーは描画前に破棄・再生成) + 鮮度確認
55
- const rawUserId = (serverData as { userId?: unknown }).userId
56
- bootstrapDailyReportIdsStreamSession({ apiBasePath: options?.apiBasePath, userKey: typeof rawUserId === "string" ? rawUserId : null })
57
- return serverData
58
- }
59
- clientLoader.hydrate = true as const
60
- return clientLoader
61
- }