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

[Cosmos] Fix linting issues #13039

Merged
merged 18 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions sdk/cosmosdb/cosmos/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/src/utils/hashing/murmurHash.ts
9 changes: 9 additions & 0 deletions sdk/cosmosdb/cosmos/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"@typescript-eslint/no-extraneous-class": "error",
"dot-notation": "off",
"some-rule": "off",
// cosmos does not use core-http yet so their methods do not yet accept abort controllers
"@azure/azure-sdk/ts-apisurface-supportcancellation": "warn",
// this rule requires introducing breaking changes, should be fixed by the cosmos team
"@azure/azure-sdk/ts-naming-options": "warn",
// left to the cosmos team make this rule error again
"@azure/azure-sdk/ts-package-json-module": "warn",
"@azure/azure-sdk/ts-doc-internal": "warn",
// https://github.com/Azure/azure-sdk-for-js/issues/12951
"tsdoc/syntax": "warn",
"@typescript-eslint/tslint/config": [
"error",
{
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
"publicTrimmedFilePath": "./dist/types/latest/index.d.ts"
"publicTrimmedFilePath": "./dist/types/latest/cosmos.d.ts"
},
"messages": {
"tsdocMessageReporting": {
Expand Down
15 changes: 9 additions & 6 deletions sdk/cosmosdb/cosmos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@
"README.md",
"LICENSE"
],
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/cosmosdb/cosmos#readme",
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/cosmosdb/cosmos/README.md",
"bugs": {
"url": "https://github.com/Azure/azure-sdk-for-js/issues"
},
"sideEffects": false,
"types": "./dist/types/latest/index.d.ts",
"types": "./dist/types/latest/cosmos.d.ts",
"typesVersions": {
"<3.6": {
"*": [
"./dist/types/3.1/index.d.ts"
"./dist/types/3.1/cosmos.d.ts"
]
}
},
"engine": {
"engines": {
"node": ">=8.0.0"
},
"scripts": {
Expand All @@ -64,8 +67,8 @@
"integration-test:browser": "echo skipped",
"integration-test:node": "mocha -r test/mocha.env.ts -r ts-node/register -r esm -r dotenv/config -r ./test/public/common/setup.ts \"./test/internal/**/*.spec.ts\" \"./test/public/**/*.spec.ts\" --timeout 100000",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "eslint package.json src test samples --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json src test samples --ext .ts -f html -o cosmos-lintReport.html || exit 0",
"lint:fix": "eslint package.json api-extractor.json src test samples --ext .ts --fix --fix-type [problem,suggestion]",
"lint": "eslint package.json api-extractor.json src samples --ext .ts",
"pack": "npm pack 2>&1",
"prebuild": "npm run clean",
"test:browser": "npm run unit-test:browser && npm run integration-test:browser",
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/prep-samples.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require("fs");

// work around TS not being able to find the typings when not importing from a package reference.
fs.copyFileSync("./dist/types/latest/index.d.ts", "./dist/index.d.ts");
fs.copyFileSync("./dist/types/latest/cosmos.d.ts", "./dist/index.d.ts");
128 changes: 62 additions & 66 deletions sdk/cosmosdb/cosmos/review/cosmos.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,7 @@ export const Constants: {
TopologyPathSegment: string;
DatabaseAccountPathSegment: string;
};
PartitionKeyRange: {
MinInclusive: string;
MaxExclusive: string;
Id: string;
};
PartitionKeyRange: PartitionKeyRangePropertiesNames;
QueryRangeConstants: {
MinInclusive: string;
MaxExclusive: string;
Expand All @@ -411,7 +407,7 @@ export class Container {
getQueryPlan(query: string | SqlQuerySpec): Promise<Response<PartitionedQueryExecutionInfo>>;
// (undocumented)
readonly id: string;
item(id: string, partitionKeyValue?: any): Item;
item(id: string, partitionKeyValue?: PartitionKey): Item;
get items(): Items;
read(options?: RequestOptions): Promise<ContainerResponse>;
readOffer(options?: RequestOptions): Promise<OfferResponse>;
Expand Down Expand Up @@ -524,7 +520,7 @@ export interface CreateOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Create;
// (undocumented)
partitionKey?: string | number | null | {} | undefined;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
// (undocumented)
resourceBody: JSONObject;
}
Expand Down Expand Up @@ -634,7 +630,7 @@ export interface DeleteOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Delete;
// (undocumented)
partitionKey?: string | number | null | {} | undefined;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
}

// @public (undocumented)
Expand Down Expand Up @@ -668,7 +664,7 @@ export interface ErrorResponse extends Error {
}

// @public (undocumented)
export function extractPartitionKey(document: any, partitionKeyDefinition: PartitionKeyDefinition): PartitionKey[];
export function extractPartitionKey(document: unknown, partitionKeyDefinition: PartitionKeyDefinition): PartitionKey[];

// @public
export interface FeedOptions extends SharedOptions {
Expand Down Expand Up @@ -851,7 +847,7 @@ export class Items {
readChangeFeed<T>(partitionKey: string | number | boolean, changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
// @deprecated
readChangeFeed<T>(changeFeedOptions?: ChangeFeedOptions): ChangeFeedIterator<T>;
upsert(body: any, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>;
upsert(body: unknown, options?: RequestOptions): Promise<ItemResponse<ItemDefinition>>;
upsert<T extends ItemDefinition>(body: T, options?: RequestOptions): Promise<ItemResponse<T>>;
}

Expand Down Expand Up @@ -1002,7 +998,7 @@ export interface PartitionedQueryExecutionInfo {
}

// @public (undocumented)
export type PartitionKey = PartitionKeyDefinition | string | number | {};
export type PartitionKey = PartitionKeyDefinition | string | number | unknown;

// @public (undocumented)
export interface PartitionKeyDefinition {
Expand Down Expand Up @@ -1030,6 +1026,16 @@ export interface PartitionKeyRange {
throughputFraction: number;
}

// @public (undocumented)
export interface PartitionKeyRangePropertiesNames {
// (undocumented)
Id: "id";
// (undocumented)
MaxExclusive: "maxExclusive";
// (undocumented)
MinInclusive: "minInclusive";
}

// @public
export class Permission {
constructor(user: User, id: string, clientContext: ClientContext);
Expand Down Expand Up @@ -1262,7 +1268,7 @@ export interface ReadOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Read;
// (undocumented)
partitionKey?: string | number | null | {} | undefined;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
}

// @public (undocumented)
Expand All @@ -1280,7 +1286,7 @@ export interface ReplaceOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Replace;
// (undocumented)
partitionKey?: string | number | null | {} | undefined;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
// (undocumented)
resourceBody: JSONObject;
}
Expand Down Expand Up @@ -1512,65 +1518,64 @@ export interface SqlQuerySpec {
}

// @public (undocumented)
export const StatusCode: {
Ok: 200;
Created: 201;
Accepted: 202;
NoContent: 204;
NotModified: 304;
BadRequest: 400;
Unauthorized: 401;
Forbidden: 403;
NotFound: 404;
MethodNotAllowed: 405;
RequestTimeout: 408;
Conflict: 409;
Gone: 410;
PreconditionFailed: 412;
RequestEntityTooLarge: 413;
TooManyRequests: 429;
RetryWith: 449;
InternalServerError: 500;
ServiceUnavailable: 503;
OperationPaused: 1200;
OperationCancelled: number;
};
export type StatusCode = number;

// @public (undocumented)
export type StatusCode = typeof StatusCode[keyof typeof StatusCode];
export const StatusCodes: StatusCodesType;

// @public (undocumented)
export const StatusCodes: {
Ok: 200;
Created: 201;
export interface StatusCodesType {
// (undocumented)
Accepted: 202;
NoContent: 204;
NotModified: 304;
// (undocumented)
BadRequest: 400;
Unauthorized: 401;
Forbidden: 403;
NotFound: 404;
MethodNotAllowed: 405;
RequestTimeout: 408;
// (undocumented)
Conflict: 409;
// (undocumented)
Created: 201;
// (undocumented)
Forbidden: 403;
// (undocumented)
Gone: 410;
// (undocumented)
InternalServerError: 500;
// (undocumented)
MethodNotAllowed: 405;
// (undocumented)
NoContent: 204;
// (undocumented)
NotFound: 404;
// (undocumented)
NotModified: 304;
// (undocumented)
Ok: 200;
// (undocumented)
OperationCancelled: 1201;
// (undocumented)
OperationPaused: 1200;
// (undocumented)
PreconditionFailed: 412;
// (undocumented)
RequestEntityTooLarge: 413;
TooManyRequests: 429;
// (undocumented)
RequestTimeout: 408;
// (undocumented)
RetryWith: 449;
InternalServerError: 500;
// (undocumented)
ServiceUnavailable: 503;
OperationPaused: 1200;
OperationCancelled: 1201;
};
// (undocumented)
TooManyRequests: 429;
// (undocumented)
Unauthorized: 401;
}

// @public
export class StoredProcedure {
constructor(container: Container, id: string, clientContext: ClientContext);
// (undocumented)
readonly container: Container;
delete(options?: RequestOptions): Promise<StoredProcedureResponse>;
execute<T = any>(partitionKey: any, params?: any[], options?: RequestOptions): Promise<ResourceResponse<T>>;
execute<T = any>(partitionKey: PartitionKey, params?: any[], options?: RequestOptions): Promise<ResourceResponse<T>>;
// (undocumented)
readonly id: string;
read(options?: RequestOptions): Promise<StoredProcedureResponse>;
Expand Down Expand Up @@ -1603,16 +1608,7 @@ export class StoredProcedures {
}

// @public (undocumented)
export const SubStatusCode: {
Unknown: 0;
CrossPartitionQueryNotServable: 1004;
PartitionKeyRangeGone: 1002;
ReadSessionNotAvailable: 1002;
WriteForbidden: number;
};

// @public (undocumented)
export type SubStatusCode = typeof SubStatusCode[keyof typeof SubStatusCode];
export type SubStatusCode = number;

// @public
export class TimeSpan {
Expand All @@ -1621,8 +1617,8 @@ export class TimeSpan {
// (undocumented)
static additionDoesOverflow(a: number, b: number): boolean;
// (undocumented)
static compare(t1: TimeSpan, t2: TimeSpan): 0 | 1 | -1;
compareTo(value: TimeSpan): 0 | 1 | -1;
static compare(t1: TimeSpan, t2: TimeSpan): 1 | 0 | -1;
compareTo(value: TimeSpan): 1 | -1 | 0;
// (undocumented)
days(): number;
duration(): TimeSpan;
Expand Down Expand Up @@ -1757,7 +1753,7 @@ export interface UpsertOperationInput {
// (undocumented)
operationType: typeof BulkOperationType.Upsert;
// (undocumented)
partitionKey?: string | number | null | {} | undefined;
partitionKey?: string | number | null | Record<string, unknown> | undefined;
// (undocumented)
resourceBody: JSONObject;
}
Expand Down
24 changes: 24 additions & 0 deletions sdk/cosmosdb/cosmos/samples/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"plugins": ["@azure/azure-sdk", "@typescript-eslint/tslint"],
"extends": ["plugin:@azure/azure-sdk/recommended"],
"parserOptions": {
"createDefaultProgram": true
},
"rules": {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/no-extraneous-class": "error",
"dot-notation": "off",
"some-rule": "off",
// ChangeFeed.ts has problems with this rule
"no-irregular-whitespace": "off",
"@typescript-eslint/tslint/config": [
"error",
{
"rules": {
"import-blacklist": [true, "assert", "util"],
"no-floating-promises": true
}
}
]
}
}
16 changes: 8 additions & 8 deletions sdk/cosmosdb/cosmos/samples/BulkUpdateWithSproc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ logSampleHeader("Bulk Update Using Stored Procedures");
// Only to make TypeScript happy
let getContext: any;

function body(continuation: string) {
function body(continuation: string): void {
const collection = getContext().getCollection();
const response = getContext().getResponse();
const responseBody: any = { updatedDocumentIds: [] }; // Setup Initial Response
Expand All @@ -28,20 +28,20 @@ function body(continuation: string) {
}
);

function updateDocs(documents: any, responseBody: any) {
function updateDocs(documents: any, responseBodyParam: any): void {
if (documents.length === 0) {
// If no documents are left to update, we are done
response.setBody(responseBody);
response.setBody(responseBodyParam);
} else {
// Grab the next document to update
const document = documents.pop();
document.state = "open";
collection.replaceDocument(document._self, document, {}, function(err: any) {
if (err) throw err;
// If we have successfully updated the document, include it in the returned document ids
responseBody.updatedDocumentIds.push(document.id);
// Call update with remaning documents
updateDocs(documents, responseBody);
responseBodyParam.updatedDocumentIds.push(document.id);
// Call update with remaining documents
updateDocs(documents, responseBodyParam);
});
}
}
Expand All @@ -50,7 +50,7 @@ function body(continuation: string) {
// Establish a new instance of the CosmosClient to be used throughout this demo
const client = new CosmosClient({ endpoint, key });

async function run() {
async function run(): Promise<void> {
// ensuring a database & container exists for us to work with
logStep("Create database '" + databaseId + "' and container '" + containerId + "'");
const { database } = await client.databases.createIfNotExists({ id: databaseId });
Expand All @@ -72,7 +72,7 @@ async function run() {
logStep("Execute stored procedure and follow continuation tokens");
let continuation: string = undefined;
let totalUpdatedDocuments = 0;
while (true) {
for (;;) {
const response = await storedProcedure.execute(undefined, [continuation]);
const result: any = response.resource;
totalUpdatedDocuments = totalUpdatedDocuments + result.updatedDocumentIds.length;
Expand Down
Loading