* Stable stringify for dirty-detection. * * Sort keys so object equality is positional-independent. Drop * `lastAccessedAt` — we update it on every read, so including it * would make every getSession() look dirty and defeat the * "only flush real mutations" invariant.
(value: unknown)
| 140 | * "only flush real mutations" invariant. |
| 141 | */ |
| 142 | function stableStringify(value: unknown): string { |
| 143 | return JSON.stringify(value, (k, v) => { |
| 144 | if (k === 'lastAccessedAt') return undefined; |
| 145 | if (v && typeof v === 'object' && !Array.isArray(v)) { |
| 146 | const sorted: Record<string, unknown> = {}; |
| 147 | for (const key of Object.keys(v as Record<string, unknown>).sort()) { |
| 148 | if (key === 'lastAccessedAt') continue; |
| 149 | sorted[key] = (v as Record<string, unknown>)[key]; |
| 150 | } |
| 151 | return sorted; |
| 152 | } |
| 153 | return v; |
| 154 | }); |
| 155 | } |
| 156 | |
| 157 | // ── Session shape helpers ──────────────────────────────────────── |
| 158 |
no outgoing calls
no test coverage detected