import { IConfiguration , IEntrypoint , IEntrypointsStorage , } from "@staticdeploy/core" ; import { Knex } from "knex" ; import convertErrors from "./common/convertErrors" ; import tables from "./common/tables" ; @ convertErrors export default class EntrypointsStorage implements IEntrypointsStorage { constructor ( private knex ) { } async findOne ( id ) { const [ entrypoint = null ] = await this . knex ( tables . entrypoints ) . where ( { id , } ) ; return entrypoint ; } async findOneByUrlMatcher ( urlMatcher ) { const [ entrypoint = null ] = await this . knex ( tables . entrypoints ) . where ( { urlMatcher , } ) ; return entrypoint ; } async findManyByAppId ( appId ) { const entrypoints = await this . knex ( tables . entrypoints ) . where ( { appId , } ) ; return entrypoints ; } async findManyByUrlMatcherHostname ( urlMatcherHostname ) { const entrypoints = await this . knex ( tables . entrypoints ) . where ( "urlMatcher" , "like" , `${ urlMatcherHostname }%` ) ; return entrypoints ; } async oneExistsWithUrlMatcher ( urlMatcher ) { const [ entrypoint = null ] = await this . knex ( tables . entrypoints ) . select ( "id" ) . where ( { urlMatcher } ) ; return entrypoint !== null ; } async anyExistsWithAppId ( appId ) { const [ entrypoint = null ] = await this . knex ( tables . entrypoints ) . select ( "id" ) . where ( { appId } ) . limit ( 1 ) ; return entrypoint !== null ; } async anyExistsWithBundleIdIn ( bundleIds ) { const [ entrypoint = null ] = await this . knex ( tables . entrypoints ) . select ( "id" ) . whereIn ( "bundleId" , bundleIds ) . limit ( 1 ) ; return entrypoint !== null ; } async createOne ( toBeCreatedEntrypoint ) { const [ createdApp ] = await this . knex ( tables . entrypoints ) . insert ( toBeCreatedEntrypoint ) . returning ( "*" ) ; return createdApp ; } async updateOne ( id , patch ) { const [ updatedApp ] = await this . knex ( tables . entrypoints ) . where ( { id } ) . update ( patch ) . returning ( "*" ) ; return updatedApp ; } async deleteOne ( id ) { await this . knex ( tables . entrypoints ) . where ( { id } ) . delete ( ) ; } }