From e24532fb29ff96e99d4f1f5b9312f795bef8be56 Mon Sep 17 00:00:00 2001 From: Rafael <rpd17@inf.ufpr.br> Date: Thu, 5 Apr 2018 11:27:12 -0300 Subject: [PATCH] Issue #68: Add call-signature for method Signed-off-by: Rafael <rpd17@inf.ufpr.br> --- src/adapter/postgres.spec.ts | 2 +- src/adapter/sql.ts | 2 +- src/core/aggregate.spec.ts | 40 --------------------- src/core/aggregate.ts | 70 ------------------------------------ src/core/engine.ts | 26 +++++++------- src/util/graph.ts | 4 +-- test/monet/fixture.ts | 6 ++-- test/postgres/fixture.ts | 6 ++-- 8 files changed, 23 insertions(+), 133 deletions(-) delete mode 100644 src/core/aggregate.spec.ts delete mode 100644 src/core/aggregate.ts diff --git a/src/adapter/postgres.spec.ts b/src/adapter/postgres.spec.ts index e9b1cafe..2279807d 100644 --- a/src/adapter/postgres.spec.ts +++ b/src/adapter/postgres.spec.ts @@ -35,7 +35,7 @@ describe("postgres adapter", () => { let config: any; let adapter: Adapter; let fixture; - before(function (done) { + before(function (done): void { // Arrow function not used to get acces to this and skip the test config = ConfigParser.parse("config/test.yaml"); if (config.adapter === "postgres") { diff --git a/src/adapter/sql.ts b/src/adapter/sql.ts index 3600c1b8..0ef7ca22 100644 --- a/src/adapter/sql.ts +++ b/src/adapter/sql.ts @@ -551,7 +551,7 @@ export abstract class SQLAdapter extends Adapter { return r; } - private buildQuery(target: View, views: ExpandedView[], toSort: boolean) { + private buildQuery(target: View, views: ExpandedView[], toSort: boolean): string { const metrics = target.metrics; const dimensions = target.dimensions; const clauses = target.clauses; diff --git a/src/core/aggregate.spec.ts b/src/core/aggregate.spec.ts deleted file mode 100644 index bcc3a3f6..00000000 --- a/src/core/aggregate.spec.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blendb. - * - * blendb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blendb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blendb. If not, see <http://www.gnu.org/licenses/>. - */ - -import { expect } from "chai"; - -import { Aggregate } from "./aggregate"; - -describe("aggregate class", () => { - it("should be instantiated with an array metrics and one of dimensions", () => { - let aggr = new Aggregate(["met:one"], ["dim:one", "dim:two"]); - expect(aggr).to.be.an("object"); - }); - - it("should not be instantiated with an empty array of metrics", () => { - let aggr = new Aggregate([], ["dim:one", "dim:two"]); - expect(aggr).to.be.an("object"); - }); - - it("should not be instantiated with an empty array of dimensions", () => { - let aggr = new Aggregate(["met:one"], []); - expect(aggr).to.be.an("object"); - }); -}); diff --git a/src/core/aggregate.ts b/src/core/aggregate.ts deleted file mode 100644 index a1e3ccf5..00000000 --- a/src/core/aggregate.ts +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2015 Centro de Computacao Cientifica e Software Livre - * Departamento de Informatica - Universidade Federal do Parana - * - * This file is part of blendb. - * - * blendb is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * blendb is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with blendb. If not, see <http://www.gnu.org/licenses/>. - */ - -export interface IAggregateData { - metrics: any; - dimensions: any; -} - -export class Aggregate { - public metrics: string[]; - public dimensions: string[]; - private data: IAggregateData[]; - - constructor(metrics: string[], dimensions: string[], options?: any) { - this.metrics = metrics; - this.dimensions = dimensions; - - this.data = []; - } - - public push(data: IAggregateData) { - this.data.push(data); - } - - public truncate() { - this.data = []; - } - - public find(query: any) { - let result: any = []; - - this.data.forEach((doc: IAggregateData) => { - let match = true; - - for (let key in query) { - if (query.hasOwnProperty(key)) { - let value = query[key]; - - if (doc.dimensions[key] !== value) { - match = false; - break; - } - } - } - - if (match) { - result.push(doc); - } - }); - - return result; - } -} diff --git a/src/core/engine.ts b/src/core/engine.ts index cbbb4729..e2d4ef14 100644 --- a/src/core/engine.ts +++ b/src/core/engine.ts @@ -18,8 +18,8 @@ * along with blend. If not, see <http://www.gnu.org/licenses/>. */ -import { Dimension } from "./dimension"; -import { Metric } from "./metric"; +import { Dimension, DimensionStrOptions } from "./dimension"; +import { Metric, MetricStrOptions } from "./metric"; import { Clause } from "./clause"; import { Filter } from "./filter"; import { View } from "./view"; @@ -45,11 +45,11 @@ export class Engine { this.graph = new Graph(); } - public getViews() { + public getViews(): View[] { return this.views; } - public getMetricsDescription() { + public getMetricsDescription(): MetricStrOptions[] { return this.metrics.map((i) => i.strOptions()); } @@ -61,11 +61,11 @@ export class Engine { return this.sources.map((i) => i.strOptions()); } - public getDimensionsDescription() { + public getDimensionsDescription(): DimensionStrOptions[] { return this.dimensions.map((i) => i.strOptions()); } - public addView(view: View) { + public addView(view: View): View { if (this.graph.addView(view)) { this.views.push(view); return view; @@ -74,7 +74,7 @@ export class Engine { return null; } - public addEnumType(enumType: EnumType) { + public addEnumType(enumType: EnumType): EnumType { this.enumTypes.push(enumType); return enumType; } @@ -84,7 +84,7 @@ export class Engine { return sourc; } - public addMetric(metric: Metric) { + public addMetric(metric: Metric): Metric { if (this.graph.addMetric(metric)) { this.metrics.push(metric); return metric; @@ -93,7 +93,7 @@ export class Engine { return null; } - public getMetricByName(name: string) { + public getMetricByName(name: string): Metric { let result = this.metrics.find(metric => metric.name === name); if (!result) { @@ -103,7 +103,7 @@ export class Engine { return result; } - public addDimension(dimension: Dimension) { + public addDimension(dimension: Dimension): Dimension { if (this.graph.addDimension(dimension)) { this.dimensions.push(dimension); return dimension; @@ -112,7 +112,7 @@ export class Engine { return null; } - public getDimensionByName(name: string) { + public getDimensionByName(name: string): Dimension { let result = this.dimensions.find(dimension => dimension.name === name); if (!result) { @@ -172,11 +172,11 @@ export class Engine { throw new Error("Filter could not be created: Operator on \"" + strFilter + "\" could not be extracted"); } } - public query (q: Query) { + public query (q: Query): View { return this.selectOptimalView(q); } - private selectOptimalView (q: Query) { + private selectOptimalView (q: Query): View { let optimalViews = this.graph.cover(q); if (optimalViews.length === 0) { throw new Error ("Engine views cannot cover the query"); diff --git a/src/util/graph.ts b/src/util/graph.ts index 2a9e536d..145b2228 100644 --- a/src/util/graph.ts +++ b/src/util/graph.ts @@ -282,7 +282,7 @@ export class Graph { the array, adds the id and checkEdge would return true, if the id already exists return false */ - private edge(idV: string, idU: string, value: View) { + private edge(idV: string, idU: string, value: View): void { // Assuming that checkEdge is called first let v: Vertex = this.verticeMap[idV]; let u: Vertex = this.verticeMap[idU]; @@ -522,7 +522,7 @@ export class Graph { /* Check if a set of filter/clauses of a view suits for the query */ - private passConstraints(queryClauses: Clause[], viewClauses: Clause[]) { + private passConstraints(queryClauses: Clause[], viewClauses: Clause[]): boolean { /* TODO: Enhance constraint check. diff --git a/test/monet/fixture.ts b/test/monet/fixture.ts index 3c16edc9..2ff73091 100644 --- a/test/monet/fixture.ts +++ b/test/monet/fixture.ts @@ -45,7 +45,7 @@ export class Fixture { this.database = config.database; } - public load(schemas: LoadView[], create: boolean, cb: (err: Error) => void) { + public load(schemas: LoadView[], create: boolean, cb: (err: Error) => void): void { let client = new MDB({ user: this.config.user, dbname: this.config.database, @@ -93,7 +93,7 @@ export class Fixture { }); } - private typeConvertion(t: string) { + private typeConvertion(t: string): string { switch (t) { case "integer": return "INTEGER"; @@ -108,7 +108,7 @@ export class Fixture { } } - private createTransSet(view: View, filePath: string, create: boolean) { + private createTransSet(view: View, filePath: string, create: boolean): TransSet { let props = []; for (let i = 0; i < view.metrics.length; ++i) { diff --git a/test/postgres/fixture.ts b/test/postgres/fixture.ts index c966c551..4fdc0134 100644 --- a/test/postgres/fixture.ts +++ b/test/postgres/fixture.ts @@ -44,7 +44,7 @@ export class Fixture { this.database = config.database; } - public load(schemas: LoadView[], create: boolean, cb: (err: Error) => void) { + public load(schemas: LoadView[], create: boolean, cb: (err: Error) => void): void { let client = new Client(this.config); /* @@ -96,7 +96,7 @@ export class Fixture { }); } - private typeConvertion(t: string) { + private typeConvertion(t: string): string { switch (t) { case "integer": return "INTEGER"; @@ -111,7 +111,7 @@ export class Fixture { } } - private createTransSet(view: View, filePath: string, create: boolean) { + private createTransSet(view: View, filePath: string, create: boolean): TransSet { let props = []; for (let i = 0; i < view.metrics.length; ++i) { -- GitLab