Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable noUnusedLocals and noUnusedParameters #275

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/client/Container/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import {
getIdFromLink,
getPathFromLink,
isResourceValid,
parsePath,
ResourceType
} from "../../common";
import { PartitionKeyDefinition } from "../../documents";
import { PartitionKey } from "../../index";
import { QueryIterator } from "../../queryIterator";
import { FeedOptions, RequestOptions, ResourceResponse } from "../../request";
import { Conflict, Conflicts } from "../Conflict";
Expand Down
2 changes: 1 addition & 1 deletion src/client/Container/ContainerDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IndexingPolicy, PartitionKey, PartitionKeyDefinition } from "../../documents";
import { IndexingPolicy, PartitionKeyDefinition } from "../../documents";
import { ConflictResolutionPolicy } from "../Conflict/ConflictResolutionPolicy";
import { UniqueKeyPolicy } from "./UniqueKeyPolicy";

Expand Down
2 changes: 0 additions & 2 deletions src/client/Permission/PermissionBody.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Resource } from "../Resource";

export interface PermissionBody {
/** System generated resource token for the particular resource and user */
_token: string;
Expand Down
7 changes: 1 addition & 6 deletions src/client/Trigger/Trigger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ClientContext } from "../../ClientContext";
import { createTriggerUri, getIdFromLink, getPathFromLink, isResourceValid, ResourceType } from "../../common";
import { CosmosClient } from "../../CosmosClient";
import { RequestOptions } from "../../request";
import { Container } from "../Container";
import { TriggerDefinition } from "./TriggerDefinition";
Expand All @@ -19,8 +18,6 @@ export class Trigger {
return createTriggerUri(this.container.database.id, this.container.id, this.id);
}

private client: CosmosClient;

