mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-26 07:26:58 +00:00
Make explicit any an error (#81)
Co-authored-by: Steve Faulkner <stfaul@microsoft.com>
This commit is contained in:
parent
b1e20796c2
commit
99c6a7ebcc
@ -1,5 +1,6 @@
|
|||||||
**/node_modules/
|
**/node_modules/
|
||||||
dist/
|
dist/
|
||||||
|
Contracts/
|
||||||
src/Api/Apis.ts
|
src/Api/Apis.ts
|
||||||
src/AuthType.ts
|
src/AuthType.ts
|
||||||
src/Bindings/BindingHandlersRegisterer.ts
|
src/Bindings/BindingHandlersRegisterer.ts
|
||||||
|
@ -39,6 +39,7 @@ module.exports = {
|
|||||||
curly: "error",
|
curly: "error",
|
||||||
"@typescript-eslint/no-unused-vars": "error",
|
"@typescript-eslint/no-unused-vars": "error",
|
||||||
"@typescript-eslint/no-extraneous-class": "error",
|
"@typescript-eslint/no-extraneous-class": "error",
|
||||||
"no-null/no-null": "error"
|
"no-null/no-null": "error",
|
||||||
|
"@typescript-eslint/no-explicit-any": "error"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -16,6 +16,7 @@ import { MessageHandler } from "./MessageHandler";
|
|||||||
import { MessageTypes } from "../Contracts/ExplorerContracts";
|
import { MessageTypes } from "../Contracts/ExplorerContracts";
|
||||||
import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils";
|
import { NotificationConsoleUtils } from "../Utils/NotificationConsoleUtils";
|
||||||
import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient";
|
import { ResourceProviderClient } from "../ResourceProvider/ResourceProviderClient";
|
||||||
|
import { MinimalQueryIterator } from "./IteratorUtilities";
|
||||||
|
|
||||||
const defaultHeaders = {
|
const defaultHeaders = {
|
||||||
[HttpHeaders.apiType]: ApiType.MongoDB.toString(),
|
[HttpHeaders.apiType]: ApiType.MongoDB.toString(),
|
||||||
@ -23,7 +24,7 @@ const defaultHeaders = {
|
|||||||
[CosmosSDKConstants.HttpHeaders.Version]: "2017-11-15"
|
[CosmosSDKConstants.HttpHeaders.Version]: "2017-11-15"
|
||||||
};
|
};
|
||||||
|
|
||||||
function authHeaders(): any {
|
function authHeaders() {
|
||||||
if (window.authType === AuthType.EncryptedToken) {
|
if (window.authType === AuthType.EncryptedToken) {
|
||||||
return { [HttpHeaders.guestAccessToken]: CosmosClient.accessToken() };
|
return { [HttpHeaders.guestAccessToken]: CosmosClient.accessToken() };
|
||||||
} else {
|
} else {
|
||||||
@ -31,21 +32,21 @@ function authHeaders(): any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function queryIterator(databaseId: string, collection: Collection, query: string): any {
|
export function queryIterator(databaseId: string, collection: Collection, query: string): MinimalQueryIterator {
|
||||||
let continuationToken: string;
|
let continuationToken: string;
|
||||||
return {
|
return {
|
||||||
fetchNext: () => {
|
fetchNext: () => {
|
||||||
return queryDocuments(databaseId, collection, false, query).then(response => {
|
return queryDocuments(databaseId, collection, false, query).then(response => {
|
||||||
continuationToken = response.continuationToken;
|
continuationToken = response.continuationToken;
|
||||||
const headers = {} as any;
|
const headers: { [key: string]: string | number } = {};
|
||||||
response.headers.forEach((value: any, key: any) => {
|
response.headers.forEach((value, key) => {
|
||||||
headers[key] = value;
|
headers[key] = value;
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
resources: response.documents,
|
resources: response.documents,
|
||||||
headers,
|
headers,
|
||||||
requestCharge: headers[CosmosSDKConstants.HttpHeaders.RequestCharge],
|
requestCharge: Number(headers[CosmosSDKConstants.HttpHeaders.RequestCharge]),
|
||||||
activityId: headers[CosmosSDKConstants.HttpHeaders.ActivityId],
|
activityId: String(headers[CosmosSDKConstants.HttpHeaders.ActivityId]),
|
||||||
hasMoreResults: !!continuationToken
|
hasMoreResults: !!continuationToken
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -114,7 +115,8 @@ export function queryDocuments(
|
|||||||
headers: response.headers
|
headers: response.headers
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return errorHandling(response, "querying documents", params);
|
errorHandling(response, "querying documents", params);
|
||||||
|
return undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +167,7 @@ export function createDocument(
|
|||||||
databaseId: string,
|
databaseId: string,
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
partitionKeyProperty: string,
|
partitionKeyProperty: string,
|
||||||
documentContent: any
|
documentContent: unknown
|
||||||
): Promise<DataModels.DocumentId> {
|
): Promise<DataModels.DocumentId> {
|
||||||
const databaseAccount = CosmosClient.databaseAccount();
|
const databaseAccount = CosmosClient.databaseAccount();
|
||||||
const resourceEndpoint = databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint;
|
const resourceEndpoint = databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint;
|
||||||
@ -204,7 +206,7 @@ export function updateDocument(
|
|||||||
databaseId: string,
|
databaseId: string,
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
documentId: ViewModels.DocumentId,
|
documentId: ViewModels.DocumentId,
|
||||||
documentContent: any
|
documentContent: unknown
|
||||||
): Promise<DataModels.DocumentId> {
|
): Promise<DataModels.DocumentId> {
|
||||||
const databaseAccount = CosmosClient.databaseAccount();
|
const databaseAccount = CosmosClient.databaseAccount();
|
||||||
const resourceEndpoint = databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint;
|
const resourceEndpoint = databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint;
|
||||||
@ -228,7 +230,7 @@ export function updateDocument(
|
|||||||
return window
|
return window
|
||||||
.fetch(`${endpoint}?${queryString.stringify(params)}`, {
|
.fetch(`${endpoint}?${queryString.stringify(params)}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
body: documentContent,
|
body: JSON.stringify(documentContent),
|
||||||
headers: {
|
headers: {
|
||||||
...defaultHeaders,
|
...defaultHeaders,
|
||||||
...authHeaders(),
|
...authHeaders(),
|
||||||
@ -248,7 +250,7 @@ export function deleteDocument(
|
|||||||
databaseId: string,
|
databaseId: string,
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
documentId: ViewModels.DocumentId
|
documentId: ViewModels.DocumentId
|
||||||
): Promise<any> {
|
): Promise<void> {
|
||||||
const databaseAccount = CosmosClient.databaseAccount();
|
const databaseAccount = CosmosClient.databaseAccount();
|
||||||
const resourceEndpoint = databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint;
|
const resourceEndpoint = databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint;
|
||||||
const idComponents = documentId.self.split("/");
|
const idComponents = documentId.self.split("/");
|
||||||
@ -295,7 +297,7 @@ export function createMongoCollectionWithProxy(
|
|||||||
sharedThroughput: boolean,
|
sharedThroughput: boolean,
|
||||||
isSharded: boolean,
|
isSharded: boolean,
|
||||||
autopilotOptions?: DataModels.RpOptions
|
autopilotOptions?: DataModels.RpOptions
|
||||||
): Promise<any> {
|
): Promise<DataModels.Collection> {
|
||||||
const databaseAccount = CosmosClient.databaseAccount();
|
const databaseAccount = CosmosClient.databaseAccount();
|
||||||
const params: DataModels.MongoParameters = {
|
const params: DataModels.MongoParameters = {
|
||||||
resourceUrl: databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint,
|
resourceUrl: databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint,
|
||||||
@ -335,7 +337,7 @@ export function createMongoCollectionWithProxy(
|
|||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
return undefined;
|
return response.json();
|
||||||
}
|
}
|
||||||
return errorHandling(response, "creating collection", params);
|
return errorHandling(response, "creating collection", params);
|
||||||
});
|
});
|
||||||
@ -352,7 +354,7 @@ export function createMongoCollectionWithARM(
|
|||||||
sharedThroughput: boolean,
|
sharedThroughput: boolean,
|
||||||
isSharded: boolean,
|
isSharded: boolean,
|
||||||
additionalOptions?: DataModels.RpOptions
|
additionalOptions?: DataModels.RpOptions
|
||||||
): Promise<any> {
|
): Promise<DataModels.CreateCollectionWithRpResponse> {
|
||||||
const databaseAccount = CosmosClient.databaseAccount();
|
const databaseAccount = CosmosClient.databaseAccount();
|
||||||
const params: DataModels.MongoParameters = {
|
const params: DataModels.MongoParameters = {
|
||||||
resourceUrl: databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint,
|
resourceUrl: databaseAccount.properties.mongoEndpoint || databaseAccount.properties.documentEndpoint,
|
||||||
@ -396,7 +398,9 @@ export function getEndpoint(databaseAccount: ViewModels.DatabaseAccount): string
|
|||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function errorHandling(response: any, action: string, params: any): Promise<any> {
|
// TODO: This function throws most of the time except on Forbidden which is a bit strange
|
||||||
|
// It causes problems for TypeScript understanding the types
|
||||||
|
async function errorHandling(response: Response, action: string, params: unknown): Promise<void> {
|
||||||
const errorMessage = await response.text();
|
const errorMessage = await response.text();
|
||||||
// Log the error where the user can see it
|
// Log the error where the user can see it
|
||||||
NotificationConsoleUtils.logConsoleMessage(
|
NotificationConsoleUtils.logConsoleMessage(
|
||||||
@ -420,7 +424,7 @@ export async function _createMongoCollectionWithARM(
|
|||||||
armEndpoint: string,
|
armEndpoint: string,
|
||||||
params: DataModels.MongoParameters,
|
params: DataModels.MongoParameters,
|
||||||
rpOptions: DataModels.RpOptions
|
rpOptions: DataModels.RpOptions
|
||||||
): Promise<any> {
|
): Promise<DataModels.CreateCollectionWithRpResponse> {
|
||||||
const rpPayloadToCreateCollection: DataModels.MongoCreationRequest = {
|
const rpPayloadToCreateCollection: DataModels.MongoCreationRequest = {
|
||||||
properties: {
|
properties: {
|
||||||
resource: {
|
resource: {
|
||||||
@ -448,12 +452,13 @@ export async function _createMongoCollectionWithARM(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await new ResourceProviderClient(armEndpoint).putAsync(
|
return new ResourceProviderClient<DataModels.CreateCollectionWithRpResponse>(armEndpoint).putAsync(
|
||||||
getARMCreateCollectionEndpoint(params),
|
getARMCreateCollectionEndpoint(params),
|
||||||
DataExplorerConstants.ArmApiVersions.publicVersion,
|
DataExplorerConstants.ArmApiVersions.publicVersion,
|
||||||
rpPayloadToCreateCollection
|
rpPayloadToCreateCollection
|
||||||
);
|
);
|
||||||
} catch (response) {
|
} catch (response) {
|
||||||
return errorHandling(response, "creating collection", undefined);
|
errorHandling(response, "creating collection", undefined);
|
||||||
|
return undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user