| 1 | import { StoredOrchestrationShellSnapshot } from "@t3tools/client-runtime/platform"; |
| 2 | import { deferPullRequests, detachPullRequests } from "@t3tools/client-runtime/state/shell"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Predicate from "effect/Predicate"; |
| 5 | import * as Schema from "effect/Schema"; |
| 6 | |
| 7 | const decodeJson = Schema.decodeUnknownEffect(Schema.fromJsonString(Schema.Unknown)); |
| 8 | const decodeStoredShell = Schema.decodeUnknownEffect(StoredOrchestrationShellSnapshot); |
| 9 | |
| 10 | /** |
| 11 | * Decode the shell cache payload with each thread's pull request links left out, so the |
| 12 | * thread list can paint first; `loadPullRequests` decodes the links afterwards. |
| 13 | */ |
| 14 | export const decodeStoredShellSnapshot = Effect.fnUntraced(function* (raw: string) { |
| 15 | const parsed = yield* decodeJson(raw); |
| 16 | const rawLinks = Predicate.isObject(parsed) ? detachPullRequests(parsed.snapshot) : []; |
| 17 | const stored = yield* decodeStoredShell(parsed); |
| 18 | return { ...stored, snapshot: deferPullRequests(stored.snapshot, rawLinks) }; |
| 19 | }); |