@microsoft/kiota
Version:
npm package exposing Kiota CLI functionality to TypeScript
108 lines • 6.04 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.generatePlugin = generatePlugin;
const rpc = __importStar(require("vscode-jsonrpc/node"));
const __1 = require("..");
const connect_1 = __importDefault(require("../connect"));
const types_1 = require("../types");
const path = __importStar(require("path"));
/**
* Generates a plugin based on the provided options.
*
* @param {PluginGenerationOptions} pluginGenerationOptions - The options for generating the plugin.
* @param {string} pluginGenerationOptions.openAPIFilePath - The file path to the OpenAPI specification.
* @param {string} pluginGenerationOptions.pluginName - The name of the plugin to generate.
* @param {string} pluginGenerationOptions.outputPath - The output path where the generated plugin will be saved.
* @param {ConsumerOperation} pluginGenerationOptions.operation - The operation to perform during generation.
* @param {string} pluginGenerationOptions.workingDirectory - The working directory for the generation process.
* @param {KiotaPluginType} [pluginGenerationOptions.pluginType] - The type of the plugin to generate.
* @param {string[]} [pluginGenerationOptions.includePatterns] - The patterns to include in the generation process.
* @param {string[]} [pluginGenerationOptions.excludePatterns] - The patterns to exclude from the generation process.
* @param {boolean} [pluginGenerationOptions.clearCache] - Whether to clear the cache before generation.
* @param {boolean} [pluginGenerationOptions.cleanOutput] - Whether to clean the output directory before generation.
* @param {string[]} [pluginGenerationOptions.disabledValidationRules] - The validation rules to disable during generation.
* @param {boolean} [pluginGenerationOptions.noWorkspace] - Whether to generate without a workspace.
* @param {PluginAuthType | null} [pluginGenerationOptions.pluginAuthType] - The authentication type for the plugin, if any.
* @param {string} [pluginGenerationOptions.pluginAuthRefid] - The reference ID for the plugin authentication, if any.
* @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.
*/
async function generatePlugin(pluginGenerationOptions) {
const pluginType = pluginGenerationOptions.pluginType ?? types_1.KiotaPluginType.ApiPlugin;
const result = await (0, connect_1.default)(async (connection) => {
const request = new rpc.RequestType1("GeneratePlugin");
return await connection.sendRequest(request, {
openAPIFilePath: pluginGenerationOptions.descriptionPath,
outputPath: pluginGenerationOptions.outputPath,
operation: pluginGenerationOptions.operation,
clientClassName: pluginGenerationOptions.pluginName,
pluginTypes: [pluginType],
cleanOutput: pluginGenerationOptions.cleanOutput ?? false,
clearCache: pluginGenerationOptions.clearCache ?? false,
disabledValidationRules: pluginGenerationOptions.disabledValidationRules ?? [],
excludePatterns: pluginGenerationOptions.excludePatterns ?? [],
includePatterns: pluginGenerationOptions.includePatterns ?? [],
noWorkspace: pluginGenerationOptions.noWorkspace ?? null,
pluginAuthType: pluginGenerationOptions.pluginAuthType ?? null,
pluginAuthRefid: pluginGenerationOptions.pluginAuthRefid ?? '',
});
}, pluginGenerationOptions.workingDirectory);
if (result instanceof Error) {
throw result;
}
if (result) {
const outputPath = pluginGenerationOptions.outputPath;
const pluginName = pluginGenerationOptions.pluginName;
const pathOfSpec = path.join(outputPath, `${pluginName.toLowerCase()}-openapi.yml`);
const plugingTypeName = types_1.KiotaPluginType[pluginType];
const pathPluginManifest = path.join(outputPath, `${pluginName.toLowerCase()}-${plugingTypeName.toLowerCase()}.json`);
return {
aiPlugin: pathPluginManifest,
openAPISpec: pathOfSpec,
isSuccess: (0, __1.checkForSuccess)(result),
logs: result
};
}
return undefined;
}
;
//# sourceMappingURL=generatePlugin.js.map