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