') as any).text(mdxString).html();
+ public sendQuery(storeOptions: XmlaStoreOptions, mdxString: string): DeferredObj
{
+ const encodedMdxString: string = $('').text(mdxString).html();
return this.execXMLA(
storeOptions,
- stringFormat(XMLA_EXECUTE_TEMPLATE, mdxString, storeOptions.catalog, getLocaleIdProperty()),
+ stringFormat(
+ XMLA_EXECUTE_TEMPLATE,
+ encodedMdxString,
+ storeOptions.catalog,
+ getLocaleIdProperty(),
+ ),
);
}
- processTotalCount(data, options, totalCountXml) {
- const axes: any = [];
+ public processTotalCount(
+ data: XmlaLoadResult,
+ options: XmlaLoadOptions,
+ totalCountXml: Document,
+ ): void {
const columnOptions = options.columns || [];
const rowOptions = options.rows || [];
- if (columnOptions.length) {
- axes.push({});
- }
- if (rowOptions.length) {
- axes.push({});
- }
- const cells = this.parseCells(totalCountXml, [[{}], [{}, {}]], 1);
+ // @ts-expect-error the cells of the totals request hold counts
+ const cells: number[][][] = this.parseCells(totalCountXml, [[{}], [{}, {}]], 1);
if (!columnOptions.length && rowOptions.length) {
data.rowCount = Math.max(cells[0][0][0] - 1, 0);
}
@@ -1066,17 +1155,15 @@ class XmlaStore {
}
}
- getFields() {
+ public getFields(): DeferredObj {
const options = this._options;
- const { catalog } = options;
- const { cube } = options;
+ const { catalog, cube } = options;
const localeIdProperty = getLocaleIdProperty();
const dimensionsRequest = this.execXMLA(options, stringFormat(XMLA_DISCOVER_TEMPLATE, catalog, cube, 'MDSCHEMA_DIMENSIONS', localeIdProperty));
const measuresRequest = this.execXMLA(options, stringFormat(XMLA_DISCOVER_TEMPLATE, catalog, cube, 'MDSCHEMA_MEASURES', localeIdProperty));
const hierarchiesRequest = this.execXMLA(options, stringFormat(XMLA_DISCOVER_TEMPLATE, catalog, cube, 'MDSCHEMA_HIERARCHIES', localeIdProperty));
const levelsRequest = this.execXMLA(options, stringFormat(XMLA_DISCOVER_TEMPLATE, catalog, cube, 'MDSCHEMA_LEVELS', localeIdProperty));
- // @ts-expect-error
- const result = new Deferred();
+ const result = Deferred();
when(dimensionsRequest, measuresRequest, hierarchiesRequest, levelsRequest)
.then((dimensionsResponse, measuresResponse, hierarchiesResponse, levelsResponse) => {
@@ -1084,61 +1171,70 @@ class XmlaStore {
.done((measureGroupsResponse) => {
const dimensions = this.parseDimensionsDiscoverRowSet(dimensionsResponse);
const hierarchies = this.parseDiscoverRowSet(hierarchiesResponse, 'HIERARCHY', dimensions);
- const levels = this.parseDiscoverRowSet(levelsResponse, 'LEVEL', dimensions);
+ // @ts-expect-error the LEVEL rows have a hierarchyName
+ const levels: (XmlaDiscoveredField & { hierarchyName: string })[] = this.parseDiscoverRowSet(levelsResponse, 'LEVEL', dimensions);
const measureGroups = this.parseMeasureGroupDiscoverRowSet(measureGroupsResponse);
const fields = this.parseDiscoverRowSet(measuresResponse, 'MEASURE', dimensions, measureGroups)
.concat(hierarchies);
- const levelsByHierarchy = {};
+ const levelsByHierarchy: Record = {};
- each(levels, (_, level) => {
+ levels.forEach((level) => {
levelsByHierarchy[level.hierarchyName] = levelsByHierarchy[level.hierarchyName]
|| [];
levelsByHierarchy[level.hierarchyName].push(level);
});
- each(hierarchies, (_, hierarchy) => {
+ hierarchies.forEach((hierarchy) => {
if (levelsByHierarchy[hierarchy.dataField]
&& levelsByHierarchy[hierarchy.dataField].length > 1) {
- hierarchy.groupName = hierarchy.hierarchyName = hierarchy.dataField;
+ hierarchy.hierarchyName = hierarchy.dataField;
+ hierarchy.groupName = hierarchy.hierarchyName;
- fields.push.apply(fields, levelsByHierarchy[hierarchy.hierarchyName]);
+ fields.push(...levelsByHierarchy[hierarchy.hierarchyName]);
}
});
result.resolve(fields);
+ // @ts-expect-error fail() gets the error, but is typed with the resolve value
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises -- ignores the result
}).fail(result.reject);
+ // @ts-expect-error fail() gets the error, but is typed with the resolve value
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises -- ignores the result
}).fail(result.reject);
return result;
}
- load(options) {
- // @ts-expect-error
- const result = new Deferred();
+ public load(options: XmlaLoadOptions): DeferredObj {
+ const result = Deferred();
const storeOptions = this._options;
- const parseOptions = {
+ const parseOptions: XmlaParseOptions = {
skipValues: options.skipValues,
};
const mdxString = this.generateMDX(options, storeOptions.cube, parseOptions);
- let rowCountMdx;
+ // eslint-disable-next-line @typescript-eslint/init-declarations -- assigned in the if
+ let rowCountMdx: string | undefined;
if (options.rowSkip || options.rowTake || options.columnTake || options.columnSkip) {
- rowCountMdx = this.generateMDX(extend({}, options, {
+ rowCountMdx = this.generateMDX({
+ ...options,
totalsOnly: true,
rowSkip: null,
rowTake: null,
columnSkip: null,
columnTake: null,
- }), storeOptions.cube, {});
+ }, storeOptions.cube, {});
}
- const load = () => {
+ const load = (): void => {
if (mdxString) {
- when(
+ when(
this.sendQuery(storeOptions, mdxString),
rowCountMdx && this.sendQuery(storeOptions, rowCountMdx),
)
- .done((executeXml, rowCountXml) => {
- const error = this.checkError(executeXml) || rowCountXml && this.checkError(rowCountXml);
+ // @ts-expect-error when() types its results alike, but only the second can be empty
+ .done((executeXml: Document, rowCountXml: Document | '' | undefined) => {
+ const error = this.checkError(executeXml)
+ ?? (rowCountXml && this.checkError(rowCountXml));
if (!error) {
const response = this.parseResult(executeXml, parseOptions);
if (rowCountXml) {
@@ -1147,8 +1243,11 @@ class XmlaStore {
result.resolve(response);
} else {
+ // @ts-expect-error reject() gets the error, but is typed with the resolve value
result.reject(error);
}
+ // @ts-expect-error fail() gets the error, but is typed with the resolve value
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises -- ignores the result
}).fail(result.reject);
} else {
result.resolve({
@@ -1170,13 +1269,15 @@ class XmlaStore {
return result;
}
- supportPaging() {
+ public supportPaging(): boolean {
return true;
}
- getDrillDownItems(options, params) {
- // @ts-expect-error
- const result = new Deferred();
+ public getDrillDownItems(
+ options: XmlaLoadOptions,
+ params: DrillDownParams,
+ ): DeferredObj[]> {
+ const result = Deferred[]>();
const storeOptions = this._options;
const mdxString = this.generateDrillDownMDX(options, storeOptions.cube, params);
@@ -1187,8 +1288,11 @@ class XmlaStore {
if (!error) {
result.resolve(this.parseDrillDownRowSet(executeXml));
} else {
+ // @ts-expect-error reject() gets the error, but is typed with the resolve value
result.reject(error);
}
+ // @ts-expect-error fail() gets the error, but is typed with the resolve value
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises -- ignores the result
}).fail(result.reject);
} else {
result.resolve([]);
diff --git a/packages/devextreme/js/__internal/grids/pivot_grid/xmla_store/types.ts b/packages/devextreme/js/__internal/grids/pivot_grid/xmla_store/types.ts
new file mode 100644
index 000000000000..d35ae839fb40
--- /dev/null
+++ b/packages/devextreme/js/__internal/grids/pivot_grid/xmla_store/types.ts
@@ -0,0 +1,106 @@
+import type {
+ DiscoveredField,
+ PivotGridField,
+ PivotGridHeaderItem,
+ PivotGridLoadOptions,
+} from '@ts/grids/pivot_grid/types';
+
+/** getFields() gives the levels of a multi-level hierarchy its hierarchyName. */
+export type XmlaField = PivotGridField & {
+ hierarchyName?: string;
+ /** The MDX expression of a calculated measure. */
+ expression?: unknown;
+};
+
+export type XmlaLoadOptions = Omit<
+ PivotGridLoadOptions,
+ 'rows' | 'columns' | 'values' | 'filters'
+> & {
+ rows: XmlaField[];
+ columns: XmlaField[];
+ values?: XmlaField[];
+ filters?: XmlaField[];
+ delay?: number;
+};
+
+/** load() requests the totals with the paging reset to null. */
+export type XmlaMdxOptions = Omit<
+ XmlaLoadOptions,
+ 'rowSkip' | 'rowTake' | 'columnSkip' | 'columnTake'
+> & {
+ rowSkip?: number | null;
+ rowTake?: number | null;
+ columnSkip?: number | null;
+ columnTake?: number | null;
+ totalsOnly?: boolean;
+};
+
+/** The dataFields of the visible levels, by hierarchyName. */
+export type XmlaVisibleLevels = Record;
+
+/** generateMDX() sets measureCount and visibleLevels for parseResult(). */
+export interface XmlaParseOptions {
+ skipValues?: boolean;
+ measureCount?: number;
+ visibleLevels?: XmlaVisibleLevels;
+}
+
+/** Old IE gave XML nodes a text property instead of textContent. */
+export type XmlaNode = Element & { text?: string };
+
+/** A tuple member of the response. An axis the response lacks gets one member with only a level. */
+export interface XmlaAxisMember {
+ level: number;
+ caption?: string;
+ value?: string | number;
+ index?: number;
+ hasValue?: boolean;
+ name?: string;
+ hierarchyName?: string | null;
+ parentName?: string;
+ levelName?: string;
+}
+
+export interface XmlaHeaderItem extends PivotGridHeaderItem {
+ text?: string;
+ key?: string;
+ level?: number;
+ levelName?: string;
+ hierarchyName?: string | null;
+ parentName?: string;
+ added?: boolean;
+ children?: XmlaHeaderItems;
+}
+
+/** processMember() hashes the items of a level by name. */
+export type XmlaHeaderItems = XmlaHeaderItem[] & {
+ hash?: Record;
+ grandTotalHash?: Record;
+};
+
+export type XmlaCellValue = number | string | null;
+
+export interface XmlaLoadResult {
+ columns: XmlaHeaderItem[];
+ rows: XmlaHeaderItem[];
+ values?: XmlaCellValue[][][];
+ grandTotalColumnIndex?: number;
+ grandTotalRowIndex?: number;
+ rowCount?: number;
+ columnCount?: number;
+}
+
+export interface XmlaDimensions {
+ /** The captions of the dimensions, by unique name. */
+ names: Record;
+ /** The unique names of the default hierarchies. */
+ defaultHierarchies: Record;
+}
+
+export interface XmlaDiscoveredField extends DiscoveredField {
+ dimension: string;
+ caption: string;
+ hierarchyName?: string;
+ isMeasure: boolean;
+ isDefault: boolean;
+}