import { hashContent } from "@joincivil/utils" ; import { MapObject , StorageHeader } from "@joincivil/typescript-types" ; import { ContentProvider } from "./contentprovider" ; export class InMemoryProvider implements ContentProvider { private data : MapObject < string > = { } ; public scheme ( ) { return "memory" ; } public async get ( what ) { const uri = what . uri ; if ( this . data . uri === undefined ) { throw new Error ( "No such URI (" + uri + ") found in InMemoryProvider" ) ; } return this . data [ uri ] ; } public async put ( content ) { const contentHash = hashContent ( content ) ; const uri = this . scheme ( ) + "://" + contentHash ; this . data [ uri ] = content ; return { uri , contentHash } ; } }