import { IConfiguration , IEntrypoint , IEntrypointsStorage , } from "@staticdeploy/core" ; import { defaults , filter , find } from "lodash" ; import cloneMethodsIO from "./common/cloneMethodsIO" ; import convertErrors from "./common/convertErrors" ; import { ICollection } from "./common/ICollection" ; @ cloneMethodsIO @ convertErrors export default class EntrypointsStorage implements IEntrypointsStorage { constructor ( private entrypoints ) { } async findOne ( id ) { return this . entrypoints [ id ] || null ; } async findOneByUrlMatcher ( urlMatcher ) { return find ( this . entrypoints , { urlMatcher } ) || null ; } async findManyByAppId ( appId ) { return filter ( this . entrypoints , { appId } ) ; } async findManyByUrlMatcherHostname ( urlMatcherHostname ) { return filter ( this . entrypoints , ( entrypoint ) => entrypoint . urlMatcher . startsWith ( urlMatcherHostname ) ) ; } async oneExistsWithUrlMatcher ( urlMatcher ) { return ! ! find ( this . entrypoints , { urlMatcher } ) ; } async anyExistsWithAppId ( appId ) { return ! ! find ( this . entrypoints , { appId } ) ; } async anyExistsWithBundleIdIn ( bundleIds ) { return ! ! find ( this . entrypoints , ( e ) => e . bundleId !== null && bundleIds . includes ( e . bundleId ) ) ; } async createOne ( toBeCreatedEntrypoint ) { this . entrypoints [ toBeCreatedEntrypoint . id ] = toBeCreatedEntrypoint ; return toBeCreatedEntrypoint ; } async updateOne ( id , patch ) { this . entrypoints [ id ] = { ... this . entrypoints [ id ] , ... defaults ( patch , this . entrypoints [ id ] ) , } ; return this . entrypoints [ id ] ; } async deleteOne ( id ) { delete this . entrypoints [ id ] ; } }