import { IApp , IAppsStorage , IConfiguration } from "@staticdeploy/core" ; import { defaults , find , toArray } from "lodash" ; import cloneMethodsIO from "./common/cloneMethodsIO" ; import convertErrors from "./common/convertErrors" ; import { ICollection } from "./common/ICollection" ; @ cloneMethodsIO @ convertErrors export default class AppsStorage implements IAppsStorage { constructor ( private apps ) { } async findOne ( id ) { return this . apps [ id ] || null ; } async findOneByName ( name ) { return find ( this . apps , { name } ) || null ; } async findMany ( ) { return toArray ( this . apps ) ; } async oneExistsWithId ( id ) { return ! ! this . apps [ id ] ; } async oneExistsWithName ( name ) { return ! ! find ( this . apps , { name } ) ; } async createOne ( toBeCreatedApp ) { this . apps [ toBeCreatedApp . id ] = toBeCreatedApp ; return toBeCreatedApp ; } async updateOne ( id , patch ) { this . apps [ id ] = { ... this . apps [ id ] , ... defaults ( patch , this . apps [ id ] ) , } ; return this . apps [ id ] ; } async deleteOne ( id ) { delete this . apps [ id ] ; } }