@hearthlog/runtime 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +235 -0
  2. package/package.json +51 -3
  3. package/src/access/session.ts +223 -0
  4. package/src/access/user-session.ts +61 -0
  5. package/src/ai/decisions.ts +89 -0
  6. package/src/calendar/draft.ts +84 -0
  7. package/src/calendar/feeds.ts +91 -0
  8. package/src/calendar/groups.ts +198 -0
  9. package/src/calendar/logic.ts +141 -0
  10. package/src/calendar/preferences.ts +40 -0
  11. package/src/calendar/weeks.ts +56 -0
  12. package/src/commands/index.ts +184 -0
  13. package/src/commands/local-commit.ts +214 -0
  14. package/src/commands/standard.ts +8 -0
  15. package/src/commands/validation.ts +206 -0
  16. package/src/db/bootstrap.ts +72 -0
  17. package/src/db/calendar.ts +638 -0
  18. package/src/db/dynamic-ddl.ts +127 -0
  19. package/src/db/entities.ts +208 -0
  20. package/src/db/history.ts +194 -0
  21. package/src/db/index.ts +1240 -0
  22. package/src/db/kv.ts +33 -0
  23. package/src/db/local-statistics.ts +106 -0
  24. package/src/db/module-projections.ts +46 -0
  25. package/src/db/raw-browser.ts +361 -0
  26. package/src/db/read-repositories.ts +29 -0
  27. package/src/db/read-session.ts +47 -0
  28. package/src/db/schema-version.ts +76 -0
  29. package/src/db/session-context.ts +33 -0
  30. package/src/event/code-export.ts +65 -0
  31. package/src/event/dynamic-entities.ts +503 -0
  32. package/src/event/dynamic-materializer.ts +288 -0
  33. package/src/event/handlers.ts +490 -0
  34. package/src/event/index.ts +53 -0
  35. package/src/event/meta-entity-types.ts +165 -0
  36. package/src/event/projection-builder.ts +384 -0
  37. package/src/event/queries.ts +126 -0
  38. package/src/event/rebuild.ts +176 -0
  39. package/src/event/reference-lookup.ts +93 -0
  40. package/src/event/registry.ts +158 -0
  41. package/src/event/schema-effects.ts +45 -0
  42. package/src/event/types.ts +20 -0
  43. package/src/history/action-boundary.ts +18 -0
  44. package/src/history/action-detail.ts +23 -0
  45. package/src/history/change-comparison.ts +29 -0
  46. package/src/history/change-display.ts +41 -0
  47. package/src/history/contracts.ts +63 -0
  48. package/src/history/history.ts +372 -0
  49. package/src/history/legacy-replay.ts +69 -0
  50. package/src/history/legacy-url.ts +9 -0
  51. package/src/history/lineage.ts +123 -0
  52. package/src/history/log-format.ts +17 -0
  53. package/src/history/log-map.ts +110 -0
  54. package/src/history/navigation.ts +14 -0
  55. package/src/history/point-snapshot.ts +229 -0
  56. package/src/history/timeline.ts +215 -0
  57. package/src/history/url.ts +18 -0
  58. package/src/ledger/README.md +118 -0
  59. package/src/ledger/admin-client.ts +616 -0
  60. package/src/ledger/client.ts +10 -0
  61. package/src/ledger/config.ts +117 -0
  62. package/src/ledger/entity-id.ts +115 -0
  63. package/src/ledger/errors.ts +144 -0
  64. package/src/ledger/http-client.ts +590 -0
  65. package/src/ledger/index.ts +67 -0
  66. package/src/ledger/socket.ts +400 -0
  67. package/src/ledger/types.ts +202 -0
  68. package/src/ledger/version-tracker-singleton.ts +12 -0
  69. package/src/ledger/version-tracker.ts +259 -0
  70. package/src/log-management.ts +123 -0
  71. package/src/log-validation.ts +19 -0
  72. package/src/native/reminders.ts +2 -0
  73. package/src/native/shell.svelte.ts +136 -0
  74. package/src/native/shell.ts +102 -0
  75. package/src/pwa/registration.ts +169 -0
  76. package/src/recovery/local-recovery.ts +59 -0
  77. package/src/recovery/reset-sequence.ts +13 -0
  78. package/src/runtime/clock.ts +43 -0
  79. package/src/runtime/kept-page-data.svelte.ts +42 -0
  80. package/src/runtime/page-data.svelte.ts +160 -0
  81. package/src/runtime/phone-header.svelte.ts +17 -0
  82. package/src/runtime/read-coordinator.ts +103 -0
  83. package/src/runtime/refresh.ts +15 -0
  84. package/src/runtime/start-page.ts +56 -0
  85. package/src/runtime/view.ts +83 -0
  86. package/src/runtime/workspace.ts +62 -0
  87. package/src/storage/indexeddb-statistics.ts +153 -0
  88. package/src/store/attention.svelte.ts +51 -0
  89. package/src/store/conflict-merge.ts +169 -0
  90. package/src/store/entity-sync-state.svelte.ts +36 -0
  91. package/src/store/event-log.svelte.ts +109 -0
  92. package/src/store/events.svelte.ts +14 -0
  93. package/src/store/local-context.ts +93 -0
  94. package/src/store/local-store.svelte.ts +58 -0
  95. package/src/store/log-version.svelte.ts +35 -0
  96. package/src/store/logs.svelte.ts +60 -0
  97. package/src/store/moved.svelte.ts +43 -0
  98. package/src/store/offline-readiness.svelte.ts +188 -0
  99. package/src/store/outbox-request.ts +61 -0
  100. package/src/store/outbox.ts +426 -0
  101. package/src/store/pending-work-transfer.ts +49 -0
  102. package/src/store/pending-work.ts +143 -0
  103. package/src/store/sync-coordinator.ts +170 -0
  104. package/src/store/sync-invalidation.ts +10 -0
  105. package/src/store/sync-issues.ts +406 -0
  106. package/src/store/sync-progress.ts +54 -0
  107. package/src/store/sync-state.ts +127 -0
  108. package/src/store/sync.svelte.ts +1010 -0
  109. package/src/store/tab-coordination.ts +164 -0
  110. package/src/testing/e2e-seed.ts +40 -0
  111. package/src/testing/local-database.ts +120 -0
  112. package/src/testing/projection-database.ts +105 -0
  113. package/src/testing/test-entities.ts +28 -0
  114. package/src/theme/appearance.svelte.ts +111 -0
  115. package/src/utils/address.ts +5 -0
  116. package/src/utils/async.ts +30 -0
  117. package/src/utils/long-press.ts +70 -0
  118. package/src/utils/perf-dataset.ts +405 -0
  119. package/src/utils/perf.ts +627 -0
  120. package/README.md +0 -3
