From b12768f63aa712f0d2629c884af954d716ede826 Mon Sep 17 00:00:00 2001 From: Peter Hale Date: Tue, 26 Mar 2024 10:44:59 -0600 Subject: [PATCH] chore: add docs and remove unneeded type --- .git2gus/config.json | 2 +- src/services/serviceProvider.ts | 102 ++++++++++++++++++++++++-------- src/types/index.ts | 23 ------- 3 files changed, 77 insertions(+), 50 deletions(-) diff --git a/.git2gus/config.json b/.git2gus/config.json index 1ac8331..77732f4 100644 --- a/.git2gus/config.json +++ b/.git2gus/config.json @@ -7,7 +7,7 @@ "type:feedback": "", "type:duplicate": "" }, - "defaultBuild": "offcore.tooling.56", + "defaultBuild": "offcore.tooling.60", "hideWorkItemUrl": "true", "statusWhenClosed": "CLOSED" } diff --git a/src/services/serviceProvider.ts b/src/services/serviceProvider.ts index 7181043..afaabdc 100644 --- a/src/services/serviceProvider.ts +++ b/src/services/serviceProvider.ts @@ -7,12 +7,25 @@ import { ServiceParams, ServiceReturnType, ServiceType } from '../types'; import * as vscode from 'vscode'; +/** + * The ServiceProvider class is a utility class that provides services of different types. + * Each service type can have multiple instances, identified by their instance names. + * @class + */ export class ServiceProvider { private static serviceMap: Map< ServiceType, Map> > = new Map(); + /** + * Retrieves a service instance of the specified type and instance name. + * If the service instance does not exist, it will be created. + * @param type - The type of the service. + * @param instanceName - The name of the service instance. + * @param rest - Additional parameters for the service. + * @returns The service instance. + */ static async getService( type: T, instanceName: string, @@ -41,10 +54,21 @@ export class ServiceProvider { return serviceInstance; } + /** + * Checks if a service of the specified type exists. + * @param type - The type of the service. + * @returns True if the service exists, false otherwise. + */ static hasService(type: T): boolean { return ServiceProvider.serviceMap.has(type); } + /** + * Checks if a service instance of the specified type and instance name exists. + * @param type - The type of the service. + * @param instanceName - The name of the service instance. + * @returns True if the service instance exists, false otherwise. + */ static has(type: T, instanceName: string): boolean { if (ServiceProvider.serviceMap.has(type)) { const serviceInstances = ServiceProvider.serviceMap.get(type); @@ -53,6 +77,58 @@ export class ServiceProvider { return false; } + /** + * Removes all instances of a service of the specified type. + * @param type - The type of the service. + */ + static clear(type: T): void { + if (ServiceProvider.serviceMap.has(type)) { + ServiceProvider.serviceMap.get(type)?.clear(); + } + } + + /** + * Removes a service instance of the specified type and instance name. + * @param type - The type of the service. + * @param instanceName - The name of the service instance. + */ + static remove(type: T, instanceName: string): void { + if (ServiceProvider.serviceMap.has(type)) { + const serviceInstances = ServiceProvider.serviceMap.get(type); + + if (serviceInstances?.has(instanceName)) { + serviceInstances.delete(instanceName); + } + } + } + + /** + * Removes a service of the specified type, including all its instances. + * @param type - The type of the service. + */ + static removeService(type: T): void { + if (ServiceProvider.serviceMap.has(type)) { + ServiceProvider.serviceMap.delete(type); + } + } + + /** + * Removes all services, including all their instances. + */ + static clearAllServices(): void { + ServiceProvider.serviceMap.clear(); + } + + /** + * Materializes a service instance of the specified type and instance name. + * If the service instance does not exist, it will be created. + * @private + * @param type - The type of the service. + * @param instanceName - The name of the service instance. + * @param rest - Additional parameters for the service. + * @returns The service instance. + * @throws {Error} If the service type is unsupported or if the service instance could not be created. + */ private static async materializeService( type: T, instanceName: string, @@ -85,30 +161,4 @@ export class ServiceProvider { return serviceInstance; } - - static clear(type: T): void { - if (ServiceProvider.serviceMap.has(type)) { - ServiceProvider.serviceMap.get(type)?.clear(); - } - } - - static remove(type: T, instanceName: string): void { - if (ServiceProvider.serviceMap.has(type)) { - const serviceInstances = ServiceProvider.serviceMap.get(type); - - if (serviceInstances?.has(instanceName)) { - serviceInstances.delete(instanceName); - } - } - } - - static removeService(type: T): void { - if (ServiceProvider.serviceMap.has(type)) { - ServiceProvider.serviceMap.delete(type); - } - } - - static clearAllServices(): void { - ServiceProvider.serviceMap.clear(); - } } diff --git a/src/types/index.ts b/src/types/index.ts index b88183a..c0f1edb 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -5,29 +5,6 @@ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause */ -/** - * The common set of `Logger` options. - */ -export interface LoggerOptions { - /** - * The logger name. - */ - name: string; - - /** - * The desired log level. - */ - level?: LoggerLevelValue; - - /** - * Create a logger with the fields set - */ - fields?: Fields; - - /** log to memory instead of to a file. Intended for Unit Testing */ - useMemoryLogger?: boolean; -} - /** * Standard `Logger` levels. *