(
content: string,
options: WorksetPathOptions = {}
)
| 166 | } |
| 167 | |
| 168 | export function parseWorksetsState( |
| 169 | content: string, |
| 170 | options: WorksetPathOptions = {} |
| 171 | ): WorksetsState { |
| 172 | let raw: unknown; |
| 173 | try { |
| 174 | raw = parseYaml(content); |
| 175 | } catch (error) { |
| 176 | const message = error instanceof Error ? error.message : String(error); |
| 177 | throw invalidWorksetsFileError(message, options); |
| 178 | } |
| 179 | |
| 180 | const result = WorksetsStateSchema.safeParse(raw); |
| 181 | if (!result.success) { |
| 182 | throw invalidWorksetsFileError(formatZodIssues(result.error), options); |
| 183 | } |
| 184 | |
| 185 | for (const [name, entry] of Object.entries(result.data.worksets)) { |
| 186 | if (!isKebabId(name)) { |
| 187 | throw invalidWorksetsFileError( |
| 188 | `workset name '${name}' ${KEBAB_ID_DESCRIPTION}`, |
| 189 | options |
| 190 | ); |
| 191 | } |
| 192 | |
| 193 | const problem = memberListProblem(entry.members); |
| 194 | if (problem !== null) { |
| 195 | throw invalidWorksetsFileError(`workset '${name}': ${problem}`, options); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | return result.data; |
| 200 | } |
| 201 | |
| 202 | export function serializeWorksetsState( |
| 203 | state: WorksetsState, |
no test coverage detected