diff --git a/package.json b/package.json index 8870469..790e3bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "powerbi-models", - "version": "0.10.1", + "version": "0.10.2", "description": "Contains JavaScript & TypeScript object models for Microsoft Power BI JavaScript SDK. For each model there is a TypeScript interface, a json schema definitions, and a validation function to ensure and object is valid.", "main": "dist/models.js", "typings": "dist/models.d.ts", diff --git a/src/models.ts b/src/models.ts index 40ff2d3..ebaf215 100644 --- a/src/models.ts +++ b/src/models.ts @@ -147,7 +147,7 @@ export interface IBasicFilter extends IFilter { values: (string | number | boolean)[]; } -export type BasicFilterOperators = "In" | "NotIn"; +export type BasicFilterOperators = "In" | "NotIn" | "All"; export type AdvancedFilterLogicalOperators = "And" | "Or"; export type AdvancedFilterConditionOperators = "None" | "LessThan" | "LessThanOrEqual" | "GreaterThan" | "GreaterThanOrEqual" | "Contains" | "DoesNotContain" | "StartsWith" | "DoesNotStartWith" | "Is" | "IsNot" | "IsBlank" | "IsNotBlank"; @@ -232,8 +232,8 @@ export class BasicFilter extends Filter { this.operator = operator; this.schemaUrl = BasicFilter.schemaUrl; - if (values.length === 0) { - throw new Error(`values must be a non-empty array. You passed: ${values}`); + if (values.length === 0 && operator !== "All") { + throw new Error(`values must be a non-empty array unless your operator is "All". You passed: ${values}`); } /** diff --git a/test/models.spec.ts b/test/models.spec.ts index 7920610..69ab540 100644 --- a/test/models.spec.ts +++ b/test/models.spec.ts @@ -362,6 +362,27 @@ describe('Unit | Models', function () { false ] }; + // Act + const filter = new models.BasicFilter( + expectedFilter.target, + expectedFilter.operator, + expectedFilter.values); + + // Assert + expect(models.validateFilter(filter.toJSON())).toBeUndefined(); + }); + + it("should return undefined if object is valid basic filter schema with operator All", function () { + // Arrange + const expectedFilter: models.IBasicFilter = { + $schema: "http://powerbi.com/product/schema#advanced", + target: { + table: "a", + column: "b" + }, + operator: "All", + values: [] + }; // Act const filter = new models.BasicFilter(