diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f1ed2cade..ab81efc508 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a bug where OpenAPI schemas with `format` but without `type` keyword would generate `UntypedNode` instead of proper types. [#7315](https://github.com/microsoft/kiota/issues/7315) - Fixed a bug where discriminator mappings for oneOf types with allOf-inherited schemas would incorrectly use schema names as keys instead of resolving the base type discriminator mappings. [#7339](https://github.com/microsoft/kiota/issues/7339) - Fixed TypeScript enum imports to use `import type` for type aliases to support `verbatimModuleSyntax`. [#7332](https://github.com/microsoft/kiota/pull/7332) +- Fixed a bug where the kiota npm package esm variant would fail to resolve modules. +- Fixes a bug where the kiota npm package type definitions would be misplaced. ## [1.30.0] - 2026-01-26 @@ -1706,4 +1708,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial GitHub release - diff --git a/vscode/package.json b/vscode/package.json index 40ce828585..5d8d5bdd5b 100644 --- a/vscode/package.json +++ b/vscode/package.json @@ -8,7 +8,9 @@ }, "scripts": { "lint": "npm run lint --w=\"@microsoft/kiota\" && npm run lint --w=kiota", - "build": "npm run build --w=\"@microsoft/kiota\" && npm run build --w=kiota", + "build": "npm run build:package && npm run build:vscode", + "build:package": "npm run build --w=\"@microsoft/kiota\"", + "build:vscode": "npm run build --w=kiota", "test:vscode": "npm run build && npm run test --w=kiota", "test:vscode:coverage": "npm run build && npm run test:coverage --w=kiota", "test:package": "npm run build --w=\"@microsoft/kiota\" && npm run test --w=\"@microsoft/kiota\"", @@ -36,4 +38,4 @@ "packages/npm-package", "packages/microsoft-kiota" ] -} +} \ No newline at end of file diff --git a/vscode/packages/npm-package/connect.ts b/vscode/packages/npm-package/connect.ts index c36fc72b22..4625fa9c74 100644 --- a/vscode/packages/npm-package/connect.ts +++ b/vscode/packages/npm-package/connect.ts @@ -1,6 +1,6 @@ import * as cp from 'child_process'; import * as rpc from 'vscode-jsonrpc/node'; -import { ensureKiotaIsPresent, getKiotaPath } from './install'; +import { ensureKiotaIsPresent, getKiotaPath } from './install.js'; export default async function connectToKiota(callback: (connection: rpc.MessageConnection) => Promise, workingDirectory: string = process.cwd()): Promise { diff --git a/vscode/packages/npm-package/index.ts b/vscode/packages/npm-package/index.ts index 585948e70b..1858eb05d7 100644 --- a/vscode/packages/npm-package/index.ts +++ b/vscode/packages/npm-package/index.ts @@ -1,13 +1,13 @@ -export * from './config'; -export * from './lib/generateClient'; -export * from './lib/generatePlugin'; -export * from './lib/getKiotaTree'; -export * from './lib/getKiotaVersion'; -export * from './lib/getManifestDetails'; -export * from './lib/languageInformation'; -export * from './lib/migrateFromLockFile'; -export * from './lib/removeItem'; -export * from './lib/searchDescription'; -export * from './lib/updateClients'; -export * from './types'; -export * from './utils'; \ No newline at end of file +export * from './config.js'; +export * from './lib/generateClient.js'; +export * from './lib/generatePlugin.js'; +export * from './lib/getKiotaTree.js'; +export * from './lib/getKiotaVersion.js'; +export * from './lib/getManifestDetails.js'; +export * from './lib/languageInformation.js'; +export * from './lib/migrateFromLockFile.js'; +export * from './lib/removeItem.js'; +export * from './lib/searchDescription.js'; +export * from './lib/updateClients.js'; +export * from './types.js'; +export * from './utils.js'; \ No newline at end of file diff --git a/vscode/packages/npm-package/install.ts b/vscode/packages/npm-package/install.ts index 58e0011274..174a9856ed 100644 --- a/vscode/packages/npm-package/install.ts +++ b/vscode/packages/npm-package/install.ts @@ -1,28 +1,34 @@ -import AdmZip from 'adm-zip'; -import { createHash } from 'crypto'; -import * as https from 'https'; -import * as fs from 'fs'; -import * as path from 'path'; -import { getKiotaConfig } from './config'; +import AdmZip from "adm-zip"; +import { createHash } from "node:crypto"; +import * as https from "node:https"; +import * as fs from "node:fs"; +import * as path from "node:path"; +import { fileURLToPath } from "node:url"; +import { getKiotaConfig } from "./config.js"; -import runtimeJson from './runtime.json'; +import runtimeJson from "./runtime.json" with { type: "json" }; const kiotaInstallStatusKey = "kiotaInstallStatus"; const installDelayInMs = 30000; // 30 seconds -const state: { [key: string]: any } = {}; +const state: { [key: string]: number | undefined } = {}; let kiotaPath: string | undefined; -const binariesRootDirectory = '.kiotabin'; +const binariesRootDirectory = ".kiotabin"; const baseDownloadUrl = "https://github.com/microsoft/kiota/releases/download"; +// eslint-disable-next-line @typescript-eslint/naming-convention +const __filename = fileURLToPath(import.meta.url); +// eslint-disable-next-line @typescript-eslint/naming-convention +const __dirname = path.dirname(__filename); + export interface Package { platformId: string; sha256: string; } -const windowsPlatform = 'win'; -const osxPlatform = 'osx'; -const linuxPlatform = 'linux'; +const windowsPlatform = "win"; +const osxPlatform = "osx"; +const linuxPlatform = "linux"; /** * Checks if a file or directory exists asynchronously @@ -56,7 +62,10 @@ async function isDirectoryEmpty(dirPath: string): Promise { async function runIfNotLocked(action: () => Promise) { const installStartTimeStamp = state[kiotaInstallStatusKey]; const currentTimeStamp = new Date().getTime(); - if (!installStartTimeStamp || (currentTimeStamp - installStartTimeStamp) > installDelayInMs) { + if ( + !installStartTimeStamp || + currentTimeStamp - installStartTimeStamp > installDelayInMs + ) { //locking the context to prevent multiple downloads across multiple instances //overriding after 30 seconds to prevent stale locks state[kiotaInstallStatusKey] = currentTimeStamp; @@ -73,16 +82,29 @@ export async function ensureKiotaIsPresent() { if (installPath) { const runtimeDependencies = getRuntimeDependenciesPackages(); const currentPlatform = getCurrentPlatform(); - await ensureKiotaIsPresentInPath(installPath, runtimeDependencies, currentPlatform); + await ensureKiotaIsPresentInPath( + installPath, + runtimeDependencies, + currentPlatform, + ); } } -export async function ensureKiotaIsPresentInPath(installPath: string, runtimeDependencies: Package[], currentPlatform: string) { +export async function ensureKiotaIsPresentInPath( + installPath: string, + runtimeDependencies: Package[], + currentPlatform: string, +) { if (installPath) { - if (!await checkFileExists(installPath) || await isDirectoryEmpty(installPath)) { + if ( + !(await checkFileExists(installPath)) || + (await isDirectoryEmpty(installPath)) + ) { await runIfNotLocked(async () => { try { - const packageToInstall = runtimeDependencies.find((p) => p.platformId === currentPlatform); + const packageToInstall = runtimeDependencies.find( + (p) => p.platformId === currentPlatform, + ); if (!packageToInstall) { throw new Error("Could not find package to install"); } @@ -90,24 +112,34 @@ export async function ensureKiotaIsPresentInPath(installPath: string, runtimeDep const zipFilePath = `${installPath}.zip`; // If env variable that points to kiota binary zip exists, use it to copy the file instead of downloading it const kiotaBinaryZip = process.env.KIOTA_SIDELOADING_BINARY_ZIP_PATH; - if (kiotaBinaryZip && await checkFileExists(kiotaBinaryZip)) { + if (kiotaBinaryZip && (await checkFileExists(kiotaBinaryZip))) { fs.copyFileSync(kiotaBinaryZip, zipFilePath); } else { const downloadUrl = getDownloadUrl(currentPlatform); await downloadFileFromUrl(downloadUrl, zipFilePath); - if (!await doesFileHashMatch(zipFilePath, packageToInstall.sha256)) { - throw new Error("Hash validation of the downloaded file mismatch"); + if ( + !(await doesFileHashMatch(zipFilePath, packageToInstall.sha256)) + ) { + throw new Error( + "Hash validation of the downloaded file mismatch", + ); } } unzipFile(zipFilePath, installPath); - if ((currentPlatform.startsWith(linuxPlatform) || currentPlatform.startsWith(osxPlatform)) && installPath) { + if ( + (currentPlatform.startsWith(linuxPlatform) || + currentPlatform.startsWith(osxPlatform)) && + installPath + ) { const fileName = getKiotaFileName(); const kiotaFilePath = path.join(installPath, fileName); makeExecutable(kiotaFilePath); } - } catch (error) { + } catch { fs.rmSync(installPath, { recursive: true, force: true }); - throw new Error("Kiota download failed. Check the logs for more information."); + throw new Error( + "Kiota download failed. Check the logs for more information.", + ); } }); } @@ -137,19 +169,25 @@ function getRuntimeVersion(): string { } function getKiotaFileName(): string { - return process.platform === 'win32' ? 'kiota.exe' : 'kiota'; + return process.platform === "win32" ? "kiota.exe" : "kiota"; } function getKiotaPathInternal(withFileName = true): string | undefined { const fileName = getKiotaFileName(); const runtimeDependencies = getRuntimeDependenciesPackages(); const currentPlatform = getCurrentPlatform(); - const packageToInstall = runtimeDependencies.find((p) => p.platformId === currentPlatform); + const packageToInstall = runtimeDependencies.find( + (p) => p.platformId === currentPlatform, + ); const baseDir = getBaseDir(); const runtimeVersion = getRuntimeVersion(); if (packageToInstall) { const installPath = path.join(baseDir, binariesRootDirectory); - const directoryPath = path.join(installPath, runtimeVersion, currentPlatform); + const directoryPath = path.join( + installPath, + runtimeVersion, + currentPlatform, + ); if (withFileName) { return path.join(directoryPath, fileName); } @@ -163,26 +201,41 @@ function unzipFile(zipFilePath: string, destinationPath: string) { zip.extractAllTo(destinationPath, true); } -async function doesFileHashMatch(destinationPath: string, hashValue: string): Promise { - const hash = createHash('sha256'); - return new Promise((resolve, reject) => { - fs.createReadStream(destinationPath).pipe(hash).on('finish', () => { - const computedValue = hash.digest('hex'); - hash.destroy(); - resolve(computedValue.toUpperCase() === hashValue.toUpperCase()); - }); +async function doesFileHashMatch( + destinationPath: string, + hashValue: string, +): Promise { + const hash = createHash("sha256"); + return new Promise((resolve) => { + fs.createReadStream(destinationPath) + .pipe(hash) + .on("finish", () => { + const computedValue = hash.digest("hex"); + hash.destroy(); + resolve(computedValue.toUpperCase() === hashValue.toUpperCase()); + }); }); } -function downloadFileFromUrl(url: string, destinationPath: string): Promise { +function downloadFileFromUrl( + url: string, + destinationPath: string, +): Promise { return new Promise((resolve) => { - https.get(url, (response: any) => { - if (response.statusCode && response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) { - resolve(downloadFileFromUrl(response.headers.location, destinationPath)); + https.get(url, (response) => { + if ( + response.statusCode && + response.statusCode >= 300 && + response.statusCode < 400 && + response.headers.location + ) { + resolve( + downloadFileFromUrl(response.headers.location, destinationPath), + ); } else { const filePath = fs.createWriteStream(destinationPath); response.pipe(filePath); - filePath.on('finish', () => { + filePath.on("finish", () => { filePath.close(); resolve(undefined); }); @@ -197,12 +250,19 @@ function getDownloadUrl(platform: string): string { export function getRuntimeDependenciesPackages(): Package[] { if (runtimeJson.runtimeDependencies) { - return JSON.parse(JSON.stringify(runtimeJson.runtimeDependencies)); + return JSON.parse( + JSON.stringify(runtimeJson.runtimeDependencies), + ); } throw new Error("No runtime dependencies found"); } export function getCurrentPlatform(): string { - const binPathSegmentOS = process.platform === 'win32' ? windowsPlatform : process.platform === 'darwin' ? osxPlatform : linuxPlatform; + const binPathSegmentOS = + process.platform === "win32" + ? windowsPlatform + : process.platform === "darwin" + ? osxPlatform + : linuxPlatform; return `${binPathSegmentOS}-${process.arch}`; } diff --git a/vscode/packages/npm-package/jest.common.config.cjs b/vscode/packages/npm-package/jest.common.config.cjs index a9d58a1a7b..0d1ace4372 100644 --- a/vscode/packages/npm-package/jest.common.config.cjs +++ b/vscode/packages/npm-package/jest.common.config.cjs @@ -4,6 +4,7 @@ module.exports = { testMatch: [ '**/?(*.)+(spec).ts?(x)' ], + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], transform: { '^.+\\.ts?$': ['ts-jest', { tsconfig: 'tsconfig.json', diff --git a/vscode/packages/npm-package/lib/generateClient.ts b/vscode/packages/npm-package/lib/generateClient.ts index 3bf65071f4..21494d8b71 100644 --- a/vscode/packages/npm-package/lib/generateClient.ts +++ b/vscode/packages/npm-package/lib/generateClient.ts @@ -1,8 +1,13 @@ import * as rpc from "vscode-jsonrpc/node"; -import { checkForSuccess, ConsumerOperation, GenerationConfiguration, KiotaLogEntry } from ".."; -import connectToKiota from "../connect"; -import { KiotaGenerationLanguage, KiotaResult } from "../types"; +import { + checkForSuccess, + ConsumerOperation, + GenerationConfiguration, + KiotaLogEntry, +} from "../index.js"; +import connectToKiota from "../connect.js"; +import { KiotaGenerationLanguage, KiotaResult } from "../types.js"; export interface ClientGenerationOptions { openAPIFilePath: string; @@ -54,35 +59,39 @@ export interface ClientGenerationOptions { * @returns {Promise} 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 { +export async function generateClient( + clientGenerationOptions: ClientGenerationOptions, +): Promise { const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType1( - "Generate" - ); + const request = new rpc.RequestType1< + GenerationConfiguration, + KiotaLogEntry[], + void + >("Generate"); - return await connection.sendRequest( - request, - { - openAPIFilePath: clientGenerationOptions.openAPIFilePath, - clientClassName: clientGenerationOptions.clientClassName, - clientNamespaceName: clientGenerationOptions.clientNamespaceName, - language: clientGenerationOptions.language, - outputPath: clientGenerationOptions.outputPath, - operation: clientGenerationOptions.operation, + return await connection.sendRequest(request, { + openAPIFilePath: clientGenerationOptions.openAPIFilePath, + clientClassName: clientGenerationOptions.clientClassName, + clientNamespaceName: clientGenerationOptions.clientNamespaceName, + language: clientGenerationOptions.language, + outputPath: clientGenerationOptions.outputPath, + operation: clientGenerationOptions.operation, - deserializers: clientGenerationOptions.deserializers ?? [], - disabledValidationRules: clientGenerationOptions.disabledValidationRules ?? [], - excludeBackwardCompatible: clientGenerationOptions.excludeBackwardCompatible ?? false, - excludePatterns: clientGenerationOptions.excludePatterns ?? [], - includeAdditionalData: clientGenerationOptions.includeAdditionalData ?? false, - cleanOutput: clientGenerationOptions.cleanOutput ?? false, - clearCache: clientGenerationOptions.clearCache ?? false, - includePatterns: clientGenerationOptions.includePatterns ?? [], - serializers: clientGenerationOptions.serializers ?? [], - structuredMimeTypes: clientGenerationOptions.structuredMimeTypes ?? [], - usesBackingStore: clientGenerationOptions.usesBackingStore ?? false, - } as GenerationConfiguration, - ); + deserializers: clientGenerationOptions.deserializers ?? [], + disabledValidationRules: + clientGenerationOptions.disabledValidationRules ?? [], + excludeBackwardCompatible: + clientGenerationOptions.excludeBackwardCompatible ?? false, + excludePatterns: clientGenerationOptions.excludePatterns ?? [], + includeAdditionalData: + clientGenerationOptions.includeAdditionalData ?? false, + cleanOutput: clientGenerationOptions.cleanOutput ?? false, + clearCache: clientGenerationOptions.clearCache ?? false, + includePatterns: clientGenerationOptions.includePatterns ?? [], + serializers: clientGenerationOptions.serializers ?? [], + structuredMimeTypes: clientGenerationOptions.structuredMimeTypes ?? [], + usesBackingStore: clientGenerationOptions.usesBackingStore ?? false, + } as GenerationConfiguration); }, clientGenerationOptions.workingDirectory); if (result instanceof Error) { @@ -92,10 +101,9 @@ export async function generateClient(clientGenerationOptions: ClientGenerationOp if (result) { return { isSuccess: checkForSuccess(result as KiotaLogEntry[]), - logs: result + logs: result, }; } return undefined; -}; - +} diff --git a/vscode/packages/npm-package/lib/getKiotaVersion.ts b/vscode/packages/npm-package/lib/getKiotaVersion.ts index 1c578af2aa..a67fabb176 100644 --- a/vscode/packages/npm-package/lib/getKiotaVersion.ts +++ b/vscode/packages/npm-package/lib/getKiotaVersion.ts @@ -1,6 +1,6 @@ import * as rpc from "vscode-jsonrpc/node"; -import connectToKiota from '../connect'; +import connectToKiota from "../connect.js"; /** * Retrieves the version of Kiota by connecting to the Kiota service. @@ -9,7 +9,6 @@ import connectToKiota from '../connect'; * @throws {Error} If an error occurs while connecting to the Kiota service or retrieving the version. */ export async function getKiotaVersion(): Promise { - const result = await connectToKiota(async (connection) => { const request = new rpc.RequestType0("GetVersion"); return await connection.sendRequest(request); @@ -26,4 +25,4 @@ export async function getKiotaVersion(): Promise { } } return undefined; -}; \ No newline at end of file +} diff --git a/vscode/packages/npm-package/lib/getManifestDetails.ts b/vscode/packages/npm-package/lib/getManifestDetails.ts index 0a1b320235..40d1f2f961 100644 --- a/vscode/packages/npm-package/lib/getManifestDetails.ts +++ b/vscode/packages/npm-package/lib/getManifestDetails.ts @@ -1,7 +1,10 @@ import * as rpc from "vscode-jsonrpc/node"; -import { KiotaGetManifestDetailsConfiguration, KiotaManifestResult } from ".."; -import connectToKiota from "../connect"; +import { + KiotaGetManifestDetailsConfiguration, + KiotaManifestResult, +} from "../index.js"; +import connectToKiota from "../connect.js"; export interface ManifestOptions { manifestPath: string; @@ -19,18 +22,23 @@ export interface ManifestOptions { * @returns {Promise} 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 { +export async function getManifestDetails({ + manifestPath, + clearCache, + apiIdentifier, +}: ManifestOptions): Promise { const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType('GetManifestDetails'); + const request = new rpc.RequestType< + KiotaGetManifestDetailsConfiguration, + KiotaManifestResult, + void + >("GetManifestDetails"); - return await connection.sendRequest( - request, - { - manifestPath, - apiIdentifier: apiIdentifier ?? '', - clearCache: clearCache ?? false, - } - ); + return await connection.sendRequest(request, { + manifestPath, + apiIdentifier: apiIdentifier ?? "", + clearCache: clearCache ?? false, + }); }); if (result instanceof Error) { @@ -38,4 +46,4 @@ export async function getManifestDetails({ manifestPath, clearCache, apiIdentifi } return result; -}; \ No newline at end of file +} diff --git a/vscode/packages/npm-package/lib/getPluginManifest.ts b/vscode/packages/npm-package/lib/getPluginManifest.ts index 09b55d67bc..1d2e9831ac 100644 --- a/vscode/packages/npm-package/lib/getPluginManifest.ts +++ b/vscode/packages/npm-package/lib/getPluginManifest.ts @@ -1,7 +1,7 @@ import * as rpc from "vscode-jsonrpc/node"; -import connectToKiota from "../connect"; -import { PluginManifestResult } from "../types"; +import connectToKiota from "../connect.js"; +import { PluginManifestResult } from "../types.js"; export interface GetPluginManifestOptions { descriptionPath: string; @@ -15,9 +15,15 @@ export interface GetPluginManifestOptions { * @returns {Promise} A promise that resolves to the result or undefined if an error occurs. * @throws {Error} Throws an error if the result is an instance of Error. */ -export async function getPluginManifest({ descriptionPath }: GetPluginManifestOptions): Promise { +export async function getPluginManifest({ + descriptionPath, +}: GetPluginManifestOptions): Promise { const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType('ShowPlugin'); + const request = new rpc.RequestType< + GetPluginManifestOptions, + PluginManifestResult, + void + >("ShowPlugin"); const response = await connection.sendRequest(request, { descriptionPath, @@ -25,7 +31,6 @@ export async function getPluginManifest({ descriptionPath }: GetPluginManifestOp // Mapping return response; - }); if (result instanceof Error) { @@ -33,4 +38,4 @@ export async function getPluginManifest({ descriptionPath }: GetPluginManifestOp } return result; -}; \ No newline at end of file +} diff --git a/vscode/packages/npm-package/lib/languageInformation.ts b/vscode/packages/npm-package/lib/languageInformation.ts index 2991deb9eb..a2ad7c71e1 100644 --- a/vscode/packages/npm-package/lib/languageInformation.ts +++ b/vscode/packages/npm-package/lib/languageInformation.ts @@ -1,10 +1,11 @@ import * as rpc from "vscode-jsonrpc/node"; -import { LanguagesInformation } from ".."; -import connectToKiota from "../connect"; +import { LanguagesInformation } from "../index.js"; +import connectToKiota from "../connect.js"; export interface LanguageInformationConfiguration { - descriptionUrl: string; clearCache: boolean; + descriptionUrl: string; + clearCache: boolean; } /** @@ -17,50 +18,55 @@ export interface LanguageInformationConfiguration { * @returns {Promise} 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 { - const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType0( - "Info" - ); - return await connection.sendRequest( - request, - ); - }); +export async function getLanguageInformationInternal(): Promise< + LanguagesInformation | undefined +> { + const result = await connectToKiota( + async (connection) => { + const request = new rpc.RequestType0("Info"); + return await connection.sendRequest(request); + }, + ); if (result instanceof Error) { throw result; } 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} 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 { - const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType2( - "InfoForDescription" - ); - return await connection.sendRequest( - request, - descriptionUrl, - clearCache - ); - }); +export async function getLanguageInformationForDescription({ + descriptionUrl, + clearCache, +}: LanguageInformationConfiguration): Promise< + LanguagesInformation | undefined +> { + const result = await connectToKiota( + async (connection) => { + const request = new rpc.RequestType2< + string, + boolean, + LanguagesInformation, + void + >("InfoForDescription"); + return await connection.sendRequest(request, descriptionUrl, clearCache); + }, + ); if (result instanceof Error) { throw result; } return result; -}; \ No newline at end of file +} diff --git a/vscode/packages/npm-package/lib/migrateFromLockFile.ts b/vscode/packages/npm-package/lib/migrateFromLockFile.ts index e383da97db..b578ba90d5 100644 --- a/vscode/packages/npm-package/lib/migrateFromLockFile.ts +++ b/vscode/packages/npm-package/lib/migrateFromLockFile.ts @@ -1,7 +1,7 @@ import * as rpc from "vscode-jsonrpc/node"; -import { KiotaLogEntry } from ".."; -import connectToKiota from "../connect"; +import { KiotaLogEntry } from "../index.js"; +import connectToKiota from "../connect.js"; /** * Migrates data from a lock file located in the specified directory. @@ -14,15 +14,14 @@ import connectToKiota from "../connect"; * @returns {Promise} 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 { +export async function migrateFromLockFile( + lockFileDirectory: string, +): Promise { const result = await connectToKiota(async (connection) => { const request = new rpc.RequestType1( - "MigrateFromLockFile" - ); - return await connection.sendRequest( - request, - lockFileDirectory + "MigrateFromLockFile", ); + return await connection.sendRequest(request, lockFileDirectory); }); if (result instanceof Error) { @@ -30,4 +29,4 @@ export async function migrateFromLockFile(lockFileDirectory: string): Promise} 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 { +export async function removePlugin({ + pluginName, + cleanOutput, + workingDirectory, +}: RemovePluginConfiguration): Promise { const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType2( - "RemovePlugin" - ); - return await connection.sendRequest( - request, - pluginName, - cleanOutput - ); + const request = new rpc.RequestType2< + string, + boolean, + KiotaLogEntry[], + void + >("RemovePlugin"); + return await connection.sendRequest(request, pluginName, cleanOutput); }, workingDirectory); if (result instanceof Error) { @@ -44,13 +47,13 @@ export async function removePlugin({ pluginName, cleanOutput, workingDirectory } if (result) { return { - isSuccess: result.some(k => k.message.includes('removed successfully')), - logs: result + isSuccess: result.some((k) => k.message.includes("removed successfully")), + logs: result, }; } return undefined; -}; +} /** * Removes a client using the provided configuration. @@ -62,16 +65,19 @@ export async function removePlugin({ pluginName, cleanOutput, workingDirectory } * @returns {Promise} 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 { +export async function removeClient({ + clientName, + cleanOutput, + workingDirectory, +}: RemoveClientConfiguration): Promise { const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType2( - "RemoveClient" - ); - return await connection.sendRequest( - request, - clientName, - cleanOutput - ); + const request = new rpc.RequestType2< + string, + boolean, + KiotaLogEntry[], + void + >("RemoveClient"); + return await connection.sendRequest(request, clientName, cleanOutput); }, workingDirectory); if (result instanceof Error) { @@ -80,10 +86,10 @@ export async function removeClient({ clientName, cleanOutput, workingDirectory } if (result) { return { - isSuccess: result.some(k => k.message.includes('removed successfully')), - logs: result + isSuccess: result.some((k) => k.message.includes("removed successfully")), + logs: result, }; } return undefined; -}; \ No newline at end of file +} diff --git a/vscode/packages/npm-package/lib/searchDescription.ts b/vscode/packages/npm-package/lib/searchDescription.ts index 766db46bb1..13a5702d0d 100644 --- a/vscode/packages/npm-package/lib/searchDescription.ts +++ b/vscode/packages/npm-package/lib/searchDescription.ts @@ -1,7 +1,7 @@ import * as rpc from "vscode-jsonrpc/node"; -import { KiotaSearchResult, KiotaSearchResultItem } from ".."; -import connectToKiota from '../connect'; +import { KiotaSearchResult, KiotaSearchResultItem } from "../index.js"; +import connectToKiota from "../connect.js"; export interface SearchConfiguration { searchTerm: string; @@ -17,16 +17,20 @@ export interface SearchConfiguration { * @returns {Promise | 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 | undefined> { +export async function searchDescription({ + searchTerm, + clearCache, +}: SearchConfiguration): Promise< + Record | undefined +> { const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType2( - "Search" - ); - return await connection.sendRequest( - request, - searchTerm, - clearCache, - ); + const request = new rpc.RequestType2< + string, + boolean, + KiotaSearchResult, + void + >("Search"); + return await connection.sendRequest(request, searchTerm, clearCache); }); if (result instanceof Error) { @@ -38,4 +42,4 @@ export async function searchDescription({ searchTerm, clearCache }: SearchConfig } return undefined; -}; \ No newline at end of file +} diff --git a/vscode/packages/npm-package/lib/updateClients.ts b/vscode/packages/npm-package/lib/updateClients.ts index b479eec9f7..4c9818c978 100644 --- a/vscode/packages/npm-package/lib/updateClients.ts +++ b/vscode/packages/npm-package/lib/updateClients.ts @@ -1,7 +1,7 @@ import * as rpc from "vscode-jsonrpc/node"; -import { KiotaLogEntry } from ".."; -import connectToKiota from "../connect"; +import { KiotaLogEntry } from "../index.js"; +import connectToKiota from "../connect.js"; export interface UpdateClientsConfiguration { cleanOutput: boolean; @@ -11,21 +11,29 @@ export interface UpdateClientsConfiguration { /** * 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} 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 { +export async function updateClients({ + cleanOutput, + clearCache, + workspacePath, +}: UpdateClientsConfiguration): Promise { const result = await connectToKiota(async (connection) => { - const request = new rpc.RequestType3( - "Update" - ); + const request = new rpc.RequestType3< + string, + boolean, + boolean, + KiotaLogEntry[], + void + >("Update"); return await connection.sendRequest( request, workspacePath, @@ -39,4 +47,4 @@ export async function updateClients({ cleanOutput, clearCache, workspacePath }: } return result; -}; \ No newline at end of file +} diff --git a/vscode/packages/npm-package/tsconfig.cjs.json b/vscode/packages/npm-package/tsconfig.cjs.json index cc9752b01d..d233e2bf5b 100644 --- a/vscode/packages/npm-package/tsconfig.cjs.json +++ b/vscode/packages/npm-package/tsconfig.cjs.json @@ -4,6 +4,6 @@ "outDir": "./dist/cjs", "module": "CommonJS", "declaration": true, - "declarationDir": "./dist/cjs/types" + "declarationDir": "./dist/cjs" } } diff --git a/vscode/packages/npm-package/tsconfig.esm.json b/vscode/packages/npm-package/tsconfig.esm.json index 396bc45f90..c83e656ae7 100644 --- a/vscode/packages/npm-package/tsconfig.esm.json +++ b/vscode/packages/npm-package/tsconfig.esm.json @@ -4,6 +4,6 @@ "outDir": "./dist/esm", "module": "ESNext", "declaration": true, - "declarationDir": "./dist/esm/types" + "declarationDir": "./dist/esm" } } diff --git a/vscode/packages/npm-package/types.ts b/vscode/packages/npm-package/types.ts index eaed5534a9..7a25b6c3f4 100644 --- a/vscode/packages/npm-package/types.ts +++ b/vscode/packages/npm-package/types.ts @@ -34,10 +34,15 @@ export interface KiotaLogEntry { } export enum OpenApiAuthType { + // eslint-disable-next-line @typescript-eslint/naming-convention None = 0, + // eslint-disable-next-line @typescript-eslint/naming-convention ApiKey = 1, + // eslint-disable-next-line @typescript-eslint/naming-convention Http = 2, + // eslint-disable-next-line @typescript-eslint/naming-convention OAuth2 = 3, + // eslint-disable-next-line @typescript-eslint/naming-convention OpenIdConnect = 4, } @@ -80,8 +85,7 @@ export interface KiotaShowConfiguration extends CacheClearableConfiguration { includeKiotaValidationRules: boolean; } -export interface KiotaGetManifestDetailsConfiguration - extends CacheClearableConfiguration { +export interface KiotaGetManifestDetailsConfiguration extends CacheClearableConfiguration { manifestPath: string; apiIdentifier: string; } @@ -97,6 +101,8 @@ export enum OpenApiSpecVersion { V3_0 = 1, // eslint-disable-next-line @typescript-eslint/naming-convention V3_1 = 2, + // eslint-disable-next-line @typescript-eslint/naming-convention + V3_2 = 3, } export interface KiotaTreeResult extends KiotaLoggedResult { @@ -141,7 +147,7 @@ export enum ConsumerOperation { } export function generationLanguageToString( - language: KiotaGenerationLanguage + language: KiotaGenerationLanguage, ): string { switch (language) { case KiotaGenerationLanguage.CSharp: @@ -167,6 +173,33 @@ export function generationLanguageToString( } } +export function parseGenerationLanguage( + language: string, +): KiotaGenerationLanguage { + switch (language.toLowerCase()) { + case "csharp": + return KiotaGenerationLanguage.CSharp; + case "java": + return KiotaGenerationLanguage.Java; + case "typescript": + return KiotaGenerationLanguage.TypeScript; + case "php": + return KiotaGenerationLanguage.PHP; + case "python": + return KiotaGenerationLanguage.Python; + case "go": + return KiotaGenerationLanguage.Go; + case "ruby": + return KiotaGenerationLanguage.Ruby; + case "dart": + return KiotaGenerationLanguage.Dart; + case "http": + return KiotaGenerationLanguage.HTTP; + default: + throw new Error(`unknown language: ${language}`); + } +} + export const allGenerationLanguages = [ KiotaGenerationLanguage.CSharp, KiotaGenerationLanguage.Go, @@ -300,8 +333,6 @@ export interface KiotaResult extends KiotaLoggedResult { isSuccess: boolean; } -export interface ValidateOpenApiResult extends KiotaLoggedResult {} - export interface GeneratePluginResult extends KiotaResult { aiPlugin: string; openAPISpec: string; @@ -309,7 +340,9 @@ export interface GeneratePluginResult extends KiotaResult { export interface PluginManifestResult extends KiotaResult { isValid: boolean; + // eslint-disable-next-line @typescript-eslint/naming-convention schema_version: string; + // eslint-disable-next-line @typescript-eslint/naming-convention name_for_human: string; functions: PluginFunction[]; runtime: PluginRuntime[]; @@ -322,12 +355,14 @@ export interface PluginFunction { export interface PluginAuth { type: string; // None, OAuthPluginVault, ApiKeyPluginVault + // eslint-disable-next-line @typescript-eslint/naming-convention reference_id?: string; } export interface PluginRuntime { type: string; auth: PluginAuth; + // eslint-disable-next-line @typescript-eslint/naming-convention run_for_functions: string[]; } diff --git a/vscode/packages/npm-package/utils.ts b/vscode/packages/npm-package/utils.ts index f4b1216810..c290cc17eb 100644 --- a/vscode/packages/npm-package/utils.ts +++ b/vscode/packages/npm-package/utils.ts @@ -1,4 +1,4 @@ -import { KiotaLogEntry, MaturityLevel, DependencyType, LogLevel } from "./types"; +import { KiotaLogEntry, MaturityLevel, DependencyType, LogLevel } from './types.js'; export function getLogEntriesForLevel(logEntries: KiotaLogEntry[], ...levels: LogLevel[]): KiotaLogEntry[] { return logEntries.filter((entry) => levels.indexOf(entry.level) !== -1);