(raw)
| 576 | } |
| 577 | |
| 578 | function normalizeState(raw) { |
| 579 | if (!raw || typeof raw !== "object") { |
| 580 | return createInitialState(); |
| 581 | } |
| 582 | const fallback = createInitialState(); |
| 583 | const templatePackId = safeString(raw.templatePackId, fallback.templatePackId); |
| 584 | const normalizedTemplatePackId = TEMPLATE_PACKS[templatePackId] ? templatePackId : fallback.templatePackId; |
| 585 | return { |
| 586 | sections: Array.isArray(raw.sections) ? raw.sections : fallback.sections, |
| 587 | templatePackId: normalizedTemplatePackId, |
| 588 | fieldSuggestions: raw.fieldSuggestions && typeof raw.fieldSuggestions === "object" ? raw.fieldSuggestions : fallback.fieldSuggestions, |
| 589 | sectionSchemas: raw.sectionSchemas && typeof raw.sectionSchemas === "object" ? raw.sectionSchemas : fallback.sectionSchemas, |
| 590 | changeLog: Array.isArray(raw.changeLog) ? raw.changeLog : [], |
| 591 | contentProposals: Array.isArray(raw.contentProposals) ? raw.contentProposals : [], |
| 592 | milestones: Array.isArray(raw.milestones) ? raw.milestones : [], |
| 593 | theme: raw.theme && typeof raw.theme === "object" ? raw.theme : fallback.theme, |
| 594 | branch: safeString(raw.branch, fallback.branch), |
| 595 | lastUpdated: safeString(raw.lastUpdated, fallback.lastUpdated), |
| 596 | }; |
| 597 | } |
| 598 | |
| 599 | async function loadState() { |
| 600 | if (stateLoaded) { |
no test coverage detected