@itwin/insights-client
Version:
Insights client for the iTwin platform
198 lines • 13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AggregationsClient = void 0;
const Errors_1 = require("../../common/Errors");
const EntityListIteratorImpl_1 = require("../../common/iterators/EntityListIteratorImpl");
const IteratorUtil_1 = require("../../common/iterators/IteratorUtil");
const OperationsBase_1 = require("../../common/OperationsBase");
const AggregationProperties_1 = require("../interfaces/AggregationProperties");
class AggregationsClient extends OperationsBase_1.OperationsBase {
constructor(basePath) {
super(basePath ?? OperationsBase_1.REPORTING_BASE_PATH);
}
async getAggregationProperties(accessToken, aggregationTableSetId, aggregationTableId, top) {
const properties = [];
const aggregationPropertyIterator = this.getAggregationPropertiesIterator(accessToken, aggregationTableSetId, aggregationTableId, top);
for await (const aggregationProperty of aggregationPropertyIterator) {
properties.push(aggregationProperty);
}
return properties;
}
getAggregationPropertiesIterator(accessToken, aggregationTableSetId, aggregationTableId, top) {
if (!this.topIsValid(top)) {
throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000].");
}
let url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}/properties`;
url += top ? `/?$top=${top}` : "";
const request = this.createRequest("GET", accessToken);
return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.getEntityCollectionPage)(url, async (nextUrl) => {
const response = await this.fetchJSON(nextUrl, request);
return {
values: response.aggregationProperties,
// eslint-disable-next-line @typescript-eslint/naming-convention
_links: response._links,
};
}));
}
async getAggregationProperty(accessToken, aggregationTableSetId, aggregationTableId, aggregationPropertyId) {
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}/properties/${encodeURIComponent(aggregationPropertyId)}`;
const requestOptions = this.createRequest("GET", accessToken);
return (await this.fetchJSON(url, requestOptions)).aggregationProperty;
}
async updateAggregationProperty(accessToken, aggregationTableSetId, aggregationTableId, aggregationPropertyId, property) {
if (null == property.propertyName && null == property.sourcePropertyName && null == property.type) {
throw new Errors_1.RequiredError("property", "All properties of property were missing.");
}
if (null != property.propertyName && !this.isSimpleIdentifier(property.propertyName)) {
throw new Errors_1.RequiredError("propertyName", "Field propertyName was invalid.");
}
if (null != property.sourcePropertyName && !this.isSimpleIdentifier(property.sourcePropertyName)) {
throw new Errors_1.RequiredError("sourcePropertyName", "Field sourcePropertyName was invalid.");
}
if (null != property.type && property.type === AggregationProperties_1.AggregationPropertyType.Undefined) {
throw new Errors_1.RequiredError("type", "Required field type was null or undefined.");
}
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}/properties/${encodeURIComponent(aggregationPropertyId)}`;
const requestOptions = this.createRequest("PATCH", accessToken, JSON.stringify(property));
return (await this.fetchJSON(url, requestOptions)).aggregationProperty;
}
async createAggregationProperty(accessToken, aggregationTableSetId, aggregationTableId, property) {
if (!this.isSimpleIdentifier(property.propertyName)) {
throw new Errors_1.RequiredError("propertyName", "Field propertyName was invalid.");
}
if (!this.isSimpleIdentifier(property.sourcePropertyName)) {
throw new Errors_1.RequiredError("sourcePropertyName", "Field sourcePropertyName was invalid.");
}
if (property.type === AggregationProperties_1.AggregationPropertyType.Undefined) {
throw new Errors_1.RequiredError("type", "Required field type was null or undefined.");
}
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}/properties`;
const requestOptions = this.createRequest("POST", accessToken, JSON.stringify(property));
return (await this.fetchJSON(url, requestOptions)).aggregationProperty;
}
async deleteAggregationProperty(accessToken, aggregationTableSetId, aggregationTableId, aggregationPropertyId) {
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}/properties/${encodeURIComponent(aggregationPropertyId)}`;
const requestOptions = this.createRequest("DELETE", accessToken);
return this.fetchJSON(url, requestOptions);
}
async getAggregationTableSets(accessToken, datasourceId, datasourceType, top) {
const tablesets = [];
const aggregationTableSetsIterator = this.getAggregationTableSetsIterator(accessToken, datasourceId, datasourceType, top);
for await (const aggregationTableSet of aggregationTableSetsIterator) {
tablesets.push(aggregationTableSet);
}
return tablesets;
}
getAggregationTableSetsIterator(accessToken, datasourceId, datasourceType, top) {
if (!this.topIsValid(top)) {
throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000].");
}
let url = `${this.basePath}/datasources/aggregations?datasourceId=${encodeURIComponent(datasourceId)}&datasourceType=${encodeURIComponent(datasourceType)}`;
url += top ? `&$top=${top}` : "";
const request = this.createRequest("GET", accessToken);
return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.getEntityCollectionPage)(url, async (nextUrl) => {
const response = await this.fetchJSON(nextUrl, request);
return {
values: response.aggregationTableSets,
// eslint-disable-next-line @typescript-eslint/naming-convention
_links: response._links,
};
}));
}
async getAggregationTableSet(accessToken, aggregationTableSetId) {
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}`;
const requestOptions = this.createRequest("GET", accessToken);
return (await this.fetchJSON(url, requestOptions)).aggregationTableSet;
}
async updateAggregationTableSet(accessToken, aggregationTableSetId, tableset) {
if (null == tableset.tableSetName && null == tableset.description) {
throw new Errors_1.RequiredError("tableset", "All properties of tableset were missing.");
}
if (null != tableset.tableSetName && !this.isSimpleIdentifier(tableset.tableSetName)) {
throw new Errors_1.RequiredError("tableSetName", "Field tableSetName was invalid.");
}
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}`;
const requestOptions = this.createRequest("PATCH", accessToken, JSON.stringify(tableset));
return (await this.fetchJSON(url, requestOptions)).aggregationTableSet;
}
async createAggregationTableSet(accessToken, tableset) {
if (!this.isSimpleIdentifier(tableset.tableSetName)) {
throw new Errors_1.RequiredError("tableSetName", "Field tableSetName was invalid.");
}
if (!this.isSimpleIdentifier(tableset.datasourceType)) {
throw new Errors_1.RequiredError("datasourceType", "Field datasourceType was invalid.");
}
if (!tableset.datasourceId) {
throw new Errors_1.RequiredError("datasourceId", "Required field datasourceId was null or undefined.");
}
const url = `${this.basePath}/datasources/aggregations`;
const requestOptions = this.createRequest("POST", accessToken, JSON.stringify(tableset));
return (await this.fetchJSON(url, requestOptions)).aggregationTableSet;
}
async deleteAggregationTableSet(accessToken, aggregationTableSetId) {
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}`;
const requestOptions = this.createRequest("DELETE", accessToken);
return this.fetchJSON(url, requestOptions);
}
async getAggregationTables(accessToken, aggregationTableSetId, top) {
const tables = [];
const aggregationTablesIterator = this.getAggregationTablesIterator(accessToken, aggregationTableSetId, top);
for await (const aggregationTable of aggregationTablesIterator) {
tables.push(aggregationTable);
}
return tables;
}
getAggregationTablesIterator(accessToken, aggregationTableSetId, top) {
if (!this.topIsValid(top)) {
throw new Errors_1.RequiredError("top", "Parameter top was outside of the valid range [1-1000].");
}
let url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables`;
url += top ? `?$top=${top}` : "";
const request = this.createRequest("GET", accessToken);
return new EntityListIteratorImpl_1.EntityListIteratorImpl(async () => (0, IteratorUtil_1.getEntityCollectionPage)(url, async (nextUrl) => {
const response = await this.fetchJSON(nextUrl, request);
return {
values: response.aggregationTables,
// eslint-disable-next-line @typescript-eslint/naming-convention
_links: response._links,
};
}));
}
async getAggregationTable(accessToken, aggregationTableSetId, aggregationTableId) {
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}`;
const requestOptions = this.createRequest("GET", accessToken);
return (await this.fetchJSON(url, requestOptions)).aggregationTable;
}
async updateAggregationTable(accessToken, aggregationTableSetId, aggregationTableId, table) {
if (null == table.tableName && null == table.description && null == table.sourceTableName) {
throw new Errors_1.RequiredError("table", "All properties of table were missing.");
}
if (null != table.tableName && !this.isSimpleIdentifier(table.tableName)) {
throw new Errors_1.RequiredError("tableName", "Field tableName was invalid.");
}
if (null != table.sourceTableName && !this.isSimpleIdentifier(table.sourceTableName)) {
throw new Errors_1.RequiredError("sourceTableName", "Field sourceTableName was invalid.");
}
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}`;
const requestOptions = this.createRequest("PATCH", accessToken, JSON.stringify(table));
return (await this.fetchJSON(url, requestOptions)).aggregationTable;
}
async createAggregationTable(accessToken, aggregationTableSetId, table) {
if (!this.isSimpleIdentifier(table.tableName)) {
throw new Errors_1.RequiredError("tableName", "Field tableName was invalid.");
}
if (!this.isSimpleIdentifier(table.sourceTableName)) {
throw new Errors_1.RequiredError("sourceTableName", "Field sourceTableName was invalid.");
}
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables`;
const requestOptions = this.createRequest("POST", accessToken, JSON.stringify(table));
return (await this.fetchJSON(url, requestOptions)).aggregationTable;
}
async deleteAggregationTable(accessToken, aggregationTableSetId, aggregationTableId) {
const url = `${this.basePath}/datasources/aggregations/${encodeURIComponent(aggregationTableSetId)}/tables/${encodeURIComponent(aggregationTableId)}`;
const requestOptions = this.createRequest("DELETE", accessToken);
return this.fetchJSON(url, requestOptions);
}
}
exports.AggregationsClient = AggregationsClient;
//# sourceMappingURL=AggregationsClient.js.map