import { Actions} from '../actions'; import * as serialize from "../serialize" import { Storage } from "./storage" export class MemoryStorage implements Storage{ storage: Array //@ts-ignore remote: Storage pubKey: string constructor(pubKey: string){ this.storage = [] this.pubKey = pubKey; } async put(action: Actions): Promise { if(action.__origin === ""){ action.__origin = this.pubKey; } this.storage.push(serialize.actionToJSON(action)) return } async get(): Promise> { return this.storage.map(serialize.actionFromJSON); } origin():string{ return this.pubKey } async clear():Promise { this.storage = [] } async flush(): Promise { return; } async addRemote(remoteStorage: Storage){ this.remote = remoteStorage; } // appKey and pubKey are nops in this and assumes user has added a remote storage for in memory purposes async getForeign(_appKey:string, _pubKey:string): Promise> { return this.remote.get() } }