@@ -0,0 +1,127 @@
1
+ import type { LocalStorePhase } from './local-store.svelte.js';
2
+
3
+ export type SyncPhase =
4
+ | 'offline'
5
+ | 'idle'
6
+ | 'syncing'
7
+ | 'pending'
8
+ | 'blocked'
9
+ | 'waiting'
10
+ | 'error'
11
+ | 'synced';
12
+
13
+ export interface SyncStateInput {
14
+ isOnline: boolean;
15
+ isSyncing: boolean;
16
+ hasCompletedSync: boolean;
17
+ hasError: boolean;
18
+ waitingForLedger?: boolean;
19
+ pendingUploads: number;
20
+ needsAttention: number;
21
+ }
22
+
23
+ export interface SyncPresentation {
24
+ label: string;
25
+ description: string;
26
+ tone: 'neutral' | 'success' | 'warning' | 'danger';
27
+ }
28
+
29
+ export function deriveSyncPhase(input: SyncStateInput): SyncPhase {
30
+ if (!input.isOnline) return 'offline';
31
+ if (input.needsAttention > 0) return 'blocked';
32
+ if (input.hasError && input.waitingForLedger) return 'waiting';
33
+ if (input.hasError) return 'error';
34
+ if (input.isSyncing) return 'syncing';
35
+ if (input.pendingUploads > 0) return 'pending';
36
+ if (input.hasCompletedSync) return 'synced';
37
+ return 'idle';
38
+ }
39
+
40
+ export function describeAppDataState(input: {
41
+ localStorePhase: LocalStorePhase;
42
+ syncPhase: SyncPhase;
43
+ pendingUploads: number;
44
+ needsAttention: number;
45
+ lastSyncedAt: Date | null;
46
+ syncErrorMessage?: string | null;
47
+ localStoreErrorMessage?: string | null;
48
+ }): SyncPresentation {
49
+ if (input.localStorePhase === 'booting') {
50
+ return {
51
+ label: 'Preparing local data',
52
+ description: 'Checking the local database',
53
+ tone: 'neutral',
54
+ };
55
+ }
56
+ if (input.localStorePhase === 'failed') {
57
+ return {
58
+ label: 'Local data unavailable',
59
+ description: input.localStoreErrorMessage || 'The local database could not be opened',
60
+ tone: 'danger',
61
+ };
62
+ }
63
+ if (input.localStorePhase === 'degraded') {
64
+ return {
65
+ label: 'Local data limited',
66
+ description: input.localStoreErrorMessage || 'No event log is selected',
67
+ tone: 'warning',
68
+ };
69
+ }
70
+
71
+ switch (input.syncPhase) {
72
+ case 'offline':
73
+ return {
74
+ label: 'Offline',
75
+ description: 'Changes stay on this device',
76
+ tone: 'warning',
77
+ };
78
+ case 'blocked':
79
+ return {
80
+ label: `${input.needsAttention} need attention`,
81
+ description: 'Some local changes could not sync',
82
+ tone: 'danger',
83
+ };
84
+ case 'waiting':
85
+ return {
86
+ label: input.pendingUploads > 0 ? 'Waiting to upload' : 'Ledger unreachable',
87
+ description: 'Changes stay on this device and sync when Ledger responds',
88
+ tone: 'warning',
89
+ };
90
+ case 'error':
91
+ return {
92
+ label: 'Sync error',
93
+ description: input.syncErrorMessage || 'Ledger could not be reached',
94
+ tone: 'danger',
95
+ };
96
+ case 'syncing':
97
+ return {
98
+ label: 'Syncing',
99
+ description: input.pendingUploads > 0
100
+ ? `Uploading ${input.pendingUploads} local ${input.pendingUploads === 1 ? 'change' : 'changes'}`
101
+ : 'Checking Ledger for changes',
102
+ tone: 'neutral',
103
+ };
104
+ case 'pending':
105
+ return {
106
+ label: `${input.pendingUploads} pending`,
107
+ description: 'Local changes are waiting to upload',
108
+ tone: 'warning',
109
+ };
110
+ case 'synced':
111
+ return {
112
+ label: 'Synced',
113
+ description: input.lastSyncedAt
114
+ ? `Updated ${input.lastSyncedAt.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}`
115
+ : 'Ledger is up to date',
116
+ tone: 'success',
117
+ };
118
+ case 'idle':
119
+ default:
120
+ return {
121
+ label: 'Not synced yet',
122
+ description: 'Waiting for the first Ledger check',
123
+ tone: 'neutral',
124
+ };
125
+ }
126
+ }
127
+