@gooddata/sdk-model
Advanced tools
Comparing version 8.0.0-alpha.14 to 8.0.0-alpha.21
@@ -80,1 +80,30 @@ import { Identifier } from "./index"; | ||
export declare function newDimension(items?: DimensionItem[], totals?: ITotal[]): IDimension; | ||
/** | ||
* Result of search of item among list of dimensions. | ||
* | ||
* @public | ||
*/ | ||
export declare type ItemInDimension = { | ||
/** | ||
* Content of dimension where the item was found. | ||
*/ | ||
dim: IDimension; | ||
/** | ||
* Index of dimension where the item was found. | ||
*/ | ||
dimIdx: number; | ||
/** | ||
* Index of the item within the dimension where it was found. | ||
*/ | ||
itemIdx: number; | ||
}; | ||
/** | ||
* Looks for item with the provided local identifier among the dimensions. | ||
* | ||
* @param dims - list of dimensions to look in | ||
* @param localId - local identifier to find among item identifiers | ||
* @returns list of items in dimensions, empty if not found, may contain more than one entry if | ||
* item is in multiple dimensions | ||
* @public | ||
*/ | ||
export declare function dimensionsFindItem(dims: IDimension[], localId: string): ItemInDimension[]; |
"use strict"; | ||
// (C) 2019 GoodData Corporation | ||
// (C) 2019-2020 GoodData Corporation | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -116,1 +116,22 @@ __assign = Object.assign || function(t) { | ||
exports.newDimension = newDimension; | ||
/** | ||
* Looks for item with the provided local identifier among the dimensions. | ||
* | ||
* @param dims - list of dimensions to look in | ||
* @param localId - local identifier to find among item identifiers | ||
* @returns list of items in dimensions, empty if not found, may contain more than one entry if | ||
* item is in multiple dimensions | ||
* @public | ||
*/ | ||
function dimensionsFindItem(dims, localId) { | ||
var result = []; | ||
for (var dimIdx = 0; dimIdx < dims.length; dimIdx++) { | ||
var dim = dims[dimIdx]; | ||
var itemIdx = dim.itemIdentifiers.findIndex(function (i) { return i === localId; }); | ||
if (itemIdx >= 0) { | ||
result.push({ dim: dim, dimIdx: dimIdx, itemIdx: itemIdx }); | ||
} | ||
} | ||
return result; | ||
} | ||
exports.dimensionsFindItem = dimensionsFindItem; |
@@ -5,3 +5,3 @@ export { IAttribute, isAttribute, attributeLocalId, AttributePredicate, anyAttribute, idMatchAttribute, attributesFind, attributeUri, attributeIdentifier, attributeAlias, attributeAttributeDisplayFormObjRef, } from "./execution/attribute"; | ||
export { ObjectType, Identifier, Uri, UriRef, IdentifierRef, LocalIdRef, ObjRef, ObjRefInScope, isUriRef, isIdentifierRef, objRefToString, isLocalIdRef, areObjRefsEqual, isObjRef, } from "./execution/base"; | ||
export { IDimension, isDimension, dimensionTotals, DimensionItem, newTwoDimensional, newDimension, MeasureGroupIdentifier, dimensionSetTotals, } from "./execution/base/dimension"; | ||
export { IDimension, isDimension, dimensionTotals, DimensionItem, newTwoDimensional, newDimension, MeasureGroupIdentifier, dimensionSetTotals, dimensionsFindItem, ItemInDimension, } from "./execution/base/dimension"; | ||
export { idRef, uriRef, localIdRef } from "./execution/base/factory"; | ||
@@ -8,0 +8,0 @@ export { TotalType, ITotal, isTotal, newTotal, totalIsNative } from "./execution/base/totals"; |
@@ -36,2 +36,3 @@ "use strict"; | ||
exports.dimensionSetTotals = dimension_1.dimensionSetTotals; | ||
exports.dimensionsFindItem = dimension_1.dimensionsFindItem; | ||
var factory_2 = require("./execution/base/factory"); | ||
@@ -38,0 +39,0 @@ exports.idRef = factory_2.idRef; |
{ | ||
"name": "@gooddata/sdk-model", | ||
"version": "8.0.0-alpha.14", | ||
"version": "8.0.0-alpha.21", | ||
"author": "GoodData", | ||
@@ -30,3 +30,3 @@ "description": "GoodData Model definitions used by UI components and Backend SPI and its implementations", | ||
"validate": "tsc -p tsconfig.build.json --noEmit && npm run tslint && npm run prettier-check", | ||
"validate-ci": "tsc -p tsconfig.build.json --noEmit && npm run tslint-ci && npm run prettier-check" | ||
"validate-ci": "npm run tslint-ci && npm run prettier-check" | ||
}, | ||
@@ -33,0 +33,0 @@ "dependencies": { |
@@ -1,2 +0,2 @@ | ||
// (C) 2019 GoodData Corporation | ||
// (C) 2019-2020 GoodData Corporation | ||
@@ -157,1 +157,47 @@ import invariant from "ts-invariant"; | ||
} | ||
/** | ||
* Result of search of item among list of dimensions. | ||
* | ||
* @public | ||
*/ | ||
export type ItemInDimension = { | ||
/** | ||
* Content of dimension where the item was found. | ||
*/ | ||
dim: IDimension; | ||
/** | ||
* Index of dimension where the item was found. | ||
*/ | ||
dimIdx: number; | ||
/** | ||
* Index of the item within the dimension where it was found. | ||
*/ | ||
itemIdx: number; | ||
}; | ||
/** | ||
* Looks for item with the provided local identifier among the dimensions. | ||
* | ||
* @param dims - list of dimensions to look in | ||
* @param localId - local identifier to find among item identifiers | ||
* @returns list of items in dimensions, empty if not found, may contain more than one entry if | ||
* item is in multiple dimensions | ||
* @public | ||
*/ | ||
export function dimensionsFindItem(dims: IDimension[], localId: string): ItemInDimension[] { | ||
const result: ItemInDimension[] = []; | ||
for (let dimIdx = 0; dimIdx < dims.length; dimIdx++) { | ||
const dim = dims[dimIdx]; | ||
const itemIdx = dim.itemIdentifiers.findIndex(i => i === localId); | ||
if (itemIdx >= 0) { | ||
result.push({ dim, dimIdx, itemIdx }); | ||
} | ||
} | ||
return result; | ||
} |
@@ -5,2 +5,3 @@ // (C) 2019-2020 GoodData Corporation | ||
dimensionSetTotals, | ||
dimensionsFindItem, | ||
dimensionTotals, | ||
@@ -104,1 +105,16 @@ IDimension, | ||
}); | ||
describe("dimensionsFindItem", () => { | ||
const TestDimensions = newTwoDimensional(["localId1", "localId2"], ["localId3", "localId4", "localId2"]); | ||
const Scenarios: Array<[string, IDimension[], string]> = [ | ||
["find one item in first dimension", TestDimensions, "localId1"], | ||
["find one item in second dimension", TestDimensions, "localId4"], | ||
["find one item in both dimensions", TestDimensions, "localId2"], | ||
["find no item", TestDimensions, "localId0"], | ||
]; | ||
it.each(Scenarios)("should %s", (_desc, dims, id) => { | ||
expect(dimensionsFindItem(dims, id)).toMatchSnapshot(); | ||
}); | ||
}); |
@@ -53,2 +53,4 @@ // (C) 2019-2020 GoodData Corporation | ||
dimensionSetTotals, | ||
dimensionsFindItem, | ||
ItemInDimension, | ||
} from "./execution/base/dimension"; | ||
@@ -55,0 +57,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
701669
17264
1