Skip to content

Commit

Permalink
document Kiota functions with detailed JSDoc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
thewahome committed Feb 12, 2025
1 parent 98cdcd2 commit 18e0f29
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 4 deletions.
7 changes: 7 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/generateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ interface ClientGenerationOptions {
workingDirectory: string;
}

/**
* Generates a client based on the provided client generation options.
*
* @param {ClientGenerationOptions} clientGenerationOptions - The options for generating the client.
* @returns {Promise<KiotaResult | undefined>} A promise that resolves to a KiotaResult if successful, or undefined if not.
* @throws {Error} If an error occurs during the client generation process.
*/
export async function generateClient(clientGenerationOptions: ClientGenerationOptions): Promise<KiotaResult | undefined> {
const result = await connectToKiota<KiotaLogEntry[]>(async (connection) => {
const request = new rpc.RequestType1<GenerationConfiguration, KiotaLogEntry[], void>(
Expand Down
10 changes: 10 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/generatePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ interface PluginGenerationOptions {
workingDirectory: string;
}

/**
* Generates a plugin based on the provided options.
*
* @param {PluginGenerationOptions} pluginGenerationOptions - The options for generating the plugin.
* @returns {Promise<KiotaResult | undefined>} A promise that resolves to a KiotaResult if successful, or undefined if not.
* @throws {Error} If an error occurs during the generation process.
*
* The function connects to Kiota and sends a request to generate a plugin using the provided options.
* It handles the response and checks for success, returning the result or throwing an error if one occurs.
*/
export async function generatePlugin(pluginGenerationOptions: PluginGenerationOptions
): Promise<KiotaResult | undefined> {
const result = await connectToKiota<KiotaLogEntry[]>(async (connection) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import * as rpc from "vscode-jsonrpc/node";

import connectToKiota from '../connect';

/**
* Retrieves the version of Kiota by connecting to the Kiota service.
*
* @returns {Promise<string | undefined>} A promise that resolves to the Kiota version string if available, otherwise undefined.
* @throws {Error} If an error occurs while connecting to the Kiota service or retrieving the version.
*/
export async function getKiotaVersion(): Promise<string | undefined> {

const result = await connectToKiota<string>(async (connection) => {
Expand Down
10 changes: 10 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/getManifestDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ interface ManifestOptions {
apiIdentifier?: string;
}

/**
* Retrieves the manifest details for a given API.
*
* @param {ManifestOptions} options - The options for retrieving the manifest details.
* @param {string} options.manifestPath - The path to the manifest file.
* @param {boolean} options.clearCache - Whether to clear the cache before retrieving the manifest details.
* @param {string} [options.apiIdentifier] - The identifier of the API.
* @returns {Promise<KiotaManifestResult | undefined>} A promise that resolves to the manifest details or undefined if not found.
* @throws {Error} Throws an error if the request fails.
*/
export async function getManifestDetails({ manifestPath, clearCache, apiIdentifier }: ManifestOptions): Promise<KiotaManifestResult | undefined> {
const result = await connectToKiota(async (connection) => {
const request = new rpc.RequestType<KiotaGetManifestDetailsConfiguration, KiotaManifestResult, void>('GetManifestDetails');
Expand Down
21 changes: 21 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/languageInformation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ interface LanguageInformationConfiguration {
descriptionUrl: string; clearCache: boolean;
}

/**
* Retrieves language information by connecting to Kiota.
*
* This function establishes a connection to Kiota and sends a request to retrieve
* language information. If the request is successful, it returns the language information.
* If an error occurs during the request, the error is thrown.
*
* @returns {Promise<LanguagesInformation | undefined>} A promise that resolves to the language information or undefined if an error occurs.
* @throws {Error} Throws an error if the request fails.
*/
export async function getLanguageInformationInternal(): Promise<LanguagesInformation | undefined> {
const result = await connectToKiota<LanguagesInformation>(async (connection) => {
const request = new rpc.RequestType0<LanguagesInformation, void>(
Expand All @@ -24,6 +34,17 @@ export async function getLanguageInformationInternal(): Promise<LanguagesInforma
return result;
};

/**
* Retrieves language information based on the provided description URL.
*
* @param {LanguageInformationConfiguration} config - The configuration object containing the description URL and cache clearing option.
* @param {string} config.descriptionUrl - The URL of the description to retrieve language information for.
* @param {boolean} config.clearCache - A flag indicating whether to clear the cache before retrieving the information.
*
* @returns {Promise<LanguagesInformation | undefined>} A promise that resolves to the language information or undefined if an error occurs.
*
* @throws {Error} Throws an error if the request fails.
*/
export async function getLanguageInformationForDescription({ descriptionUrl, clearCache }: LanguageInformationConfiguration):
Promise<LanguagesInformation | undefined> {
const result = await connectToKiota<LanguagesInformation>(async (connection) => {
Expand Down
11 changes: 11 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/migrateFromLockFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ import * as rpc from "vscode-jsonrpc/node";
import { KiotaLogEntry } from "..";
import connectToKiota from "../connect";

/**
* Migrates data from a lock file located in the specified directory.
*
* This function connects to the Kiota service and sends a request to migrate data from the lock file.
* If the migration is successful, it returns an array of `KiotaLogEntry` objects.
* If an error occurs during the migration, the error is thrown.
*
* @param {string} lockFileDirectory - The directory where the lock file is located.
* @returns {Promise<KiotaLogEntry[] | undefined>} A promise that resolves to an array of `KiotaLogEntry` objects if the migration is successful, or `undefined` if no data is migrated.
* @throws {Error} If an error occurs during the migration process.
*/
export async function migrateFromLockFile(lockFileDirectory: string): Promise<KiotaLogEntry[] | undefined> {
const result = await connectToKiota(async (connection) => {
const request = new rpc.RequestType1<string, KiotaLogEntry[], void>(
Expand Down
24 changes: 20 additions & 4 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/removeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ interface RemoveClientConfiguration extends RemoveItemConfiguration {
clientName: string;
}

/**
* Removes a plugin from the Kiota environment.
*
* @param {RemovePluginConfiguration} config - The configuration for removing the plugin.
* @param {string} config.pluginName - The name of the plugin to remove.
* @param {boolean} config.cleanOutput - Whether to clean the output directory after removal.
* @param {string} config.workingDirectory - The working directory where the operation should be performed.
* @returns {Promise<KiotaResult | undefined>} A promise that resolves to a KiotaResult if the operation is successful, or undefined if no result is returned.
* @throws {Error} Throws an error if the operation fails.
*/
export async function removePlugin({ pluginName, cleanOutput, workingDirectory }: RemovePluginConfiguration): Promise<KiotaResult | undefined> {
const result = await connectToKiota(async (connection) => {
const request = new rpc.RequestType2<string, boolean, KiotaLogEntry[], void>(
Expand All @@ -42,10 +52,16 @@ export async function removePlugin({ pluginName, cleanOutput, workingDirectory }
return undefined;
};





/**
* Removes a client using the provided configuration.
*
* @param {RemoveClientConfiguration} param0 - The configuration for removing the client.
* @param {string} param0.clientName - The name of the client to be removed.
* @param {boolean} param0.cleanOutput - A flag indicating whether to clean the output.
* @param {string} param0.workingDirectory - The working directory for the operation.
* @returns {Promise<KiotaResult | undefined>} A promise that resolves to a KiotaResult if the client was removed successfully, or undefined if no result is returned.
* @throws {Error} Throws an error if the result is an instance of Error.
*/
export async function removeClient({ clientName, cleanOutput, workingDirectory }: RemoveClientConfiguration): Promise<KiotaResult | undefined> {
const result = await connectToKiota(async (connection) => {
const request = new rpc.RequestType2<string, boolean, KiotaLogEntry[], void>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ interface SearchConfiguration {
clearCache: boolean;
}

/**
* Searches for a description based on the provided search term and cache settings.
*
* @param {SearchConfiguration} param0 - The search configuration object.
* @param {string} param0.searchTerm - The term to search for.
* @param {boolean} param0.clearCache - Whether to clear the cache before searching.
* @returns {Promise<Record<string, KiotaSearchResultItem> | undefined>} A promise that resolves to a record of search results or undefined if no results are found.
* @throws {Error} Throws an error if the search operation fails.
*/
export async function searchDescription({ searchTerm, clearCache }: SearchConfiguration): Promise<Record<string, KiotaSearchResultItem> | undefined> {
const result = await connectToKiota(async (connection) => {
const request = new rpc.RequestType2<string, boolean, KiotaSearchResult, void>(
Expand Down
11 changes: 11 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/showKiotaResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ interface KiotaResultOptions {
clearCache: boolean;
}

/**
* Asynchronously shows the Kiota result based on the provided options.
*
* @param {KiotaResultOptions} options - The options to configure the Kiota result.
* @param {string[]} options.includeFilters - Filters to include in the result.
* @param {string} options.descriptionPath - The path to the description file.
* @param {string[]} options.excludeFilters - Filters to exclude from the result.
* @param {boolean} options.clearCache - Whether to clear the cache before showing the result.
* @returns {Promise<KiotaShowResult | undefined>} A promise that resolves to the Kiota show result or undefined if an error occurs.
* @throws {Error} Throws an error if the result is an instance of Error.
*/
export async function showKiotaResult({ includeFilters, descriptionPath, excludeFilters, clearCache }: KiotaResultOptions): Promise<KiotaShowResult | undefined> {
const result = await connectToKiota(async (connection) => {
const request = new rpc.RequestType<KiotaShowConfiguration, KiotaShowResult, void>('Show');
Expand Down
12 changes: 12 additions & 0 deletions vscode/microsoft-kiota/src/kiotaInterop/lib/updateClients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ interface UpdateClientsConfiguration {
workspacePath: string;
}

/**
* Updates the clients by connecting to Kiota and sending a request to update.
*
* @param {UpdateClientsConfiguration} config - The configuration object containing the following properties:
* @param {boolean} config.cleanOutput - Whether to clean the output directory before updating.
* @param {boolean} config.clearCache - Whether to clear the cache before updating.
* @param {string} config.workspacePath - The path to the workspace where the clients are located.
*
* @returns {Promise<KiotaLogEntry[] | undefined>} A promise that resolves to an array of Kiota log entries if the update is successful, or undefined if there is an error.
*
* @throws {Error} Throws an error if the result of the update is an instance of Error.
*/
export async function updateClients({ cleanOutput, clearCache, workspacePath }: UpdateClientsConfiguration): Promise<KiotaLogEntry[] | undefined> {
const result = await connectToKiota(async (connection) => {
const request = new rpc.RequestType3<string, boolean, boolean, KiotaLogEntry[], void>(
Expand Down

0 comments on commit 18e0f29

Please sign in to comment.