packageDocumentation module import { ClassInfo , ClassInfoJSON , InstanceKey , InstanceKeyJSON } from "../EC" ; import { LabelDefinition , LabelDefinitionJSON } from "../LabelDefinition" ; import { ValuesDictionary } from "../Utils" ; import { DisplayValue , DisplayValueJSON , DisplayValuesMapJSON , Value , ValueJSON , ValuesMapJSON } from "./Value" ; public export interface ItemJSON { beta inputKeys ? : InstanceKeyJSON [ ] ; primaryKeys : InstanceKeyJSON [ ] ; labelDefinition : LabelDefinitionJSON ; imageId : string ; classInfo ? : ClassInfoJSON ; values : ValuesDictionary < ValueJSON > ; displayValues : ValuesDictionary < DisplayValueJSON > ; mergedFieldNames : string [ ] ; extendedData ? : { [ key ] : any ; } ; } public export class Item { beta public inputKeys ? : InstanceKey [ ] ; /** Keys of instances whose data is contained in this item */ public primaryKeys : InstanceKey [ ] ; /** Display label of the item */ public label : LabelDefinition ; /** ID of the image associated with this item */ public imageId : string ; /** For cases when item consists only of same class instances, information about the ECClass */ public classInfo ? : ClassInfo ; /** Raw values dictionary */ public values : ValuesDictionary < Value > ; /** Display values dictionary */ public displayValues : ValuesDictionary < DisplayValue > ; /** List of field names whose values are merged (see [Merging values]($docs/presentation/Content/Terminology#value-merging)) */ public mergedFieldNames : string [ ] ; /** Extended data injected into this content item */ public extendedData ? : { [ key ] : any ; } ; param primaryKeys param label param imageId param classInfo param values param displayValues param mergedFieldNames param extendedData public constructor ( primaryKeys , label , imageId , classInfo , values , displayValues , mergedFieldNames , extendedData ? ) { this . primaryKeys = primaryKeys ; this . imageId = imageId ; this . classInfo = classInfo ; this . values = values ; this . displayValues = displayValues ; this . mergedFieldNames = mergedFieldNames ; this . extendedData = extendedData ; this . label = ( typeof label === "string" ) ? LabelDefinition . fromLabelString ( label ) : label ; } /**
     * Is value of field with the specified name merged in this record.
     */ public isFieldMerged ( fieldName ) { return - 1 !== this . mergedFieldNames . indexOf ( fieldName ) ; } /** Serialize this object to JSON */ public toJSON ( ) { const { label , ... baseItem } = this ; return { ... baseItem , ... ( this . inputKeys ? { inputKeys : this . inputKeys . map ( InstanceKey . toJSON ) } : { } ) , primaryKeys : this . primaryKeys . map ( InstanceKey . toJSON ) , classInfo : this . classInfo ? ClassInfo . toJSON ( this . classInfo ) : undefined , values : Value . toJSON ( this . values ) as ValuesMapJSON , displayValues : DisplayValue . toJSON ( this . displayValues ) as DisplayValuesMapJSON , labelDefinition : LabelDefinition . toJSON ( label ) } ; } /** Deserialize [[Item]] from JSON */ public static fromJSON ( json ) { if ( ! json ) return undefined ; if ( typeof json === "string" ) return JSON . parse ( json , Item . reviver ) ; const item = Object . create ( Item . prototype ) ; const { labelDefinition , ... baseJson } = json ; return Object . assign ( item , baseJson , { ... ( json . inputKeys ? { inputKeys : json . inputKeys . map ( ( ik ) => InstanceKey . fromJSON ( ik ) ) } : { } ) , primaryKeys : json . primaryKeys . map ( ( pk ) => InstanceKey . fromJSON ( pk ) ) , classInfo : json . classInfo ? ClassInfo . fromJSON ( json . classInfo ) : undefined , values : Value . fromJSON ( json . values ) , displayValues : DisplayValue . fromJSON ( json . displayValues ) , label : LabelDefinition . fromJSON ( labelDefinition ) } as Partial < Item > ) ; } internal public static reviver ( key , value ) { return key === "" ? Item . fromJSON ( value ) : value ; } }