All files / src/lib isStream.ts

66.66% Statements 4/6
50% Branches 4/8
100% Functions 0/0
66.66% Lines 4/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37            103x                 262536x           109674x       262536x                      
import {
  ObjectTypeEnum,
  SimulationObjectRetrieveRead,
} from "../api/apiStore.gen";
import schema, { type UnitOpConfig } from "../data/unitOpConfigs";
 
const energyStreamTypes = new Set<string>([
  "energy_stream",
  "ac_stream",
  "transformer_stream",
]);
 
function getConfig(
  objectType: ObjectTypeEnum | undefined,
): UnitOpConfig | undefined {
  return objectType
    ? (schema as Record<string, UnitOpConfig>)[objectType]
    : undefined;
}
 
export function isStream(object?: SimulationObjectRetrieveRead): boolean {
  return !!(object && isStreamType(object.objectType));
}
 
export function isStreamType(objectType?: ObjectTypeEnum): boolean {
  return !!getConfig(objectType)?.isStream;
}
 
export function isEnergyStream(object?: SimulationObjectRetrieveRead): boolean {
  return !!(object && isEnergyStreamType(object.objectType));
}
 
// optional but handy for enum checks (e.g., ObjectTypeEnum.EnergyStream)
export function isEnergyStreamType(objectType?: ObjectTypeEnum): boolean {
  return !!objectType && energyStreamTypes.has(objectType);
}