diff --git a/packages/authentication/azure/src/azureIdentityAccessTokenProvider.ts b/packages/authentication/azure/src/azureIdentityAccessTokenProvider.ts index 9bf08e7d7..9643c4ee3 100644 --- a/packages/authentication/azure/src/azureIdentityAccessTokenProvider.ts +++ b/packages/authentication/azure/src/azureIdentityAccessTokenProvider.ts @@ -14,7 +14,6 @@ import { type ObservabilityOptions, ObservabilityOptionsImpl } from "./observabi /** Access token provider that leverages the Azure Identity library to retrieve an access token. */ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider { /** - *@constructor *@param credentials The tokenCredential implementation to use for authentication. *@param scopes The scopes to use for authentication. *@param options The options to use for authentication. @@ -55,7 +54,7 @@ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider { } }); }; - private getAuthorizationTokenInternal = async (url?: string, additionalAuthenticationContext?: Record, span?: Span): Promise => { + private readonly getAuthorizationTokenInternal = async (url?: string, additionalAuthenticationContext?: Record, span?: Span): Promise => { if (!url || !this.allowedHostsValidator.isUrlHostValid(url)) { span?.setAttribute("com.microsoft.kiota.authentication.is_url_valid", false); return ""; @@ -63,7 +62,7 @@ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider { validateProtocol(url); span?.setAttribute("com.microsoft.kiota.authentication.is_url_valid", true); let decodedClaims = ""; - if (additionalAuthenticationContext && additionalAuthenticationContext[AzureIdentityAccessTokenProvider.claimsKey]) { + if (additionalAuthenticationContext?.[AzureIdentityAccessTokenProvider.claimsKey]) { const rawClaims = additionalAuthenticationContext[AzureIdentityAccessTokenProvider.claimsKey] as string; decodedClaims = inNodeEnv() ? Buffer.from(rawClaims, "base64").toString() : atob(rawClaims); } @@ -81,7 +80,7 @@ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider { const result = await this.credentials.getToken(this.scopes, localOptions); return result?.token ?? ""; }; - private getSchemeAndHostFromUrl = (url: string): string[] => { + private readonly getSchemeAndHostFromUrl = (url: string): string[] => { const urlParts = url.split("://"); if (urlParts.length === 0) { // relative url @@ -96,13 +95,13 @@ export class AzureIdentityAccessTokenProvider implements AccessTokenProvider { throw new Error("invalid url"); } }; - private getSchemeFromLocation = (): string => { + private readonly getSchemeFromLocation = (): string => { if (!inNodeEnv()) { return window.location.protocol.replace(":", ""); } return ""; }; - private getHostFromLocation = (): string => { + private readonly getHostFromLocation = (): string => { if (!inNodeEnv()) { return window.location.host; } diff --git a/packages/authentication/spfx/src/azureAdSpfxAccessTokenProvider.ts b/packages/authentication/spfx/src/azureAdSpfxAccessTokenProvider.ts index 5fe07bddf..1dce2a872 100644 --- a/packages/authentication/spfx/src/azureAdSpfxAccessTokenProvider.ts +++ b/packages/authentication/spfx/src/azureAdSpfxAccessTokenProvider.ts @@ -15,10 +15,10 @@ export class AzureAdSpfxAccessTokenProvider implements AccessTokenProvider { private readonly allowedHostsValidator: AllowedHostsValidator; /** - *@constructor *@param tokenProvider The tokenProvider provided by the SharePoint framework *@param applicationIdUri The application ID URI of the Azure AD App that we want to Authenticate *@param allowedHosts The allowed hosts to use for authentication. + * @param observabilityOptions *@param useCachedToken Allows the developer to specify if cached tokens should be returned. */ public constructor( @@ -52,9 +52,9 @@ export class AzureAdSpfxAccessTokenProvider implements AccessTokenProvider { } }); }; - private getAuthorizationTokenInternal = async ( + private readonly getAuthorizationTokenInternal = async ( url?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + additionalAuthenticationContext?: Record, span?: Span, ): Promise => { diff --git a/packages/authentication/spfx/src/azureAdSpfxAuthenticationProvider.ts b/packages/authentication/spfx/src/azureAdSpfxAuthenticationProvider.ts index fa1b7cf40..40a90e85f 100644 --- a/packages/authentication/spfx/src/azureAdSpfxAuthenticationProvider.ts +++ b/packages/authentication/spfx/src/azureAdSpfxAuthenticationProvider.ts @@ -13,10 +13,10 @@ import { type ObservabilityOptions, ObservabilityOptionsImpl } from "./observabi export class AzureAdSpfxAuthenticationProvider extends BaseBearerTokenAuthenticationProvider { /** - *@constructor *@param tokenProvider The tokenProvider provided by the SharePoint framework *@param applicationIdUri The application ID URI of the Azure AD App that we want to Authenticate *@param allowedHosts The allowed hosts to use for authentication. + * @param observabilityOptions *@param useCachedToken Allows the developer to specify if cached tokens should be returned. */ public constructor(tokenProvider: AadTokenProvider, applicationIdUri: string, allowedHosts: Set = new Set(["graph.microsoft.com", "graph.microsoft.us", "dod-graph.microsoft.us", "graph.microsoft.de", "microsoftgraph.chinacloudapi.cn", "canary.graph.microsoft.com"]), useCachedToken?: boolean, observabilityOptions: ObservabilityOptions = new ObservabilityOptionsImpl()) { diff --git a/packages/http/fetch/src/fetchRequestAdapter.ts b/packages/http/fetch/src/fetchRequestAdapter.ts index 53f89d226..2202bc83a 100644 --- a/packages/http/fetch/src/fetchRequestAdapter.ts +++ b/packages/http/fetch/src/fetchRequestAdapter.ts @@ -54,14 +54,14 @@ export class FetchRequestAdapter implements RequestAdapter { this.observabilityOptions = new ObservabilityOptionsImpl(observabilityOptions); } } - private getResponseContentType = (response: Response): string | undefined => { + private readonly getResponseContentType = (response: Response): string | undefined => { const header = response.headers.get("content-type")?.toLowerCase(); if (!header) return undefined; const segments = header.split(";"); if (segments.length === 0) return undefined; else return segments[0]; }; - private getResponseHandler = (response: RequestInformation): ResponseHandler | undefined => { + private readonly getResponseHandler = (response: RequestInformation): ResponseHandler | undefined => { const options = response.getRequestOptions(); const responseHandlerOption = options[ResponseHandlerOptionKey] as ResponseHandlerOption; return responseHandlerOption?.responseHandler; @@ -157,7 +157,7 @@ export class FetchRequestAdapter implements RequestAdapter { } }); }; - private startTracingSpan = (requestInfo: RequestInformation, methodName: string, callback: (arg0: Span) => Promise): Promise => { + private readonly startTracingSpan = (requestInfo: RequestInformation, methodName: string, callback: (arg0: Span) => Promise): Promise => { const urlTemplate = decodeURIComponent(requestInfo.urlTemplate ?? ""); const telemetryPathValue = urlTemplate.replace(/\{\?[^}]+\}/gi, ""); return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan(`${methodName} - ${telemetryPathValue}`, async (span) => { @@ -221,7 +221,7 @@ export class FetchRequestAdapter implements RequestAdapter { if (this.shouldReturnUndefined(response)) return undefined; switch (responseType) { case "ArrayBuffer": - // eslint-disable-next-line no-case-declarations + if (!response.body) { return undefined; } @@ -264,7 +264,7 @@ export class FetchRequestAdapter implements RequestAdapter { } finally { span.end(); } - }) as Promise; + }); }; public sendNoResponseContent = (requestInfo: RequestInformation, errorMappings: ErrorMappings | undefined): Promise => { if (!requestInfo) { @@ -308,7 +308,7 @@ export class FetchRequestAdapter implements RequestAdapter { try { span.setAttribute(FetchRequestAdapter.responseTypeAttributeKey, "enum"); const result = rootNode.getEnumValue(enumObject); - return result as unknown as EnumObject[keyof EnumObject]; + return result as EnumObject[keyof EnumObject]; } finally { deserializeSpan.end(); } @@ -356,7 +356,7 @@ export class FetchRequestAdapter implements RequestAdapter { } }); }; - public enableBackingStore = (backingStoreFactory?: BackingStoreFactory | undefined): void => { + public enableBackingStore = (backingStoreFactory?: BackingStoreFactory ): void => { this.parseNodeFactory = enableBackingStoreForParseNodeFactory(this.parseNodeFactory); this.serializationWriterFactory = enableBackingStoreForSerializationWriterFactory(this.serializationWriterFactory); if (!this.serializationWriterFactory || !this.parseNodeFactory) throw new Error("unable to enable backing store"); @@ -364,7 +364,7 @@ export class FetchRequestAdapter implements RequestAdapter { BackingStoreFactorySingleton.instance = backingStoreFactory; } }; - private getRootParseNode = (response: Response): Promise => { + private readonly getRootParseNode = (response: Response): Promise => { return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getRootParseNode", async (span) => { try { const payload = await response.arrayBuffer(); @@ -377,18 +377,21 @@ export class FetchRequestAdapter implements RequestAdapter { } }); }; - private shouldReturnUndefined = (response: Response): boolean => { + private readonly shouldReturnUndefined = (response: Response): boolean => { return response.status === 204 || !response.body; }; - /** purges the response body if it hasn't been read to release the connection to the server */ - private purgeResponseBody = async (response: Response): Promise => { + /** + * purges the response body if it hasn't been read to release the connection to the server + * @param response + */ + private readonly purgeResponseBody = async (response: Response): Promise => { if (!response.bodyUsed && response.body) { await response.arrayBuffer(); } }; public static readonly errorMappingFoundAttributeName = "com.microsoft.kiota.error.mapping_found"; public static readonly errorBodyFoundAttributeName = "com.microsoft.kiota.error.body_found"; - private throwIfFailedResponse = (response: Response, errorMappings: ErrorMappings | undefined, spanForAttributes: Span): Promise => { + private readonly throwIfFailedResponse = (response: Response, errorMappings: ErrorMappings | undefined, spanForAttributes: Span): Promise => { return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("throwIfFailedResponse", async (span) => { try { if (response.ok) return; @@ -435,7 +438,7 @@ export class FetchRequestAdapter implements RequestAdapter { } }); }; - private getHttpResponseMessage = (requestInfo: RequestInformation, spanForAttributes: Span, claims?: string): Promise => { + private readonly getHttpResponseMessage = (requestInfo: RequestInformation, spanForAttributes: Span, claims?: string): Promise => { return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getHttpResponseMessage", async (span) => { try { if (!requestInfo) { @@ -444,7 +447,7 @@ export class FetchRequestAdapter implements RequestAdapter { this.setBaseUrlForRequestInformation(requestInfo); const additionalContext = {} as Record; if (claims) { - additionalContext["claims"] = claims; + additionalContext.claims = claims; } await this.authenticationProvider.authenticateRequest(requestInfo, additionalContext); const request = await this.getRequestFromRequestInformation(requestInfo, spanForAttributes); @@ -473,7 +476,7 @@ export class FetchRequestAdapter implements RequestAdapter { }); }; public static readonly authenticateChallengedEventKey = "com.microsoft.kiota.authenticate_challenge_received"; - private retryCAEResponseIfRequired = async (requestInfo: RequestInformation, response: Response, spanForAttributes: Span, claims?: string) => { + private readonly retryCAEResponseIfRequired = async (requestInfo: RequestInformation, response: Response, spanForAttributes: Span, claims?: string) => { return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("retryCAEResponseIfRequired", async (span) => { try { const responseClaims = this.getClaimsFromResponse(response, claims); @@ -489,7 +492,7 @@ export class FetchRequestAdapter implements RequestAdapter { } }); }; - private getClaimsFromResponse = (response: Response, claims?: string) => { + private readonly getClaimsFromResponse = (response: Response, claims?: string) => { if (response.status === 401 && !claims) { // avoid infinite loop, we only retry once // no need to check for the content since it's an array and it doesn't need to be rewound @@ -506,16 +509,16 @@ export class FetchRequestAdapter implements RequestAdapter { } return undefined; }; - private setBaseUrlForRequestInformation = (requestInfo: RequestInformation): void => { - requestInfo.pathParameters["baseurl"] = this.baseUrl; + private readonly setBaseUrlForRequestInformation = (requestInfo: RequestInformation): void => { + requestInfo.pathParameters.baseurl = this.baseUrl; }; - private getRequestFromRequestInformation = (requestInfo: RequestInformation, spanForAttributes: Span): Promise => { + private readonly getRequestFromRequestInformation = (requestInfo: RequestInformation, spanForAttributes: Span): Promise => { return trace.getTracer(this.observabilityOptions.getTracerInstrumentationName()).startActiveSpan("getRequestFromRequestInformation", async (span) => { try { const method = requestInfo.httpMethod?.toString(); const uri = requestInfo.URL; spanForAttributes.setAttribute("http.request.method", method ?? ""); - const uriContainsScheme = uri.indexOf("://") > -1; + const uriContainsScheme = uri.includes("://"); const schemeSplatUri = uri.split("://"); if (uriContainsScheme) { spanForAttributes.setAttribute("server.address", schemeSplatUri[0]); @@ -548,7 +551,7 @@ export class FetchRequestAdapter implements RequestAdapter { } }); }; - private foldHeaderValue = (value: string[] | null): string => { + private readonly foldHeaderValue = (value: string[] | null): string => { if (!value || value.length < 1) { return ""; } else if (value.length === 1) { diff --git a/packages/http/fetch/src/httpClient.ts b/packages/http/fetch/src/httpClient.ts index abece54d6..297dd49c4 100644 --- a/packages/http/fetch/src/httpClient.ts +++ b/packages/http/fetch/src/httpClient.ts @@ -14,18 +14,18 @@ import { MiddlewareFactory } from "./"; export class HttpClient { private middleware: Middleware | undefined; /** - * @public - * @constructor + * * Creates an instance of a HttpClient which contains the middlewares and fetch implementation for request execution. - * @param {...Middleware} middleware - The first middleware of the middleware chain or a sequence of all the Middleware handlers + * @param middleware - The first middleware of the middleware chain or a sequence of all the Middleware handlers * If middlewares param is undefined, the httpClient instance will use the default array of middlewares. * Set middlewares to `null` if you do not wish to use middlewares. + * @param customFetch + * @param middlewares * If custom fetch is undefined, the httpClient instance uses the `DefaultFetchHandler` - * @param {(request: string, init?: RequestInit) => Promise < Response >} custom fetch function - a Fetch API implementation - * + * @param custom fetch function - a Fetch API implementation */ public constructor( - private customFetch?: (request: string, init: RequestInit) => Promise, + private readonly customFetch?: (request: string, init: RequestInit) => Promise, ...middlewares: Middleware[] ) { // If no middlewares are provided, use the default ones @@ -41,10 +41,10 @@ export class HttpClient { } /** - * @private + * * Processes the middleware parameter passed to set this.middleware property * The calling function should validate if middleware is not undefined or not empty. - * @param {...Middleware} middleware - The middleware passed + * @param middleware - The middleware passed * @returns Nothing */ private setMiddleware(...middleware: Middleware[]): void { @@ -58,6 +58,8 @@ export class HttpClient { * Executes a request and returns a promise resolving the response. * @param url the request url. * @param options request options. + * @param requestInit + * @param requestOptions * @returns the promise resolving the response. */ public async executeFetch(url: string, requestInit: RequestInit, requestOptions?: Record): Promise { diff --git a/packages/http/fetch/src/kiotaClientFactory.ts b/packages/http/fetch/src/kiotaClientFactory.ts index 2370cded4..ae15550fc 100644 --- a/packages/http/fetch/src/kiotaClientFactory.ts +++ b/packages/http/fetch/src/kiotaClientFactory.ts @@ -9,12 +9,11 @@ import { Middleware, MiddlewareFactory } from "."; import { HttpClient } from "./httpClient"; /** - * @class + * * Class containing function(s) related to the middleware pipelines. */ export class KiotaClientFactory { /** - * @public * @static * Returns an instance of HttpClient with the provided middlewares and custom fetch implementation both parameters are optional. * if not provided, the default fetch implementation and middlewares will be used. diff --git a/packages/http/fetch/src/middlewares/browser/middlewareFactory.ts b/packages/http/fetch/src/middlewares/browser/middlewareFactory.ts index b503d7d08..45d2c297e 100644 --- a/packages/http/fetch/src/middlewares/browser/middlewareFactory.ts +++ b/packages/http/fetch/src/middlewares/browser/middlewareFactory.ts @@ -14,12 +14,12 @@ import { UserAgentHandler } from "../userAgentHandler"; import { CompressionHandler } from "../compressionHandler"; /** - * @class + * * Class containing function(s) related to the middleware pipelines. */ export class MiddlewareFactory { /** - * @public + * @param customFetch * @static * Returns the default middleware chain an array with the middleware handlers * @returns an array of the middleware handlers of the default middleware chain diff --git a/packages/http/fetch/src/middlewares/chaosHandler.ts b/packages/http/fetch/src/middlewares/chaosHandler.ts index 72504eaf3..b60f22c00 100644 --- a/packages/http/fetch/src/middlewares/chaosHandler.ts +++ b/packages/http/fetch/src/middlewares/chaosHandler.ts @@ -20,16 +20,14 @@ import type { ChaosHandlerOptions } from "./options/chaosHandlerOptions"; import { ChaosStrategy } from "./options/chaosStrategy"; /** - * @class + * * Class - * @implements Middleware + * Middleware * Class representing RedirectHandler */ export class ChaosHandler implements Middleware { /** * A member holding options to customize the handler behavior - * - * @private */ options: ChaosHandlerOptions = { chaosStrategy: ChaosStrategy.RANDOM, @@ -39,19 +37,16 @@ export class ChaosHandler implements Middleware { /** * container for the manual map that has been written by the client - * - * @private */ - private manualMap: Map>; + private readonly manualMap: Map>; /** @inheritdoc */ next: Middleware | undefined; /** - * @public - * @constructor + * * To create an instance of ChaosHandler - * @param {ChaosHandlerOptions} [options = new ChaosHandlerOptions()] - The chaos handler options instance + * @param [options] - The chaos handler options instance * @param manualMap - The Map passed by user containing url-statusCode info */ public constructor(options?: Partial, manualMap?: Map>) { @@ -67,20 +62,18 @@ export class ChaosHandler implements Middleware { /** * Fetches a random status code for the RANDOM mode from the predefined array - * @private - * @param {string} requestMethod - the API method for the request + * @param requestMethod - the API method for the request * @returns a random status code from a given set of status codes */ private generateRandomStatusCode(requestMethod: HttpMethod): number { - const statusCodeArray: number[] = methodStatusCode[requestMethod] as number[]; + const statusCodeArray: number[] = methodStatusCode[requestMethod]; return statusCodeArray[Math.floor(Math.random() * statusCodeArray.length)]; } /** * Strips out the host url and returns the relative url only - * @private - * @param {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object - * @param {string} urlMethod - the complete URL + * @param chaosHandlerOptions - The ChaosHandlerOptions object + * @param urlMethod - the complete URL * @returns the string as relative URL */ private getRelativeURL(chaosHandlerOptions: ChaosHandlerOptions, urlMethod: string): string { @@ -94,10 +87,10 @@ export class ChaosHandler implements Middleware { /** * Gets a status code from the options or a randomly generated status code - * @param {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object - * @param {string} requestURL - the URL for the request - * @param {HttpMethod} requestMethod - the API method for the request - * @returns {number} generated statusCode + * @param chaosHandlerOptions - The ChaosHandlerOptions object + * @param requestURL - the URL for the request + * @param requestMethod - the API method for the request + * @returns generated statusCode */ private getStatusCode(chaosHandlerOptions: ChaosHandlerOptions, requestURL: string, requestMethod: HttpMethod): number { if (chaosHandlerOptions.chaosStrategy === ChaosStrategy.MANUAL) { @@ -136,11 +129,11 @@ export class ChaosHandler implements Middleware { /** * Generates a respondy for the chaoe response - * @private - * @param {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object - * @param {string} requestID - request id - * @param {string} requestDate - date of the request - * * @returns response body + * @param chaosHandlerOptions - The ChaosHandlerOptions object + * @param requestID - request id + * @param requestDate - date of the request + * @returns response body + * @param statusCode */ private createResponseBody(chaosHandlerOptions: ChaosHandlerOptions, statusCode: number) { if (chaosHandlerOptions.responseBody) { @@ -165,9 +158,9 @@ export class ChaosHandler implements Middleware { /** * Composes a new chaotic response code with the configured parameters - * @param {string} url - * @param {FetchRequestInit} fetchRequestInit - * @returns {Response} + * @param url + * @param fetchRequestInit + * @returns */ private createChaosResponse(url: string, fetchRequestInit: FetchRequestInit): any { if (fetchRequestInit.method === undefined) { @@ -188,7 +181,7 @@ export class ChaosHandler implements Middleware { }; } - public execute(url: string, requestInit: RequestInit, requestOptions?: Record | undefined): Promise { + public execute(url: string, requestInit: RequestInit, requestOptions?: Record ): Promise { const obsOptions = getObservabilityOptionsFromRequest(requestOptions); if (obsOptions) { return trace.getTracer(obsOptions.getTracerInstrumentationName()).startActiveSpan("chaosHandler - execute", (span) => { @@ -203,7 +196,7 @@ export class ChaosHandler implements Middleware { return this.runChaos(url, requestInit, requestOptions); } public static readonly chaosHandlerTriggeredEventKey = "com.microsoft.kiota.chaos_handler_triggered"; - private runChaos(url: string, requestInit: RequestInit, requestOptions?: Record | undefined, span?: Span): Promise { + private runChaos(url: string, requestInit: RequestInit, requestOptions?: Record , span?: Span): Promise { if (Math.floor(Math.random() * 100) < this.options.chaosPercentage) { span?.addEvent(ChaosHandler.chaosHandlerTriggeredEventKey); return Promise.resolve(this.createChaosResponse(url, requestInit as FetchRequestInit)); diff --git a/packages/http/fetch/src/middlewares/compressionHandler.ts b/packages/http/fetch/src/middlewares/compressionHandler.ts index 0411effbb..b421faefc 100644 --- a/packages/http/fetch/src/middlewares/compressionHandler.ts +++ b/packages/http/fetch/src/middlewares/compressionHandler.ts @@ -21,24 +21,21 @@ export class CompressionHandler implements Middleware { next: Middleware | undefined; /** - * @private * @static * A member holding the name of content range header */ private static readonly CONTENT_RANGE_HEADER = "Content-Range"; /** - * @private * @static * A member holding the name of content encoding header */ private static readonly CONTENT_ENCODING_HEADER = "Content-Encoding"; /** - * @public - * @constructor + * * Creates a new instance of the CompressionHandler class - * @param {CompressionHandlerOptions} handlerOptions The options for the compression handler. + * @param handlerOptions The options for the compression handler. * @returns An instance of the CompressionHandler class */ public constructor(private readonly handlerOptions: CompressionHandlerOptions = new CompressionHandlerOptions()) { @@ -50,7 +47,7 @@ export class CompressionHandler implements Middleware { /** * @inheritdoc */ - public execute(url: string, requestInit: RequestInit, requestOptions?: Record | undefined): Promise { + public execute(url: string, requestInit: RequestInit, requestOptions?: Record ): Promise { let currentOptions = this.handlerOptions; if (requestOptions?.[CompressionHandlerOptionsKey]) { currentOptions = requestOptions[CompressionHandlerOptionsKey] as CompressionHandlerOptions; diff --git a/packages/http/fetch/src/middlewares/customFetchHandler.ts b/packages/http/fetch/src/middlewares/customFetchHandler.ts index 6a7bc8c0d..7cc51af53 100644 --- a/packages/http/fetch/src/middlewares/customFetchHandler.ts +++ b/packages/http/fetch/src/middlewares/customFetchHandler.ts @@ -12,14 +12,13 @@ import type { Middleware } from "./middleware"; /** - * @class - * @implements Middleware + * Middleware * Class for FetchHandler */ export class CustomFetchHandler implements Middleware { /** - * @private + * * The next middleware in the middleware chain */ next: Middleware | undefined; diff --git a/packages/http/fetch/src/middlewares/headersInspectionHandler.ts b/packages/http/fetch/src/middlewares/headersInspectionHandler.ts index bb5986b68..3b5276cf4 100644 --- a/packages/http/fetch/src/middlewares/headersInspectionHandler.ts +++ b/packages/http/fetch/src/middlewares/headersInspectionHandler.ts @@ -13,24 +13,22 @@ import type { Middleware } from "./middleware"; import { HeadersInspectionOptions, HeadersInspectionOptionsKey } from "./options/headersInspectionOptions"; /** - * @class - * @implements Middleware + * Middleware * Inspects the headers of the request and response */ export class HeadersInspectionHandler implements Middleware { /** - * @constructor - * @public + * * Creates new instance of HeadersInspectionHandler - * @param {HeadersInspectionOptions} _options The options for inspecting the headers + * @param _options The options for inspecting the headers */ public constructor(private readonly _options: HeadersInspectionOptions = new HeadersInspectionOptions()) {} /** - * @private + * * The next middleware in the middleware chain */ next: Middleware | undefined; - public execute(url: string, requestInit: RequestInit, requestOptions?: Record | undefined): Promise { + public execute(url: string, requestInit: RequestInit, requestOptions?: Record ): Promise { let currentOptions = this._options; if (requestOptions?.[HeadersInspectionOptionsKey]) { currentOptions = requestOptions[HeadersInspectionOptionsKey] as HeadersInspectionOptions; diff --git a/packages/http/fetch/src/middlewares/middleware.ts b/packages/http/fetch/src/middlewares/middleware.ts index 349bf7623..11a2e1a2d 100644 --- a/packages/http/fetch/src/middlewares/middleware.ts +++ b/packages/http/fetch/src/middlewares/middleware.ts @@ -12,7 +12,6 @@ export interface Middleware { next: Middleware | undefined; /** - * @public * @async * Main method of the middleware. * @param requestInit The Fetch RequestInit object. diff --git a/packages/http/fetch/src/middlewares/middlewareFactory.ts b/packages/http/fetch/src/middlewares/middlewareFactory.ts index 96ef7edb3..fff751fd5 100644 --- a/packages/http/fetch/src/middlewares/middlewareFactory.ts +++ b/packages/http/fetch/src/middlewares/middlewareFactory.ts @@ -15,12 +15,12 @@ import { UserAgentHandler } from "./userAgentHandler"; import { CompressionHandler } from "./compressionHandler"; /** - * @class + * * Class containing function(s) related to the middleware pipelines. */ export class MiddlewareFactory { /** - * @public + * @param customFetch * @static * Returns the default middleware chain an array with the middleware handlers * @returns an array of the middleware handlers of the default middleware chain diff --git a/packages/http/fetch/src/middlewares/options/ChaosHandlerData.ts b/packages/http/fetch/src/middlewares/options/ChaosHandlerData.ts index e013ad08c..689bf1ed7 100644 --- a/packages/http/fetch/src/middlewares/options/ChaosHandlerData.ts +++ b/packages/http/fetch/src/middlewares/options/ChaosHandlerData.ts @@ -8,7 +8,7 @@ /** * Contains RequestMethod to corresponding array of possible status codes, used for Random mode */ -export const methodStatusCode: { [key: string]: number[] } = { +export const methodStatusCode: Record = { GET: [429, 500, 502, 503, 504], POST: [429, 500, 502, 503, 504, 507], PUT: [429, 500, 502, 503, 504, 507], @@ -19,7 +19,7 @@ export const methodStatusCode: { [key: string]: number[] } = { /** * Contains statusCode to statusMessage map */ -export const httpStatusCode: { [key: number]: string } = { +export const httpStatusCode: Record = { 100: "Continue", 101: "Switching Protocols", 102: "Processing", diff --git a/packages/http/fetch/src/middlewares/options/chaosHandlerOptions.ts b/packages/http/fetch/src/middlewares/options/chaosHandlerOptions.ts index 4d348c786..c1a08a992 100644 --- a/packages/http/fetch/src/middlewares/options/chaosHandlerOptions.ts +++ b/packages/http/fetch/src/middlewares/options/chaosHandlerOptions.ts @@ -23,28 +23,20 @@ export const ChaosHandlerOptionsKey = "ChaosHandlerOptionsKey"; export interface ChaosHandlerOptions { /** * Speficies the base url path for the destination server, used when relative paths are preffered to strip out paths - * - * @public */ baseUrl?: string; /** * Specifies the startegy used for the Testing Handler -> RANDOM/MANUAL - * - * @public */ chaosStrategy: ChaosStrategy; /** * Status code to be returned in the response - * - * @public */ statusCode?: number; /** * The Message to be returned in the response - * - * @public */ statusMessage: string; @@ -52,21 +44,16 @@ export interface ChaosHandlerOptions { * The percentage of randomness/chaos in the handler * * Setting the default value as 10% - * @public */ chaosPercentage: number; /** * The response body to be returned in the response - * - * @public */ responseBody?: any; /** * The response headers to be returned in the response - * - * @public */ headers?: FetchHeaders; } diff --git a/packages/http/fetch/src/middlewares/options/chaosStrategy.ts b/packages/http/fetch/src/middlewares/options/chaosStrategy.ts index 5450f86df..aeeac436c 100644 --- a/packages/http/fetch/src/middlewares/options/chaosStrategy.ts +++ b/packages/http/fetch/src/middlewares/options/chaosStrategy.ts @@ -11,7 +11,6 @@ /** * Strategy used for Testing Handler - * @enum */ export enum ChaosStrategy { MANUAL, diff --git a/packages/http/fetch/src/middlewares/options/headersInspectionOptions.ts b/packages/http/fetch/src/middlewares/options/headersInspectionOptions.ts index d913dc459..0cbbd43d1 100644 --- a/packages/http/fetch/src/middlewares/options/headersInspectionOptions.ts +++ b/packages/http/fetch/src/middlewares/options/headersInspectionOptions.ts @@ -29,8 +29,7 @@ export interface HeadersInspectionOptionsParams { } /** - * @class - * @implements RequestOption + * RequestOption * Options * Options to inspect headers */ @@ -38,7 +37,6 @@ export class HeadersInspectionOptions implements RequestOption { private readonly requestHeaders: Headers = new Headers(); private readonly responseHeaders = new Headers(); /** - * @public * @getter * Gets the request headers * @returns the request headers @@ -48,7 +46,6 @@ export class HeadersInspectionOptions implements RequestOption { } /** - * @public * @getter * Gets the response headers * @returns the response headers @@ -58,26 +55,21 @@ export class HeadersInspectionOptions implements RequestOption { } /** - * @public - * @member * @default false * whether to inspect request headers */ public inspectRequestHeaders: boolean; /** - * @public - * @member * @default false * whether to inspect response headers */ public inspectResponseHeaders: boolean; /** - * @public - * @constructor + * * To create an instance of HeadersInspectionOptions - * @param {HeadersInspectionOptionsParams} [options = {}] - The headers inspection options value + * @param [options] - The headers inspection options value * @returns An instance of HeadersInspectionOptions * @example const options = new HeadersInspectionOptions({ inspectRequestHeaders: true, inspectResponseHeaders: true }); */ diff --git a/packages/http/fetch/src/middlewares/options/parametersNameDecodingOptions.ts b/packages/http/fetch/src/middlewares/options/parametersNameDecodingOptions.ts index c41fd8366..b04630ca7 100644 --- a/packages/http/fetch/src/middlewares/options/parametersNameDecodingOptions.ts +++ b/packages/http/fetch/src/middlewares/options/parametersNameDecodingOptions.ts @@ -35,13 +35,13 @@ export interface ParametersNameDecodingHandlerOptionsParams { /** The ParametersNameDecodingOptions request class */ export class ParametersNameDecodingHandlerOptions implements RequestOption { /** - * @public + * * Whether to decode the specified characters in the request query parameters names */ public enable: boolean; /** - * @public + * * The characters to decode * @default [".", "-", "~", "$"] */ @@ -52,10 +52,9 @@ export class ParametersNameDecodingHandlerOptions implements RequestOption { } /** - * @public - * @constructor + * * To create an instance of ParametersNameDecodingHandlerOptions - * @param {ParametersNameDecodingHandlerOptionsParams} [options = {}] - The optional parameters + * @param [options] - The optional parameters * @returns An instance of ParametersNameDecodingHandlerOptions * @example ParametersNameDecodingHandlerOptions({ enable: true, charactersToDecode: [".", "-", "~", "$"] }); */ diff --git a/packages/http/fetch/src/middlewares/options/redirectHandlerOptions.ts b/packages/http/fetch/src/middlewares/options/redirectHandlerOptions.ts index 72dbb4de4..41791fa25 100644 --- a/packages/http/fetch/src/middlewares/options/redirectHandlerOptions.ts +++ b/packages/http/fetch/src/middlewares/options/redirectHandlerOptions.ts @@ -12,7 +12,7 @@ import type { RequestOption } from "@microsoft/kiota-abstractions"; /** - * @type + * * A type declaration for shouldRetry callback */ export type ShouldRedirect = (response: Response) => boolean; @@ -25,48 +25,44 @@ export interface RedirectHandlerOptionsParams { } /** - * @class - * @implements MiddlewareOptions + * MiddlewareOptions * A class representing RedirectHandlerOptions */ export class RedirectHandlerOptions implements RequestOption { /** - * @private * @static * A member holding default max redirects value */ - private static DEFAULT_MAX_REDIRECTS = 5; + private static readonly DEFAULT_MAX_REDIRECTS = 5; /** - * @private * @static * A member holding maximum max redirects value */ - private static MAX_MAX_REDIRECTS = 20; + private static readonly MAX_MAX_REDIRECTS = 20; /** - * @private + * * A member holding default shouldRedirect callback */ - private static defaultShouldRetry: ShouldRedirect = () => true; + private static readonly defaultShouldRetry: ShouldRedirect = () => true; /** - * @public + * * A member holding the max redirects value */ public maxRedirects: number; /** - * @public + * * A member holding the should redirect callback */ public shouldRedirect: ShouldRedirect; /** - * @public - * @constructor + * * To create an instance of RedirectHandlerOptions - * @param {RedirectHandlerOptionsParams} [options = {}] - The redirect handler options instance + * @param [options] - The redirect handler options instance * @returns An instance of RedirectHandlerOptions * @throws Error if maxRedirects is more than 20 or less than 0 * @example const options = new RedirectHandlerOptions({ maxRedirects: 5 }); diff --git a/packages/http/fetch/src/middlewares/options/retryHandlerOptions.ts b/packages/http/fetch/src/middlewares/options/retryHandlerOptions.ts index ab61c7fbe..dd3027347 100644 --- a/packages/http/fetch/src/middlewares/options/retryHandlerOptions.ts +++ b/packages/http/fetch/src/middlewares/options/retryHandlerOptions.ts @@ -14,7 +14,7 @@ import type { RequestOption } from "@microsoft/kiota-abstractions"; import type { FetchResponse } from "../../utils/fetchDefinitions"; /** - * @type + * * A type declaration for shouldRetry callback */ export type ShouldRetry = (delay: number, attempt: number, request: string, options: RequestInit | undefined, response: FetchResponse) => boolean; @@ -45,46 +45,41 @@ export interface RetryHandlerOptionsParams { } /** - * @class - * @implements RequestOption + * RequestOption * Options * Class for RetryHandlerOptions */ export class RetryHandlerOptions implements RequestOption { /** - * @private * @static * A member holding default delay value in seconds */ - private static DEFAULT_DELAY = 3; + private static readonly DEFAULT_DELAY = 3; /** - * @private * @static * A member holding default maxRetries value */ - private static DEFAULT_MAX_RETRIES = 3; + private static readonly DEFAULT_MAX_RETRIES = 3; /** - * @private * @static * A member holding maximum delay value in seconds */ - private static MAX_DELAY = 180; + private static readonly MAX_DELAY = 180; /** - * @private * @static * A member holding maximum maxRetries value */ - private static MAX_MAX_RETRIES = 10; + private static readonly MAX_MAX_RETRIES = 10; /** - * @private + * * A member holding default shouldRetry callback */ - private static defaultShouldRetry: ShouldRetry = () => true; + private static readonly defaultShouldRetry: ShouldRetry = () => true; /* * @public @@ -93,22 +88,21 @@ export class RetryHandlerOptions implements RequestOption { public delay: number; /** - * @public + * * A member holding maxRetries value */ public maxRetries: number; /** - * @public + * * A member holding shouldRetry callback */ public shouldRetry: ShouldRetry; /** - * @public - * @constructor + * * To create an instance of RetryHandlerOptions - * @param {RetryHandlerOptionsParams} options - The RetryHandlerOptionsParams object + * @param options - The RetryHandlerOptionsParams object * @returns An instance of RetryHandlerOptions * @example const options = new RetryHandlerOptions({ maxRetries: 4 }); */ @@ -131,10 +125,10 @@ export class RetryHandlerOptions implements RequestOption { } /** - * @private + * * Creates an error object with a message and name - * @param {string} message - The error message - * @param {string} name - The error name + * @param message - The error message + * @param name - The error name * @returns An error object */ private createError(message: string, name: string): Error { @@ -144,7 +138,7 @@ export class RetryHandlerOptions implements RequestOption { } /** - * @public + * * To get the maximum delay * @returns A maximum delay */ diff --git a/packages/http/fetch/src/middlewares/options/userAgentHandlerOptions.ts b/packages/http/fetch/src/middlewares/options/userAgentHandlerOptions.ts index 356071e7d..a78c09a15 100644 --- a/packages/http/fetch/src/middlewares/options/userAgentHandlerOptions.ts +++ b/packages/http/fetch/src/middlewares/options/userAgentHandlerOptions.ts @@ -21,19 +21,16 @@ export const UserAgentHandlerOptionsKey = "UserAgentHandlerOptionKey"; */ export interface UserAgentHandlerOptionsParams { /** - * @member * @default true * Specifies whether to add the user agent header to the request */ enable?: boolean; /** - * @member * @default "kiota-typescript" * The product name to be added to the user agent header */ productName?: string; /** - * @member * @default "1.0.0-preview.12" * The product version to be added to the user agent header */ @@ -51,7 +48,6 @@ export class UserAgentHandlerOptions implements RequestOption { public enable: boolean; /** - * @member * @default "kiota-typescript" * The product name to be added to the user agent header */ @@ -68,10 +64,9 @@ export class UserAgentHandlerOptions implements RequestOption { } /** - * @public - * @constructor + * * To create an instance of UserAgentHandlerOptions - * @param {UserAgentHandlerOptionsParams} [options = {}] - The options for the UserAgentHandler + * @param [options] - The options for the UserAgentHandler * @example const options = new UserAgentHandlerOptions({ enable: false }); */ public constructor(options: Partial = {}) { diff --git a/packages/http/fetch/src/middlewares/options/version.ts b/packages/http/fetch/src/middlewares/options/version.ts index 8c30fb8e8..21efd6a85 100644 --- a/packages/http/fetch/src/middlewares/options/version.ts +++ b/packages/http/fetch/src/middlewares/options/version.ts @@ -1,3 +1,9 @@ -// x-release-please-start-version +/** + * ------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. + * See License in the project root for license information. + * ------------------------------------------------------------------------------------------- + */ + export const libraryVersion = "1.0.0-preview.24"; // x-release-please-end diff --git a/packages/http/fetch/src/middlewares/parametersNameDecodingHandler.ts b/packages/http/fetch/src/middlewares/parametersNameDecodingHandler.ts index 1827fdc02..dd1c941b8 100644 --- a/packages/http/fetch/src/middlewares/parametersNameDecodingHandler.ts +++ b/packages/http/fetch/src/middlewares/parametersNameDecodingHandler.ts @@ -18,10 +18,9 @@ import { ParametersNameDecodingHandlerOptions, ParametersNameDecodingHandlerOpti export class ParametersNameDecodingHandler implements Middleware { /** - * @public - * @constructor + * * To create an instance of ParametersNameDecodingHandler - * @param {ParametersNameDecodingHandlerOptions} [options = new ParametersNameDecodingHandlerOptions()] - The parameters name decoding handler options value + * @param [options] - The parameters name decoding handler options value */ public constructor(private readonly options: ParametersNameDecodingHandlerOptions = new ParametersNameDecodingHandlerOptions()) { if (!options) { @@ -31,7 +30,6 @@ export class ParametersNameDecodingHandler implements Middleware { /** @inheritdoc */ next: Middleware | undefined; /** - * @public * @async * To execute the current middleware * @param {string} url - The url to be fetched @@ -41,7 +39,7 @@ export class ParametersNameDecodingHandler implements Middleware { */ public execute(url: string, requestInit: RequestInit, requestOptions?: Record): Promise { let currentOptions = this.options; - if (requestOptions && requestOptions[ParametersNameDecodingHandlerOptionsKey]) { + if (requestOptions?.[ParametersNameDecodingHandlerOptionsKey]) { currentOptions = requestOptions[ParametersNameDecodingHandlerOptionsKey] as ParametersNameDecodingHandlerOptions; } const obsOptions = getObservabilityOptionsFromRequest(requestOptions); @@ -59,7 +57,7 @@ export class ParametersNameDecodingHandler implements Middleware { } private decodeParameters(url: string, requestInit: RequestInit, currentOptions: ParametersNameDecodingHandlerOptions, requestOptions?: Record): Promise { let updatedUrl = url; - if (currentOptions && currentOptions.enable && url.indexOf("%") > -1 && currentOptions.charactersToDecode && currentOptions.charactersToDecode.length > 0) { + if (currentOptions && currentOptions.enable && url.includes("%") && currentOptions.charactersToDecode && currentOptions.charactersToDecode.length > 0) { currentOptions.charactersToDecode.forEach((character) => { updatedUrl = updatedUrl.replace(new RegExp(`%${character.charCodeAt(0).toString(16)}`, "gi"), character); }); diff --git a/packages/http/fetch/src/middlewares/redirectHandler.ts b/packages/http/fetch/src/middlewares/redirectHandler.ts index 61390773f..92e161657 100644 --- a/packages/http/fetch/src/middlewares/redirectHandler.ts +++ b/packages/http/fetch/src/middlewares/redirectHandler.ts @@ -18,18 +18,17 @@ import type { Middleware } from "./middleware"; import { RedirectHandlerOptionKey, RedirectHandlerOptions } from "./options/redirectHandlerOptions"; /** - * @class + * * Class - * @implements Middleware + * Middleware * Class representing RedirectHandler */ export class RedirectHandler implements Middleware { /** - * @private * @static * A member holding the array of redirect status codes */ - private static REDIRECT_STATUS_CODES: Set = new Set([ + private static readonly REDIRECT_STATUS_CODES = new Set([ 301, // Moved Permanently 302, // Found 303, // See Other @@ -38,53 +37,48 @@ export class RedirectHandler implements Middleware { ]); /** - * @private * @static * A member holding SeeOther status code */ - private static STATUS_CODE_SEE_OTHER = 303; + private static readonly STATUS_CODE_SEE_OTHER = 303; /** - * @private * @static * A member holding the name of the location header */ - private static LOCATION_HEADER = "Location"; + private static readonly LOCATION_HEADER = "Location"; /** - * @private * @static * A member representing the authorization header name */ - private static AUTHORIZATION_HEADER = "Authorization"; + private static readonly AUTHORIZATION_HEADER = "Authorization"; /** - * @private * @static * A member holding the manual redirect value */ - private static MANUAL_REDIRECT = "manual"; + private static readonly MANUAL_REDIRECT = "manual"; /** Next middleware to be executed*/ next: Middleware | undefined; /** * - * @public - * @constructor + * * To create an instance of RedirectHandler - * @param {RedirectHandlerOptions} [options = new RedirectHandlerOptions()] - The redirect handler options instance + * @param [options] - The redirect handler options instance * @returns An instance of RedirectHandler */ - public constructor(private options: RedirectHandlerOptions = new RedirectHandlerOptions()) { + public constructor(private readonly options: RedirectHandlerOptions = new RedirectHandlerOptions()) { if (!options) { throw new Error("The options parameter is required."); } } /** - * @private + * * To check whether the response has the redirect status code or not - * @param {Response} response - The response object + * @param response - The response object * @returns A boolean representing whether the response contains the redirect status code or not */ private isRedirect(response: FetchResponse): boolean { @@ -92,9 +86,9 @@ export class RedirectHandler implements Middleware { } /** - * @private + * * To check whether the response has location header or not - * @param {Response} response - The response object + * @param response - The response object * @returns A boolean representing the whether the response has location header or not */ private hasLocationHeader(response: FetchResponse): boolean { @@ -102,9 +96,9 @@ export class RedirectHandler implements Middleware { } /** - * @private + * * To get the redirect url from location header in response object - * @param {Response} response - The response object + * @param response - The response object * @returns A redirect url from location header */ private getLocationHeader(response: FetchResponse): string | null { @@ -112,20 +106,20 @@ export class RedirectHandler implements Middleware { } /** - * @private + * * To check whether the given url is a relative url or not - * @param {string} url - The url string value + * @param url - The url string value * @returns A boolean representing whether the given url is a relative url or not */ private isRelativeURL(url: string): boolean { - return url.indexOf("://") === -1; + return !url.includes("://"); } /** - * @private + * * To check whether the authorization header in the request should be dropped for consequent redirected requests - * @param {string} requestUrl - The request url value - * @param {string} redirectUrl - The redirect url value + * @param requestUrl - The request url value + * @param redirectUrl - The redirect url value * @returns A boolean representing whether the authorization header in the request should be dropped for consequent redirected requests */ private shouldDropAuthorizationHeader(requestUrl: string, redirectUrl: string): boolean { @@ -144,10 +138,11 @@ export class RedirectHandler implements Middleware { } /** - * @private * @async * To execute the next middleware and to handle in case of redirect response returned by the server * @param {Context} context - The context object + * @param fetchRequestInit + * @param url * @param {number} redirectCount - The redirect count value * @param {Record} [requestOptions = {}] - The request options * @param {RedirectHandlerOptions} currentOptions - The redirect handler options instance @@ -162,7 +157,7 @@ export class RedirectHandler implements Middleware { if (redirectCount < currentOptions.maxRedirects && this.isRedirect(response) && this.hasLocationHeader(response) && currentOptions.shouldRedirect(response)) { ++redirectCount; if (response.status === RedirectHandler.STATUS_CODE_SEE_OTHER) { - fetchRequestInit["method"] = HttpMethod.GET; + fetchRequestInit.method = HttpMethod.GET; delete fetchRequestInit.body; } else { const redirectUrl = this.getLocationHeader(response); @@ -191,16 +186,18 @@ export class RedirectHandler implements Middleware { } /** - * @public * @async + * @param url + * @param requestInit + * @param requestOptions * To execute the current middleware - * @param {Context} context - The context object of the request + * @param context - The context object of the request * @returns A Promise that resolves to nothing */ public execute(url: string, requestInit: RequestInit, requestOptions?: Record): Promise { const redirectCount = 0; let currentOptions = this.options; - if (requestOptions && requestOptions[RedirectHandlerOptionKey]) { + if (requestOptions?.[RedirectHandlerOptionKey]) { currentOptions = requestOptions[RedirectHandlerOptionKey] as RedirectHandlerOptions; } (requestInit as FetchRequestInit).redirect = RedirectHandler.MANUAL_REDIRECT; diff --git a/packages/http/fetch/src/middlewares/retryHandler.ts b/packages/http/fetch/src/middlewares/retryHandler.ts index 9bad5f0e4..7932ee496 100644 --- a/packages/http/fetch/src/middlewares/retryHandler.ts +++ b/packages/http/fetch/src/middlewares/retryHandler.ts @@ -19,50 +19,45 @@ import { type Middleware } from "./middleware"; import { RetryHandlerOptionKey, RetryHandlerOptions } from "./options/retryHandlerOptions"; /** - * @class - * @implements Middleware + * Middleware * Class for RetryHandler */ export class RetryHandler implements Middleware { /** - * @private * @static * A list of status codes that needs to be retried */ - private static RETRY_STATUS_CODES: Set = new Set([ + private static readonly RETRY_STATUS_CODES = new Set([ 429, // Too many requests 503, // Service unavailable 504, // Gateway timeout ]); /** - * @private * @static * A member holding the name of retry attempt header */ - private static RETRY_ATTEMPT_HEADER = "Retry-Attempt"; + private static readonly RETRY_ATTEMPT_HEADER = "Retry-Attempt"; /** - * @private * @static * A member holding the name of retry after header */ - private static RETRY_AFTER_HEADER = "Retry-After"; + private static readonly RETRY_AFTER_HEADER = "Retry-After"; /** - * @private + * * The next middleware in the middleware chain */ next: Middleware | undefined; /** - * @public - * @constructor + * * To create an instance of RetryHandler - * @param {RetryHandlerOptions} [options = new RetryHandlerOptions()] - The retry handler options value + * @param [options] - The retry handler options value * @returns An instance of RetryHandler */ - public constructor(private options: RetryHandlerOptions = new RetryHandlerOptions()) { + public constructor(private readonly options: RetryHandlerOptions = new RetryHandlerOptions()) { if (!options) { throw new Error("The options parameter is required."); } @@ -70,9 +65,9 @@ export class RetryHandler implements Middleware { /** * - * @private + * * To check whether the response has the retry status code - * @param {Response} response - The response object + * @param response - The response object * @returns Whether the response has retry status code or not */ private isRetry(response: FetchResponse): boolean { @@ -80,9 +75,9 @@ export class RetryHandler implements Middleware { } /** - * @private + * * To check whether the payload is buffered or not - * @param {RequestInit} options - The options of a request + * @param options - The options of a request * @returns Whether the payload is buffered or not */ private isBuffered(options: FetchRequestInit): boolean { @@ -98,11 +93,11 @@ export class RetryHandler implements Middleware { } /** - * @private + * * To get the delay for a retry - * @param {Response} response - The response object - * @param {number} retryAttempts - The current attempt count - * @param {number} delay - The delay value in seconds + * @param response - The response object + * @param retryAttempts - The current attempt count + * @param delay - The delay value in seconds * @returns A delay for a retry */ private getDelay(response: FetchResponse, retryAttempts: number, delay: number): number { @@ -125,9 +120,9 @@ export class RetryHandler implements Middleware { } /** - * @private + * * To get an exponential back off value - * @param {number} attempts - The current attempt count + * @param attempts - The current attempt count * @returns An exponential back off value */ private getExponentialBackOffTime(attempts: number): number { @@ -135,7 +130,6 @@ export class RetryHandler implements Middleware { } /** - * @private * @async * To add delay for the execution * @param {number} delaySeconds - The delay value in seconds @@ -147,10 +141,11 @@ export class RetryHandler implements Middleware { } /** - * @private * @async * To execute the middleware with retries * @param {Context} context - The context object + * @param fetchRequestInit + * @param url * @param {number} retryAttempts - The current attempt count * @param {Record} [requestOptions = {}] - The request options * @param {RetryHandlerOptions} currentOptions - The retry middleware options instance @@ -192,17 +187,19 @@ export class RetryHandler implements Middleware { } /** - * @public * @async + * @param url + * @param requestInit + * @param requestOptions * To execute the current middleware - * @param {Context} context - The context object of the request + * @param context - The context object of the request * @returns A Promise that resolves to nothing */ public execute(url: string, requestInit: RequestInit, requestOptions?: Record): Promise { const retryAttempts = 0; let currentOptions = this.options; - if (requestOptions && requestOptions[RetryHandlerOptionKey]) { + if (requestOptions?.[RetryHandlerOptionKey]) { currentOptions = requestOptions[RetryHandlerOptionKey] as RetryHandlerOptions; } const obsOptions = getObservabilityOptionsFromRequest(requestOptions); diff --git a/packages/http/fetch/src/middlewares/telemetryHandler.ts b/packages/http/fetch/src/middlewares/telemetryHandler.ts index 1a6e1fd85..23309aaac 100644 --- a/packages/http/fetch/src/middlewares/telemetryHandler.ts +++ b/packages/http/fetch/src/middlewares/telemetryHandler.ts @@ -11,12 +11,12 @@ import type { TelemetryHandlerOptions } from "./options/telemetryHandlerOptions" export const TelemetryHandlerOptionsKey = "TelemetryHandlerOptionsKey"; export class TelemetryHandler implements Middleware { - constructor(private telemetryHandlerOptions: TelemetryHandlerOptions) {} + constructor(private readonly telemetryHandlerOptions: TelemetryHandlerOptions) {} next: Middleware | undefined; execute(url: string, requestInit: RequestInit, requestOptions?: Record): Promise { if (this.telemetryHandlerOptions && this.telemetryHandlerOptions.telemetryConfigurator) { this.telemetryHandlerOptions.telemetryConfigurator(url, requestInit, requestOptions, this.telemetryHandlerOptions.telemetryInformation); - } else if (requestOptions && requestOptions[TelemetryHandlerOptionsKey]) { + } else if (requestOptions?.[TelemetryHandlerOptionsKey]) { (requestOptions[TelemetryHandlerOptionsKey] as TelemetryHandlerOptions).telemetryConfigurator(url, requestInit, requestOptions); } if (!this.next) { diff --git a/packages/http/fetch/src/middlewares/urlReplaceHandler.ts b/packages/http/fetch/src/middlewares/urlReplaceHandler.ts index f16ba7398..b5acd8763 100644 --- a/packages/http/fetch/src/middlewares/urlReplaceHandler.ts +++ b/packages/http/fetch/src/middlewares/urlReplaceHandler.ts @@ -17,10 +17,9 @@ import { UrlReplaceHandlerOptions, UrlReplaceHandlerOptionsKey } from "./options */ export class UrlReplaceHandler implements Middleware { /** - * @public - * @constructor + * * Creates a new instance of the UrlReplaceHandler class - * @param {UrlReplaceHandlerOptions} handlerOptions The options for the url replace handler. + * @param handlerOptions The options for the url replace handler. * @returns An instance of the UrlReplaceHandler class */ public constructor(private readonly handlerOptions: UrlReplaceHandlerOptions = new UrlReplaceHandlerOptions()) { @@ -32,9 +31,9 @@ export class UrlReplaceHandler implements Middleware { /** * @inheritdoc */ - public execute(url: string, requestInit: RequestInit, requestOptions?: Record | undefined): Promise { + public execute(url: string, requestInit: RequestInit, requestOptions?: Record ): Promise { let currentOptions = this.handlerOptions; - if (requestOptions && requestOptions[UrlReplaceHandlerOptionsKey]) { + if (requestOptions?.[UrlReplaceHandlerOptionsKey]) { currentOptions = requestOptions[UrlReplaceHandlerOptionsKey] as UrlReplaceHandlerOptions; } const obsOptions = getObservabilityOptionsFromRequest(requestOptions); @@ -50,7 +49,7 @@ export class UrlReplaceHandler implements Middleware { } return this.replaceTokensInUrl(currentOptions, url, requestInit, requestOptions); } - private replaceTokensInUrl(options: UrlReplaceHandlerOptions, url: string, requestInit: RequestInit, requestOptions?: Record | undefined): Promise { + private replaceTokensInUrl(options: UrlReplaceHandlerOptions, url: string, requestInit: RequestInit, requestOptions?: Record ): Promise { if (options.enabled) { Object.keys(options.urlReplacements).forEach((replacementKey) => { url = url.replace(replacementKey, options.urlReplacements[replacementKey]); diff --git a/packages/http/fetch/src/middlewares/userAgentHandler.ts b/packages/http/fetch/src/middlewares/userAgentHandler.ts index ef2c0eda6..a3156daea 100644 --- a/packages/http/fetch/src/middlewares/userAgentHandler.ts +++ b/packages/http/fetch/src/middlewares/userAgentHandler.ts @@ -21,16 +21,16 @@ import { UserAgentHandlerOptions, UserAgentHandlerOptionsKey } from "./options/u const USER_AGENT_HEADER_KEY = "User-Agent"; export class UserAgentHandler implements Middleware { /** - * @public - * @constructor + * @param _options + * * To create an instance of UserAgentHandler - * @param {UserAgentHandlerOption} [options = new UserAgentHandlerOption()] - The options for the middleware + * @param [options] - The options for the middleware */ public constructor(private readonly _options: UserAgentHandlerOptions = new UserAgentHandlerOptions()) {} /** @inheritdoc */ next: Middleware | undefined; /** @inheritdoc */ - public execute(url: string, requestInit: RequestInit, requestOptions?: Record | undefined): Promise { + public execute(url: string, requestInit: RequestInit, requestOptions?: Record ): Promise { const obsOptions = getObservabilityOptionsFromRequest(requestOptions); if (obsOptions) { return trace.getTracer(obsOptions.getTracerInstrumentationName()).startActiveSpan("userAgentHandler - execute", (span) => { @@ -45,19 +45,19 @@ export class UserAgentHandler implements Middleware { return this.addValue(url, requestInit, requestOptions); } } - private async addValue(url: string, requestInit: RequestInit, requestOptions?: Record | undefined): Promise { + private async addValue(url: string, requestInit: RequestInit, requestOptions?: Record ): Promise { let currentOptions = this._options; - if (requestOptions && requestOptions[UserAgentHandlerOptionsKey]) { + if (requestOptions?.[UserAgentHandlerOptionsKey]) { currentOptions = requestOptions[UserAgentHandlerOptionsKey] as UserAgentHandlerOptions; } if (currentOptions.enable) { const additionalValue = `${currentOptions.productName}/${currentOptions.productVersion}`; const currentValue = getRequestHeader(requestInit as FetchRequestInit, USER_AGENT_HEADER_KEY); - if (!currentValue || currentValue.indexOf(additionalValue) === -1) { + if (!currentValue?.includes(additionalValue)) { appendRequestHeader(requestInit as FetchRequestInit, USER_AGENT_HEADER_KEY, additionalValue, " "); } } - const response = await this.next?.execute(url, requestInit as RequestInit, requestOptions); + const response = await this.next?.execute(url, requestInit, requestOptions); if (!response) throw new Error("No response returned by the next middleware"); return response; } diff --git a/packages/http/fetch/src/observabilityOptions.ts b/packages/http/fetch/src/observabilityOptions.ts index c53c57dea..e2c216a67 100644 --- a/packages/http/fetch/src/observabilityOptions.ts +++ b/packages/http/fetch/src/observabilityOptions.ts @@ -1,3 +1,9 @@ +/** + * ------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License. + * See License in the project root for license information. + * ------------------------------------------------------------------------------------------- + */ import type { RequestOption } from "@microsoft/kiota-abstractions"; /** Holds the tracing, metrics and logging configuration for the request adapter */ @@ -28,6 +34,10 @@ export class ObservabilityOptionsImpl implements ObservabilityOptions, Observabi } } +/** + * + * @param requestOptions + */ export function getObservabilityOptionsFromRequest(requestOptions?: Record): ObservabilityOptionsInternal | undefined { if (requestOptions) { const observabilityOptions = requestOptions[ObservabilityOptionKey]; diff --git a/packages/serialization/form/src/formParseNode.ts b/packages/serialization/form/src/formParseNode.ts index c9229ec8f..35140754a 100644 --- a/packages/serialization/form/src/formParseNode.ts +++ b/packages/serialization/form/src/formParseNode.ts @@ -11,6 +11,7 @@ export class FormParseNode implements ParseNode { private readonly _fields: Record = {}; /** * + * @param _rawString */ constructor(private readonly _rawString: string) { if (!_rawString) { @@ -29,7 +30,7 @@ export class FormParseNode implements ParseNode { } }); } - private normalizeKey = (key: string): string => decodeURIComponent(key).trim(); + private readonly normalizeKey = (key: string): string => decodeURIComponent(key).trim(); public getByteArrayValue(): ArrayBuffer | undefined { throw new Error("serialization of byt arrays is not supported with URI encoding"); } @@ -113,7 +114,7 @@ export class FormParseNode implements ParseNode { } return getEnumValueFromStringValue(rawValue, type as Record) as T; }; - private assignFieldValues = (model: T, parsableFactory: ParsableFactory): void => { + private readonly assignFieldValues = (model: T, parsableFactory: ParsableFactory): void => { const fields = parsableFactory(this)(model); Object.entries(this._fields) .filter((x) => !/^null$/i.test(x[1])) diff --git a/packages/serialization/form/src/formSerializationWriter.ts b/packages/serialization/form/src/formSerializationWriter.ts index 3d85508fd..51945d757 100644 --- a/packages/serialization/form/src/formSerializationWriter.ts +++ b/packages/serialization/form/src/formSerializationWriter.ts @@ -12,14 +12,14 @@ import type { Guid } from "guid-typescript"; export class FormSerializationWriter implements SerializationWriter { public writeByteArrayValue( // eslint-disable-next-line @typescript-eslint/no-unused-vars - key?: string | undefined, + key?: string , // eslint-disable-next-line @typescript-eslint/no-unused-vars - value?: ArrayBuffer | null | undefined, + value?: ArrayBuffer | null , ): void { throw new Error("serialization of byt arrays is not supported with URI encoding"); } private readonly writer: string[] = []; - private static propertySeparator = `&`; + private static readonly propertySeparator = `&`; private depth = -1; public onBeforeObjectSerialization: ((value: Parsable) => void) | undefined; public onAfterObjectSerialization: ((value: Parsable) => void) | undefined; @@ -34,10 +34,10 @@ export class FormSerializationWriter implements SerializationWriter { this.writer.push(FormSerializationWriter.propertySeparator); } }; - private writePropertyName = (key: string): void => { + private readonly writePropertyName = (key: string): void => { this.writer.push(encodeURIComponent(key)); }; - private shouldWriteValueOrNull = (key?: string, value?: T | null): boolean => { + private readonly shouldWriteValueOrNull = (key?: string, value?: T | null): boolean => { if (value === null) { this.writeNullValue(key); return false; @@ -90,9 +90,9 @@ export class FormSerializationWriter implements SerializationWriter { } }; public writeCollectionOfObjectValues = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars + _key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + _values?: T[] | null, ): void => { throw new Error(`serialization of collections is not supported with URI encoding`); @@ -115,13 +115,13 @@ export class FormSerializationWriter implements SerializationWriter { serializerMethod(this, value); this.onAfterObjectSerialization && this.onAfterObjectSerialization(value); if (this.writer.length > 0 && this.writer[this.writer.length - 1] === FormSerializationWriter.propertySeparator) { - //removing the last separator + // removing the last separator this.writer.pop(); } key && this.writer.push(FormSerializationWriter.propertySeparator); } }; - public writeEnumValue = (key?: string | undefined, ...values: (T | null | undefined)[]): void => { + public writeEnumValue = (key?: string , ...values: (T | null | undefined)[]): void => { if (values.length > 0) { const rawValues = values.filter((x) => x !== undefined).map((x) => `${x}`); if (rawValues.length > 0) { @@ -136,7 +136,7 @@ export class FormSerializationWriter implements SerializationWriter { return this.convertStringToArrayBuffer(this.writer.join(``)); }; - private convertStringToArrayBuffer = (str: string): ArrayBuffer => { + private readonly convertStringToArrayBuffer = (str: string): ArrayBuffer => { const encoder = new TextEncoder(); const encodedString = encoder.encode(str); return encodedString.buffer; @@ -150,7 +150,7 @@ export class FormSerializationWriter implements SerializationWriter { } }; - private writeAnyValue = (key?: string | undefined, value?: unknown | null | undefined): void => { + private readonly writeAnyValue = (key?: string , value?: unknown | null ): void => { if (value === null) { return this.writeNullValue(key); } diff --git a/packages/serialization/json/src/jsonParseNode.ts b/packages/serialization/json/src/jsonParseNode.ts index 8550dab21..7df131425 100644 --- a/packages/serialization/json/src/jsonParseNode.ts +++ b/packages/serialization/json/src/jsonParseNode.ts @@ -72,7 +72,7 @@ export class JsonParseNode implements ParseNode { value = createUntypedNumber(this._jsonNode as number) as unknown as T; } else if (Array.isArray(this._jsonNode)) { const nodes: UntypedNode[] = []; - // eslint-disable-next-line @typescript-eslint/no-unused-vars + this._jsonNode.forEach((x) => { nodes.push(new JsonParseNode(x).getObjectValue(createUntypedNodeFromDiscriminatorValue)); }); @@ -100,7 +100,7 @@ export class JsonParseNode implements ParseNode { return value; }; - private assignFieldValues = (model: T, parsableFactory: ParsableFactory): void => { + private readonly assignFieldValues = (model: T, parsableFactory: ParsableFactory): void => { const fields = parsableFactory(this)(model); if (!this._jsonNode) return; Object.entries(this._jsonNode).forEach(([k, v]) => { diff --git a/packages/serialization/json/src/jsonSerializationWriter.ts b/packages/serialization/json/src/jsonSerializationWriter.ts index 299ca29be..a8f51a7ad 100644 --- a/packages/serialization/json/src/jsonSerializationWriter.ts +++ b/packages/serialization/json/src/jsonSerializationWriter.ts @@ -10,7 +10,7 @@ import { DateOnly, Duration, isUntypedNode, type ModelSerializerFunction, type P import type { Guid } from "guid-typescript"; export class JsonSerializationWriter implements SerializationWriter { - public writeByteArrayValue(key?: string | undefined, value?: ArrayBuffer | undefined): void { + public writeByteArrayValue(key?: string , value?: ArrayBuffer ): void { if (!value) { throw new Error("value cannot be undefined"); } @@ -18,8 +18,8 @@ export class JsonSerializationWriter implements SerializationWriter { this.writeStringValue(key, b64); } private readonly writer: string[] = []; - private static propertySeparator = `,`; - private shouldWriteValueOrNull = (key?: string, value?: T | null): boolean => { + private static readonly propertySeparator = `,`; + private readonly shouldWriteValueOrNull = (key?: string, value?: T | null): boolean => { if (value === null) { this.writeNullValue(key); return false; @@ -40,7 +40,7 @@ export class JsonSerializationWriter implements SerializationWriter { key && this.writer.push(JsonSerializationWriter.propertySeparator); } }; - private writePropertyName = (key: string): void => { + private readonly writePropertyName = (key: string): void => { this.writer.push(`"${key}":`); }; public writeBooleanValue = (key?: string, value?: boolean | null): void => { @@ -114,7 +114,7 @@ export class JsonSerializationWriter implements SerializationWriter { this.writer.push(JsonSerializationWriter.propertySeparator); }); if (values.length > 0) { - //removing the last separator + // removing the last separator this.writer.pop(); } this.endArray(); @@ -209,7 +209,7 @@ export class JsonSerializationWriter implements SerializationWriter { } }; - public writeEnumValue = (key?: string | undefined, ...values: (T | undefined | null)[]): void => { + public writeEnumValue = (key?: string , ...values: (T | undefined | null)[]): void => { if (values.length > 0) { const rawValues = values.filter((x) => x !== undefined).map((x) => `${x}`); if (rawValues.length > 0) { @@ -240,13 +240,13 @@ export class JsonSerializationWriter implements SerializationWriter { } }; - private readonly writeNonParsableObjectValue = (key?: string | undefined, value?: object | undefined) => { + private readonly writeNonParsableObjectValue = (key?: string , value?: object ) => { if (key) { this.writePropertyName(key); } this.writer.push(JSON.stringify(value), JsonSerializationWriter.propertySeparator); }; - private readonly writeAnyValue = (key?: string | undefined, value?: unknown | null | undefined): void => { + private readonly writeAnyValue = (key?: string , value?: unknown | null ): void => { if (value === undefined) { return; } diff --git a/packages/serialization/multipart/src/multipartSerializationWriter.ts b/packages/serialization/multipart/src/multipartSerializationWriter.ts index 133c2734f..ad341d086 100644 --- a/packages/serialization/multipart/src/multipartSerializationWriter.ts +++ b/packages/serialization/multipart/src/multipartSerializationWriter.ts @@ -12,10 +12,10 @@ import type { Guid } from "guid-typescript"; /** Serialization writer for multipart/form-data */ export class MultipartSerializationWriter implements SerializationWriter { public writeByteArrayValue( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - key?: string | undefined, - // eslint-disable-next-line @typescript-eslint/no-unused-vars - value?: ArrayBuffer | undefined, + + key?: string , + + value?: ArrayBuffer , ): void { if (!value) { throw new Error("value cannot be undefined"); @@ -41,7 +41,7 @@ export class MultipartSerializationWriter implements SerializationWriter { this.writeRawStringValue(value); } }; - private writeRawStringValue = (value?: string | null): void => { + private readonly writeRawStringValue = (value?: string | null): void => { if (value) { this.writeByteArrayValue(undefined, new TextEncoder().encode(value).buffer); } @@ -79,17 +79,17 @@ export class MultipartSerializationWriter implements SerializationWriter { throw new Error(`serialization of null values is not supported with multipart`); }; public writeCollectionOfPrimitiveValues = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars + _key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + _values?: T[] | null, ): void => { throw new Error(`serialization of collections is not supported with multipart`); }; public writeCollectionOfObjectValues = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars + _key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + _values?: T[] | null, ): void => { throw new Error(`serialization of collections is not supported with multipart`); @@ -111,7 +111,7 @@ export class MultipartSerializationWriter implements SerializationWriter { }; public writeEnumValue = ( // eslint-disable-next-line @typescript-eslint/no-unused-vars - key?: string | undefined, + key?: string , // eslint-disable-next-line @typescript-eslint/no-unused-vars ...values: (T | null | undefined)[] ): void => { diff --git a/packages/serialization/text/src/textParseNode.ts b/packages/serialization/text/src/textParseNode.ts index 8bfa6c0a3..ca822283b 100644 --- a/packages/serialization/text/src/textParseNode.ts +++ b/packages/serialization/text/src/textParseNode.ts @@ -8,12 +8,13 @@ import { DateOnly, Duration, type Parsable, type ParsableFactory, parseGuidString, type ParseNode, TimeOnly, inNodeEnv, getEnumValueFromStringValue } from "@microsoft/kiota-abstractions"; export class TextParseNode implements ParseNode { - private static noStructuredDataMessage = "text does not support structured data"; + private static readonly noStructuredDataMessage = "text does not support structured data"; /** * + * @param text */ constructor(private readonly text: string) { - if (this.text && this.text.length > 1 && this.text.charAt(0) === '"' && this.text.charAt(this.text.length - 1) === '"') { + if (this.text && this.text.length > 1 && this.text.startsWith('"') && this.text.endsWith('"')) { this.text = this.text.substring(1, this.text.length - 2); } } @@ -59,7 +60,7 @@ export class TextParseNode implements ParseNode { throw new Error(TextParseNode.noStructuredDataMessage); } - // eslint-disable-next-line @typescript-eslint/no-unused-vars + public getCollectionOfEnumValues = (type: any): T[] => { throw new Error(TextParseNode.noStructuredDataMessage); }; diff --git a/packages/serialization/text/src/textSerializationWriter.ts b/packages/serialization/text/src/textSerializationWriter.ts index 11dd51398..979c0034a 100644 --- a/packages/serialization/text/src/textSerializationWriter.ts +++ b/packages/serialization/text/src/textSerializationWriter.ts @@ -10,7 +10,7 @@ import { inNodeEnv, type DateOnly, type Duration, type ModelSerializerFunction, import type { Guid } from "guid-typescript"; export class TextSerializationWriter implements SerializationWriter { - public writeByteArrayValue(key?: string | undefined, value?: ArrayBuffer | null | undefined): void { + public writeByteArrayValue(key?: string , value?: ArrayBuffer | null ): void { if (!value) { throw new Error("value cannot be undefined"); } @@ -18,7 +18,7 @@ export class TextSerializationWriter implements SerializationWriter { this.writeStringValue(key, b64); } - private static noStructuredDataMessage = "text does not support structured data"; + private static readonly noStructuredDataMessage = "text does not support structured data"; private readonly writer: string[] = []; public onBeforeObjectSerialization: ((value: Parsable) => void) | undefined; public onAfterObjectSerialization: ((value: Parsable) => void) | undefined; @@ -99,32 +99,32 @@ export class TextSerializationWriter implements SerializationWriter { this.writeStringValue(key, `null`); }; public writeCollectionOfPrimitiveValues = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars + key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + values?: T[] | null, ): void => { throw new Error(TextSerializationWriter.noStructuredDataMessage); }; public writeCollectionOfObjectValues = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars + key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + values?: T[] | null, serializerMethod?: ModelSerializerFunction, ): void => { throw new Error(TextSerializationWriter.noStructuredDataMessage); }; public writeObjectValue = ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars + key?: string, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + value?: T | null, serializerMethod?: ModelSerializerFunction, ): void => { throw new Error(TextSerializationWriter.noStructuredDataMessage); }; - public writeEnumValue = (key?: string | undefined, ...values: (T | null | undefined)[]): void => { + public writeEnumValue = (key?: string , ...values: (T | null | undefined)[]): void => { if (values.length > 0) { const rawValues = values.filter((x) => x !== undefined).map((x) => `${x}`); if (rawValues.length > 0) { @@ -139,13 +139,13 @@ export class TextSerializationWriter implements SerializationWriter { return this.convertStringToArrayBuffer(this.writer.join(``)); }; - private convertStringToArrayBuffer = (str: string): ArrayBuffer => { + private readonly convertStringToArrayBuffer = (str: string): ArrayBuffer => { const encoder = new TextEncoder(); const encodedString = encoder.encode(str); return encodedString.buffer; }; - // eslint-disable-next-line @typescript-eslint/no-unused-vars + public writeAdditionalData = (value: Record | undefined): void => { throw new Error(TextSerializationWriter.noStructuredDataMessage); };