import { apiCall } from "@shlack/utils" ; import { isTeam , isTypedArray , ITeam } from "@shlack/types" ; let cachedAllTeamsList ; export async function getAllTeams ( ) { if ( typeof cachedAllTeamsList === "undefined" ) cachedAllTeamsList = apiCall ( "teams" ) . then ( ( rawData ) => { if ( isTypedArray ( rawData , isTeam ) ) return rawData ; throw new Error ( `Unexpected value for teams array\n${ JSON . stringify ( rawData ) }` ) ; } ) ; return await cachedAllTeamsList ; } const cachedTeamRecords = { } ; export async function getTeamById ( id ) { let cached = cachedTeamRecords [ id ] ; if ( typeof cached === "undefined" ) cached = cachedTeamRecords [ id ] = apiCall ( `teams/${ id }` ) . then ( ( rawData ) => { if ( isTeam ( rawData ) ) return rawData ; throw new Error ( `Unexpected value for team\n${ JSON . stringify ( rawData ) }` ) ; } ) ; return await cached ; }