import { IList , IListEntityProps } from "../../@types/lib" ; import { ITargetInfoProps } from "../../@types/utils" ; import { SP } from "gd-sprest-def" ; import { Base , Request } from "../utils" ; import { Web } from "./web" ; /**
 * List
 */ export const List = ( ( listName , targetInfo ? ) => { let list = new Base ( targetInfo ) ; list . targetInfo . defaultToWebFl = true ; list . targetInfo . endpoint = "web/lists/getByTitle('" + listName . replace ( /\'/g , "''" ) + "')" ; Request . addMethods ( list , { __metadata : { type : "SP.List" } } ) ; return list ; } ) as any as IList ; List . getByEntityName = ( ( props ) => { let query = Web ( props . url , props . targetInfo ) . Lists ( ) . query ( { Filter : "EntityTypeName eq '" + props . name + "'" , Top : 1 } ) ; if ( props . callback ) { query . execute ( ( lists ) => { props . callback ( lists . results ? lists . results [ 0 ] : null as any ) ; } ) ; } else { let list = query . executeAndWait ( ) ; return list . results ? list . results [ 0 ] : list ; } } ) as any ; List . getDataAsStream = ( ( listFullUrl , parameters = { } ) => { let params = "?listFullUrl='" + listFullUrl + "'" ; for ( let key in parameters ) { params += "&" + key + "=" + parameters [ key ] ; } return new Base ( { endpoint : "SP.List.getListDataAsStream" + params } ) as any ; } ) ;