import path from "path" ; import { Awaitable , Storage , StorageFactory } from "@miniflare/shared" ; export class PluginStorageFactory implements StorageFactory { private readonly pluginName : string ; constructor ( private readonly inner , pluginName , private readonly defaultPersistRoot = ".mf" ) { this . pluginName = pluginName . substring ( 0 , pluginName . length - 6 ) . toLowerCase ( ) ; } storage ( namespace , persist ? ) { if ( persist === undefined || persist === false ) { return this . inner . storage ( `${ this . pluginName }:` + namespace ) ; } else if ( persist === true ) { return this . inner . storage ( namespace , path . join ( this . defaultPersistRoot , this . pluginName ) ) ; } else { return this . inner . storage ( namespace , persist ) ; } } dispose ( ) { return this . inner . dispose ?. ( ) ; } }