/**
* @hidden
* @param container The parent {@link Container}.
Expand All @@ -30,9 +27,7 @@ export class Trigger {
public readonly container: Container,
public readonly id: string,
private readonly clientContext: ClientContext
) {
this.client = this.container.database.client;
}
) {}

/**
* Read the {@link TriggerDefinition} for the given {@link Trigger}.
Expand Down
2 changes: 0 additions & 2 deletions src/common/helper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { ConnectionPolicy } from "../documents/ConnectionPolicy";
import { CosmosHeaders } from "../queryExecutionContext/CosmosHeaders";
import { RequestContext } from "../request/RequestContext";
import { Constants, OperationType, ResourceType } from "./constants";

/** @hidden */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ export class AggregateEndpointComponent implements IEndpointComponent {
public async nextItem(): Promise<Response<any>> {
try {
let resHeaders: CosmosHeaders;
let resources: any;
if (this.aggregateValues === undefined) {
({ result: resources, headers: resHeaders } = await this._getAggregateResult());
({ headers: resHeaders } = await this._getAggregateResult());
}
const resource =
this.aggregateValuesIndex < this.aggregateValues.length
Expand All @@ -130,7 +129,7 @@ export class AggregateEndpointComponent implements IEndpointComponent {
*/
public async current(): Promise<Response<any>> {
if (this.aggregateValues === undefined) {
const { result: resouces, headers } = await this._getAggregateResult();
const { headers } = await this._getAggregateResult();
return {
result: this.aggregateValues[this.aggregateValuesIndex],
headers
Expand Down
11 changes: 1 addition & 10 deletions src/queryExecutionContext/defaultQueryExecutionContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { ClientContext } from "../ClientContext";
import { Constants } from "../common";
import { ClientSideMetrics, QueryMetrics } from "../queryMetrics";
import { Response } from "../request";
import { IExecutionContext } from "./index";
import { SqlQuerySpec } from "./SqlQuerySpec";

/** @hidden */
export type FetchFunctionCallback = (options: any) => Promise<Response<any>>;
Expand All @@ -18,7 +16,6 @@ enum STATES {
/** @hidden */
export class DefaultQueryExecutionContext implements IExecutionContext {
private static readonly STATES = STATES;
private query: string | SqlQuerySpec;
private resources: any; // TODO: any resources
private currentIndex: number;
private currentPartitionIndex: number;
Expand All @@ -37,14 +34,8 @@ export class DefaultQueryExecutionContext implements IExecutionContext {
* An array of functions may be used to query more than one partition.
* @ignore
*/
constructor(
private clientContext: ClientContext,
query: string | SqlQuerySpec,
options: any,
fetchFunctions: FetchFunctionCallback | FetchFunctionCallback[]
) {
constructor(options: any, fetchFunctions: FetchFunctionCallback | FetchFunctionCallback[]) {
// TODO: any options
this.query = query;
this.resources = [];
this.currentIndex = 0;
this.currentPartitionIndex = 0;
Expand Down
22 changes: 1 addition & 21 deletions src/queryExecutionContext/documentProducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,12 @@ import { FetchResult, FetchResultType } from "./FetchResult";
import { CosmosHeaders, getInitialHeader, mergeHeaders } from "./headerUtils";
import { FetchFunctionCallback, SqlQuerySpec } from "./index";

/** @hidden */
const HttpHeaders = Constants;

/** @hidden */
enum DocumentProducerStates {
started = "started",
inProgress = "inProgress",
ended = "ended"
}

/** @hidden */
export class DocumentProducer {
// // Static Members
// STATES: Object.freeze({ started: "started", inProgress: "inProgress", ended: "ended" })
private static readonly STATES = DocumentProducerStates;
private collectionLink: string;
private query: string | SqlQuerySpec;
public targetPartitionKeyRange: any; // TODO: any partitionkeyrange
public fetchResults: FetchResult[];
private state: DocumentProducerStates;
public allFetched: boolean;
private err: Error;
public previousContinuationToken: string;
Expand Down Expand Up @@ -56,7 +42,6 @@ export class DocumentProducer {
this.targetPartitionKeyRange = targetPartitionKeyRange;
this.fetchResults = [];

this.state = DocumentProducer.STATES.started;
this.allFetched = false;
this.err = undefined;

Expand All @@ -65,8 +50,7 @@ export class DocumentProducer {
this.respHeaders = getInitialHeader();

// tslint:disable-next-line:no-shadowed-variable
this.internalExecutionContext = new DefaultQueryExecutionContext(clientContext, query, options, this.fetchFunction);
this.state = DocumentProducer.STATES.inProgress;
this.internalExecutionContext = new DefaultQueryExecutionContext(options, this.fetchFunction);
}
/**
* Synchronously gives the contiguous buffered results (stops at the first non result) if any
Expand Down Expand Up @@ -131,16 +115,12 @@ export class DocumentProducer {
private _updateStates(err: any, allFetched: boolean) {
// TODO: any Error
if (err) {
this.state = DocumentProducer.STATES.ended;
this.err = err;
return;
}
if (allFetched) {
this.allFetched = true;
}
if (this.allFetched && this.peekBufferedItems().length === 0) {
this.state = DocumentProducer.STATES.ended;
}
if (this.internalExecutionContext.continuation === this.continuationToken) {
// nothing changed
return;
Expand Down
35 changes: 0 additions & 35 deletions src/queryExecutionContext/parallelQueryExecutionContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ClientContext } from "../ClientContext";
import { PARITIONKEYRANGE } from "../routing/smartRoutingMapProvider";
import { DocumentProducer } from "./documentProducer";
import { IExecutionContext } from "./IExecutionContext";
import { ParallelQueryExecutionContextBase } from "./parallelQueryExecutionContextBase";
Expand Down Expand Up @@ -41,38 +40,4 @@ export class ParallelQueryExecutionContext extends ParallelQueryExecutionContext
const b = docProd2.getTargetParitionKeyRange()["minInclusive"];
return a === b ? 0 : a > b ? 1 : -1;
}

private _buildContinuationTokenFrom(documentProducer: DocumentProducer) {
// given the document producer constructs the continuation token
if (documentProducer.allFetched && documentProducer.peekBufferedItems().length === 0) {
return undefined;
}

const min = documentProducer.targetPartitionKeyRange[PARITIONKEYRANGE.MinInclusive];
const max = documentProducer.targetPartitionKeyRange[PARITIONKEYRANGE.MaxExclusive];
const range = {
min,
max,
id: documentProducer.targetPartitionKeyRange.id
};

// TODO: static method
const withNullDefault = (token: any) => {
if (token) {
return token;
} else if (token === null || token === undefined) {
return null;
}
};

const documentProducerContinuationToken =
documentProducer.peekBufferedItems().length > 0
? documentProducer.previousContinuationToken
: documentProducer.continuationToken;

return {
token: withNullDefault(documentProducerContinuationToken),
range
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
* @instance
*/
private async _getReplacementPartitionKeyRanges(documentProducer: DocumentProducer) {
const routingMapProvider = this.clientContext.partitionKeyDefinitionCache;
const partitionKeyRange = documentProducer.targetPartitionKeyRange;
// Download the new routing map
this.routingProvider = new SmartRoutingMapProvider(this.clientContext);
Expand Down Expand Up @@ -282,7 +281,7 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
checkNextDocumentProducerCallback: any
) => {
try {
const { result: afterItem, headers } = await documentProducerToCheck.current();
const { result: afterItem } = await documentProducerToCheck.current();
if (afterItem === undefined) {
// no more results left in this document producer, so we don't enqueue it
} else {
Expand Down Expand Up @@ -336,7 +335,7 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
const documentProducer = this.orderByPQ.peek();
// Check if split happened
try {
const { result: element, headers } = await documentProducer.current();
await documentProducer.current();
elseCallback();
} catch (err) {
if (ParallelQueryExecutionContextBase._needPartitionKeyRangeCacheRefresh(err)) {
Expand Down Expand Up @@ -443,7 +442,7 @@ export abstract class ParallelQueryExecutionContextBase implements IExecutionCon
// we need to put back the document producer to the queue if it has more elements.
// the lock will be released after we know document producer must be put back in the queue or not
try {
const { result: afterItem, headers: currentHeaders } = await documentProducer.current();
const { result: afterItem } = await documentProducer.current();
if (afterItem === undefined) {
// no more results is left in this document producer
} else {
Expand Down
7 changes: 1 addition & 6 deletions src/queryExecutionContext/proxyQueryExecutionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ export class ProxyQueryExecutionContext implements IExecutionContext {
// clone options
this.options = JSON.parse(JSON.stringify(options || {}));
this.resourceLink = resourceLink;
this.queryExecutionContext = new DefaultQueryExecutionContext(
this.clientContext,
this.query,
this.options,
this.fetchFunctions
);
this.queryExecutionContext = new DefaultQueryExecutionContext(this.options, this.fetchFunctions);
}
/**
* Execute a provided function on the next element in the ProxyQueryExecutionContext.
Expand Down
10 changes: 2 additions & 8 deletions src/routing/CollectionRoutingMapFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function compareRanges(a: any, b: any) {
}

/** @hidden */
export function createCompleteRoutingMap(partitionKeyRangeInfoTuppleList: any[], collectionUniqueId: string) {
export function createCompleteRoutingMap(partitionKeyRangeInfoTuppleList: any[]) {
const rangeById: any = {}; // TODO: any
const rangeByInfo: any = {}; // TODO: any

Expand All @@ -34,13 +34,7 @@ export function createCompleteRoutingMap(partitionKeyRangeInfoTuppleList: any[],
if (!isCompleteSetOfRange(partitionKeyOrderedRange)) {
return undefined;
}
return new InMemoryCollectionRoutingMap(
rangeById,
rangeByInfo,
partitionKeyOrderedRange,
orderedPartitionInfo,
collectionUniqueId
);
return new InMemoryCollectionRoutingMap(partitionKeyOrderedRange, orderedPartitionInfo);
}

function isCompleteSetOfRange(partitionKeyOrderedRange: any) {
Expand Down
15 changes: 1 addition & 14 deletions src/routing/inMemoryCollectionRoutingMap.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,20 @@
import * as bs from "binary-search-bounds"; // TODO: missing types
import { Constants } from "../common";
import { Range } from "../range";
import { QueryRange } from "./QueryRange";

/** @hidden */
export class InMemoryCollectionRoutingMap {
private rangeById: Range[];
private rangeByInfo: string;
private orderedPartitionKeyRanges: any[];
private orderedRanges: QueryRange[];
// TODO: chrande made this public, even though it is implementation detail for a test
public orderedPartitionInfo: any;
private collectionUniqueId: any;

/**
* Represents a InMemoryCollectionRoutingMap Object,
* Stores partition key ranges in an efficient way with some additional information and provides
* convenience methods for working with set of ranges.
*/
constructor(
rangeById: Range[],
rangeByInfo: string,
orderedPartitionKeyRanges: any[],
orderedPartitionInfo: any,
collectionUniqueId: string
) {
this.rangeById = rangeById;
this.rangeByInfo = rangeByInfo;
constructor(orderedPartitionKeyRanges: any[], orderedPartitionInfo: any) {
this.orderedPartitionKeyRanges = orderedPartitionKeyRanges;
this.orderedRanges = orderedPartitionKeyRanges.map(pkr => {
return new QueryRange(
Expand All @@ -37,7 +25,6 @@ export class InMemoryCollectionRoutingMap {
);
});
this.orderedPartitionInfo = orderedPartitionInfo;
this.collectionUniqueId = collectionUniqueId;
}
public getOrderedParitionKeyRanges() {
return this.orderedPartitionKeyRanges;
Expand Down
2 changes: 1 addition & 1 deletion src/routing/partitionKeyRangeCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class PartitionKeyRangeCache {
try {
const { resources } = await this.clientContext.queryPartitionKeyRanges(collectionLink).fetchAll();

crm = createCompleteRoutingMap(resources.map(r => [r, true]), collectionId);
crm = createCompleteRoutingMap(resources.map(r => [r, true]));

this.collectionRoutingMapByCollectionId[collectionId] = crm;
this.sem.leave();
Expand Down
4 changes: 3 additions & 1 deletion src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"sourceMap": true,
"newLine": "LF",
"resolveJsonModule": true,
"composite": true
"composite": true,
"noUnusedLocals": true,
"noUnusedParameters": true
},
"include": ["./**/*"]
}
10 changes: 5 additions & 5 deletions test/unit/inMemoryCollectionRoutingMap.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe("InMemoryCollectionRoutingMap Tests", function() {
{ id: "4", minInclusive: "05C1E9CD673398", maxExclusive: "FF" }
];
const partitionRangeWithInfo = partitionKeyRanges.map(r => [r, true]);
const collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo, "sample collection id");
const collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo);

it("queryCompleteRange", function() {
const completeRange = new QueryRange("", "FF", true, false);
Expand Down Expand Up @@ -97,7 +97,7 @@ describe("InMemoryCollectionRoutingMap Tests", function() {
]
];

const collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo, "sample collection id");
const collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo);

it("validate _orderedPartitionKeyRanges", function() {
assert.equal("0", collectionRoutingMap.getOrderedParitionKeyRanges()[0].id);
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("InMemoryCollectionRoutingMap Tests", function() {
];
const collectionUniqueId = "";
try {
const collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo, "sample collection id");
const collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo);
assert.fail("must throw exception");
} catch (e) {
assert.equal(e.message, "Ranges overlap");
Expand All @@ -217,7 +217,7 @@ describe("InMemoryCollectionRoutingMap Tests", function() {
2
]
];
let collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo, "sample collection id");
let collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo);
assert.equal(collectionRoutingMap, null);

partitionRangeWithInfo = [
Expand All @@ -238,7 +238,7 @@ describe("InMemoryCollectionRoutingMap Tests", function() {
2
]
];
collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo, "sample collection id");
collectionRoutingMap = createCompleteRoutingMap(partitionRangeWithInfo);
assert.notEqual(collectionRoutingMap, null);
});
});
Expand Down