hidden packageDocumentation import { IStorage } from "@inrupt/solid-client-authn-core" ; import { existsSync , writeFileSync , readFileSync , promises } from "fs" ; hidden export class FileSystemStorage implements IStorage { private map : Record < string , string > = { } ; constructor ( private path ) { if ( ! existsSync ( path ) ) { writeFileSync ( path , "{}" , { encoding : "utf-8" , } ) ; } try { this . map = JSON . parse ( readFileSync ( path , { encoding : "utf-8" , } ) ) ; } catch ( e ) { throw new Error ( `An error happened while parsing JSON content of [${ path }]: ${ e }` ) ; } } get = async ( key ) : Promise < string | undefined > => this . map [ key ] || undefined ; set = async ( key , value ) : Promise < void > => { this . map [ key ] = value ; return promises . writeFile ( this . path , JSON . stringify ( this . map , null , "  " ) , { encoding : "utf-8" , } ) ; } ; delete = async ( key ) : Promise < void > => { delete this . map [ key ] ; return promises . writeFile ( this . path , JSON . stringify ( this . map , null , "  " ) , { encoding : "utf-8" , } ) ; } ; }