import { DefaultState , useState , versionControl } from "~/State" ; import { useCharacters } from "~/composables/Characters" ; import Ajv from "ajv" ; import apiSchema from "~/utils/ApiSchema.json" ; type ImportData = Partial < typeof DefaultState > ; const ajv = new Ajv ( ) ; export const validateImportData = ajv . compile < ImportData > ( apiSchema ) ; export function updateStateFromImportData ( data ) { const state = useState ( ) ; const { createCharactersFromData } = useCharacters ( ) ; for ( const [ key , value ] of Object . entries ( data ) ) { state . value [ key as keyof typeof DefaultState ] = value as any ; if ( key === "chars" ) { createCharactersFromData ( state . value . chars ) ; } } state . value . version = "0.2.0" ; versionControl ( ) ; }