File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed
Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ import {
3636 saveComponent ,
3737 type UserComponent ,
3838} from "@/utils/localforage" ;
39+ import { componentSpecFromYaml } from "@/utils/yaml" ;
3940
4041export interface ExistingAndNewComponent {
4142 existingComponent : UserComponent | undefined ;
@@ -445,7 +446,7 @@ async function hydrateFromPartialContentfulComponentReference(
445446 : component . text ;
446447
447448 const spec = isTextOnlyComponentReference ( component )
448- ? ( yaml . load ( component . text ) as ComponentSpec )
449+ ? componentSpecFromYaml ( component . text )
449450 : component . spec ;
450451
451452 if ( ! text || ! spec ) {
Original file line number Diff line number Diff line change 1- import type { ComponentSpec } from "./componentSpec" ;
1+ import yaml from "js-yaml" ;
2+
3+ import { type ComponentSpec , isValidComponentSpec } from "./componentSpec" ;
24import { componentSpecToText } from "./componentStore" ;
35
46const copyToYaml = (
@@ -14,4 +16,16 @@ const copyToYaml = (
1416 ) ;
1517} ;
1618
19+ export function componentSpecFromYaml ( yamlText : string ) : ComponentSpec {
20+ const loadedSpec = yaml . load ( yamlText ) ;
21+ if ( typeof loadedSpec !== "object" || loadedSpec === null ) {
22+ throw new Error ( "Invalid component specification format" ) ;
23+ }
24+ if ( ! isValidComponentSpec ( loadedSpec ) ) {
25+ throw new Error ( "Invalid component specification format" ) ;
26+ }
27+
28+ return loadedSpec ;
29+ }
30+
1731export default copyToYaml ;
You can’t perform that action at this time.
0 commit comments