import type { DType } from '@h5web/shared' ; import { DTypeClass , EntityKind , isNumericType } from '@h5web/shared' ; import type { H5GroveDatasetReponse , H5GroveEntityResponse , H5GroveExternalLinkResponse , H5GroveGroupResponse , H5GroveSoftLinkResponse , } from './models' ; export function isGroupResponse ( response ) { return response . type === EntityKind . Group ; } export function isDatasetResponse ( response ) { return response . type === EntityKind . Dataset ; } export function isSoftLinkResponse ( response ) { return response . type === 'soft_link' ; } export function isExternalLinkResponse ( response ) { return response . type === 'external_link' ; } export function typedArrayFromDType ( dtype ) { if ( ! isNumericType ( dtype ) ) { return undefined ; } const { class : dtypeClass , size } = dtype ; if ( dtypeClass === DTypeClass . Integer ) { switch ( size ) { case 8 : return Int8Array ; case 16 : return Int16Array ; case 32 : return Int32Array ; case 64 : return undefined ; } } if ( dtypeClass === DTypeClass . Unsigned ) { switch ( size ) { case 8 : return Uint8Array ; case 16 : return Uint16Array ; case 32 : return Uint32Array ; case 64 : return undefined ; } } if ( dtypeClass === DTypeClass . Float ) { switch ( size ) { case 16 : return undefined ; case 32 : return Float32Array ; case 64 : return Float64Array ; } } return undefined ; }