import { checkAssetId , toQueryString } from "../../utils" ; import { SdkClient } from "../common/sdk-client" ; import { TimeSeriesModels } from "./iot-timeseries-models" ; export class extends SdkClient export class TimeSeriesClient extends SdkClient { private _baseUrl : string = "/api/iottimeseries/v3" ; param { string } entity param { string } propertysetname param { { from ? : Date ; to ? : Date ; limit ? : number ; select ? : string ; sort ? : string } } optional returns { Promise < TimeSeriesModels . Timeseries [ ] > } memberOf public async GetTimeSeries ( entity , propertysetname , optional ? ) { checkAssetId ( entity ) ; const qs = toQueryString ( optional ) ; return ( await this . HttpAction ( { verb : "GET" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/timeseries/${ entity }/${ propertysetname }?${ qs }` , message : "GetTimeSeries" , } ) ) as TimeSeriesModels . Timeseries [ ] ; } param { string } entity param { string } propertysetname param { { from ? : Date ; to ? : Date ; limit ? : number ; select ? : string ; sort ? : string ; * } } optional returns { Promise < TimeSeriesModels . BulkTimeseries > } memberOf public async GetTimeSeriesBulkStyle ( entity , propertysetname , optional ? ) { checkAssetId ( entity ) ; const qs = toQueryString ( optional ) ; const url = `${ this . _baseUrl }/timeseries/${ entity }/${ propertysetname }?${ qs }` ; return await this . GetNextRecordsBulkStyle ( url ) ; } public async GetNextRecordsBulkStyle ( url ) { const response = ( await this . HttpAction ( { verb : "GET" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : url , message : "GetTimeSeries" , rawResponse : true , } ) ) as Response ; const nextRecord = response . headers . get ( "link" ) ?. replace ( '; rel="next"' , "" ) . replace ( /</g , "" ) . replace ( />/g , "" ) . replace ( this . GetGateway ( ) , "" ) ; const values = ( await response . json ( ) ) as Array < { [ key ] : any ; } > ; return { records : values , nextRecord : nextRecord , } as TimeSeriesModels . BulkTimeseries ; } param { string } entity param { string } propertysetname param { TimeSeriesModels . Timeseries [ ] } timeseries returns memberOf public async PutTimeSeries ( entity , propertysetname , timeseries ) { checkAssetId ( entity ) ; return await this . HttpAction ( { verb : "PUT" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/timeseries/${ entity }/${ propertysetname }` , body : timeseries , message : "PutTimeSeries" , noResponse : true , } ) ; } param { string } entity param { string } propertysetname param { Date } from param { Date } to returns memberOf public async DeleteTimeSeries ( entity , propertysetname , from , to ) { checkAssetId ( entity ) ; const qs = toQueryString ( { from : from , to : to } ) ; return await this . HttpAction ( { verb : "DELETE" , gateway : this . GetGateway ( ) , authorization : await this . GetToken ( ) , baseUrl : `${ this . _baseUrl }/timeseries/${ entity }/${ propertysetname }?${ qs }` , message : "DeleteTimeSeries" , noResponse : true , } ) ; } }