import ListById from "./Base/ListById" ; import * as _ from "lodash" ; const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ; export default class Projects extends ListById { static schema : SupCore . Data . Schema = { name : { type : "string" , minLength : 1 , maxLength : 80 } , description : { type : "string" , maxLength : 300 } , formatVersion : { type : "number?" } , systemId : { type : "string" } } ; static sort ( a , b ) { return a . name . localeCompare ( b . name ) ; } pub : SupCore . Data . ProjectManifestPub [ ] ; byId : { [ id ] : SupCore . Data . ProjectManifestPub ; } ; constructor ( pub ) { super ( pub , Projects . schema ) ; this . generateNextId = this . generateProjectId ; } private generateProjectId = ( ) => { let id = null ; while ( true ) { id = "" ; for ( let i = 0 ; i < 4 ; i ++ ) id += _ . sample ( characters ) ; if ( this . byId [ id ] == null ) break ; } return id ; } ; }