(raw: string)
| 92 | }; |
| 93 | |
| 94 | export const parseCliServerConnectionStore = (raw: string): CliServerConnectionStore => { |
| 95 | const decoded = decodeStoreJson(raw); |
| 96 | if (Option.isNone(decoded)) return emptyCliServerConnectionStore; |
| 97 | const record = decoded.value; |
| 98 | |
| 99 | const profiles = record.profiles.flatMap((value): readonly CliServerConnectionProfile[] => { |
| 100 | const connection = decodeConnection(value.connection); |
| 101 | if (!connection) return []; |
| 102 | try { |
| 103 | return [{ name: validateCliServerConnectionProfileName(value.name), connection }]; |
| 104 | } catch { |
| 105 | return []; |
| 106 | } |
| 107 | }); |
| 108 | |
| 109 | const defaultProfile = |
| 110 | record.defaultProfile && profiles.some((profile) => profile.name === record.defaultProfile) |
| 111 | ? record.defaultProfile |
| 112 | : null; |
| 113 | |
| 114 | return { |
| 115 | version: 1, |
| 116 | defaultProfile, |
| 117 | profiles, |
| 118 | }; |
| 119 | }; |
| 120 | |
| 121 | const serializeCliServerConnectionStore = (store: CliServerConnectionStore): string => |
| 122 | `${JSON.stringify(store, null, 2)}\n`; |
no test coverage detected