import basicCharsRegexp from "../common/basicCharsRegexp" ; import { BundleNameOrTagNotValidError , BundleNameTagCombinationNotValidError , } from "../common/errors" ; import { IAsset , IAssetWithoutContent } from "./Asset" ; export interface IBundle { id : string ; name : string ; tag : string ; description : string ; hash : string ; assets : IAsset [ ] ; fallbackAssetPath : string ; fallbackStatusCode : number ; createdAt : Date ; } export interface IBundleWithoutAssetsContent extends IBundle { assets : IAssetWithoutContent [ ] ; } export interface IBaseBundle { id : IBundle [ "id" ] ; name : IBundle [ "name" ] ; tag : IBundle [ "tag" ] ; createdAt : IBundle [ "createdAt" ] ; } export function isBundleNameOrTagValid ( nameOrTag ) { return basicCharsRegexp . test ( nameOrTag ) ; } export function validateBundleNameOrTag ( nameOrTag , type ) { if ( ! isBundleNameOrTagValid ( nameOrTag ) ) { throw new BundleNameOrTagNotValidError ( nameOrTag , type ) ; } } export function isBundleNameTagCombinationValid ( nameTagCombination ) { const segments = nameTagCombination . split ( ":" ) ; if ( segments . length !== 2 ) { return false ; } const [ name , tag ] = segments ; return isBundleNameOrTagValid ( name ) && isBundleNameOrTagValid ( tag ) ; } export function validateBundleNameTagCombination ( nameTagCombination ) { if ( ! isBundleNameTagCombinationValid ( nameTagCombination ) ) { throw new BundleNameTagCombinationNotValidError ( nameTagCombination ) ; } } export function formNameTagCombination ( name , tag ) { return `${ name }:${ tag }` ; } export function splitNameTagCombination ( nameTagCombination ) { validateBundleNameTagCombination ( nameTagCombination ) ; return nameTagCombination . split ( ":" ) as [ string , string ] ; }