@microsoft/windows-admin-center-sdk
Version:
Microsoft - Windows Admin Center Shell
70 lines (68 loc) • 2.44 kB
JavaScript
import { map } from 'rxjs/operators';
import { SharedCache } from '../shared-cache';
import { GatewayInventoryDetail } from './gateway-inventory-detail';
/**
* Gateway Inventory Detail cache class.
*/
export class GatewayInventoryDetailCache extends SharedCache {
appContext;
static uniqueId = '@msft-sme/shell:gatewayInventoryDetail';
static uniqueVersion = 1;
static gatewayName = 'gateway';
/**
* Initializes a new instance of the GatewayInventoryCache class.
*
* @param appContext the app context.
* @param options the option of shared cache.
*/
constructor(appContext, options) {
super(GatewayInventoryDetailCache.uniqueId, GatewayInventoryDetailCache.uniqueVersion, () => this.dataInstanceId(), (instance) => this.dataSerialize(instance), (serialized) => this.dataDeserialize(serialized), () => this.dataQuery(), options);
this.appContext = appContext;
}
/**
* Defines how to collect the gateway inventory detail data.
*
* @return the Observable of GatewayInventoryDetail data.
*/
dataQuery() {
return this.appContext.gateway.get('gateway/latestversion')
.pipe(map((versionDetail) => {
const inventoryDetail = new GatewayInventoryDetail();
if (versionDetail) {
inventoryDetail.latestVersion =
versionDetail.destinationUrl.substring(versionDetail.destinationUrl.lastIndexOf('/') + 1);
}
else {
inventoryDetail.latestVersion = null;
}
return inventoryDetail;
}));
}
/**
* Defines how to identify the cache entry by params.
*
* @return the id string.
*/
dataInstanceId() {
return GatewayInventoryDetailCache.gatewayName;
}
/**
* Defines how to deserialize the class object from serialized data.
*
* @param serialized the serialized string;
*/
dataDeserialize(serialized) {
const inventory = JSON.parse(serialized);
return new GatewayInventoryDetail(inventory);
}
/**
* Defines how to serialize the class object to seralized data.
*
* @param instance the class instance.
*/
dataSerialize(instance) {
// automatically strip out class related data.
return JSON.stringify(instance);
}
}
//# sourceMappingURL=gateway-inventory-detail-cache.js.map