UNPKG

166 kBTypeScriptView Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94declare module powerbi.data {
95 /** Allows generic traversal and type discovery for a SQExpr tree. */
96 interface ISQExprVisitorWithArg<T, TArg> {
97 visitEntity(expr: SQEntityExpr, arg: TArg): T;
98 visitColumnRef(expr: SQColumnRefExpr, arg: TArg): T;
99 visitMeasureRef(expr: SQMeasureRefExpr, arg: TArg): T;
100 visitAggr(expr: SQAggregationExpr, arg: TArg): T;
101 visitPercentile(expr: SQPercentileExpr, arg: TArg): T;
102 visitHierarchy(expr: SQHierarchyExpr, arg: TArg): T;
103 visitHierarchyLevel(expr: SQHierarchyLevelExpr, arg: TArg): T;
104 visitPropertyVariationSource(expr: SQPropertyVariationSourceExpr, arg: TArg): T;
105 visitSelectRef(expr: SQSelectRefExpr, arg: TArg): T;
106 visitAnd(expr: SQAndExpr, arg: TArg): T;
107 visitBetween(expr: SQBetweenExpr, arg: TArg): T;
108 visitIn(expr: SQInExpr, arg: TArg): T;
109 visitOr(expr: SQOrExpr, arg: TArg): T;
110 visitCompare(expr: SQCompareExpr, arg: TArg): T;
111 visitContains(expr: SQContainsExpr, arg: TArg): T;
112 visitExists(expr: SQExistsExpr, arg: TArg): T;
113 visitNot(expr: SQNotExpr, arg: TArg): T;
114 visitStartsWith(expr: SQStartsWithExpr, arg: TArg): T;
115 visitConstant(expr: SQConstantExpr, arg: TArg): T;
116 visitDateSpan(expr: SQDateSpanExpr, arg: TArg): T;
117 visitDateAdd(expr: SQDateAddExpr, arg: TArg): T;
118 visitNow(expr: SQNowExpr, arg: TArg): T;
119 visitDefaultValue(expr: SQDefaultValueExpr, arg: TArg): T;
120 visitAnyValue(expr: SQAnyValueExpr, arg: TArg): T;
121 visitArithmetic(expr: SQArithmeticExpr, arg: TArg): T;
122 visitFillRule(expr: SQFillRuleExpr, arg: TArg): T;
123 visitResourcePackageItem(expr: SQResourcePackageItemExpr, arg: TArg): T;
124 visitScopedEval(expr: SQScopedEvalExpr, arg: TArg): T;
125 visitWithRef(expr: SQWithRefExpr, arg: TArg): T;
126 visitTransformTableRef(expr: SQTransformTableRefExpr, arg: TArg): T;
127 visitTransformOutputRoleRef(expr: SQTransformOutputRoleRefExpr, arg: TArg): T;
128 }
129 interface ISQExprVisitor<T> extends ISQExprVisitorWithArg<T, void> {
130 }
131 /** Default IQueryExprVisitorWithArg implementation that others may derive from. */
132 class DefaultSQExprVisitorWithArg<T, TArg> implements ISQExprVisitorWithArg<T, TArg> {
133 visitEntity(expr: SQEntityExpr, arg: TArg): T;
134 visitColumnRef(expr: SQColumnRefExpr, arg: TArg): T;
135 visitMeasureRef(expr: SQMeasureRefExpr, arg: TArg): T;
136 visitAggr(expr: SQAggregationExpr, arg: TArg): T;
137 visitPercentile(expr: SQPercentileExpr, arg: TArg): T;
138 visitHierarchy(expr: SQHierarchyExpr, arg: TArg): T;
139 visitHierarchyLevel(expr: SQHierarchyLevelExpr, arg: TArg): T;
140 visitPropertyVariationSource(expr: SQPropertyVariationSourceExpr, arg: TArg): T;
141 visitSelectRef(expr: SQSelectRefExpr, arg: TArg): T;
142 visitBetween(expr: SQBetweenExpr, arg: TArg): T;
143 visitIn(expr: SQInExpr, arg: TArg): T;
144 visitAnd(expr: SQAndExpr, arg: TArg): T;
145 visitOr(expr: SQOrExpr, arg: TArg): T;
146 visitCompare(expr: SQCompareExpr, arg: TArg): T;
147 visitContains(expr: SQContainsExpr, arg: TArg): T;
148 visitExists(expr: SQExistsExpr, arg: TArg): T;
149 visitNot(expr: SQNotExpr, arg: TArg): T;
150 visitStartsWith(expr: SQStartsWithExpr, arg: TArg): T;
151 visitConstant(expr: SQConstantExpr, arg: TArg): T;
152 visitDateSpan(expr: SQDateSpanExpr, arg: TArg): T;
153 visitDateAdd(expr: SQDateAddExpr, arg: TArg): T;
154 visitNow(expr: SQNowExpr, arg: TArg): T;
155 visitDefaultValue(expr: SQDefaultValueExpr, arg: TArg): T;
156 visitAnyValue(expr: SQAnyValueExpr, arg: TArg): T;
157 visitArithmetic(expr: SQArithmeticExpr, arg: TArg): T;
158 visitFillRule(expr: SQFillRuleExpr, arg: TArg): T;
159 visitResourcePackageItem(expr: SQResourcePackageItemExpr, arg: TArg): T;
160 visitScopedEval(expr: SQScopedEvalExpr, arg: TArg): T;
161 visitWithRef(expr: SQWithRefExpr, arg: TArg): T;
162 visitTransformTableRef(expr: SQTransformTableRefExpr, arg: TArg): T;
163 visitTransformOutputRoleRef(expr: SQTransformOutputRoleRefExpr, arg: TArg): T;
164 visitDefault(expr: SQExpr, arg: TArg): T;
165 }
166 /** Default ISQExprVisitor implementation that others may derive from. */
167 class DefaultSQExprVisitor<T> extends DefaultSQExprVisitorWithArg<T, void> implements ISQExprVisitor<T> {
168 }
169 /** Default ISQExprVisitor implementation that implements default traversal and that others may derive from. */
170 class DefaultSQExprVisitorWithTraversal implements ISQExprVisitor<void>, IFillRuleDefinitionVisitor<void, void> {
171 visitEntity(expr: SQEntityExpr): void;
172 visitColumnRef(expr: SQColumnRefExpr): void;
173 visitMeasureRef(expr: SQMeasureRefExpr): void;
174 visitAggr(expr: SQAggregationExpr): void;
175 visitPercentile(expr: SQPercentileExpr): void;
176 visitHierarchy(expr: SQHierarchyExpr): void;
177 visitHierarchyLevel(expr: SQHierarchyLevelExpr): void;
178 visitPropertyVariationSource(expr: SQPropertyVariationSourceExpr): void;
179 visitSelectRef(expr: SQSelectRefExpr): void;
180 visitBetween(expr: SQBetweenExpr): void;
181 visitIn(expr: SQInExpr): void;
182 visitAnd(expr: SQAndExpr): void;
183 visitOr(expr: SQOrExpr): void;
184 visitCompare(expr: SQCompareExpr): void;
185 visitContains(expr: SQContainsExpr): void;
186 visitExists(expr: SQExistsExpr): void;
187 visitNot(expr: SQNotExpr): void;
188 visitStartsWith(expr: SQStartsWithExpr): void;
189 visitConstant(expr: SQConstantExpr): void;
190 visitDateSpan(expr: SQDateSpanExpr): void;
191 visitDateAdd(expr: SQDateAddExpr): void;
192 visitNow(expr: SQNowExpr): void;
193 visitDefaultValue(expr: SQDefaultValueExpr): void;
194 visitAnyValue(expr: SQAnyValueExpr): void;
195 visitArithmetic(expr: SQArithmeticExpr): void;
196 visitFillRule(expr: SQFillRuleExpr): void;
197 visitLinearGradient2(gradient2: LinearGradient2Definition): void;
198 visitLinearGradient3(gradient3: LinearGradient3Definition): void;
199 visitResourcePackageItem(expr: SQResourcePackageItemExpr): void;
200 visitScopedEval(expr: SQScopedEvalExpr): void;
201 visitWithRef(expr: SQWithRefExpr): void;
202 visitTransformTableRef(expr: SQTransformTableRefExpr): void;
203 visitTransformOutputRoleRef(expr: SQTransformOutputRoleRefExpr): void;
204 visitDefault(expr: SQExpr): void;
205 private visitFillRuleStop(stop);
206 }
207}
208
209declare module powerbi {
210 /** Defines a custom enumeration data type, and its values. */
211 interface IEnumType {
212 /** Gets the members of the enumeration, limited to the validMembers, if appropriate. */
213 members(validMembers?: EnumMemberValue[]): IEnumMember[];
214 }
215 function createEnumType(members: IEnumMember[]): IEnumType;
216}
217
218declare module powerbi {
219 import SQExpr = powerbi.data.SQExpr;
220 interface FillDefinition {
221 solid?: {
222 color?: SQExpr;
223 };
224 gradient?: {
225 startColor?: SQExpr;
226 endColor?: SQExpr;
227 };
228 pattern?: {
229 patternKind?: SQExpr;
230 color?: SQExpr;
231 };
232 }
233 function createSolidFillDefinition(color: string): FillDefinition;
234 module FillSolidColorTypeDescriptor {
235 /** Gets a value indicating whether the descriptor is nullable or not. */
236 function nullable(descriptor: FillSolidColorTypeDescriptor): boolean;
237 }
238}
239
240declare module powerbi {
241 import SQExpr = powerbi.data.SQExpr;
242 interface FillRuleTypeDescriptor {
243 }
244 interface FillRuleDefinition extends FillRuleGeneric<SQExpr, SQExpr> {
245 }
246 interface FillRule extends FillRuleGeneric<string, number> {
247 }
248 type LinearGradient2 = LinearGradient2Generic<string, number>;
249 type LinearGradient3 = LinearGradient3Generic<string, number>;
250 type LinearGradient2Definition = LinearGradient2Generic<SQExpr, SQExpr>;
251 type LinearGradient3Definition = LinearGradient3Generic<SQExpr, SQExpr>;
252 type RuleColorStopDefinition = RuleColorStopGeneric<SQExpr, SQExpr>;
253 type RuleColorStop = RuleColorStopGeneric<string, number>;
254 interface IFillRuleDefinitionVisitor<T2, T3> {
255 visitLinearGradient2(linearGradient2: LinearGradient2Definition, arg?: any): T2;
256 visitLinearGradient3(linearGradient3: LinearGradient3Definition, arg?: any): T3;
257 }
258}
259
260declare module powerbi {
261 import SQExpr = powerbi.data.SQExpr;
262 interface ImageTypeDescriptor {
263 }
264 type ImageDefinition = ImageDefinitionGeneric<SQExpr>;
265 module ImageDefinition {
266 const urlType: ValueTypeDescriptor;
267 }
268}
269
270declare module powerbi {
271 import SQExpr = powerbi.data.SQExpr;
272 interface ParagraphsTypeDescriptor {
273 }
274 type ParagraphsDefinition = ParagraphDefinition[];
275 type ParagraphDefinition = ParagraphDefinitionGeneric<SQExpr>;
276 type TextRunDefinition = TextRunDefinitionGeneric<SQExpr>;
277 interface ParagraphDefinitionGeneric<TExpr> {
278 horizontalTextAlignment?: string;
279 textRuns: TextRunDefinitionGeneric<TExpr>[];
280 }
281 interface TextRunDefinitionGeneric<TExpr> {
282 textStyle?: TextRunStyle;
283 url?: string;
284 value: string | TExpr;
285 }
286}
287
288declare module powerbi {
289 import SemanticFilter = powerbi.data.SemanticFilter;
290 type StructuralObjectDefinition = FillDefinition | FillRuleDefinition | SemanticFilter | DefaultValueDefinition | ImageDefinition | ParagraphsDefinition;
291 module StructuralTypeDescriptor {
292 function isValid(type: StructuralTypeDescriptor): boolean;
293 }
294}
295
296declare module powerbi {
297 interface ValueTypeDescriptor {
298 extendedType?: ExtendedType;
299 }
300 /** Describes a data value type, including a primitive type and extended type if any (derived from data category). */
301 class ValueType implements ValueTypeDescriptor {
302 private static typeCache;
303 private underlyingType;
304 private category;
305 private temporalType;
306 private geographyType;
307 private miscType;
308 private formattingType;
309 private enumType;
310 private scriptingType;
311 /** Do not call the ValueType constructor directly. Use the ValueType.fromXXX methods. */
312 constructor(type: ExtendedType, category?: string, enumType?: IEnumType);
313 /** Creates or retrieves a ValueType object based on the specified ValueTypeDescriptor. */
314 static fromDescriptor(descriptor: ValueTypeDescriptor): ValueType;
315 /** Advanced: Generally use fromDescriptor instead. Creates or retrieves a ValueType object for the specified ExtendedType. */
316 static fromExtendedType(extendedType: ExtendedType): ValueType;
317 /** Creates or retrieves a ValueType object for the specified PrimitiveType and data category. */
318 static fromPrimitiveTypeAndCategory(primitiveType: PrimitiveType, category?: string): ValueType;
319 /** Creates a ValueType to describe the given IEnumType. */
320 static fromEnum(enumType: IEnumType): ValueType;
321 /** Determines if the specified type is compatible from at least one of the otherTypes. */
322 static isCompatibleTo(type: ValueTypeDescriptor, otherTypes: ValueTypeDescriptor[]): boolean;
323 /** Determines if the instance ValueType is convertable from the 'other' ValueType. */
324 isCompatibleFrom(other: ValueType): boolean;
325 /**
326 * Determines if the instance ValueType is equal to the 'other' ValueType
327 * @param {ValueType} other the other ValueType to check equality against
328 * @returns True if the instance ValueType is equal to the 'other' ValueType
329 */
330 equals(other: ValueType): boolean;
331 /** Gets the exact primitive type of this ValueType. */
332 primitiveType: PrimitiveType;
333 /** Gets the exact extended type of this ValueType. */
334 extendedType: ExtendedType;
335 /** Gets the data category string (if any) for this ValueType. */
336 categoryString: string;
337 /** Indicates whether the type represents text values. */
338 text: boolean;
339 /** Indicates whether the type represents any numeric value. */
340 numeric: boolean;
341 /** Indicates whether the type represents integer numeric values. */
342 integer: boolean;
343 /** Indicates whether the type represents Boolean values. */
344 bool: boolean;
345 /** Indicates whether the type represents any date/time values. */
346 dateTime: boolean;
347 /** Indicates whether the type represents duration values. */
348 duration: boolean;
349 /** Indicates whether the type represents binary values. */
350 binary: boolean;
351 /** Indicates whether the type represents none values. */
352 none: boolean;
353 /** Returns an object describing temporal values represented by the type, if it represents a temporal type. */
354 temporal: TemporalType;
355 /** Returns an object describing geographic values represented by the type, if it represents a geographic type. */
356 geography: GeographyType;
357 /** Returns an object describing the specific values represented by the type, if it represents a miscellaneous extended type. */
358 misc: MiscellaneousType;
359 /** Returns an object describing the formatting values represented by the type, if it represents a formatting type. */
360 formatting: FormattingType;
361 /** Returns an object describing the enum values represented by the type, if it represents an enumeration type. */
362 enum: IEnumType;
363 scripting: ScriptType;
364 }
365 class ScriptType implements ScriptTypeDescriptor {
366 private underlyingType;
367 constructor(type: ExtendedType);
368 source: boolean;
369 }
370 class TemporalType implements TemporalTypeDescriptor {
371 private underlyingType;
372 constructor(type: ExtendedType);
373 year: boolean;
374 month: boolean;
375 }
376 class GeographyType implements GeographyTypeDescriptor {
377 private underlyingType;
378 constructor(type: ExtendedType);
379 address: boolean;
380 city: boolean;
381 continent: boolean;
382 country: boolean;
383 county: boolean;
384 region: boolean;
385 postalCode: boolean;
386 stateOrProvince: boolean;
387 place: boolean;
388 latitude: boolean;
389 longitude: boolean;
390 }
391 class MiscellaneousType implements MiscellaneousTypeDescriptor {
392 private underlyingType;
393 constructor(type: ExtendedType);
394 image: boolean;
395 imageUrl: boolean;
396 webUrl: boolean;
397 barcode: boolean;
398 }
399 class FormattingType implements FormattingTypeDescriptor {
400 private underlyingType;
401 constructor(type: ExtendedType);
402 color: boolean;
403 formatString: boolean;
404 alignment: boolean;
405 labelDisplayUnits: boolean;
406 fontSize: boolean;
407 labelDensity: boolean;
408 }
409 /** Defines primitive value types. Must be consistent with types defined by server conceptual schema. */
410 enum PrimitiveType {
411 Null = 0,
412 Text = 1,
413 Decimal = 2,
414 Double = 3,
415 Integer = 4,
416 Boolean = 5,
417 Date = 6,
418 DateTime = 7,
419 DateTimeZone = 8,
420 Time = 9,
421 Duration = 10,
422 Binary = 11,
423 None = 12,
424 }
425 /** Defines extended value types, which include primitive types and known data categories constrained to expected primitive types. */
426 enum ExtendedType {
427 Numeric = 256,
428 Temporal = 512,
429 Geography = 1024,
430 Miscellaneous = 2048,
431 Formatting = 4096,
432 Scripting = 8192,
433 Null = 0,
434 Text = 1,
435 Decimal = 258,
436 Double = 259,
437 Integer = 260,
438 Boolean = 5,
439 Date = 518,
440 DateTime = 519,
441 DateTimeZone = 520,
442 Time = 521,
443 Duration = 10,
444 Binary = 11,
445 None = 12,
446 Year = 66048,
447 Year_Text = 66049,
448 Year_Integer = 66308,
449 Year_Date = 66054,
450 Year_DateTime = 66055,
451 Month = 131584,
452 Month_Text = 131585,
453 Month_Integer = 131844,
454 Month_Date = 131590,
455 Month_DateTime = 131591,
456 Address = 6554625,
457 City = 6620161,
458 Continent = 6685697,
459 Country = 6751233,
460 County = 6816769,
461 Region = 6882305,
462 PostalCode = 6947840,
463 PostalCode_Text = 6947841,
464 PostalCode_Integer = 6948100,
465 StateOrProvince = 7013377,
466 Place = 7078913,
467 Latitude = 7144448,
468 Latitude_Decimal = 7144706,
469 Latitude_Double = 7144707,
470 Longitude = 7209984,
471 Longitude_Decimal = 7210242,
472 Longitude_Double = 7210243,
473 Image = 13109259,
474 ImageUrl = 13174785,
475 WebUrl = 13240321,
476 Barcode = 13305856,
477 Barcode_Text = 13305857,
478 Barcode_Integer = 13306116,
479 Color = 19664897,
480 FormatString = 19730433,
481 Alignment = 20058113,
482 LabelDisplayUnits = 20123649,
483 FontSize = 20189443,
484 LabelDensity = 20254979,
485 Enumeration = 26214401,
486 ScriptSource = 32776193,
487 SearchEnabled = 65541,
488 }
489}
490
491declare module powerbi.data {
492 /**
493 * Represents the versions of the data shape binding structure.
494 * NOTE Keep this file in sync with the Sql\InfoNav\src\Data\Contracts\DsqGeneration\DataShapeBindingVersions.cs
495 * file in the TFS Dev branch.
496 */
497 const enum DataShapeBindingVersions {
498 /** The initial version of data shape binding */
499 Version0 = 0,
500 /** Explicit subtotal support for axis groupings. */
501 Version1 = 1,
502 }
503 interface DataShapeBindingLimitTarget {
504 Primary?: number;
505 }
506 enum DataShapeBindingLimitType {
507 Top = 0,
508 First = 1,
509 Last = 2,
510 Sample = 3,
511 Bottom = 4,
512 }
513 interface DataShapeBindingLimit {
514 Count?: number;
515 Target: DataShapeBindingLimitTarget;
516 Type: DataShapeBindingLimitType;
517 }
518 interface DataShapeBinding {
519 Version?: number;
520 Primary: DataShapeBindingAxis;
521 Secondary?: DataShapeBindingAxis;
522 Aggregates?: DataShapeBindingAggregate[];
523 Projections?: number[];
524 Limits?: DataShapeBindingLimit[];
525 Highlights?: FilterDefinition[];
526 DataReduction?: DataShapeBindingDataReduction;
527 IncludeEmptyGroups?: boolean;
528 SuppressedJoinPredicates?: number[];
529 }
530 interface DataShapeBindingDataReduction {
531 Primary?: DataShapeBindingDataReductionAlgorithm;
532 Secondary?: DataShapeBindingDataReductionAlgorithm;
533 DataVolume?: number;
534 }
535 interface DataShapeBindingDataReductionAlgorithm {
536 Top?: DataShapeBindingDataReductionTopLimit;
537 Sample?: DataShapeBindingDataReductionSampleLimit;
538 Bottom?: DataShapeBindingDataReductionBottomLimit;
539 Window?: DataShapeBindingDataReductionDataWindow;
540 }
541 interface DataShapeBindingDataReductionTopLimit {
542 Count?: number;
543 }
544 interface DataShapeBindingDataReductionSampleLimit {
545 Count?: number;
546 }
547 interface DataShapeBindingDataReductionBottomLimit {
548 Count?: number;
549 }
550 interface DataShapeBindingDataReductionDataWindow {
551 Count?: number;
552 RestartTokens?: RestartToken;
553 }
554 interface DataShapeBindingAxis {
555 Groupings: DataShapeBindingAxisGrouping[];
556 }
557 enum SubtotalType {
558 None = 0,
559 Before = 1,
560 After = 2,
561 }
562 interface DataShapeBindingAxisGrouping {
563 Projections: number[];
564 GroupBy?: number[];
565 SuppressedProjections?: number[];
566 Subtotal?: SubtotalType;
567 ShowItemsWithNoData?: number[];
568 }
569 interface DataShapeBindingAggregate {
570 Select: number;
571 Kind?: DataShapeBindingAggregateKind;
572 Aggregations?: DataShapeBindingSelectAggregateContainer[];
573 }
574 const enum DataShapeBindingAggregateKind {
575 None = 0,
576 Min = 1,
577 Max = 2,
578 }
579 interface DataShapeBindingSelectAggregateContainer {
580 Percentile?: DataShapeBindingSelectPercentileAggregate;
581 Min?: DataShapeBindingSelectMinAggregate;
582 Max?: DataShapeBindingSelectMaxAggregate;
583 }
584 interface DataShapeBindingSelectPercentileAggregate {
585 Exclusive?: boolean;
586 K: number;
587 }
588 interface DataShapeBindingSelectMaxAggregate {
589 }
590 interface DataShapeBindingSelectMinAggregate {
591 }
592}
593
594declare module powerbi.data {
595 module DataShapeBindingDataReduction {
596 function createFrom(reduction: ReductionAlgorithm): DataShapeBindingDataReductionAlgorithm;
597 }
598}
599
600declare module powerbi.data {
601 interface FederatedConceptualSchemaInitOptions {
602 schemas: {
603 [name: string]: ConceptualSchema;
604 };
605 links?: ConceptualSchemaLink[];
606 }
607 /** Represents a federated conceptual schema. */
608 class FederatedConceptualSchema {
609 private schemas;
610 private links;
611 constructor(options: FederatedConceptualSchemaInitOptions);
612 schema(name: string): ConceptualSchema;
613 }
614 /** Describes a semantic relationship between ConceptualSchemas. */
615 interface ConceptualSchemaLink {
616 }
617}
618
619declare module powerbi.data {
620 module Selector {
621 function filterFromSelector(selectors: Selector[], isNot?: boolean): SemanticFilter;
622 function matchesData(selector: Selector, identities: DataViewScopeIdentity[]): boolean;
623 function matchesKeys(selector: Selector, keysList: SQExpr[][]): boolean;
624 /** Determines whether two selectors are equal. */
625 function equals(x: Selector, y: Selector): boolean;
626 function getKey(selector: Selector): string;
627 function containsWildcard(selector: Selector): boolean;
628 function hasRoleWildcard(selector: Selector): boolean;
629 function isRoleWildcard(dataItem: DataRepetitionSelector): dataItem is DataViewRoleWildcard;
630 }
631}
632
633declare module powerbi.data {
634 interface QueryDefinition {
635 Version?: number;
636 From: EntitySource[];
637 Where?: QueryFilter[];
638 OrderBy?: QuerySortClause[];
639 Select: QueryExpressionContainer[];
640 GroupBy?: QueryExpressionContainer[];
641 Transform?: QueryTransform[];
642 }
643 interface FilterDefinition {
644 Version?: number;
645 From: EntitySource[];
646 Where: QueryFilter[];
647 }
648 enum EntitySourceType {
649 Table = 0,
650 Pod = 1,
651 Expression = 2,
652 }
653 interface EntitySource {
654 Name: string;
655 EntitySet?: string;
656 Entity?: string;
657 Schema?: string;
658 Expression?: QueryExpressionContainer;
659 Type?: EntitySourceType;
660 }
661 interface QueryFilter {
662 Target?: QueryExpressionContainer[];
663 Condition: QueryExpressionContainer;
664 }
665 interface QuerySortClause {
666 Expression: QueryExpressionContainer;
667 Direction: SortDirection;
668 }
669 interface QueryExpressionContainer {
670 Name?: string;
671 SourceRef?: QuerySourceRefExpression;
672 Column?: QueryColumnExpression;
673 Measure?: QueryMeasureExpression;
674 Aggregation?: QueryAggregationExpression;
675 Percentile?: QueryPercentileExpression;
676 Hierarchy?: QueryHierarchyExpression;
677 HierarchyLevel?: QueryHierarchyLevelExpression;
678 PropertyVariationSource?: QueryPropertyVariationSourceExpression;
679 Subquery?: QuerySubqueryExpression;
680 And?: QueryBinaryExpression;
681 Between?: QueryBetweenExpression;
682 In?: QueryInExpression;
683 Or?: QueryBinaryExpression;
684 Comparison?: QueryComparisonExpression;
685 Not?: QueryNotExpression;
686 Contains?: QueryContainsExpression;
687 StartsWith?: QueryStartsWithExpression;
688 Exists?: QueryExistsExpression;
689 Boolean?: QueryBooleanExpression;
690 DateTime?: QueryDateTimeExpression;
691 DateTimeSecond?: QueryDateTimeSecondExpression;
692 Date?: QueryDateTimeExpression;
693 Decimal?: QueryDecimalExpression;
694 Integer?: QueryIntegerExpression;
695 Null?: QueryNullExpression;
696 Number?: QueryNumberExpression;
697 String?: QueryStringExpression;
698 Literal?: QueryLiteralExpression;
699 DateSpan?: QueryDateSpanExpression;
700 DateAdd?: QueryDateAddExpression;
701 Now?: QueryNowExpression;
702 DefaultValue?: QueryDefaultValueExpression;
703 AnyValue?: QueryAnyValueExpression;
704 Arithmetic?: QueryArithmeticExpression;
705 ScopedEval?: QueryScopedEvalExpression;
706 WithRef?: QueryWithRefExpression;
707 TransformTableRef?: QueryTransformTableRefExpression;
708 TransformOutputRoleRef?: QueryTransformOutputRoleRefExpression;
709 FillRule?: QueryFillRuleExpression;
710 ResourcePackageItem?: QueryResourcePackageItem;
711 SelectRef?: QuerySelectRefExpression;
712 }
713 interface QueryPropertyExpression {
714 Expression: QueryExpressionContainer;
715 Property: string;
716 }
717 interface QueryColumnExpression extends QueryPropertyExpression {
718 }
719 interface QueryMeasureExpression extends QueryPropertyExpression {
720 }
721 interface QuerySourceRefExpression {
722 Source: string;
723 }
724 interface QuerySelectRefExpression {
725 ExpressionName: string;
726 }
727 interface QueryAggregationExpression {
728 Function: QueryAggregateFunction;
729 Expression: QueryExpressionContainer;
730 }
731 interface QueryPercentileExpression {
732 Expression: QueryExpressionContainer;
733 K: number;
734 Exclusive?: boolean;
735 }
736 interface QueryHierarchyExpression {
737 Expression: QueryExpressionContainer;
738 Hierarchy: string;
739 }
740 interface QueryHierarchyLevelExpression {
741 Expression: QueryExpressionContainer;
742 Level: string;
743 }
744 interface QueryPropertyVariationSourceExpression {
745 Expression: QueryExpressionContainer;
746 Name: string;
747 Property: string;
748 }
749 interface QuerySubqueryExpression {
750 Query: QueryDefinition;
751 }
752 interface QueryBinaryExpression {
753 Left: QueryExpressionContainer;
754 Right: QueryExpressionContainer;
755 }
756 interface QueryBetweenExpression {
757 Expression: QueryExpressionContainer;
758 LowerBound: QueryExpressionContainer;
759 UpperBound: QueryExpressionContainer;
760 }
761 interface QueryInExpression {
762 Expressions: QueryExpressionContainer[];
763 Values: QueryExpressionContainer[][];
764 }
765 interface QueryComparisonExpression extends QueryBinaryExpression {
766 ComparisonKind: QueryComparisonKind;
767 }
768 interface QueryContainsExpression extends QueryBinaryExpression {
769 }
770 interface QueryNotExpression {
771 Expression: QueryExpressionContainer;
772 }
773 interface QueryStartsWithExpression extends QueryBinaryExpression {
774 }
775 interface QueryExistsExpression {
776 Expression: QueryExpressionContainer;
777 }
778 interface QueryConstantExpression<T> {
779 Value: T;
780 }
781 interface QueryLiteralExpression {
782 Value: string;
783 }
784 interface QueryBooleanExpression extends QueryConstantExpression<boolean> {
785 }
786 interface QueryDateTimeExpression extends QueryConstantExpression<string> {
787 }
788 interface QueryDateTimeSecondExpression extends QueryConstantExpression<string> {
789 }
790 interface QueryDecimalExpression extends QueryConstantExpression<number> {
791 }
792 interface QueryIntegerExpression extends QueryConstantExpression<number> {
793 }
794 interface QueryNumberExpression extends QueryConstantExpression<string> {
795 }
796 interface QueryNullExpression {
797 }
798 interface QueryStringExpression extends QueryConstantExpression<string> {
799 }
800 interface QueryDateSpanExpression {
801 TimeUnit: TimeUnit;
802 Expression: QueryExpressionContainer;
803 }
804 interface QueryDateAddExpression {
805 Amount: number;
806 TimeUnit: TimeUnit;
807 Expression: QueryExpressionContainer;
808 }
809 interface QueryNowExpression {
810 }
811 interface QueryDefaultValueExpression {
812 }
813 interface QueryAnyValueExpression {
814 }
815 interface QueryArithmeticExpression {
816 Left: QueryExpressionContainer;
817 Right: QueryExpressionContainer;
818 Operator: ArithmeticOperatorKind;
819 }
820 const enum ArithmeticOperatorKind {
821 Add = 0,
822 Subtract = 1,
823 Multiply = 2,
824 Divide = 3,
825 }
826 function getArithmeticOperatorName(arithmeticOperatorKind: ArithmeticOperatorKind): string;
827 interface QueryFillRuleExpression {
828 Input: QueryExpressionContainer;
829 FillRule: FillRuleGeneric<QueryExpressionContainer, QueryExpressionContainer>;
830 }
831 interface QueryResourcePackageItem {
832 PackageName: string;
833 PackageType: number;
834 ItemName: string;
835 }
836 interface QueryScopedEvalExpression {
837 Expression: QueryExpressionContainer;
838 Scope: QueryExpressionContainer[];
839 }
840 interface QueryWithRefExpression {
841 ExpressionName: string;
842 }
843 interface QueryTransformTableRefExpression {
844 Source: string;
845 }
846 interface QueryTransformOutputRoleRefExpression {
847 Role: string;
848 Transform?: string;
849 }
850 enum TimeUnit {
851 Day = 0,
852 Week = 1,
853 Month = 2,
854 Year = 3,
855 Decade = 4,
856 Second = 5,
857 Minute = 6,
858 Hour = 7,
859 }
860 enum QueryAggregateFunction {
861 Sum = 0,
862 Avg = 1,
863 Count = 2,
864 Min = 3,
865 Max = 4,
866 CountNonNull = 5,
867 Median = 6,
868 StandardDeviation = 7,
869 Variance = 8,
870 }
871 enum QueryComparisonKind {
872 Equal = 0,
873 GreaterThan = 1,
874 GreaterThanOrEqual = 2,
875 LessThan = 3,
876 LessThanOrEqual = 4,
877 }
878 /** Defines semantic data types. */
879 enum SemanticType {
880 None = 0,
881 Number = 1,
882 Integer = 3,
883 DateTime = 4,
884 Time = 8,
885 Date = 20,
886 Month = 35,
887 Year = 67,
888 YearAndMonth = 128,
889 MonthAndDay = 256,
890 Decade = 515,
891 YearAndWeek = 1024,
892 String = 2048,
893 Boolean = 4096,
894 Table = 8192,
895 Range = 16384,
896 }
897 interface QueryMetadata {
898 Select?: SelectMetadata[];
899 Filters?: FilterMetadata[];
900 }
901 interface SelectMetadata {
902 Restatement: string;
903 Type?: number;
904 Format?: string;
905 DataCategory?: ConceptualDataCategory;
906 /** The select projection name. */
907 Name?: string;
908 kpiStatusGraphic?: string;
909 kpi?: DataViewKpiColumnMetadata;
910 }
911 interface FilterMetadata {
912 Restatement: string;
913 Kind?: FilterKind;
914 /** The expression being filtered. This is reflected in the filter card UI. */
915 expression?: QueryExpressionContainer;
916 }
917 enum FilterKind {
918 Default = 0,
919 Period = 1,
920 }
921 interface QueryTransform {
922 Name: string;
923 Algorithm: string;
924 Input: QueryTransformInput;
925 Output: QueryTransformOutput;
926 }
927 interface QueryTransformInput {
928 Parameters: QueryExpressionContainer[];
929 Table?: QueryTransformTable;
930 }
931 interface QueryTransformOutput {
932 Table?: QueryTransformTable;
933 }
934 interface QueryTransformTable {
935 Name: string;
936 Columns: QueryTransformTableColumn[];
937 }
938 interface QueryTransformTableColumn {
939 Role?: string;
940 Expression: QueryExpressionContainer;
941 }
942}
943
944declare module powerbi.data {
945 /** Represents a projection from a query result. */
946 interface QueryProjection {
947 /** Name of item in the semantic query Select clause. */
948 queryRef: string;
949 /** Optional format string. */
950 format?: string;
951 }
952 /** A set of QueryProjections, grouped by visualization property, and ordered within that property. */
953 interface QueryProjectionsByRole {
954 [roleName: string]: QueryProjectionCollection;
955 }
956 class QueryProjectionCollection {
957 private items;
958 private _activeProjectionRefs;
959 private _showAll;
960 constructor(items: QueryProjection[], activeProjectionRefs?: string[], showAll?: boolean);
961 /** Returns all projections in a mutable array. */
962 all(): QueryProjection[];
963 activeProjectionRefs: string[];
964 showAll: boolean;
965 addActiveQueryReference(queryRef: string): void;
966 getLastActiveQueryReference(): string;
967 /** Replaces the given oldQueryRef with newQueryRef in this QueryProjectionCollection. */
968 replaceQueryRef(oldQueryRef: string, newQueryRef: string): void;
969 clone(): QueryProjectionCollection;
970 }
971 module QueryProjectionsByRole {
972 /** Clones the QueryProjectionsByRole. */
973 function clone(roles: QueryProjectionsByRole): QueryProjectionsByRole;
974 /** Returns the QueryProjectionCollection for that role. Even returns empty collections so that 'drillable' and 'activeProjection' fields are preserved. */
975 function getRole(roles: QueryProjectionsByRole, name: string): QueryProjectionCollection;
976 }
977}
978
979declare module powerbi {
980 interface VisualElement {
981 DataRoles?: DataRole[];
982 Settings?: VisualElementSettings;
983 }
984 /** Defines common settings for a visual element. */
985 interface VisualElementSettings {
986 DisplayUnitSystemType?: DisplayUnitSystemType;
987 }
988 interface DataRole {
989 Name: string;
990 Projection: number;
991 isActive?: boolean;
992 }
993 /** The system used to determine display units used during formatting */
994 enum DisplayUnitSystemType {
995 /** Default display unit system, which saves space by using units such as K, M, bn with PowerView rules for when to pick a unit. Suitable for chart axes. */
996 Default = 0,
997 /** A verbose display unit system that will only respect the formatting defined in the model. Suitable for explore mode single-value cards. */
998 Verbose = 1,
999 /**
1000 * A display unit system that uses units such as K, M, bn if we have at least one of those units (e.g. 0.9M is not valid as it's less than 1 million).
1001 * Suitable for dashboard tile cards
1002 */
1003 WholeUnits = 2,
1004 /**A display unit system that also contains Auto and None units for data labels*/
1005 DataLabels = 3,
1006 }
1007}
1008declare module powerbi.data.contracts {
1009 interface DataViewSource {
1010 data: any;
1011 type?: string;
1012 }
1013}
1014
1015declare module powerbi {
1016 /** Repreasents the sequence of the dates/times */
1017 class DateTimeSequence {
1018 private static MIN_COUNT;
1019 private static MAX_COUNT;
1020 min: Date;
1021 max: Date;
1022 unit: DateTimeUnit;
1023 sequence: Date[];
1024 interval: number;
1025 intervalOffset: number;
1026 /** Creates new instance of the DateTimeSequence */
1027 constructor(unit: DateTimeUnit);
1028 /**
1029 * Add a new Date to a sequence.
1030 * @param date - date to add
1031 */
1032 add(date: Date): void;
1033 /**
1034 * Extends the sequence to cover new date range
1035 * @param min - new min to be covered by sequence
1036 * @param max - new max to be covered by sequence
1037 */
1038 extendToCover(min: Date, max: Date): void;
1039 /**
1040 * Move the sequence to cover new date range
1041 * @param min - new min to be covered by sequence
1042 * @param max - new max to be covered by sequence
1043 */
1044 moveToCover(min: Date, max: Date): void;
1045 /**
1046 * Calculate a new DateTimeSequence
1047 * @param dataMin - Date representing min of the data range
1048 * @param dataMax - Date representing max of the data range
1049 * @param expectedCount - expected number of intervals in the sequence
1050 * @param unit - of the intervals in the sequence
1051 */
1052 static calculate(dataMin: Date, dataMax: Date, expectedCount: number, unit?: DateTimeUnit): DateTimeSequence;
1053 static calculateYears(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1054 static calculateMonths(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1055 static calculateWeeks(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1056 static calculateDays(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1057 static calculateHours(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1058 static calculateMinutes(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1059 static calculateSeconds(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1060 static calculateMilliseconds(dataMin: Date, dataMax: Date, expectedCount: number): DateTimeSequence;
1061 static addInterval(value: Date, interval: number, unit: DateTimeUnit): Date;
1062 private static fromNumericSequence(date, sequence, unit);
1063 private static getDelta(min, max, unit);
1064 static getIntervalUnit(min: Date, max: Date, maxCount: number): DateTimeUnit;
1065 }
1066 /** DateUtils module provides DateTimeSequence with set of additional date manipulation routines */
1067 module DateUtils {
1068 /**
1069 * Adds a specified number of years to the provided date.
1070 * @param date - date value
1071 * @param yearDelta - number of years to add
1072 */
1073 function addYears(date: Date, yearDelta: number): Date;
1074 /**
1075 * Adds a specified number of months to the provided date.
1076 * @param date - date value
1077 * @param monthDelta - number of months to add
1078 */
1079 function addMonths(date: Date, monthDelta: number): Date;
1080 /**
1081 * Adds a specified number of weeks to the provided date.
1082 * @param date - date value
1083 * @param weeks - number of weeks to add
1084 */
1085 function addWeeks(date: Date, weeks: number): Date;
1086 /**
1087 * Adds a specified number of days to the provided date.
1088 * @param date - date value
1089 * @param days - number of days to add
1090 */
1091 function addDays(date: Date, days: number): Date;
1092 /**
1093 * Adds a specified number of hours to the provided date.
1094 * @param date - date value
1095 * @param hours - number of hours to add
1096 */
1097 function addHours(date: Date, hours: number): Date;
1098 /**
1099 * Adds a specified number of minutes to the provided date.
1100 * @param date - date value
1101 * @param minutes - number of minutes to add
1102 */
1103 function addMinutes(date: Date, minutes: number): Date;
1104 /**
1105 * Adds a specified number of seconds to the provided date.
1106 * @param date - date value
1107 * @param seconds - number of seconds to add
1108 */
1109 function addSeconds(date: Date, seconds: number): Date;
1110 /**
1111 * Adds a specified number of milliseconds to the provided date.
1112 * @param date - date value
1113 * @param milliseconds - number of milliseconds to add
1114 */
1115 function addMilliseconds(date: Date, milliseconds: number): Date;
1116 }
1117}
1118
1119declare module powerbi {
1120 class DisplayUnit {
1121 value: number;
1122 title: string;
1123 labelFormat: string;
1124 applicableRangeMin: number;
1125 applicableRangeMax: number;
1126 project(value: number): number;
1127 reverseProject(value: number): number;
1128 isApplicableTo(value: number): boolean;
1129 isScaling(): boolean;
1130 }
1131 class DisplayUnitSystem {
1132 units: DisplayUnit[];
1133 displayUnit: DisplayUnit;
1134 private unitBaseValue;
1135 protected static UNSUPPORTED_FORMATS: RegExp;
1136 constructor(units?: DisplayUnit[]);
1137 title: string;
1138 update(value: number): void;
1139 private findApplicableDisplayUnit(value);
1140 format(value: number, format: string, decimals?: number, trailingZeros?: boolean): string;
1141 isFormatSupported(format: string): boolean;
1142 isPercentageFormat(format: string): boolean;
1143 shouldRespectScalingUnit(format: string): boolean;
1144 getNumberOfDecimalsForFormatting(format: string, decimals?: number): number;
1145 isScalingUnit(): boolean;
1146 private formatHelper(value, nonScientificFormat, format, decimals?, trailingZeros?);
1147 /** Formats a single value by choosing an appropriate base for the DisplayUnitSystem before formatting. */
1148 formatSingleValue(value: number, format: string, decimals?: number, trailingZeros?: boolean): string;
1149 private shouldUseValuePrecision(value);
1150 protected isScientific(value: number): boolean;
1151 protected hasScientitifcFormat(format: string): boolean;
1152 protected supportsScientificFormat(format: string): boolean;
1153 protected shouldFallbackToScientific(value: number, format: string): boolean;
1154 protected getScientificFormat(data: number, format: string, decimals: number, trailingZeros: boolean): string;
1155 }
1156 /** Provides a unit system that is defined by formatting in the model, and is suitable for visualizations shown in single number visuals in explore mode. */
1157 class NoDisplayUnitSystem extends DisplayUnitSystem {
1158 constructor();
1159 }
1160 /** Provides a unit system that creates a more concise format for displaying values. This is suitable for most of the cases where
1161 we are showing values (chart axes) and as such it is the default unit system. */
1162 class DefaultDisplayUnitSystem extends DisplayUnitSystem {
1163 private static units;
1164 constructor(unitLookup: (exponent: number) => DisplayUnitSystemNames);
1165 format(data: number, format: string, decimals?: number, trailingZeros?: boolean): string;
1166 static reset(): void;
1167 private static getUnits(unitLookup);
1168 }
1169 /** Provides a unit system that creates a more concise format for displaying values, but only allows showing a unit if we have at least
1170 one of those units (e.g. 0.9M is not allowed since it's less than 1 million). This is suitable for cases such as dashboard tiles
1171 where we have restricted space but do not want to show partial units. */
1172 class WholeUnitsDisplayUnitSystem extends DisplayUnitSystem {
1173 private static units;
1174 constructor(unitLookup: (exponent: number) => DisplayUnitSystemNames);
1175 static reset(): void;
1176 private static getUnits(unitLookup);
1177 format(data: number, format: string, decimals?: number, trailingZeros?: boolean): string;
1178 }
1179 class DataLabelsDisplayUnitSystem extends DisplayUnitSystem {
1180 private static AUTO_DISPLAYUNIT_VALUE;
1181 private static NONE_DISPLAYUNIT_VALUE;
1182 protected static UNSUPPORTED_FORMATS: RegExp;
1183 private static units;
1184 constructor(unitLookup: (exponent: number) => DisplayUnitSystemNames);
1185 isFormatSupported(format: string): boolean;
1186 private static getUnits(unitLookup);
1187 format(data: number, format: string, decimals?: number, trailingZeros?: boolean): string;
1188 }
1189 interface DisplayUnitSystemNames {
1190 title: string;
1191 format: string;
1192 }
1193}
1194
1195declare module powerbi {
1196 class NumericSequence {
1197 private static MIN_COUNT;
1198 private static MAX_COUNT;
1199 private maxAllowedMargin;
1200 private canExtendMin;
1201 private canExtendMax;
1202 interval: number;
1203 intervalOffset: number;
1204 min: number;
1205 max: number;
1206 precision: number;
1207 sequence: number[];
1208 static calculate(range: NumericSequenceRange, expectedCount: number, maxAllowedMargin?: number, minPower?: number, useZeroRefPoint?: boolean, steps?: number[]): NumericSequence;
1209 /**
1210 * Calculates the sequence of int numbers which are mapped to the multiples of the units grid.
1211 * @min - The minimum of the range.
1212 * @max - The maximum of the range.
1213 * @maxCount - The max count of intervals.
1214 * @steps - array of intervals.
1215 */
1216 static calculateUnits(min: number, max: number, maxCount: number, steps: number[]): NumericSequence;
1217 trimMinMax(min: number, max: number): void;
1218 }
1219}
1220
1221declare module powerbi {
1222 class NumericSequenceRange {
1223 private static DEFAULT_MAX;
1224 private static MIN_SUPPORTED_DOUBLE;
1225 private static MAX_SUPPORTED_DOUBLE;
1226 min: number;
1227 max: number;
1228 includeZero: boolean;
1229 forcedSingleStop: number;
1230 hasDataRange: boolean;
1231 hasFixedMin: boolean;
1232 hasFixedMax: boolean;
1233 private _ensureIncludeZero();
1234 private _ensureNotEmpty();
1235 private _ensureDirection();
1236 getSize(): number;
1237 shrinkByStep(range: NumericSequenceRange, step: number): void;
1238 static calculate(dataMin: number, dataMax: number, fixedMin?: number, fixedMax?: number, includeZero?: boolean): NumericSequenceRange;
1239 static calculateDataRange(dataMin: number, dataMax: number, includeZero?: boolean): NumericSequenceRange;
1240 static calculateFixedRange(fixedMin: number, fixedMax: number, includeZero?: boolean): NumericSequenceRange;
1241 }
1242 /** Note: Exported for testability */
1243 module ValueUtil {
1244 function hasValue(value: any): boolean;
1245 }
1246}
1247
1248declare module powerbi.visuals {
1249 /**
1250 * Formats the value using provided format expression
1251 * @param value - value to be formatted and converted to string.
1252 * @param format - format to be applied if the number shouldn't be abbreviated.
1253 * If the number should be abbreviated this string is checked for special characters like $ or % if any
1254 */
1255 interface ICustomValueFormatter {
1256 (value: any, format?: string): string;
1257 }
1258 interface ICustomValueColumnFormatter {
1259 (value: any, column: DataViewMetadataColumn, formatStringProp: DataViewObjectPropertyIdentifier, nullsAreBlank?: boolean): string;
1260 }
1261 interface ValueFormatterOptions {
1262 /** The format string to use. */
1263 format?: string;
1264 /** The data value. */
1265 value?: any;
1266 /** The data value. */
1267 value2?: any;
1268 /** The number of ticks. */
1269 tickCount?: any;
1270 /** The display unit system to use */
1271 displayUnitSystemType?: DisplayUnitSystemType;
1272 /** True if we are formatting single values in isolation (e.g. card), as opposed to multiple values with a common base (e.g. chart axes) */
1273 formatSingleValues?: boolean;
1274 /** True if we want to trim off unnecessary zeroes after the decimal and remove a space before the % symbol */
1275 allowFormatBeautification?: boolean;
1276 /** Specifies the maximum number of decimal places to show*/
1277 precision?: number;
1278 /** Detect axis precision based on value */
1279 detectAxisPrecision?: boolean;
1280 /** Specifies the column type of the data value */
1281 columnType?: ValueTypeDescriptor;
1282 }
1283 interface IValueFormatter {
1284 format(value: any): string;
1285 displayUnit?: DisplayUnit;
1286 options?: ValueFormatterOptions;
1287 }
1288 /** Captures all locale-specific options used by the valueFormatter. */
1289 interface ValueFormatterLocalizationOptions {
1290 null: string;
1291 true: string;
1292 false: string;
1293 NaN: string;
1294 infinity: string;
1295 negativeInfinity: string;
1296 /** Returns a beautified form the given format string. */
1297 beautify(format: string): string;
1298 /** Returns an object describing the given exponent in the current language. */
1299 describe(exponent: number): DisplayUnitSystemNames;
1300 restatementComma: string;
1301 restatementCompoundAnd: string;
1302 restatementCompoundOr: string;
1303 }
1304 module valueFormatter {
1305 const DefaultIntegerFormat: string;
1306 const DefaultNumericFormat: string;
1307 const DefaultDateFormat: string;
1308 function getLocalizedString(stringId: string): string;
1309 function getFormatMetadata(format: string): powerbi.NumberFormat.NumericFormatMetadata;
1310 function setLocaleOptions(options: ValueFormatterLocalizationOptions): void;
1311 function createDefaultFormatter(formatString: string, allowFormatBeautification?: boolean): IValueFormatter;
1312 /** Creates an IValueFormatter to be used for a range of values. */
1313 function create(options: ValueFormatterOptions): IValueFormatter;
1314 function format(value: any, format?: string, allowFormatBeautification?: boolean): string;
1315 /**
1316 * Value formatting function to handle variant measures.
1317 * For a Date/Time value within a non-date/time field, it's formatted with the default date/time formatString instead of as a number
1318 * @param {any} value Value to be formatted
1319 * @param {DataViewMetadataColumn} column Field which the value belongs to
1320 * @param {DataViewObjectPropertyIdentifier} formatStringProp formatString Property ID
1321 * @param {boolean} nullsAreBlank? Whether to show "(Blank)" instead of empty string for null values
1322 * @returns Formatted value
1323 */
1324 function formatVariantMeasureValue(value: any, column: DataViewMetadataColumn, formatStringProp: DataViewObjectPropertyIdentifier, nullsAreBlank?: boolean): string;
1325 function getFormatString(column: DataViewMetadataColumn, formatStringProperty: DataViewObjectPropertyIdentifier, suppressTypeFallback?: boolean): string;
1326 /** The returned string will look like 'A, B, ..., and C' */
1327 function formatListAnd(strings: string[]): string;
1328 /** The returned string will look like 'A, B, ..., or C' */
1329 function formatListOr(strings: string[]): string;
1330 function getDisplayUnits(displayUnitSystemType: DisplayUnitSystemType): DisplayUnit[];
1331 }
1332}
1333
1334declare module powerbi.data {
1335 module DataViewMatrixUtils {
1336 const enum DepthFirstTraversalCallbackResult {
1337 stop = 0,
1338 continueToChildNodes = 1,
1339 skipDescendantNodes = 2,
1340 }
1341 function isLeafNode(node: DataViewMatrixNode): boolean;
1342 /**
1343 * Invokes the specified callback once per node in the node tree starting from the specified rootNodes in depth-first order.
1344 *
1345 * If rootNodes is null or undefined or empty, the specified callback will not get invoked.
1346 *
1347 * The traversalPath parameter in the callback is an ordered set of nodes that form the path from the specified
1348 * rootNodes down to the callback node argument itself. If callback node is one of the specified rootNodes,
1349 * then traversalPath will be an array of length 1 containing that very node.
1350 *
1351 * IMPORTANT: The traversalPath array passed to the callback will be modified after the callback function returns!
1352 * If your callback needs to retain a copy of the traversalPath, please clone the array before returning.
1353 */
1354 function forEachNodeDepthFirst(rootNodes: DataViewMatrixNode | DataViewMatrixNode[], callback: (node: DataViewMatrixNode, traversalPath?: DataViewMatrixNode[]) => DepthFirstTraversalCallbackResult): void;
1355 /**
1356 * Invokes the specified callback once per leaf node (including root-level leaves and descendent leaves) of the
1357 * specified rootNodes, with an optional index parameter in the callback that is the 0-based index of the
1358 * particular leaf node in the context of this forEachLeafNode(...) invocation.
1359 *
1360 * If rootNodes is null or undefined or empty, the specified callback will not get invoked.
1361 *
1362 * The traversalPath parameter in the callback is an ordered set of nodes that form the path from the specified
1363 * rootNodes down to the leafNode argument itself. If callback leafNode is one of the specified rootNodes,
1364 * then traversalPath will be an array of length 1 containing that very node.
1365 *
1366 * IMPORTANT: The traversalPath array passed to the callback will be modified after the callback function returns!
1367 * If your callback needs to retain a copy of the traversalPath, please clone the array before returning.
1368 */
1369 function forEachLeafNode(rootNodes: DataViewMatrixNode | DataViewMatrixNode[], callback: (leafNode: DataViewMatrixNode, index?: number, traversalPath?: DataViewMatrixNode[]) => void): void;
1370 /**
1371 * Invokes the specified callback once for each node at the specified targetLevel in the node tree.
1372 *
1373 * Note: Be aware that in a matrix with multiple column grouping fields and multiple value fields, the DataViewMatrixNode
1374 * for the Grand Total column in the column hierarchy can have children nodes where level > (parent.level + 1):
1375 * {
1376 * "level": 0,
1377 * "isSubtotal": true,
1378 * "children": [
1379 * { "level": 2, "isSubtotal": true },
1380 * { "level": 2, "levelSourceIndex": 1, "isSubtotal": true }
1381 * ]
1382 * }
1383 */
1384 function forEachNodeAtLevel(node: DataViewMatrixNode, targetLevel: number, callback: (node: DataViewMatrixNode) => void): void;
1385 /**
1386 * Returned an object tree where each node and its children property are inherited from the specified node
1387 * hierarchy, from the root down to the nodes at the specified deepestLevelToInherit, inclusively.
1388 *
1389 * The inherited nodes at level === deepestLevelToInherit will NOT get an inherited version of children array
1390 * property, i.e. its children property is the same array object referenced in the input node's object tree.
1391 *
1392 * @param node The input node with the hierarchy object tree.
1393 * @param deepestLevelToInherit The highest level for a node to get inherited. See DataViewMatrixNode.level property.
1394 * @param useInheritSingle If true, then a node will get inherited in the returned object tree only if it is
1395 * not already an inherited object. Same goes for the node's children property. This is useful for creating
1396 * "visual DataView" objects from "query DataView" objects, as object inheritance is the mechanism for
1397 * "visual DataView" to override properties in "query DataView", and that "query DataView" never contains
1398 * inherited objects.
1399 */
1400 function inheritMatrixNodeHierarchy(node: DataViewMatrixNode, deepestLevelToInherit: number, useInheritSingle: boolean): DataViewMatrixNode;
1401 /**
1402 * Returns true if the specified matrixOrHierarchy contains any composite grouping, i.e. a grouping on multiple columns.
1403 * An example of composite grouping is one on [Year, Quarter, Month], where a particular group instance can have
1404 * Year === 2016, Quarter === 'Qtr 1', Month === 1.
1405 *
1406 * Returns false if the specified matrixOrHierarchy does not contain any composite group,
1407 * or if matrixOrHierarchy is null or undefined.
1408 */
1409 function containsCompositeGroup(matrixOrHierarchy: DataViewMatrix | DataViewHierarchy): boolean;
1410 }
1411}
1412
1413declare module powerbi.data {
1414 module DataViewMetadataColumnUtils {
1415 interface MetadataColumnAndProjectionIndex {
1416 /**
1417 * A metadata column taken from a source collection, e.g. DataViewHierarchyLevel.sources, DataViewMatrix.valueSources...
1418 */
1419 metadataColumn: DataViewMetadataColumn;
1420 /**
1421 * The index of this.metadataColumn in its sources collection.
1422 *
1423 * E.g.1 This can be the value of the property DataViewMatrixGroupValue.levelSourceIndex which is the index of this.metadataColumn in DataViewHierarchyLevel.sources.
1424 * E.g.2 This can be the value of the property DataViewMatrixNodeValue.valueSourceIndex which refer to columns in DataViewMatrix.valueSources.
1425 */
1426 sourceIndex: number;
1427 /**
1428 * The index of this.metadataColumn in the projection ordering of a given role.
1429 * This property is undefined if the column is not projected.
1430 */
1431 projectionOrderIndex?: number;
1432 }
1433 /**
1434 * Returns true iff the specified metadataColumn is assigned to the specified targetRole.
1435 */
1436 function isForRole(metadataColumn: DataViewMetadataColumn, targetRole: string): boolean;
1437 /**
1438 * Returns true iff the specified metadataColumn is assigned to any one of the specified targetRoles.
1439 */
1440 function isForAnyRole(metadataColumn: DataViewMetadataColumn, targetRoles: string[]): boolean;
1441 /**
1442 * Left-joins each metadata column of the specified target roles in the specified columnSources
1443 * with projection ordering index into a wrapper object.
1444 *
1445 * If a metadata column is for one of the target roles but its select index is not projected, the projectionOrderIndex property
1446 * in that MetadataColumnAndProjectionIndex object will be undefined.
1447 *
1448 * If a metadata column is for one of the target roles and its select index is projected more than once, that metadata column
1449 * will be included in multiple MetadataColumnAndProjectionIndex objects, once per occurrence in projection.
1450 *
1451 * If the specified projectionOrdering does not contain duplicate values, then the returned objects will be in the same order
1452 * as their corresponding metadata column object appears in the specified columnSources.
1453 *
1454 * Note: In order for this function to reliably calculate the "source index" of a particular column, the
1455 * specified columnSources must be a non-filtered array of column sources from the DataView, such as
1456 * the DataViewHierarchyLevel.sources and DataViewMatrix.valueSources array properties.
1457 *
1458 * @param columnSources E.g. DataViewHierarchyLevel.sources, DataViewMatrix.valueSources...
1459 * @param projectionOrdering The select indices in projection ordering. It should be the ordering for the specified target roles.
1460 * @param roles The roles for filtering out the irrevalent columns in columnSources.
1461 */
1462 function leftJoinMetadataColumnsAndProjectionOrder(columnSources: DataViewMetadataColumn[], projectionOrdering: number[], roles: string[]): MetadataColumnAndProjectionIndex[];
1463 }
1464}
1465
1466declare module powerbi {
1467 interface IColorAllocator {
1468 /** Computes the color corresponding to the provided value. */
1469 color(value: PrimitiveValue): string;
1470 }
1471 interface IColorAllocatorFactory {
1472 /** Creates a gradient that that transitions between two colors. */
1473 linearGradient2(options: LinearGradient2): IColorAllocator;
1474 /** Creates a gradient that that transitions between three colors. */
1475 linearGradient3(options: LinearGradient3, splitScales: boolean): IColorAllocator;
1476 }
1477}
1478
1479declare module powerbi.data {
1480 interface CompiledDataViewRoleBindMappingWithReduction extends CompiledDataViewRoleBindMapping, HasReductionAlgorithm {
1481 }
1482 interface CompiledDataViewRoleForMappingWithReduction extends CompiledDataViewRoleForMapping, HasReductionAlgorithm {
1483 }
1484}
1485
1486declare module powerbi.data {
1487 module DataRoleHelper {
1488 function getMeasureIndexOfRole(grouped: DataViewValueColumnGroup[], roleName: string): number;
1489 function getCategoryIndexOfRole(categories: DataViewCategoryColumn[], roleName: string): number;
1490 function hasRole(column: DataViewMetadataColumn, name: string): boolean;
1491 function hasRoleInDataView(dataView: DataView, name: string): boolean;
1492 function hasRoleInValueColumn(valueColumn: DataViewValueColumn, name: string): boolean;
1493 }
1494}
1495
1496declare module powerbi.data {
1497 function createIDataViewCategoricalReader(dataView: DataView): IDataViewCategoricalReader;
1498 interface IDataViewCategoricalReader {
1499 hasCategories(): boolean;
1500 getCategoryCount(): number;
1501 getCategoryValues(roleName: string): any;
1502 getCategoryValue(roleName: string, categoryIndex: number): any;
1503 getCategoryColumn(roleName: string): DataViewCategoryColumn;
1504 getCategoryMetadataColumn(roleName: string): DataViewMetadataColumn;
1505 getCategoryColumnIdentityFields(roleName: string): powerbi.data.ISQExpr[];
1506 getCategoryDisplayName(roleName: string): string;
1507 hasCompositeCategories(): boolean;
1508 hasCategoryWithRole(roleName: string): boolean;
1509 getCategoryObjects(roleName: string, categoryIndex: number): DataViewObjects;
1510 hasValues(roleName: string): boolean;
1511 hasHighlights(roleName: string): boolean;
1512 /**
1513 * Obtains the value for the given role name, category index, and series index.
1514 *
1515 * Note: in cases where have multiple values in a role where the multiple values
1516 * are not being used to create a static series, the first is obtained. (this is
1517 * a rare case)
1518 */
1519 getValue(roleName: string, categoryIndex: number, seriesIndex?: number): any;
1520 /**
1521 * Obtains the highlighted value for the given role name, category index, and series index.
1522 *
1523 * Note: in cases where have multiple values in a role where the multiple values
1524 * are not being used to create a static series, the first is obtained. (this is
1525 * a rare case)
1526 */
1527 getHighlight(roleName: string, categoryIndex: number, seriesIndex?: number): any;
1528 /**
1529 * Obtains all the values for the given role name, category index, and series index, drawing
1530 * from each of the value columns at that intersection. Used when you have multiple
1531 * values in a role that are not conceptually a static series.
1532 */
1533 getAllValuesForRole(roleName: string, categoryIndex: number, seriesIndex?: number): any[];
1534 /**
1535 * Obtains all meta data for the given role name, category index, and series index, drawing
1536 * from each of the value columns at that intersection. Used when you have multiple
1537 * values in a role that are not conceptually a static series.
1538 */
1539 getAllValueMetadataColumnsForRole(roleName: string, seriesIndex?: number): DataViewMetadataColumn[];
1540 /**
1541 * Obtains all the highlight values for the given role name, category index, and series index, drawing
1542 * from each of the value columns at that intersection. Used when you have multiple
1543 * values in a role that are not conceptually a static series.
1544 */
1545 getAllHighlightsForRole(roleName: string, categoryIndex: number, seriesIndex?: number): any[];
1546 /**
1547 * Obtains the first non-null value for the given role name and category index.
1548 * It should mainly be used for values that are expected to be the same across
1549 * series, but avoids false nulls when the data is sparse.
1550 */
1551 getFirstNonNullValueForCategory(roleName: string, categoryIndex: number): any;
1552 getMeasureQueryName(roleName: string): string;
1553 getValueColumn(roleName: string, seriesIndex?: number): DataViewValueColumn;
1554 getValueMetadataColumn(roleName: string, seriesIndex?: number): DataViewMetadataColumn;
1555 getValueDisplayName(roleName: string, seriesIndex?: number): string;
1556 hasDynamicSeries(): boolean;
1557 /**
1558 * Get the series count. This requires a value role name for cases where you may
1559 * have a static series, but is not required if the only series you expect are dynamic
1560 * or single series.
1561 *
1562 * @param valueRoleName The role of the value for which a static series may exist
1563 */
1564 getSeriesCount(valueRoleName?: string): number;
1565 getSeriesObjects(seriesIndex: number): DataViewObjects;
1566 getSeriesValueColumns(): DataViewValueColumns;
1567 getSeriesValueColumnGroup(seriesIndex: number): DataViewValueColumnGroup;
1568 getSeriesMetadataColumn(): DataViewMetadataColumn;
1569 getSeriesColumnIdentityFields(): powerbi.data.ISQExpr[];
1570 getSeriesName(seriesIndex: number): PrimitiveValue;
1571 getSeriesDisplayName(): string;
1572 getStaticObjects(): DataViewObjects;
1573 }
1574}
1575
1576declare module powerbi.data {
1577 module DataViewConcatenateCategoricalColumns {
1578 function detectAndApply(dataView: DataView, objectDescriptors: DataViewObjectDescriptors, roleMappings: DataViewMapping[], projectionOrdering: DataViewProjectionOrdering, selects: DataViewSelectTransform[], projectionActiveItems: DataViewProjectionActiveItems): DataView;
1579 /** For applying concatenation to the DataViewCategorical that is the data for one of the frames in a play chart. */
1580 function applyToPlayChartCategorical(metadata: DataViewMetadata, objectDescriptors: DataViewObjectDescriptors, categoryRoleName: string, categorical: DataViewCategorical): DataView;
1581 }
1582}
1583
1584declare module powerbi {
1585 const enum RoleItemContext {
1586 CategoricalValue = 0,
1587 CategoricalValueGroup = 1,
1588 }
1589 interface IDataViewMappingVisitor {
1590 visitRole(role: string, context?: RoleItemContext): void;
1591 visitReduction?(reductionAlgorithm?: ReductionAlgorithm): void;
1592 }
1593 module DataViewMapping {
1594 function visitMapping(mapping: DataViewMapping, visitor: IDataViewMappingVisitor): void;
1595 function visitCategorical(mapping: DataViewCategoricalMapping, visitor: IDataViewMappingVisitor): void;
1596 function visitCategoricalCategories(mapping: DataViewRoleMappingWithReduction | DataViewListRoleMappingWithReduction, visitor: IDataViewMappingVisitor): void;
1597 function visitCategoricalValues(mapping: DataViewRoleMapping | DataViewGroupedRoleMapping | DataViewListRoleMapping, visitor: IDataViewMappingVisitor): void;
1598 function visitTable(mapping: DataViewTableMapping, visitor: IDataViewMappingVisitor): void;
1599 /**
1600 * For visiting DataViewMatrixMapping.rows, DataViewMatrixMapping.columns, or DataViewMatrixMapping.values.
1601 *
1602 * @param mapping Can be one of DataViewMatrixMapping.rows, DataViewMatrixMapping.columns, or DataViewMatrixMapping.values.
1603 * @param visitor The visitor.
1604 */
1605 function visitMatrixItems(mapping: DataViewRoleForMappingWithReduction | DataViewListRoleMappingWithReduction, visitor: IDataViewMappingVisitor): void;
1606 function visitTreeNodes(mapping: DataViewRoleForMappingWithReduction, visitor: IDataViewMappingVisitor): void;
1607 function visitTreeValues(mapping: DataViewRoleForMapping, visitor: IDataViewMappingVisitor): void;
1608 function visitGrouped(mapping: DataViewGroupedRoleMapping, visitor: IDataViewMappingVisitor): void;
1609 }
1610}
1611
1612declare module powerbi.data {
1613 interface DataViewNormalizeValuesApplyOptions {
1614 dataview: DataView;
1615 dataViewMappings: DataViewMapping[];
1616 dataRoles: VisualDataRole[];
1617 }
1618 /**
1619 * Interface of a function for deciding whether a column is tied to any role that has required type(s).
1620 *
1621 * @param columnIndex the position of the column in the select statement, i.e. the same semantic as the index property on the DataViewMetadataColumn interface.
1622 * @returns true iff the column in the specified columnIndex is tied to any role that has required type(s), i.e. if the value in that column potentially needs to get normalized.
1623 */
1624 interface IMetadataColumnFilter {
1625 (columnIndex: number): boolean;
1626 }
1627 /**
1628 * Returns true iff the specified value is of matching type as required by the role assigned to the column associated with this filter object.
1629 */
1630 interface IColumnValueFilter {
1631 (value: any): boolean;
1632 }
1633 /**
1634 * Interface of a function for deciding whether a value needs to be normalized due to not having a matching type as required by a role tied to the column associated with the specified columnIndex.
1635 *
1636 * @param columnIndex the position of the column in the select statement, i.e. the same semantic as the index property on the DataViewMetadataColumn interface.
1637 * @returns false iff the specified value needs to be normalized due to not having a matching type as required by a role tied to the column associated with the specified columnIndex.
1638 */
1639 interface IValueFilter {
1640 (columnIndex: number, value: any): boolean;
1641 }
1642 module DataViewNormalizeValues {
1643 function apply(options: DataViewNormalizeValuesApplyOptions): void;
1644 function filterVariantMeasures(dataview: DataView, dataViewMappings: DataViewMapping[], rolesToNormalize: VisualDataRole[]): void;
1645 function generateMetadataColumnFilter(columns: DataViewMetadataColumn[], rolesToNormalize: VisualDataRole[]): IMetadataColumnFilter;
1646 function generateValueFilter(columns: DataViewMetadataColumn[], rolesToNormalize: VisualDataRole[]): IValueFilter;
1647 function getColumnRequiredTypes(column: DataViewMetadataColumn, rolesToNormalize: VisualDataRole[]): ValueType[];
1648 function normalizeVariant<T>(object: T, key: string | number, columnIndex: number, valueFilter: IValueFilter): T;
1649 }
1650}
1651
1652declare module powerbi {
1653 module DataViewObjects {
1654 /** Gets the value of the given object/property pair. */
1655 function getValue<T>(objects: DataViewObjects, propertyId: DataViewObjectPropertyIdentifier, defaultValue?: T): T;
1656 /** Gets an object from objects. */
1657 function getObject(objects: DataViewObjects, objectName: string, defaultValue?: DataViewObject): DataViewObject;
1658 /** Gets a map of user-defined objects. */
1659 function getUserDefinedObjects(objects: DataViewObjects, objectName: string): DataViewObjectMap;
1660 /** Gets the solid color from a fill property. */
1661 function getFillColor(objects: DataViewObjects, propertyId: DataViewObjectPropertyIdentifier, defaultColor?: string): string;
1662 /** Returns true if the given object represents a collection of user-defined objects */
1663 function isUserDefined(objectOrMap: DataViewObject | DataViewObjectMap): boolean;
1664 }
1665 module DataViewObject {
1666 function getValue<T>(object: DataViewObject, propertyName: string, defaultValue?: T): T;
1667 /** Gets the solid color from a fill property using only a propertyName */
1668 function getFillColorByPropertyName(objects: DataViewObjects, propertyName: string, defaultColor?: string): string;
1669 }
1670}
1671
1672declare module powerbi.data {
1673 /** Defines the values for particular objects. */
1674 interface DataViewObjectDefinitions {
1675 [objectName: string]: DataViewObjectDefinition[];
1676 }
1677 interface DataViewObjectDefinition {
1678 selector?: Selector;
1679 properties: DataViewObjectPropertyDefinitions;
1680 }
1681 interface DataViewObjectPropertyDefinitions {
1682 [name: string]: DataViewObjectPropertyDefinition;
1683 }
1684 type DataViewObjectPropertyDefinition = SQExpr | StructuralObjectDefinition;
1685 module DataViewObjectDefinitions {
1686 /** Creates or reuses a DataViewObjectDefinition for matching the given objectName and selector within the defns. */
1687 function ensure(defns: DataViewObjectDefinitions, objectName: string, selector: Selector): DataViewObjectDefinition;
1688 function deleteProperty(defns: DataViewObjectDefinitions, objectName: string, selector: Selector, propertyName: string): void;
1689 function setValue(defns: DataViewObjectDefinitions, propertyId: DataViewObjectPropertyIdentifier, selector: Selector, value: DataViewObjectPropertyDefinition): void;
1690 function getValue(defns: DataViewObjectDefinitions, propertyId: DataViewObjectPropertyIdentifier, selector: Selector): DataViewObjectPropertyDefinition;
1691 function getPropertyContainer(defns: DataViewObjectDefinitions, propertyId: DataViewObjectPropertyIdentifier, selector: Selector): DataViewObjectPropertyDefinitions;
1692 function getObjectDefinition(defns: DataViewObjectDefinitions, objectName: string, selector: Selector): DataViewObjectDefinition;
1693 function propertiesAreEqual(a: DataViewObjectPropertyDefinition, b: DataViewObjectPropertyDefinition): boolean;
1694 function allPropertiesAreEqual(a: DataViewObjectPropertyDefinitions, b: DataViewObjectPropertyDefinitions): boolean;
1695 function encodePropertyValue(value: DataViewPropertyValue, valueTypeDescriptor: ValueTypeDescriptor): DataViewObjectPropertyDefinition;
1696 function clone(original: DataViewObjectDefinitions): DataViewObjectDefinitions;
1697 }
1698 module DataViewObjectDefinition {
1699 function deleteSingleProperty(defn: DataViewObjectDefinition, propertyName: string): void;
1700 }
1701}
1702
1703declare module powerbi.data {
1704 module DataViewObjectDescriptors {
1705 /** Attempts to find the format string property. This can be useful for upgrade and conversion. */
1706 function findFormatString(descriptors: DataViewObjectDescriptors): DataViewObjectPropertyIdentifier;
1707 /** Attempts to find the filter property. This can be useful for propagating filters from one visual to others. */
1708 function findFilterOutput(descriptors: DataViewObjectDescriptors): DataViewObjectPropertyIdentifier;
1709 /** Attempts to find the self filter property. */
1710 function findSelfFilter(descriptors: DataViewObjectDescriptors): DataViewObjectPropertyIdentifier;
1711 function isSelfFilter(descriptor: DataViewObjectPropertyDescriptor): boolean;
1712 /** Attempts to find the self filter enabled property. */
1713 function findSelfFilterEnabled(descriptors: DataViewObjectDescriptors): DataViewObjectPropertyIdentifier;
1714 /** Attempts to find the default value property. This can be useful for propagating schema default value. */
1715 function findDefaultValue(descriptors: DataViewObjectDescriptors): DataViewObjectPropertyIdentifier;
1716 }
1717}
1718
1719declare module powerbi.data {
1720 interface DataViewObjectDefinitionsByRepetition {
1721 metadataOnce?: DataViewObjectDefinitionsForSelector;
1722 userDefined?: DataViewObjectDefinitionsForSelector[];
1723 metadata?: DataViewObjectDefinitionsForSelector[];
1724 data: DataViewObjectDefinitionsForSelectorWithRule[];
1725 }
1726 interface DataViewObjectDefinitionsForSelector {
1727 selector?: Selector;
1728 objects: DataViewNamedObjectDefinition[];
1729 }
1730 interface DataViewObjectDefinitionsForSelectorWithRule extends DataViewObjectDefinitionsForSelector {
1731 rules?: RuleEvaluation[];
1732 }
1733 interface DataViewNamedObjectDefinition {
1734 name: string;
1735 properties: DataViewObjectPropertyDefinitions;
1736 }
1737 module DataViewObjectEvaluationUtils {
1738 function evaluateDataViewObjects(evalContext: IEvalContext, objectDescriptors: DataViewObjectDescriptors, objectDefns: DataViewNamedObjectDefinition[]): DataViewObjects;
1739 function groupObjectsBySelector(objectDefinitions: DataViewObjectDefinitions): DataViewObjectDefinitionsByRepetition;
1740 function addImplicitObjects(objectsForAllSelectors: DataViewObjectDefinitionsByRepetition, objectDescriptors: DataViewObjectDescriptors, columns: DataViewMetadataColumn[], selectTransforms: DataViewSelectTransform[]): void;
1741 }
1742}
1743
1744declare module powerbi.data {
1745 /** Responsible for evaluating object property expressions to be applied at various scopes in a DataView. */
1746 module DataViewObjectEvaluator {
1747 function run(evalContext: IEvalContext, objectDescriptor: DataViewObjectDescriptor, propertyDefinitions: DataViewObjectPropertyDefinitions): DataViewObject;
1748 /** Note: Exported for testability */
1749 function evaluateProperty(evalContext: IEvalContext, propertyDescriptor: DataViewObjectPropertyDescriptor, propertyDefinition: DataViewObjectPropertyDefinition): any;
1750 function evaluateValue(evalContext: IEvalContext, definition: SQExpr | RuleEvaluation, valueType: ValueType): any;
1751 }
1752}
1753declare module powerbi.data {
1754 /** Responsible for evaluating and setting DataViewCategorical's values grouped() function. */
1755 module DataViewCategoricalEvalGrouped {
1756 function apply(categorical: DataViewCategorical): void;
1757 }
1758}
1759declare module powerbi.data {
1760 import DataViewMatrix = powerbi.DataViewMatrix;
1761 module DataViewMatrixProjectionOrder {
1762 function apply(prototype: DataViewMatrix, matrixMapping: DataViewMatrixMapping, projectionOrdering: DataViewProjectionOrdering, context: MatrixTransformationContext): DataViewMatrix;
1763 }
1764}
1765
1766declare module powerbi.data {
1767 module DataViewPivotCategorical {
1768 /**
1769 * Pivots categories in a categorical DataView into valueGroupings.
1770 * This is akin to a mathematical matrix transpose.
1771 */
1772 function apply(dataView: DataView): DataView;
1773 }
1774}
1775
1776declare module powerbi.data {
1777 module DataViewPivotMatrix {
1778 /** Pivots row hierarchy members in a matrix DataView into column hierarchy. */
1779 function apply(dataViewMatrix: DataViewMatrix, context: MatrixTransformationContext): void;
1780 function cloneTree(node: DataViewMatrixNode): DataViewMatrixNode;
1781 function cloneTreeExecuteOnLeaf(node: DataViewMatrixNode, callback?: (node: DataViewMatrixNode) => void): DataViewMatrixNode;
1782 }
1783}
1784
1785declare module powerbi.data {
1786 module DataViewSelfCrossJoin {
1787 /**
1788 * Returns a new DataView based on the original, with a single DataViewCategorical category that is "cross joined"
1789 * to itself as a value grouping.
1790 * This is the mathematical equivalent of taking an array and turning it into an identity matrix.
1791 */
1792 function apply(dataView: DataView): DataView;
1793 }
1794}
1795
1796declare module powerbi.data {
1797 module DataViewPivotCategoricalToPrimaryGroups {
1798 /**
1799 * If mapping requests cross axis data reduction and the binding has secondary grouping, mutates the binding to
1800 * pivot the secondary before the primary.
1801 */
1802 function pivotBinding(binding: DataShapeBinding, allMappings: CompiledDataViewMapping[], finalMapping: CompiledDataViewMapping, defaultDataVolume: number): void;
1803 function unpivotResult(oldDataView: DataView, selects: DataViewSelectTransform[], dataViewMappings: DataViewMapping[], projectionActiveItems: DataViewProjectionActiveItems): DataView;
1804 }
1805}
1806declare module powerbi.data {
1807 import INumberDictionary = jsCommon.INumberDictionary;
1808 /** Responsible for removing selects from the DataView. */
1809 module DataViewRemoveSelects {
1810 function apply(dataView: DataView, targetDataViewKinds: StandardDataViewKinds, selectsToInclude: INumberDictionary<boolean>): void;
1811 }
1812}
1813declare module powerbi.data {
1814 import INumberDictionary = jsCommon.INumberDictionary;
1815 interface DataViewTransformApplyOptions {
1816 prototype: DataView;
1817 objectDescriptors: DataViewObjectDescriptors;
1818 dataViewMappings?: DataViewMapping[];
1819 transforms: DataViewTransformActions;
1820 colorAllocatorFactory: IColorAllocatorFactory;
1821 dataRoles: VisualDataRole[];
1822 }
1823 /** Describes the Transform actions to be done to a prototype DataView. */
1824 interface DataViewTransformActions {
1825 /** Describes transform metadata for each semantic query select item, as the arrays align, by index. */
1826 selects?: DataViewSelectTransform[];
1827 /** Describes the DataViewObject definitions. */
1828 objects?: DataViewObjectDefinitions;
1829 /** Describes the splitting of a single input DataView into multiple DataViews. */
1830 splits?: DataViewSplitTransform[];
1831 /** Describes the projection metadata which includes projection ordering and active items. */
1832 roles?: DataViewRoleTransformMetadata;
1833 }
1834 interface DataViewSplitTransform {
1835 selects: INumberDictionary<boolean>;
1836 }
1837 interface DataViewProjectionOrdering {
1838 [roleName: string]: number[];
1839 }
1840 interface DataViewProjectionActiveItemInfo {
1841 queryRef: string;
1842 /** Describes if the active item should be ignored in concatenation.
1843 If the active item has a drill filter, it will not be used in concatenation.
1844 If the value of suppressConcat is true, the activeItem will be ommitted from concatenation. */
1845 suppressConcat?: boolean;
1846 }
1847 interface DataViewProjectionActiveItems {
1848 [roleName: string]: DataViewProjectionActiveItemInfo[];
1849 }
1850 interface DataViewRoleTransformMetadata {
1851 /** Describes the order of selects (referenced by query index) in each role. */
1852 ordering?: DataViewProjectionOrdering;
1853 /** Describes the active items in each role. */
1854 activeItems?: DataViewProjectionActiveItems;
1855 }
1856 interface MatrixTransformationContext {
1857 rowHierarchyRewritten: boolean;
1858 columnHierarchyRewritten: boolean;
1859 hierarchyTreesRewritten: boolean;
1860 }
1861 const enum StandardDataViewKinds {
1862 None = 0,
1863 Categorical = 1,
1864 Matrix = 2,
1865 Single = 4,
1866 Table = 8,
1867 Tree = 16,
1868 }
1869 module DataViewTransform {
1870 function apply(options: DataViewTransformApplyOptions): DataView[];
1871 function transformObjects(dataView: DataView, targetDataViewKinds: StandardDataViewKinds, objectDescriptors: DataViewObjectDescriptors, objectDefinitions: DataViewObjectDefinitions, selectTransforms: DataViewSelectTransform[], colorAllocatorFactory: IColorAllocatorFactory): void;
1872 function createValueColumns(values?: DataViewValueColumn[], valueIdentityFields?: SQExpr[], source?: DataViewMetadataColumn): DataViewValueColumns;
1873 function setGrouped(values: DataViewValueColumns, groupedResult?: DataViewValueColumnGroup[]): void;
1874 }
1875}
1876
1877declare module powerbi.data {
1878 function createDisplayNameGetter(displayNameKey: string): (IStringResourceProvider) => string;
1879 function getDisplayName(displayNameGetter: data.DisplayNameGetter, resourceProvider: jsCommon.IStringResourceProvider): string;
1880}
1881
1882declare module powerbi.data {
1883 /** Represents a data reader. */
1884 interface IDataReader {
1885 /** Executes a query, with a promise of completion. The response object should be compatible with the transform implementation. */
1886 execute?(options: DataReaderExecutionOptions): RejectablePromise2<DataReaderData, IClientError>;
1887 /** Transforms the given data into a DataView. When this function is not specified, the data is put on a property on the DataView. */
1888 transform?(obj: DataReaderData): DataReaderTransformResult;
1889 /** Stops all future communication and reject and pending communication */
1890 stopCommunication?(): void;
1891 /** Resumes communication which enables future requests */
1892 resumeCommunication?(): void;
1893 /** Clear cache */
1894 clearCache?(dataSource: DataReaderDataSource): void;
1895 /** rewriteCacheEntries */
1896 rewriteCacheEntries?(dataSource: DataReaderDataSource, rewriter: DataReaderCacheRewriter): void;
1897 /** Sets the result into the local cache */
1898 setLocalCacheResult?(options: DataReaderExecutionOptions, dataAsObject: DataReaderData): void;
1899 }
1900 /** Represents a query generator. */
1901 interface IQueryGenerator {
1902 /** Query generation function to convert a (prototype) SemanticQuery to a runnable query command. */
1903 execute(options: QueryGeneratorOptions): QueryGeneratorResult;
1904 }
1905 interface IFederatedConceptualSchemaReader {
1906 /** Executes a request for conceptual schema with a promise of completion. */
1907 execute(options: FederatedConceptualSchemaReaderOptions): IPromise<FederatedConceptualSchemaResponse>;
1908 /** Transforms the given data into a FederatedConceptualSchema. */
1909 transform(obj: FederatedConceptualSchemaResponse): SchemaReaderTransformResult;
1910 }
1911 /** Represents a custom data reader plugin, to be registered in the powerbi.data.plugins object. */
1912 interface IDataReaderPlugin {
1913 /** The name of this plugin. */
1914 name: string;
1915 /** Factory method for the IDataReader. */
1916 reader(hostServices: IDataReaderHostServices): IDataReader;
1917 /** Factory method for the IQueryGenerator. */
1918 queryGenerator?(): IQueryGenerator;
1919 /** Factory method for the IFederatedConceptualSchemaReader. */
1920 schemaReader?(hostServices: IDataReaderHostServices): IFederatedConceptualSchemaReader;
1921 }
1922 interface QueryGeneratorOptions {
1923 query: SemanticQuery;
1924 mappings: CompiledDataViewMapping[];
1925 additionalProjections?: AdditionalQueryProjection[];
1926 highlightFilter?: SemanticFilter;
1927 restartToken?: RestartToken;
1928 dataWindow?: QueryGeneratorDataWindow;
1929 }
1930 interface AdditionalQueryProjection {
1931 queryName: string;
1932 selector: Selector;
1933 aggregates?: ProjectionAggregates;
1934 joinPredicate?: JoinPredicateBehavior;
1935 }
1936 interface ProjectionAggregates {
1937 min?: boolean;
1938 max?: boolean;
1939 percentiles?: ProjectionPercentileAggregate[];
1940 }
1941 interface ProjectionPercentileAggregate {
1942 exclusive?: boolean;
1943 k: number;
1944 }
1945 interface QueryGeneratorResult {
1946 command: DataReaderQueryCommand;
1947 splits?: DataViewSplitTransform[];
1948 /**
1949 * If the query generator needs to rewrite the input query, this property will contain information about the important changes.
1950 *
1951 * Any rewrite done by query generator should be internal to the particular query generator, but in some rare cases this information
1952 * is needed in order for other components to correctly consume the query result.
1953 */
1954 queryRewrites?: QueryRewriteRecordContainer[];
1955 }
1956 /**
1957 * In each instance of QueryRewriteRecordContainer, exactly one of the optional properties will be populated with change record.
1958 */
1959 interface QueryRewriteRecordContainer {
1960 selectExprAdded?: QueryRewriteSelectExprAddedRecord;
1961 aggregatesAdded?: QueryRewriteSelectExprAggregatesAddedRecord;
1962 projectionQueryRefChanged?: QueryRewriteProjectionQueryRefChangedRecord;
1963 }
1964 /** Indicates a new SQExpr got added at a particular index. */
1965 interface QueryRewriteSelectExprAddedRecord {
1966 selectIndex: number;
1967 namedSQExpr: NamedSQExpr;
1968 }
1969 interface QueryRewriteSelectExprAggregatesAddedRecord {
1970 originalQueryRef: string;
1971 aggregates: QueryRewriteAddedAggregates;
1972 }
1973 interface QueryRewriteAddedAggregates {
1974 min?: QueryRewriteAddedAggregateSource;
1975 max?: QueryRewriteAddedAggregateSource;
1976 }
1977 interface QueryRewriteAddedAggregateSource {
1978 index: number;
1979 expr: SQExpr;
1980 }
1981 /** Indicates a queryRef in the query projection for a particular role got changed. */
1982 interface QueryRewriteProjectionQueryRefChangedRecord {
1983 /** The role for which a queryRef in the query projection got changed. */
1984 role: string;
1985 /** The original queryRef. */
1986 oldQueryRef: string;
1987 /** The new, internal queryRef. */
1988 newInternalQueryRef: string;
1989 }
1990 interface DataReaderTransformResult {
1991 dataView?: DataView;
1992 restartToken?: RestartToken;
1993 error?: IClientError;
1994 warning?: IClientWarning;
1995 /** A value of true in this property indicates that the DataReaderData object from which this result is generated should not get persisted as contract cache nor server cache. */
1996 disallowPersisting?: boolean;
1997 }
1998 interface QueryGeneratorDataWindow {
1999 }
2000 interface RestartToken {
2001 }
2002 interface DataReaderQueryCommand {
2003 }
2004 /** Represents a query command defined by an IDataReader. */
2005 interface DataReaderCommand {
2006 }
2007 /** Represents a data source defined by an IDataReader. */
2008 interface DataReaderDataSource {
2009 }
2010 /** Represents arbitrary data defined by an IDataReader. */
2011 interface DataReaderData {
2012 }
2013 /** Represents cacheRewriter that will rewrite the cache of reader as defined by an IDataReader. */
2014 interface DataReaderCacheRewriter {
2015 }
2016 interface DataReaderExecutionOptions {
2017 dataSource?: DataReaderDataSource;
2018 command: DataReaderCommand;
2019 allowCache?: boolean;
2020 allowClientSideFilters?: boolean;
2021 cacheResponseOnServer?: boolean;
2022 ignoreViewportForCache?: boolean;
2023 }
2024 interface FederatedConceptualSchemaReaderOptions {
2025 dataSources: ConceptualSchemaReaderDataSource[];
2026 }
2027 interface ConceptualSchemaReaderDataSource {
2028 id: number;
2029 /** Specifies the name used in Semantic Queries to reference this DataSource. */
2030 name: string;
2031 /** Specifies the type of IDataReaderPlugin. */
2032 type?: string;
2033 }
2034 interface FederatedConceptualSchemaResponse {
2035 data: FederatedConceptualSchemaData;
2036 }
2037 interface FederatedConceptualSchemaData {
2038 }
2039 interface SchemaReaderTransformResult {
2040 schema: FederatedConceptualSchema;
2041 error?: SchemaReaderError;
2042 }
2043 interface SchemaReaderError {
2044 requestId?: string;
2045 serviceError?: ServiceError;
2046 clientError: IClientError;
2047 }
2048 interface IDataReaderHostServices {
2049 promiseFactory(): IPromiseFactory;
2050 }
2051}
2052
2053declare module powerbi {
2054 /** Enumeration of DateTimeUnits */
2055 enum DateTimeUnit {
2056 Year = 0,
2057 Month = 1,
2058 Week = 2,
2059 Day = 3,
2060 Hour = 4,
2061 Minute = 5,
2062 Second = 6,
2063 Millisecond = 7,
2064 }
2065 interface IFormattingService {
2066 /**
2067 * Formats the value using provided format expression and culture
2068 * @param value - value to be formatted and converted to string.
2069 * @param format - format to be applied. If undefined or empty then generic format is used.
2070 */
2071 formatValue(value: any, format?: string): string;
2072 /**
2073 * Replaces the indexed format tokens (for example {0:c2}) in the format string with the localized formatted arguments.
2074 * @param formatWithIndexedTokens - format string with a set of indexed format tokens.
2075 * @param args - array of values which should replace the tokens in the format string.
2076 * @param culture - localization culture. If undefined then the current culture is used.
2077 */
2078 format(formatWithIndexedTokens: string, args: any[], culture?: string): string;
2079 /** Gets a value indicating whether the specified format a standard numeric format specifier. */
2080 isStandardNumberFormat(format: string): boolean;
2081 /** Performs a custom format with a value override. Typically used for custom formats showing scaled values. */
2082 formatNumberWithCustomOverride(value: number, format: string, nonScientificOverrideFormat: string): string;
2083 /** Gets the format string to use for dates in particular units. */
2084 dateFormatString(unit: DateTimeUnit): string;
2085 }
2086}
2087
2088declare module powerbi.data {
2089 /** Represents common expression patterns for 'field' expressions such as columns, column aggregates, measures, etc. */
2090 interface FieldExprPattern {
2091 column?: FieldExprColumnPattern;
2092 columnAggr?: FieldExprColumnAggrPattern;
2093 columnHierarchyLevelVariation?: FieldExprColumnHierarchyLevelVariationPattern;
2094 entity?: FieldExprEntityPattern;
2095 entityAggr?: FieldExprEntityAggrPattern;
2096 hierarchy?: FieldExprHierarchyPattern;
2097 hierarchyLevel?: FieldExprHierarchyLevelPattern;
2098 hierarchyLevelAggr?: FieldExprHierarchyLevelAggrPattern;
2099 measure?: FieldExprMeasurePattern;
2100 percentile?: FieldExprPercentilePattern;
2101 percentOfGrandTotal?: FieldExprPercentOfGrandTotalPattern;
2102 selectRef?: FieldExprSelectRefPattern;
2103 }
2104 /** By design there is no default, no-op visitor. Components concerned with patterns need to be aware of all patterns as they are added. */
2105 interface IFieldExprPatternVisitor<T> {
2106 visitColumn(column: FieldExprColumnPattern): T;
2107 visitColumnAggr(columnAggr: FieldExprColumnAggrPattern): T;
2108 visitColumnHierarchyLevelVariation(columnHierarchyLevelVariation: FieldExprColumnHierarchyLevelVariationPattern): T;
2109 visitEntity(entity: FieldExprEntityPattern): T;
2110 visitEntityAggr(entityAggr: FieldExprEntityAggrPattern): T;
2111 visitHierarchy(hierarchy: FieldExprHierarchyPattern): T;
2112 visitHierarchyLevel(hierarchyLevel: FieldExprHierarchyLevelPattern): T;
2113 visitHierarchyLevelAggr(hierarchyLevelAggr: FieldExprHierarchyLevelAggrPattern): T;
2114 visitMeasure(measure: FieldExprMeasurePattern): T;
2115 visitPercentile(percentile: FieldExprPercentilePattern): T;
2116 visitPercentOfGrandTotal(percentOfGrandTotal: FieldExprPercentOfGrandTotalPattern): T;
2117 visitSelectRef(selectRef: FieldExprSelectRefPattern): T;
2118 }
2119 interface FieldExprEntityPattern {
2120 schema: string;
2121 entity: string;
2122 entityVar?: string;
2123 }
2124 interface FieldExprEntityItemPattern extends FieldExprEntityPattern {
2125 }
2126 interface FieldExprEntityPropertyPattern extends FieldExprEntityItemPattern {
2127 name: string;
2128 }
2129 type FieldExprColumnPattern = FieldExprEntityPropertyPattern;
2130 type FieldExprMeasurePattern = FieldExprEntityPropertyPattern;
2131 type FieldExprHierarchyPattern = FieldExprEntityPropertyPattern;
2132 type FieldExprPropertyPattern = FieldExprColumnPattern | FieldExprMeasurePattern | FieldExprHierarchyPattern;
2133 interface FieldExprEntityAggrPattern extends FieldExprEntityPattern {
2134 aggregate: QueryAggregateFunction;
2135 }
2136 interface FieldExprColumnAggrPattern extends FieldExprColumnPattern {
2137 aggregate: QueryAggregateFunction;
2138 }
2139 interface FieldExprHierarchyLevelPattern extends FieldExprEntityItemPattern {
2140 name: string;
2141 level: string;
2142 }
2143 interface FieldExprHierarchyLevelAggrPattern extends FieldExprHierarchyLevelPattern {
2144 aggregate: QueryAggregateFunction;
2145 }
2146 interface FieldExprColumnHierarchyLevelVariationPattern {
2147 source: FieldExprColumnPattern;
2148 level: FieldExprHierarchyLevelPattern;
2149 variationName: string;
2150 }
2151 interface FieldExprPercentilePattern {
2152 arg: FieldExprPattern;
2153 k: number;
2154 exclusive: boolean;
2155 }
2156 interface FieldExprPercentOfGrandTotalPattern {
2157 baseExpr: FieldExprPattern;
2158 }
2159 interface FieldExprSelectRefPattern {
2160 expressionName: string;
2161 }
2162 module SQExprBuilder {
2163 function fieldExpr(fieldExpr: FieldExprPattern): SQExpr;
2164 function fromColumnAggr(columnAggr: FieldExprColumnAggrPattern): SQAggregationExpr;
2165 function fromColumn(column: FieldExprColumnPattern): SQColumnRefExpr;
2166 function fromEntity(entityPattern: FieldExprEntityPattern): SQEntityExpr;
2167 function fromEntityAggr(entityAggr: FieldExprEntityAggrPattern): SQAggregationExpr;
2168 function fromHierarchyLevelAggr(hierarchyLevelAggr: FieldExprHierarchyLevelAggrPattern): SQAggregationExpr;
2169 function fromHierarchyLevel(hierarchyLevelPattern: FieldExprHierarchyLevelPattern): SQHierarchyLevelExpr;
2170 function fromHierarchy(hierarchyPattern: FieldExprHierarchyPattern): SQHierarchyExpr;
2171 }
2172 module SQExprConverter {
2173 function asFieldPattern(sqExpr: SQExpr, schema?: FederatedConceptualSchema): FieldExprPattern;
2174 }
2175 module FieldExprPattern {
2176 function visit<T>(expr: SQExpr | FieldExprPattern, visitor: IFieldExprPatternVisitor<T>): T;
2177 function toColumnRefSQExpr(columnPattern: FieldExprColumnPattern): SQColumnRefExpr;
2178 function getAggregate(fieldExpr: FieldExprPattern): QueryAggregateFunction;
2179 function isAggregation(fieldExpr: FieldExprPattern): boolean;
2180 function hasFieldExprName(fieldExpr: FieldExprPattern): boolean;
2181 function getPropertyName(fieldExpr: FieldExprPattern): string;
2182 function getHierarchyName(fieldExpr: FieldExprPattern): string;
2183 function getColumnRef(fieldExpr: FieldExprPattern): FieldExprPropertyPattern;
2184 function getFieldExprName(fieldExpr: FieldExprPattern): string;
2185 function getSchema(fieldExpr: FieldExprPattern): string;
2186 function toFieldExprEntityPattern(fieldExpr: FieldExprPattern): FieldExprEntityPattern;
2187 function toFieldExprEntityItemPattern(fieldExpr: FieldExprPattern): FieldExprEntityPattern;
2188 }
2189}
2190
2191declare module powerbi {
2192 module DataViewAnalysis {
2193 import QueryProjectionsByRole = powerbi.data.QueryProjectionsByRole;
2194 import DataViewObjectDescriptors = powerbi.data.DataViewObjectDescriptors;
2195 import DataViewObjectDefinitions = powerbi.data.DataViewObjectDefinitions;
2196 interface ValidateAndReshapeResult {
2197 dataView?: DataView;
2198 isValid: boolean;
2199 }
2200 interface RoleKindByQueryRef {
2201 [queryRef: string]: VisualDataRoleKind;
2202 }
2203 interface DataViewMappingResult {
2204 supportedMappings: DataViewMapping[];
2205 /** A set of mapping errors if there are no supported mappings */
2206 mappingErrors: DataViewMappingMatchError[];
2207 }
2208 enum DataViewMappingMatchErrorCode {
2209 conditionRangeTooLarge = 0,
2210 conditionRangeTooSmall = 1,
2211 conditionKindExpectedMeasure = 2,
2212 conditionKindExpectedGrouping = 3,
2213 conditionKindExpectedGroupingOrMeasure = 4,
2214 }
2215 interface DataViewMappingMatchError {
2216 code: DataViewMappingMatchErrorCode;
2217 roleName: string;
2218 mappingIndex?: number;
2219 conditionIndex?: number;
2220 }
2221 /** Reshapes the data view to match the provided schema if possible. If not, returns null */
2222 function validateAndReshape(dataView: DataView, dataViewMappings: DataViewMapping[]): ValidateAndReshapeResult;
2223 function countGroups(columns: DataViewMetadataColumn[]): number;
2224 function countMeasures(columns: DataViewMetadataColumn[]): number;
2225 /** Indicates whether the dataView conforms to the specified schema. */
2226 function supports(dataView: DataView, roleMapping: DataViewMapping, usePreferredDataViewSchema?: boolean): boolean;
2227 /**
2228 * Determines whether the value conforms to the range in the role condition, returning undefined
2229 * if so or an appropriate error code if not.
2230 */
2231 function validateRange(value: number, roleCondition: RoleCondition, ignoreMin?: boolean): DataViewMappingMatchErrorCode;
2232 /** Determines the appropriate DataViewMappings for the projections. */
2233 function chooseDataViewMappings(projections: QueryProjectionsByRole, mappings: DataViewMapping[], roleKindByQueryRef: RoleKindByQueryRef, objectDescriptors?: DataViewObjectDescriptors, objectDefinitions?: DataViewObjectDefinitions): DataViewMappingResult;
2234 function getPropertyCount(roleName: string, projections: QueryProjectionsByRole, useActiveIfAvailable?: boolean): number;
2235 function hasSameCategoryIdentity(dataView1: DataView, dataView2: DataView): boolean;
2236 function areMetadataColumnsEquivalent(column1: DataViewMetadataColumn, column2: DataViewMetadataColumn): boolean;
2237 function isMetadataEquivalent(metadata1: DataViewMetadata, metadata2: DataViewMetadata): boolean;
2238 }
2239}
2240
2241declare module powerbi.data {
2242 module DataViewRoleWildcard {
2243 function fromRoles(roles: string[]): DataViewRoleWildcard;
2244 function equals(firstRoleWildcard: DataViewRoleWildcard, secondRoleWildcard: DataViewRoleWildcard): boolean;
2245 }
2246}
2247
2248declare module powerbi {
2249 module DataViewScopeIdentity {
2250 /** Compares the two DataViewScopeIdentity values for equality. */
2251 function equals(x: DataViewScopeIdentity, y: DataViewScopeIdentity, ignoreCase?: boolean): boolean;
2252 function filterFromIdentity(identities: DataViewScopeIdentity[], isNot?: boolean): data.SemanticFilter;
2253 function filterFromExprs(orExprs: data.SQExpr[], isNot?: boolean): data.SemanticFilter;
2254 }
2255 module data {
2256 function createDataViewScopeIdentity(expr: SQExpr): DataViewScopeIdentity;
2257 }
2258}
2259
2260declare module powerbi.data {
2261 module DataViewScopeWildcard {
2262 function matches(wildcard: DataViewScopeWildcard, instance: DataViewScopeIdentity): boolean;
2263 function equals(firstScopeWildcard: DataViewScopeWildcard, secondScopeWildcard: DataViewScopeWildcard): boolean;
2264 function fromExprs(exprs: SQExpr[]): DataViewScopeWildcard;
2265 }
2266}
2267
2268declare module powerbi.data {
2269 interface IColorAllocatorCache {
2270 get(key: SQFillRuleExpr): IColorAllocator;
2271 register(key: SQFillRuleExpr, colorAllocator: IColorAllocator): this;
2272 }
2273 function createColorAllocatorCache(): IColorAllocatorCache;
2274}
2275
2276declare module powerbi.data {
2277 /** Responsible for providing specific values to be used by expression and rule evaluation. */
2278 interface IEvalContext {
2279 getColorAllocator(expr: SQFillRuleExpr): IColorAllocator;
2280 getExprValue(expr: SQExpr): PrimitiveValue;
2281 getRoleValue(roleName: string): PrimitiveValue;
2282 }
2283}
2284
2285declare module powerbi.data {
2286 interface DataViewRegressionRunOptions {
2287 dataViewMappings: DataViewMapping[];
2288 visualDataViews: DataView[];
2289 dataRoles: VisualDataRole[];
2290 objectDescriptors: DataViewObjectDescriptors;
2291 objectDefinitions: DataViewObjectDefinitions;
2292 colorAllocatorFactory: IColorAllocatorFactory;
2293 transformSelects: DataViewSelectTransform[];
2294 metadata: DataViewMetadata;
2295 projectionActiveItems: DataViewProjectionActiveItems;
2296 }
2297 module DataViewRegression {
2298 const regressionYQueryName: string;
2299 function run(options: DataViewRegressionRunOptions): DataView[];
2300 /**
2301 * This function will compute the linear regression algorithm on the sourceDataView and create a new dataView.
2302 * It works on scalar axis only.
2303 * The algorithm is as follows
2304 *
2305 * 1. Find the cartesian X and Y roles and the columns that correspond to those roles
2306 * 2. Get the data points, (X, Y) pairs, for each series, combining if needed.
2307 * 3. Compute the X and Y points for regression line using Y = Slope * X + Intercept
2308 * If highlights values are present, repeat steps 2 & 3 using highlight values.
2309 * 4. Create the new dataView using the points computed above
2310 */
2311 function linearRegressionTransform(sourceDataView: DataView, dataRoles: VisualDataRole[], regressionDataViewMapping: DataViewMapping, objectDescriptors: DataViewObjectDescriptors, objectDefinitions: DataViewObjectDefinitions, colorAllocatorFactory: IColorAllocatorFactory): DataView;
2312 }
2313}
2314
2315declare module powerbi.data {
2316 import RoleKindByQueryRef = DataViewAnalysis.RoleKindByQueryRef;
2317 interface DataViewSelectTransform {
2318 displayName?: string;
2319 queryName?: string;
2320 format?: string;
2321 type?: ValueType;
2322 roles?: {
2323 [roleName: string]: boolean;
2324 };
2325 kpi?: DataViewKpiColumnMetadata;
2326 sort?: SortDirection;
2327 expr?: SQExpr;
2328 discourageAggregationAcrossGroups?: boolean;
2329 /** Describes the default value applied to a column, if any. */
2330 defaultValue?: DefaultValueDefinition;
2331 aggregateSources?: DataViewSelectAggregateSources;
2332 }
2333 interface DataViewSelectAggregateSources {
2334 min?: DataViewSelectAggregateSource;
2335 max?: DataViewSelectAggregateSource;
2336 }
2337 interface DataViewSelectAggregateSource {
2338 index: number;
2339 }
2340 module DataViewSelectTransform {
2341 /** Convert selection info to projections */
2342 function projectionsFromSelects(selects: DataViewSelectTransform[], projectionActiveItems: DataViewProjectionActiveItems): QueryProjectionsByRole;
2343 /** Use selections and metadata to fashion query role kinds */
2344 function createRoleKindFromMetadata(selects: DataViewSelectTransform[], metadata: DataViewMetadata): RoleKindByQueryRef;
2345 }
2346}
2347declare module powerbi.data {
2348 interface ICategoricalEvalContext extends IEvalContext {
2349 setCurrentRowIndex(index: number): void;
2350 }
2351 function createCategoricalEvalContext(colorAllocatorProvider: IColorAllocatorCache, dataViewCategorical: DataViewCategorical, selectTransforms: DataViewSelectTransform[]): ICategoricalEvalContext;
2352}
2353
2354declare module powerbi.data {
2355 interface ITableEvalContext extends IEvalContext {
2356 setCurrentRowIndex(index: number): void;
2357 }
2358 function createTableEvalContext(colorAllocatorProvider: IColorAllocatorCache, dataViewTable: DataViewTable, selectTransforms: DataViewSelectTransform[]): ITableEvalContext;
2359}
2360
2361declare module powerbi.data {
2362 class RuleEvaluation {
2363 evaluate(evalContext: IEvalContext): any;
2364 }
2365}
2366
2367declare module powerbi.data {
2368 class ColorRuleEvaluation extends RuleEvaluation {
2369 private inputRole;
2370 private allocator;
2371 constructor(inputRole: string, allocator: IColorAllocator);
2372 evaluate(evalContext: IEvalContext): any;
2373 }
2374}
2375
2376declare module powerbi.data {
2377 import ArrayNamedItems = jsCommon.ArrayNamedItems;
2378 class ConceptualSchema {
2379 entities: ArrayNamedItems<ConceptualEntity>;
2380 capabilities: ConceptualCapabilities;
2381 /** Indicates whether the user can edit this ConceptualSchema. This is used to enable/disable model authoring UX. */
2382 canEdit: boolean;
2383 findProperty(entityName: string, propertyName: string): ConceptualProperty;
2384 findHierarchy(entityName: string, name: string): ConceptualHierarchy;
2385 findHierarchyByVariation(variationEntityName: string, variationColumnName: string, variationName: string, hierarchyName: string): ConceptualHierarchy;
2386 findTargetEntityOfVariation(variationEntityName: string, variationColumnName: string, variationName: string): ConceptualEntity;
2387 /**
2388 * Returns the first property of the entity whose kpi is tied to kpiProperty
2389 */
2390 findPropertyWithKpi(entityName: string, kpiProperty: ConceptualProperty): ConceptualProperty;
2391 }
2392 interface ConceptualCapabilities {
2393 discourageQueryAggregateUsage: boolean;
2394 normalizedFiveStateKpiRange: boolean;
2395 supportsMedian: boolean;
2396 supportsPercentile: boolean;
2397 supportsScopedEval: boolean;
2398 }
2399 interface ConceptualPropertyItemContainer {
2400 properties: ArrayNamedItems<ConceptualProperty>;
2401 hierarchies?: ArrayNamedItems<ConceptualHierarchy>;
2402 displayFolders?: ArrayNamedItems<ConceptualDisplayFolder>;
2403 }
2404 interface ConceptualPropertyItem {
2405 name: string;
2406 displayName: string;
2407 hidden?: boolean;
2408 }
2409 interface ConceptualEntity extends ConceptualPropertyItemContainer {
2410 name: string;
2411 displayName: string;
2412 visibility?: ConceptualVisibility;
2413 calculated?: boolean;
2414 queryable?: ConceptualQueryableState;
2415 navigationProperties?: ArrayNamedItems<ConceptualNavigationProperty>;
2416 }
2417 interface ConceptualDisplayFolder extends ConceptualPropertyItem, ConceptualPropertyItemContainer {
2418 }
2419 interface ConceptualProperty extends ConceptualPropertyItem {
2420 type: ValueType;
2421 kind: ConceptualPropertyKind;
2422 format?: string;
2423 column?: ConceptualColumn;
2424 queryable?: ConceptualQueryableState;
2425 measure?: ConceptualMeasure;
2426 kpiValue?: ConceptualProperty;
2427 }
2428 interface ConceptualHierarchy extends ConceptualPropertyItem {
2429 levels: ArrayNamedItems<ConceptualHierarchyLevel>;
2430 }
2431 interface ConceptualHierarchyLevel extends ConceptualPropertyItem {
2432 column: ConceptualProperty;
2433 }
2434 interface ConceptualNavigationProperty {
2435 name: string;
2436 isActive: boolean;
2437 sourceColumn?: ConceptualColumn;
2438 targetEntity: ConceptualEntity;
2439 sourceMultiplicity: ConceptualMultiplicity;
2440 targetMultiplicity: ConceptualMultiplicity;
2441 }
2442 interface ConceptualVariationSource {
2443 name: string;
2444 isDefault: boolean;
2445 navigationProperty?: ConceptualNavigationProperty;
2446 defaultHierarchy?: ConceptualHierarchy;
2447 defaultProperty?: ConceptualProperty;
2448 }
2449 interface ConceptualColumn {
2450 defaultAggregate?: ConceptualDefaultAggregate;
2451 keys?: ArrayNamedItems<ConceptualProperty>;
2452 idOnEntityKey?: boolean;
2453 calculated?: boolean;
2454 defaultValue?: SQConstantExpr;
2455 variations?: ArrayNamedItems<ConceptualVariationSource>;
2456 aggregateBehavior?: ConceptualAggregateBehavior;
2457 groupingDefinition?: ConceptualGroupingDefinition;
2458 }
2459 interface ConceptualGroupingDefinition {
2460 binningDefinition?: ConceptualBinningDefinition;
2461 }
2462 interface ConceptualBinningDefinition {
2463 binSize?: ConceptualBinSize;
2464 }
2465 interface ConceptualBinSize {
2466 value: number;
2467 unit: ConceptualBinUnit;
2468 }
2469 interface ConceptualMeasure {
2470 kpi?: ConceptualPropertyKpi;
2471 }
2472 interface ConceptualPropertyKpi {
2473 statusMetadata: DataViewKpiColumnMetadata;
2474 trendMetadata?: DataViewKpiColumnMetadata;
2475 status?: ConceptualProperty;
2476 goal?: ConceptualProperty;
2477 trend?: ConceptualProperty;
2478 }
2479 const enum ConceptualVisibility {
2480 Visible = 0,
2481 Hidden = 1,
2482 ShowAsVariationsOnly = 2,
2483 IsPrivate = 4,
2484 }
2485 const enum ConceptualQueryableState {
2486 Queryable = 0,
2487 Error = 1,
2488 }
2489 const enum ConceptualBinUnit {
2490 Number = 0,
2491 Percent = 1,
2492 Log = 2,
2493 Percentile = 3,
2494 Year = 4,
2495 Quarter = 5,
2496 Month = 6,
2497 Week = 7,
2498 Day = 8,
2499 }
2500 const enum ConceptualMultiplicity {
2501 ZeroOrOne = 0,
2502 One = 1,
2503 Many = 2,
2504 }
2505 const enum ConceptualPropertyKind {
2506 Column = 0,
2507 Measure = 1,
2508 Kpi = 2,
2509 }
2510 const enum ConceptualDefaultAggregate {
2511 Default = 0,
2512 None = 1,
2513 Sum = 2,
2514 Count = 3,
2515 Min = 4,
2516 Max = 5,
2517 Average = 6,
2518 DistinctCount = 7,
2519 }
2520 enum ConceptualDataCategory {
2521 None = 0,
2522 Address = 1,
2523 City = 2,
2524 Company = 3,
2525 Continent = 4,
2526 Country = 5,
2527 County = 6,
2528 Date = 7,
2529 Image = 8,
2530 ImageUrl = 9,
2531 Latitude = 10,
2532 Longitude = 11,
2533 Organization = 12,
2534 Place = 13,
2535 PostalCode = 14,
2536 Product = 15,
2537 StateOrProvince = 16,
2538 WebUrl = 17,
2539 }
2540 const enum ConceptualAggregateBehavior {
2541 Default = 0,
2542 DiscourageAcrossGroups = 1,
2543 }
2544}
2545
2546declare module powerbi {
2547 import ArrayNamedItems = jsCommon.ArrayNamedItems;
2548 import FederatedConceptualSchema = powerbi.data.FederatedConceptualSchema;
2549 import QueryProjectionsByRole = data.QueryProjectionsByRole;
2550 interface ScriptResult {
2551 source: string;
2552 provider: string;
2553 }
2554 module ScriptResultUtil {
2555 function findScriptResult(dataViewMappings: DataViewMapping[] | data.CompiledDataViewMapping[]): DataViewScriptResultMapping | data.CompiledDataViewScriptResultMapping;
2556 function extractScriptResult(dataViewMappings: data.CompiledDataViewMapping[]): ScriptResult;
2557 function extractScriptResultFromVisualConfig(dataViewMappings: DataViewMapping[], objects: powerbi.data.DataViewObjectDefinitions): ScriptResult;
2558 function getScriptInput(projections: QueryProjectionsByRole, selects: ArrayNamedItems<data.NamedSQExpr>, schema: FederatedConceptualSchema): data.ScriptInput;
2559 }
2560}
2561
2562declare module powerbi.data.segmentation {
2563 interface DataViewTableSegment extends DataViewTable {
2564 /**
2565 * Index of the last item that had a merge flag in the underlying data.
2566 * We assume merge flags are not random but adjacent to each other.
2567 */
2568 lastMergeIndex?: number;
2569 }
2570 interface DataViewTreeSegmentNode extends DataViewTreeNode {
2571 /** Indicates whether the node is a duplicate of a node from a previous segment. */
2572 isMerge?: boolean;
2573 }
2574 interface DataViewCategoricalSegment extends DataViewCategorical {
2575 /**
2576 * Index of the last item that had a merge flag in the underlying data.
2577 * We assume merge flags are not random but adjacent to each other.
2578 */
2579 lastMergeIndex?: number;
2580 }
2581 interface DataViewMatrixSegmentNode extends DataViewMatrixNode {
2582 /**
2583 * Index of the last item that had a merge flag in the underlying data.
2584 * We assume merge flags are not random but adjacent to each other.
2585 */
2586 isMerge?: boolean;
2587 }
2588 module DataViewMerger {
2589 function mergeDataViews(source: DataView, segment: DataView): void;
2590 /** Note: Public for testability */
2591 function mergeTables(source: DataViewTable, segment: DataViewTableSegment): void;
2592 /**
2593 * Merge categories values and identities
2594 *
2595 * Note: Public for testability
2596 */
2597 function mergeCategorical(source: DataViewCategorical, segment: DataViewCategoricalSegment): void;
2598 /** Note: Public for testability */
2599 function mergeTreeNodes(sourceRoot: DataViewTreeNode, segmentRoot: DataViewTreeNode, allowDifferentStructure: boolean): void;
2600 }
2601}
2602
2603declare module powerbi.data {
2604 /** Rewrites an expression tree, including all descendant nodes. */
2605 class SQExprRewriter implements ISQExprVisitor<SQExpr>, IFillRuleDefinitionVisitor<LinearGradient2Definition, LinearGradient3Definition> {
2606 visitColumnRef(expr: SQColumnRefExpr): SQExpr;
2607 visitMeasureRef(expr: SQMeasureRefExpr): SQExpr;
2608 visitAggr(expr: SQAggregationExpr): SQExpr;
2609 visitSelectRef(expr: SQSelectRefExpr): SQExpr;
2610 visitPercentile(expr: SQPercentileExpr): SQExpr;
2611 visitHierarchy(expr: SQHierarchyExpr): SQExpr;
2612 visitHierarchyLevel(expr: SQHierarchyLevelExpr): SQExpr;
2613 visitPropertyVariationSource(expr: SQPropertyVariationSourceExpr): SQExpr;
2614 visitEntity(expr: SQEntityExpr): SQExpr;
2615 visitAnd(orig: SQAndExpr): SQExpr;
2616 visitBetween(orig: SQBetweenExpr): SQExpr;
2617 visitIn(orig: SQInExpr): SQExpr;
2618 private rewriteAll(origExprs);
2619 visitOr(orig: SQOrExpr): SQExpr;
2620 visitCompare(orig: SQCompareExpr): SQExpr;
2621 visitContains(orig: SQContainsExpr): SQExpr;
2622 visitExists(orig: SQExistsExpr): SQExpr;
2623 visitNot(orig: SQNotExpr): SQExpr;
2624 visitStartsWith(orig: SQStartsWithExpr): SQExpr;
2625 visitConstant(expr: SQConstantExpr): SQExpr;
2626 visitDateSpan(orig: SQDateSpanExpr): SQExpr;
2627 visitDateAdd(orig: SQDateAddExpr): SQExpr;
2628 visitNow(orig: SQNowExpr): SQExpr;
2629 visitDefaultValue(orig: SQDefaultValueExpr): SQExpr;
2630 visitAnyValue(orig: SQAnyValueExpr): SQExpr;
2631 visitArithmetic(orig: SQArithmeticExpr): SQExpr;
2632 visitScopedEval(orig: SQScopedEvalExpr): SQExpr;
2633 visitWithRef(orig: SQWithRefExpr): SQExpr;
2634 visitTransformTableRef(orig: SQTransformTableRefExpr): SQExpr;
2635 visitTransformOutputRoleRef(orig: SQTransformOutputRoleRefExpr): SQExpr;
2636 visitFillRule(orig: SQFillRuleExpr): SQExpr;
2637 visitLinearGradient2(origGradient2: LinearGradient2Definition): LinearGradient2Definition;
2638 visitLinearGradient3(origGradient3: LinearGradient3Definition): LinearGradient3Definition;
2639 private visitFillRuleStop(stop);
2640 visitResourcePackageItem(orig: SQResourcePackageItemExpr): SQExpr;
2641 }
2642}
2643
2644declare module powerbi.data {
2645 /** Responsible for writing equality comparisons against a field to an SQInExpr. */
2646 module EqualsToInRewriter {
2647 function run(expr: SQExpr): SQExpr;
2648 }
2649}
2650
2651declare module powerbi.data {
2652 interface FilterValueScopeIdsContainer {
2653 isNot: boolean;
2654 scopeIds: DataViewScopeIdentity[];
2655 }
2656 module SQExprConverter {
2657 function asScopeIdsContainer(filter: SemanticFilter, fieldSQExprs: SQExpr[]): FilterValueScopeIdsContainer;
2658 /** Gets a comparand value from the given DataViewScopeIdentity. */
2659 function getFirstComparandValue(identity: DataViewScopeIdentity): any;
2660 }
2661}
2662
2663declare module powerbi.data {
2664 /** Recognizes DataViewScopeIdentity expression trees to extract comparison keys. */
2665 module ScopeIdentityExtractor {
2666 function getKeys(expr: SQExpr): SQExpr[];
2667 function getValues(expr: SQExpr): SQExpr[];
2668 function getInExpr(expr: SQExpr): SQInExpr;
2669 }
2670}
2671
2672declare module powerbi.data {
2673 module PrimitiveValueEncoding {
2674 function decimal(value: number): string;
2675 function double(value: number): string;
2676 function integer(value: number): string;
2677 function dateTime(value: Date): string;
2678 function text(value: string): string;
2679 function nullEncoding(): string;
2680 function boolean(value: boolean): string;
2681 }
2682}
2683
2684declare module powerbi.data {
2685 interface ISQAggregationOperations {
2686 /** Returns an array of supported aggregates for a given expr and role type. */
2687 getSupportedAggregates(expr: SQExpr, schema: FederatedConceptualSchema, targetTypes: ValueTypeDescriptor[]): QueryAggregateFunction[];
2688 isSupportedAggregate(expr: SQExpr, schema: FederatedConceptualSchema, aggregate: QueryAggregateFunction, targetTypes: ValueTypeDescriptor[]): boolean;
2689 createExprWithAggregate(expr: SQExpr, schema: FederatedConceptualSchema, aggregateNonNumericFields: boolean, targetTypes: ValueTypeDescriptor[], preferredAggregate?: QueryAggregateFunction): SQExpr;
2690 }
2691 function createSQAggregationOperations(datetimeMinMaxSupported: boolean): ISQAggregationOperations;
2692}
2693
2694declare module powerbi.data {
2695 module SQHierarchyExprUtils {
2696 function getConceptualHierarchyLevelFromExpr(conceptualSchema: FederatedConceptualSchema, fieldExpr: FieldExprPattern): ConceptualHierarchyLevel;
2697 function getConceptualHierarchyLevel(conceptualSchema: FederatedConceptualSchema, schemaName: string, entity: string, hierarchy: string, hierarchyLevel: string): ConceptualHierarchyLevel;
2698 function getConceptualHierarchy(sqExpr: SQExpr, federatedSchema: FederatedConceptualSchema): ConceptualHierarchy;
2699 function expandExpr(schema: FederatedConceptualSchema, expr: SQExpr, suppressHierarchyLevelExpansion?: boolean): SQExpr | SQExpr[];
2700 function isHierarchyOrVariation(schema: FederatedConceptualSchema, expr: SQExpr): boolean;
2701 function getSourceVariationExpr(hierarchyLevelExpr: data.SQHierarchyLevelExpr): SQColumnRefExpr;
2702 function getSourceHierarchy(hierarchyLevelExpr: data.SQHierarchyLevelExpr): SQHierarchyExpr;
2703 function getHierarchySourceAsVariationSource(hierarchyLevelExpr: SQHierarchyLevelExpr): SQPropertyVariationSourceExpr;
2704 /**
2705 * Returns true if firstExpr and secondExpr are levels in the same hierarchy and firstExpr is before secondExpr in allLevels.
2706 */
2707 function areHierarchyLevelsOrdered(allLevels: SQHierarchyLevelExpr[], firstExpr: SQExpr, secondExpr: SQExpr): boolean;
2708 /**
2709 * Given an ordered set of levels and an ordered subset of those levels, returns the index where
2710 * expr should be inserted into the subset to maintain the correct order.
2711 */
2712 function getInsertionIndex(allLevels: SQHierarchyLevelExpr[], orderedSubsetOfLevels: SQHierarchyLevelExpr[], expr: SQHierarchyLevelExpr): number;
2713 }
2714 module SQExprHierarchyToHierarchyLevelConverter {
2715 function convert(sqExpr: SQExpr, federatedSchema: FederatedConceptualSchema): SQExpr[];
2716 }
2717}
2718
2719declare module powerbi.data {
2720 interface SQExprGroup {
2721 expr: SQExpr;
2722 children: SQHierarchyLevelExpr[];
2723 /** Index of expression in the query. */
2724 selectQueryIndex: number;
2725 }
2726 module SQExprGroupUtils {
2727 /** Group all projections. Eacch group can consist of either a single property, or a collection of hierarchy items. */
2728 function groupExprs(schema: FederatedConceptualSchema, exprs: SQExpr[]): SQExprGroup[];
2729 }
2730}
2731
2732declare module powerbi.data {
2733 /** Represents an immutable expression within a SemanticQuery. */
2734 abstract class SQExpr implements ISQExpr {
2735 private _kind;
2736 constructor(kind: SQExprKind);
2737 static equals(x: SQExpr, y: SQExpr, ignoreCase?: boolean): boolean;
2738 validate(schema: FederatedConceptualSchema, aggrUtils: ISQAggregationOperations, errors?: SQExprValidationError[]): SQExprValidationError[];
2739 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2740 kind: SQExprKind;
2741 static isArithmetic(expr: SQExpr): expr is SQArithmeticExpr;
2742 static isColumn(expr: SQExpr): expr is SQColumnRefExpr;
2743 static isConstant(expr: SQExpr): expr is SQConstantExpr;
2744 static isEntity(expr: SQExpr): expr is SQEntityExpr;
2745 static isHierarchy(expr: SQExpr): expr is SQHierarchyExpr;
2746 static isHierarchyLevel(expr: SQExpr): expr is SQHierarchyLevelExpr;
2747 static isAggregation(expr: SQExpr): expr is SQAggregationExpr;
2748 static isMeasure(expr: SQExpr): expr is SQMeasureRefExpr;
2749 static isPercentile(expr: SQExpr): expr is SQPercentileExpr;
2750 static isSelectRef(expr: SQExpr): expr is SQSelectRefExpr;
2751 static isScopedEval(expr: SQExpr): expr is SQScopedEvalExpr;
2752 static isWithRef(expr: SQExpr): expr is SQWithRefExpr;
2753 static isTransformTableRef(expr: SQExpr): expr is SQTransformTableRefExpr;
2754 static isTransformOutputRoleRef(expr: SQExpr): expr is SQTransformOutputRoleRefExpr;
2755 static isResourcePackageItem(expr: SQExpr): expr is SQResourcePackageItemExpr;
2756 getMetadata(federatedSchema: FederatedConceptualSchema): SQExprMetadata;
2757 getDefaultAggregate(federatedSchema: FederatedConceptualSchema, forceAggregation?: boolean): QueryAggregateFunction;
2758 /** Return the SQExpr[] of group on columns if it has group on keys otherwise return the SQExpr of the column.*/
2759 getKeyColumns(schema: FederatedConceptualSchema): SQExpr[];
2760 /** Returns a value indicating whether the expression would group on keys other than itself.*/
2761 hasGroupOnKeys(schema: FederatedConceptualSchema): boolean;
2762 private getPropertyKeys(schema);
2763 getConceptualProperty(federatedSchema: FederatedConceptualSchema): ConceptualProperty;
2764 getTargetEntityForVariation(federatedSchema: FederatedConceptualSchema, variationName: string): string;
2765 getTargetEntity(federatedSchema: FederatedConceptualSchema): SQEntityExpr;
2766 private getHierarchyLevelConceptualProperty(federatedSchema);
2767 private getMetadataForVariation(field, federatedSchema);
2768 private getMetadataForHierarchyLevel(field, federatedSchema);
2769 private getMetadataForPercentOfGrandTotal();
2770 private getPropertyMetadata(field, property);
2771 private getMetadataForProperty(field, federatedSchema);
2772 private static getMetadataForEntity(field, federatedSchema);
2773 }
2774 const enum SQExprKind {
2775 Entity = 0,
2776 ColumnRef = 1,
2777 MeasureRef = 2,
2778 Aggregation = 3,
2779 PropertyVariationSource = 4,
2780 Hierarchy = 5,
2781 HierarchyLevel = 6,
2782 And = 7,
2783 Between = 8,
2784 In = 9,
2785 Or = 10,
2786 Contains = 11,
2787 Compare = 12,
2788 StartsWith = 13,
2789 Exists = 14,
2790 Not = 15,
2791 Constant = 16,
2792 DateSpan = 17,
2793 DateAdd = 18,
2794 Now = 19,
2795 AnyValue = 20,
2796 DefaultValue = 21,
2797 Arithmetic = 22,
2798 FillRule = 23,
2799 ResourcePackageItem = 24,
2800 ScopedEval = 25,
2801 WithRef = 26,
2802 Percentile = 27,
2803 SelectRef = 28,
2804 TransformTableRef = 29,
2805 TransformOutputRoleRef = 30,
2806 }
2807 interface SQExprMetadata {
2808 kind: FieldKind;
2809 type: ValueType;
2810 format?: string;
2811 idOnEntityKey?: boolean;
2812 aggregate?: QueryAggregateFunction;
2813 defaultAggregate?: ConceptualDefaultAggregate;
2814 }
2815 const enum FieldKind {
2816 /** Indicates the field references a column, which evaluates to a distinct set of values (e.g., Year, Name, SalesQuantity, etc.). */
2817 Column = 0,
2818 /** Indicates the field references a measure, which evaluates to a single value (e.g., SalesYTD, Sum(Sales), etc.). */
2819 Measure = 1,
2820 }
2821 /** Note: Exported for testability */
2822 function defaultAggregateForDataType(type: ValueType): QueryAggregateFunction;
2823 /** Note: Exported for testability */
2824 function defaultAggregateToQueryAggregateFunction(aggregate: ConceptualDefaultAggregate): QueryAggregateFunction;
2825 class SQEntityExpr extends SQExpr {
2826 schema: string;
2827 entity: string;
2828 variable: string;
2829 constructor(schema: string, entity: string, variable?: string);
2830 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2831 }
2832 class SQArithmeticExpr extends SQExpr {
2833 left: SQExpr;
2834 right: SQExpr;
2835 operator: ArithmeticOperatorKind;
2836 constructor(left: SQExpr, right: SQExpr, operator: ArithmeticOperatorKind);
2837 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2838 }
2839 class SQScopedEvalExpr extends SQExpr {
2840 expression: SQExpr;
2841 scope: SQExpr[];
2842 constructor(expression: SQExpr, scope: SQExpr[]);
2843 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2844 getMetadata(federatedSchema: FederatedConceptualSchema): SQExprMetadata;
2845 }
2846 class SQWithRefExpr extends SQExpr {
2847 expressionName: string;
2848 constructor(expressionName: string);
2849 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2850 }
2851 abstract class SQPropRefExpr extends SQExpr {
2852 ref: string;
2853 source: SQExpr;
2854 constructor(kind: SQExprKind, source: SQExpr, ref: string);
2855 }
2856 class SQColumnRefExpr extends SQPropRefExpr {
2857 constructor(source: SQExpr, ref: string);
2858 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2859 }
2860 class SQMeasureRefExpr extends SQPropRefExpr {
2861 constructor(source: SQExpr, ref: string);
2862 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2863 }
2864 class SQAggregationExpr extends SQExpr {
2865 arg: SQExpr;
2866 func: QueryAggregateFunction;
2867 constructor(arg: SQExpr, func: QueryAggregateFunction);
2868 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2869 }
2870 class SQPercentileExpr extends SQExpr {
2871 arg: SQExpr;
2872 k: number;
2873 exclusive: boolean;
2874 constructor(arg: SQExpr, k: number, exclusive: boolean);
2875 getMetadata(federatedSchema: FederatedConceptualSchema): SQExprMetadata;
2876 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2877 }
2878 class SQPropertyVariationSourceExpr extends SQExpr {
2879 arg: SQExpr;
2880 name: string;
2881 property: string;
2882 constructor(arg: SQExpr, name: string, property: string);
2883 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2884 }
2885 class SQHierarchyExpr extends SQExpr {
2886 arg: SQExpr;
2887 hierarchy: string;
2888 constructor(arg: SQExpr, hierarchy: string);
2889 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2890 }
2891 class SQHierarchyLevelExpr extends SQExpr {
2892 arg: SQExpr;
2893 level: string;
2894 constructor(arg: SQExpr, level: string);
2895 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2896 }
2897 class SQSelectRefExpr extends SQExpr {
2898 expressionName: string;
2899 constructor(expressionName: string);
2900 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2901 }
2902 class SQAndExpr extends SQExpr {
2903 left: SQExpr;
2904 right: SQExpr;
2905 constructor(left: SQExpr, right: SQExpr);
2906 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2907 }
2908 class SQBetweenExpr extends SQExpr {
2909 arg: SQExpr;
2910 lower: SQExpr;
2911 upper: SQExpr;
2912 constructor(arg: SQExpr, lower: SQExpr, upper: SQExpr);
2913 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2914 }
2915 class SQInExpr extends SQExpr {
2916 args: SQExpr[];
2917 values: SQExpr[][];
2918 constructor(args: SQExpr[], values: SQExpr[][]);
2919 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2920 }
2921 class SQOrExpr extends SQExpr {
2922 left: SQExpr;
2923 right: SQExpr;
2924 constructor(left: SQExpr, right: SQExpr);
2925 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2926 }
2927 class SQCompareExpr extends SQExpr {
2928 comparison: QueryComparisonKind;
2929 left: SQExpr;
2930 right: SQExpr;
2931 constructor(comparison: QueryComparisonKind, left: SQExpr, right: SQExpr);
2932 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2933 }
2934 class SQContainsExpr extends SQExpr {
2935 left: SQExpr;
2936 right: SQExpr;
2937 constructor(left: SQExpr, right: SQExpr);
2938 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2939 }
2940 class SQStartsWithExpr extends SQExpr {
2941 left: SQExpr;
2942 right: SQExpr;
2943 constructor(left: SQExpr, right: SQExpr);
2944 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2945 }
2946 class SQExistsExpr extends SQExpr {
2947 arg: SQExpr;
2948 constructor(arg: SQExpr);
2949 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2950 }
2951 class SQNotExpr extends SQExpr {
2952 arg: SQExpr;
2953 constructor(arg: SQExpr);
2954 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2955 }
2956 class SQConstantExpr extends SQExpr implements ISQConstantExpr {
2957 type: ValueType;
2958 /** The native JavaScript representation of the value. */
2959 value: any;
2960 /** The string encoded, lossless representation of the value. */
2961 valueEncoded: string;
2962 constructor(type: ValueType, value: any, valueEncoded: string);
2963 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2964 getMetadata(federatedSchema: FederatedConceptualSchema): SQExprMetadata;
2965 }
2966 class SQDateSpanExpr extends SQExpr {
2967 unit: TimeUnit;
2968 arg: SQExpr;
2969 constructor(unit: TimeUnit, arg: SQExpr);
2970 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2971 }
2972 class SQDateAddExpr extends SQExpr {
2973 unit: TimeUnit;
2974 amount: number;
2975 arg: SQExpr;
2976 constructor(unit: TimeUnit, amount: number, arg: SQExpr);
2977 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2978 }
2979 class SQNowExpr extends SQExpr {
2980 constructor();
2981 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2982 }
2983 class SQDefaultValueExpr extends SQExpr {
2984 constructor();
2985 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2986 }
2987 class SQAnyValueExpr extends SQExpr {
2988 constructor();
2989 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2990 }
2991 class SQFillRuleExpr extends SQExpr {
2992 input: SQExpr;
2993 rule: FillRuleDefinition;
2994 constructor(input: SQExpr, fillRule: FillRuleDefinition);
2995 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
2996 }
2997 class SQResourcePackageItemExpr extends SQExpr {
2998 packageName: string;
2999 packageType: number;
3000 itemName: string;
3001 constructor(packageName: string, packageType: number, itemName: string);
3002 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
3003 }
3004 class SQTransformTableRefExpr extends SQExpr {
3005 source: string;
3006 constructor(source: string);
3007 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
3008 }
3009 class SQTransformOutputRoleRefExpr extends SQExpr {
3010 role: string;
3011 transform: string;
3012 constructor(role: string, transform?: string);
3013 accept<T, TArg>(visitor: ISQExprVisitorWithArg<T, TArg>, arg?: TArg): T;
3014 }
3015 /** Provides utilities for creating & manipulating expressions. */
3016 module SQExprBuilder {
3017 function entity(schema: string, entity: string, variable?: string): SQEntityExpr;
3018 function columnRef(source: SQExpr, prop: string): SQColumnRefExpr;
3019 function measureRef(source: SQExpr, prop: string): SQMeasureRefExpr;
3020 function aggregate(source: SQExpr, aggregate: QueryAggregateFunction): SQAggregationExpr;
3021 function selectRef(expressionName: string): SQSelectRefExpr;
3022 function percentile(source: SQExpr, k: number, exclusive: boolean): SQPercentileExpr;
3023 function arithmetic(left: SQExpr, right: SQExpr, operator: ArithmeticOperatorKind): SQArithmeticExpr;
3024 function scopedEval(expression: SQExpr, scope: SQExpr[]): SQScopedEvalExpr;
3025 function withRef(expressionName: string): SQWithRefExpr;
3026 function hierarchy(source: SQExpr, hierarchy: string): SQHierarchyExpr;
3027 function propertyVariationSource(source: SQExpr, name: string, property: string): SQPropertyVariationSourceExpr;
3028 function hierarchyLevel(source: SQExpr, level: string): SQHierarchyLevelExpr;
3029 function transformTableRef(source: string): SQTransformTableRefExpr;
3030 function transformOutputRoleRef(role: string, transform?: string): SQTransformOutputRoleRefExpr;
3031 function and(left: SQExpr, right: SQExpr): SQExpr;
3032 function between(arg: SQExpr, lower: SQExpr, upper: SQExpr): SQBetweenExpr;
3033 function inExpr(args: SQExpr[], values: SQExpr[][]): SQInExpr;
3034 function or(left: SQExpr, right: SQExpr): SQExpr;
3035 function compare(kind: QueryComparisonKind, left: SQExpr, right: SQExpr): SQCompareExpr;
3036 function contains(left: SQExpr, right: SQExpr): SQContainsExpr;
3037 function exists(arg: SQExpr): SQExistsExpr;
3038 function equal(left: SQExpr, right: SQExpr): SQCompareExpr;
3039 function not(arg: SQExpr): SQNotExpr;
3040 function startsWith(left: SQExpr, right: SQExpr): SQStartsWithExpr;
3041 function nullConstant(): SQConstantExpr;
3042 function now(): SQNowExpr;
3043 function defaultValue(): SQDefaultValueExpr;
3044 function anyValue(): SQAnyValueExpr;
3045 function boolean(value: boolean): SQConstantExpr;
3046 function dateAdd(unit: TimeUnit, amount: number, arg: SQExpr): SQDateAddExpr;
3047 function dateTime(value: Date, valueEncoded?: string): SQConstantExpr;
3048 function dateSpan(unit: TimeUnit, arg: SQExpr): SQDateSpanExpr;
3049 function decimal(value: number, valueEncoded?: string): SQConstantExpr;
3050 function double(value: number, valueEncoded?: string): SQConstantExpr;
3051 function integer(value: number, valueEncoded?: string): SQConstantExpr;
3052 function text(value: string, valueEncoded?: string): SQConstantExpr;
3053 /** Returns an SQExpr that evaluates to the constant value. */
3054 function typedConstant(value: PrimitiveValue, type: ValueTypeDescriptor): SQConstantExpr;
3055 function setAggregate(expr: SQExpr, aggregate: QueryAggregateFunction): SQExpr;
3056 function removeAggregate(expr: SQExpr): SQExpr;
3057 function setPercentOfGrandTotal(expr: SQExpr): SQExpr;
3058 function removePercentOfGrandTotal(expr: SQExpr): SQExpr;
3059 function removeEntityVariables(expr: SQExpr): SQExpr;
3060 function fillRule(expr: SQExpr, rule: FillRuleDefinition): SQFillRuleExpr;
3061 function resourcePackageItem(packageName: string, packageType: number, itemName: string): SQResourcePackageItemExpr;
3062 }
3063 /** Provides utilities for obtaining information about expressions. */
3064 module SQExprInfo {
3065 function getAggregate(expr: SQExpr): QueryAggregateFunction;
3066 }
3067 const enum SQExprValidationError {
3068 invalidAggregateFunction = 0,
3069 invalidSchemaReference = 1,
3070 invalidEntityReference = 2,
3071 invalidColumnReference = 3,
3072 invalidMeasureReference = 4,
3073 invalidHierarchyReference = 5,
3074 invalidHierarchyLevelReference = 6,
3075 invalidLeftOperandType = 7,
3076 invalidRightOperandType = 8,
3077 invalidValueType = 9,
3078 invalidPercentileArgument = 10,
3079 invalidScopeArgument = 11,
3080 }
3081 class SQExprValidationVisitor extends SQExprRewriter {
3082 errors: SQExprValidationError[];
3083 private schema;
3084 private aggrUtils;
3085 constructor(schema: FederatedConceptualSchema, aggrUtils: ISQAggregationOperations, errors?: SQExprValidationError[]);
3086 visitIn(expr: SQInExpr): SQExpr;
3087 visitCompare(expr: SQCompareExpr): SQExpr;
3088 visitColumnRef(expr: SQColumnRefExpr): SQExpr;
3089 visitMeasureRef(expr: SQMeasureRefExpr): SQExpr;
3090 visitAggr(expr: SQAggregationExpr): SQExpr;
3091 visitHierarchy(expr: SQHierarchyExpr): SQExpr;
3092 visitHierarchyLevel(expr: SQHierarchyLevelExpr): SQExpr;
3093 visitPercentile(expr: SQPercentileExpr): SQExpr;
3094 visitEntity(expr: SQEntityExpr): SQExpr;
3095 visitContains(expr: SQContainsExpr): SQExpr;
3096 visitStartsWith(expr: SQContainsExpr): SQExpr;
3097 visitArithmetic(expr: SQArithmeticExpr): SQExpr;
3098 visitScopedEval(expr: SQScopedEvalExpr): SQExpr;
3099 visitWithRef(expr: SQWithRefExpr): SQExpr;
3100 visitTransformTableRef(expr: SQTransformTableRefExpr): SQExpr;
3101 visitTransformOutputRoleRef(expr: SQTransformOutputRoleRefExpr): SQExpr;
3102 private validateOperandsAndTypeForStartOrContains(left, right);
3103 private validateArithmeticTypes(left, right);
3104 private validateCompatibleType(left, right);
3105 private validateEntity(schemaName, entityName);
3106 private validateHierarchy(schemaName, entityName, hierarchyName);
3107 private validateHierarchyLevel(schemaName, entityName, hierarchyName, levelName);
3108 private register(error);
3109 private isQueryable(fieldExpr);
3110 }
3111}
3112
3113declare module powerbi.data {
3114 import ConceptualEntity = powerbi.data.ConceptualEntity;
3115 import SQEntityExpr = powerbi.data.SQEntityExpr;
3116 module SQExprUtils {
3117 function supportsArithmetic(expr: SQExpr, schema: FederatedConceptualSchema): boolean;
3118 function indexOfExpr(items: SQExpr[], searchElement: SQExpr): number;
3119 function indexOfNamedExpr(items: NamedSQExpr[], searchElement: SQExpr): number;
3120 function sequenceEqual(x: SQExpr[], y: SQExpr[]): boolean;
3121 function uniqueName(namedItems: NamedSQExpr[], expr: SQExpr, exprDefaultName?: string): string;
3122 /** Generates a default expression name */
3123 function defaultName(expr: SQExpr, fallback?: string): string;
3124 /** Gets a value indicating whether the expr is a model measure or an aggregate. */
3125 function isMeasure(expr: SQExpr): boolean;
3126 /** Gets a value indicating whether the expr is an AnyValue or equals comparison to AnyValue*/
3127 function isAnyValue(expr: SQExpr): boolean;
3128 /** Gets a value indicating whether the expr is a DefaultValue or equals comparison to DefaultValue*/
3129 function isDefaultValue(expr: SQExpr): boolean;
3130 function discourageAggregation(expr: SQExpr, schema: FederatedConceptualSchema): boolean;
3131 function getAggregateBehavior(expr: SQExpr, schema: FederatedConceptualSchema): ConceptualAggregateBehavior;
3132 function getSchemaCapabilities(expr: SQExpr, schema: FederatedConceptualSchema): ConceptualCapabilities;
3133 function getKpiMetadata(expr: SQExpr, schema: FederatedConceptualSchema): DataViewKpiColumnMetadata;
3134 function getConceptualEntity(entityExpr: SQEntityExpr, schema: FederatedConceptualSchema): ConceptualEntity;
3135 function getDefaultValue(fieldSQExpr: SQExpr, schema: FederatedConceptualSchema): SQConstantExpr;
3136 function getDefaultValues(fieldSQExprs: SQExpr[], schema: FederatedConceptualSchema): SQConstantExpr[];
3137 /** Return compare or and expression for key value pairs. */
3138 function getDataViewScopeIdentityComparisonExpr(fieldsExpr: SQExpr[], values: SQConstantExpr[]): SQExpr;
3139 function getActiveTablesNames(queryDefn: data.SemanticQuery): string[];
3140 function isRelatedToMany(schema: FederatedConceptualSchema, sourceExpr: SQEntityExpr, targetExpr: SQEntityExpr): boolean;
3141 function isRelatedToOne(schema: FederatedConceptualSchema, sourceExpr: SQEntityExpr, targetExpr: SQEntityExpr): boolean;
3142 function isRelatedOneToOne(schema: FederatedConceptualSchema, sourceExpr: SQEntityExpr, targetExpr: SQEntityExpr): boolean;
3143 /** Performs a union of the 2 arrays with SQExpr.equals as comparator to skip duplicate items,
3144 and returns a new array. When available, we should use _.unionWith from lodash. */
3145 function concatUnique(leftExprs: SQExpr[], rightExprs: SQExpr[]): SQExpr[];
3146 }
3147}
3148
3149declare module powerbi.data {
3150 class SemanticQueryRewriter {
3151 private exprRewriter;
3152 constructor(exprRewriter: ISQExprVisitor<SQExpr>);
3153 rewriteFrom(fromValue: SQFrom): SQFrom;
3154 rewriteSelect(selectItems: NamedSQExpr[], from: SQFrom): NamedSQExpr[];
3155 rewriteGroupBy(groupByitems: NamedSQExpr[], from: SQFrom): NamedSQExpr[];
3156 private rewriteNamedSQExpressions(expressions, from);
3157 rewriteOrderBy(orderByItems: SQSortDefinition[], from: SQFrom): SQSortDefinition[];
3158 rewriteWhere(whereItems: SQFilter[], from: SQFrom): SQFilter[];
3159 rewriteTransform(transformItems: SQTransform[], from: SQFrom): SQTransform[];
3160 }
3161}
3162
3163declare module powerbi.data {
3164 type SQFromSource = SQFromEntitySource | SQFromSubquerySource;
3165 /** Represents an entity reference in SemanticQuery from. */
3166 class SQFromEntitySource {
3167 schema: string;
3168 entity: string;
3169 constructor(schema: string, entity: string);
3170 accept<T, TArg>(visitor: ISQFromSourceVisitor<T, TArg>, arg: TArg): T;
3171 equals(source: SQFromEntitySource): boolean;
3172 }
3173 /** Represents a subquery reference in SemanticQuery from.
3174 for subquery use SQExpr instead of SemanticQuery when we have one for QuerySubqueryExpression
3175 */
3176 class SQFromSubquerySource {
3177 subquery: SemanticQuery;
3178 constructor(subquery: SemanticQuery);
3179 accept<T, TArg>(visitor: ISQFromSourceVisitor<T, TArg>, arg: TArg): T;
3180 equals(source: SQFromSubquerySource): boolean;
3181 }
3182 /** Represents a SemanticQuery/SemanticFilter from clause. */
3183 class SQFrom {
3184 private items;
3185 constructor(items?: {
3186 [name: string]: SQFromSource;
3187 });
3188 keys(): string[];
3189 source(key: string): SQFromSource;
3190 sources(): {
3191 [name: string]: SQFromSource;
3192 };
3193 ensureSource(source: SQFromSource, desiredVariableName?: string): QueryFromEnsureEntityResult;
3194 remove(key: string): void;
3195 private getSourceKeyFromItems(source);
3196 private addSource(source, desiredVariableName);
3197 clone(): SQFrom;
3198 equals(comparand: SQFrom): boolean;
3199 }
3200 function equals(left: SQFromSource, right: SQFromSource): boolean;
3201 function isSQFromEntitySource(source: SQFromSource): source is SQFromEntitySource;
3202 function isSQFromSubquerySource(source: SQFromSource): source is SQFromSubquerySource;
3203 interface ISQFromSourceVisitor<T, Targ> {
3204 visitEntity(source: SQFromEntitySource, arg: Targ): T;
3205 visitSubquery(source: SQFromSubquerySource, arg: Targ): T;
3206 }
3207 class SQFromSourceCandidateNameVisitor implements ISQFromSourceVisitor<string, void> {
3208 /** Converts the entity name into a short reference name. Follows the Semantic Query convention of a short name. */
3209 visitEntity(source: SQFromEntitySource): string;
3210 visitSubquery(source: SQFromSubquerySource): string;
3211 }
3212 class SQFromEntitiesVisitor implements ISQFromSourceVisitor<void, string> {
3213 entities: SQEntityExpr[];
3214 constructor();
3215 visitEntity(source: SQFromEntitySource, key: string): void;
3216 visitSubquery(source: SQFromSubquerySource, key: string): void;
3217 }
3218}
3219
3220declare module powerbi.data {
3221 import ArrayNamedItems = jsCommon.ArrayNamedItems;
3222 interface NamedSQExpr {
3223 name: string;
3224 expr: SQExpr;
3225 }
3226 interface SQFilter {
3227 target?: SQExpr[];
3228 condition: SQExpr;
3229 }
3230 /** Represents a sort over an expression. */
3231 interface SQSortDefinition {
3232 expr: SQExpr;
3233 direction: SortDirection;
3234 }
3235 interface QueryFromEnsureEntityResult {
3236 name: string;
3237 new?: boolean;
3238 }
3239 interface SQSourceRenames {
3240 [from: string]: string;
3241 }
3242 interface SQTransform {
3243 name: string;
3244 algorithm: string;
3245 input: SQTransformInput;
3246 output: SQTransformOutput;
3247 }
3248 interface SQTransformInput {
3249 parameters: NamedSQExpr[];
3250 table?: SQTransformTable;
3251 }
3252 interface SQTransformOutput {
3253 table?: SQTransformTable;
3254 }
3255 interface SQTransformTable {
3256 name: string;
3257 columns: SQTransformTableColumn[];
3258 }
3259 interface SQTransformTableColumn {
3260 role?: string;
3261 expression: NamedSQExpr;
3262 }
3263 /**
3264 * Represents a semantic query that is:
3265 * 1) Round-trippable with a JSON QueryDefinition.
3266 * 2) Immutable
3267 * 3) Long-lived and does not have strong references to a conceptual model (only names).
3268 */
3269 class SemanticQuery {
3270 private static empty;
3271 private fromValue;
3272 private whereItems;
3273 private orderByItems;
3274 private selectItems;
3275 private groupByItems;
3276 private transformItems;
3277 constructor(from: SQFrom, where: SQFilter[], orderBy: SQSortDefinition[], select: NamedSQExpr[], groupBy: NamedSQExpr[], transformItems: SQTransform[]);
3278 static create(): SemanticQuery;
3279 private static createWithTrimmedFrom(from, where, transform, orderBy, select, groupBy);
3280 from(): SQFrom;
3281 /** Returns a query equivalent to this, with the specified selected items. */
3282 select(values: NamedSQExpr[]): SemanticQuery;
3283 /** Gets the items being selected in this query. */
3284 select(): ArrayNamedItems<NamedSQExpr>;
3285 private getSelect();
3286 private static createNamedExpressionArray(items);
3287 private setSelect(values);
3288 private static rewriteExpressionsWithSourceRenames(values, from);
3289 /** Removes the given expression from the select. */
3290 removeSelect(expr: SQExpr): SemanticQuery;
3291 /** Removes the given expression from order by. */
3292 removeOrderBy(expr: SQExpr): SemanticQuery;
3293 /** Removes the given expression from transforms. */
3294 removeTransform(transform: SQTransform): SemanticQuery;
3295 selectNameOf(expr: SQExpr): string;
3296 setSelectAt(index: number, expr: SQExpr): SemanticQuery;
3297 /** Adds a the expression to the select clause. */
3298 addSelect(expr: SQExpr, exprName?: string): SemanticQuery;
3299 private createNamedExpr(currentNames, from, expr, exprName?);
3300 /** Returns a query equivalent to this, with the specified groupBy items. */
3301 groupBy(values: NamedSQExpr[]): SemanticQuery;
3302 /** Gets the groupby items in this query. */
3303 groupBy(): ArrayNamedItems<NamedSQExpr>;
3304 private getGroupBy();
3305 private setGroupBy(values);
3306 addGroupBy(expr: SQExpr): SemanticQuery;
3307 /** Gets or sets the sorting for this query. */
3308 orderBy(values: SQSortDefinition[]): SemanticQuery;
3309 orderBy(): SQSortDefinition[];
3310 private getOrderBy();
3311 private setOrderBy(values);
3312 /** Gets or sets the filters for this query. */
3313 where(values: SQFilter[]): SemanticQuery;
3314 where(): SQFilter[];
3315 private getWhere();
3316 private setWhere(values);
3317 addWhere(filter: SemanticFilter): SemanticQuery;
3318 /** Returns a query equivalent to this, with the specified transform items. */
3319 transforms(transforms: SQTransform[]): SemanticQuery;
3320 transforms(): SQTransform[];
3321 private getTransforms();
3322 private setTransforms(transforms);
3323 rewrite(exprRewriter: ISQExprVisitor<SQExpr>): SemanticQuery;
3324 static equals(x: SemanticQuery, y: SemanticQuery): boolean;
3325 }
3326 /** Represents a semantic filter condition. Round-trippable with a JSON FilterDefinition. Instances of this class are immutable. */
3327 class SemanticFilter implements ISemanticFilter {
3328 private fromValue;
3329 private whereItems;
3330 constructor(from: SQFrom, where: SQFilter[]);
3331 static fromSQExpr(contract: SQExpr): SemanticFilter;
3332 static getDefaultValueFilter(fieldSQExprs: SQExpr | SQExpr[]): SemanticFilter;
3333 static getAnyValueFilter(fieldSQExprs: SQExpr | SQExpr[]): SemanticFilter;
3334 private static getDataViewScopeIdentityComparisonFilters(fieldSQExprs, value);
3335 from(): SQFrom;
3336 conditions(): SQExpr[];
3337 where(): SQFilter[];
3338 rewrite(exprRewriter: ISQExprVisitor<SQExpr>): SemanticFilter;
3339 validate(schema: FederatedConceptualSchema, aggrUtils: ISQAggregationOperations, errors?: SQExprValidationError[]): SQExprValidationError[];
3340 /** Merges a list of SemanticFilters into one. */
3341 static merge(filters: SemanticFilter[]): SemanticFilter;
3342 static isDefaultFilter(filter: SemanticFilter): boolean;
3343 static isAnyFilter(filter: SemanticFilter): boolean;
3344 static isSameFilter(leftFilter: SemanticFilter, rightFilter: SemanticFilter): boolean;
3345 private static applyFilter(filter, from, where);
3346 }
3347 class SQExprRewriterWithSourceRenames extends SQExprRewriter {
3348 private renames;
3349 constructor(renames: SQSourceRenames);
3350 visitEntity(expr: SQEntityExpr): SQExpr;
3351 rewriteFilter(filter: SQFilter): SQFilter;
3352 rewriteArray(exprs: SQExpr[]): SQExpr[];
3353 static rewrite(expr: SQExpr, from: SQFrom): SQExpr;
3354 }
3355}
3356
3357declare module powerbi.data {
3358 module SQFilter {
3359 /**
3360 * Returns true if leftFilter and rightFilter have the same target and condition.
3361 */
3362 function equals(leftFilter: SQFilter, rightFilter: SQFilter): boolean;
3363 /**
3364 * Returns true if leftFilter and rightFilter have the same target.
3365 */
3366 function targetsEqual(leftFilter: SQFilter, rightFilter: SQFilter): boolean;
3367 function contains(filters: SQFilter[], searchTarget: SQFilter): boolean;
3368 }
3369}
3370
3371declare module powerbi.data {
3372 module SQUtils {
3373 function sqSortDefinitionEquals(left: SQSortDefinition, right: SQSortDefinition): boolean;
3374 function namedSQExprEquals(left: NamedSQExpr, right: NamedSQExpr): boolean;
3375 function sqTransformTableColumnsEquals(left: SQTransformTableColumn, right: SQTransformTableColumn): boolean;
3376 function sqTransformTableEquals(left: SQTransformTable, right: SQTransformTable): boolean;
3377 function sqTransformInputEquals(left: SQTransformInput, right: SQTransformInput): boolean;
3378 function sqTransformOutputEquals(left: SQTransformOutput, right: SQTransformOutput): boolean;
3379 function sqTransformEquals(left: SQTransform, right: SQTransform): boolean;
3380 }
3381}
3382
3383declare module powerbi.data {
3384 /** Utility for creating a DataView from columns of data. */
3385 interface IDataViewBuilderCategorical {
3386 withCategory(options: DataViewBuilderCategoryColumnOptions): IDataViewBuilderCategorical;
3387 withCategories(categories: DataViewCategoryColumn[]): IDataViewBuilderCategorical;
3388 withValues(options: DataViewBuilderValuesOptions): IDataViewBuilderCategorical;
3389 withGroupedValues(options: DataViewBuilderGroupedValuesOptions): IDataViewBuilderCategorical;
3390 build(): DataView;
3391 }
3392 interface DataViewBuilderColumnOptions {
3393 source: DataViewMetadataColumn;
3394 }
3395 interface DataViewBuilderCategoryColumnOptions extends DataViewBuilderColumnOptions {
3396 values: PrimitiveValue[];
3397 identityFrom: DataViewBuilderColumnIdentitySource;
3398 }
3399 interface DataViewBuilderValuesOptions {
3400 columns: DataViewBuilderValuesColumnOptions[];
3401 }
3402 interface DataViewBuilderGroupedValuesOptions {
3403 groupColumn: DataViewBuilderCategoryColumnOptions;
3404 valueColumns: DataViewBuilderColumnOptions[];
3405 data: DataViewBuilderSeriesData[][];
3406 }
3407 /** Indicates the source set of identities. */
3408 interface DataViewBuilderColumnIdentitySource {
3409 fields: SQExpr[];
3410 identities?: DataViewScopeIdentity[];
3411 }
3412 interface DataViewBuilderValuesColumnOptions extends DataViewBuilderColumnOptions, DataViewBuilderSeriesData {
3413 }
3414 interface DataViewBuilderSeriesData {
3415 values: PrimitiveValue[];
3416 highlights?: PrimitiveValue[];
3417 /** Client-computed maximum value for a column. */
3418 maxLocal?: any;
3419 /** Client-computed maximum value for a column. */
3420 minLocal?: any;
3421 }
3422 function createCategoricalDataViewBuilder(): IDataViewBuilderCategorical;
3423}
3424
3425declare module powerbi.data {
3426 import SQExpr = powerbi.data.SQExpr;
3427 function createStaticEvalContext(colorAllocatorCache?: IColorAllocatorCache): IEvalContext;
3428 function createStaticEvalContext(colorAllocatorCache: IColorAllocatorCache, dataView: DataView, selectTransforms: DataViewSelectTransform[]): IEvalContext;
3429 function getExprValueFromTable(expr: SQExpr, selectTransforms: DataViewSelectTransform[], table: DataViewTable, rowIdx: number): PrimitiveValue;
3430 function findSelectIndex(expr: SQExpr, selectTransforms: DataViewSelectTransform[]): number;
3431}
3432
3433declare module powerbi.data {
3434 function createMatrixEvalContext(colorAllocatorProvider: IColorAllocatorCache, dataViewMatrix: DataViewMatrix): IEvalContext;
3435}
3436
3437declare module powerbi {
3438 /** Culture interfaces. These match the Globalize library interfaces intentionally. */
3439 interface Culture {
3440 name: string;
3441 calendar: Calendar;
3442 calendars: CalendarDictionary;
3443 numberFormat: NumberFormatInfo;
3444 }
3445 interface Calendar {
3446 patterns: any;
3447 firstDay: number;
3448 }
3449 interface CalendarDictionary {
3450 [key: string]: Calendar;
3451 }
3452 interface NumberFormatInfo {
3453 decimals: number;
3454 groupSizes: number[];
3455 negativeInfinity: string;
3456 positiveInfinity: string;
3457 }
3458 /**
3459 * NumberFormat module contains the static methods for formatting the numbers.
3460 * It extends the JQuery.Globalize functionality to support complete set of .NET
3461 * formatting expressions for numeric types including custom formats.
3462 */
3463 module NumberFormat {
3464 const NumberFormatComponentsDelimeter: string;
3465 interface NumericFormatMetadata {
3466 format: string;
3467 hasLiterals: boolean;
3468 hasE: boolean;
3469 hasCommas: boolean;
3470 hasDots: boolean;
3471 hasPercent: boolean;
3472 hasPermile: boolean;
3473 precision: number;
3474 scale: number;
3475 }
3476 interface NumberFormatComponents {
3477 hasNegative: boolean;
3478 positive: string;
3479 negative: string;
3480 zero: string;
3481 }
3482 function getNumericFormat(value: number, baseFormat: string): string;
3483 function addDecimalsToFormat(baseFormat: string, decimals: number, trailingZeros: boolean): string;
3484 function hasFormatComponents(format: string): boolean;
3485 function getComponents(format: string): NumberFormatComponents;
3486 /** Evaluates if the value can be formatted using the NumberFormat */
3487 function canFormat(value: any): boolean;
3488 function isStandardFormat(format: string): boolean;
3489 /** Formats the number using specified format expression and culture */
3490 function format(value: number, format: string, culture: Culture): string;
3491 /** Performs a custom format with a value override. Typically used for custom formats showing scaled values. */
3492 function formatWithCustomOverride(value: number, format: string, nonScientificOverrideFormat: string, culture: Culture): string;
3493 /**
3494 * Returns the formatMetadata of the format
3495 * When calculating precision and scale, if format string of
3496 * positive[;negative;zero] => positive format will be used
3497 * @param (required) format - format string
3498 * @param (optional) calculatePrecision - calculate precision of positive format
3499 * @param (optional) calculateScale - calculate scale of positive format
3500 */
3501 function getCustomFormatMetadata(format: string, calculatePrecision?: boolean, calculateScale?: boolean): NumericFormatMetadata;
3502 }
3503 var formattingService: IFormattingService;
3504}
3505
3506declare module powerbi.data {
3507 /** Serializes SQExpr in a form optimized in-memory comparison, but not intended for storage on disk. */
3508 module SQExprShortSerializer {
3509 function serialize(expr: SQExpr): string;
3510 function serializeArray(exprs: SQExpr[]): string;
3511 }
3512}
3513
3514declare module powerbi.visuals {
3515 import Selector = powerbi.data.Selector;
3516 import SelectorForColumn = powerbi.SelectorForColumn;
3517 /**
3518 * A combination of identifiers used to uniquely identify
3519 * data points and their bound geometry.
3520 */
3521 class SelectionId implements ISelectionId {
3522 private selector;
3523 private selectorsByColumn;
3524 private key;
3525 private keyWithoutHighlight;
3526 highlight: boolean;
3527 constructor(selector: Selector, highlight: boolean);
3528 equals(other: SelectionId): boolean;
3529 /**
3530 * Checks equality against other for all identifiers existing in this.
3531 */
3532 includes(other: SelectionId, ignoreHighlight?: boolean): boolean;
3533 getKey(): string;
3534 getKeyWithoutHighlight(): string;
3535 hasIdentity(): boolean;
3536 getSelector(): Selector;
3537 getSelectorsByColumn(): Selector;
3538 static createNull(highlight?: boolean): SelectionId;
3539 static createWithId(id: DataViewScopeIdentity, highlight?: boolean): SelectionId;
3540 static createWithMeasure(measureId: string, highlight?: boolean): SelectionId;
3541 static createWithIdAndMeasure(id: DataViewScopeIdentity, measureId: string, highlight?: boolean): SelectionId;
3542 static createWithIdAndMeasureAndCategory(id: DataViewScopeIdentity, measureId: string, queryName: string, highlight?: boolean): SelectionId;
3543 static createWithIds(id1: DataViewScopeIdentity, id2: DataViewScopeIdentity, highlight?: boolean): SelectionId;
3544 static createWithIdsAndMeasure(id1: DataViewScopeIdentity, id2: DataViewScopeIdentity, measureId: string, highlight?: boolean): SelectionId;
3545 static createWithSelectorForColumnAndMeasure(dataMap: SelectorForColumn, measureId: string, highlight?: boolean): SelectionId;
3546 static createWithHighlight(original: SelectionId): SelectionId;
3547 private static idArray(id1, id2);
3548 }
3549 /**
3550 * This class is designed to simplify the creation of SelectionId objects
3551 * It allows chaining to build up an object before calling 'create' to build a SelectionId
3552 */
3553 class SelectionIdBuilder implements ISelectionIdBuilder {
3554 private dataMap;
3555 private measure;
3556 static builder(): SelectionIdBuilder;
3557 withCategoryIdentity(categoryColumn: DataViewCategoryColumn, identity: DataViewScopeIdentity): this;
3558 withCategory(categoryColumn: DataViewCategoryColumn, index: number): this;
3559 withSeries(seriesColumn: DataViewValueColumns, valueColumn: DataViewValueColumn | DataViewValueColumnGroup): this;
3560 withMeasure(measureId: string): this;
3561 createSelectionId(): SelectionId;
3562 private ensureDataMap();
3563 }
3564}
3565
3566declare module powerbi {
3567 import DataViewObjectDefinitions = data.DataViewObjectDefinitions;
3568 import DisplayNameGetter = data.DisplayNameGetter;
3569 /** Defines a list of style presets for a particular IVisual */
3570 interface VisualStylePresets {
3571 /** Title of PropertyPane section for selecting the style */
3572 displayName: DisplayNameGetter;
3573 /** List of style presets for the IVisual indexed by preset name */
3574 presets: VisualStylePresetCollection;
3575 }
3576 interface VisualStylePresetCollection {
3577 [stylePresetName: string]: VisualStylePreset;
3578 }
3579 /** Defines some rules to derive IVisual formatting elements from a Report Theme */
3580 interface VisualStylePreset {
3581 /** Display name for the style preset */
3582 displayName: DisplayNameGetter;
3583 /** Discription text for the style preset, can be used for a tooltip */
3584 description?: DisplayNameGetter;
3585 /**
3586 * Evaluate the style preset against a report theme and produce DataViewObjectDefinitions for affected objects
3587 * @param IVisualStyle Report theme
3588 */
3589 evaluate: (theme: IVisualStyle) => DataViewObjectDefinitions;
3590 }
3591}