UNPKG

@microsoft/kiota

Version:

npm package exposing Kiota CLI functionality to TypeScript

106 lines (105 loc) 6.03 kB
"use strict"; 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.generateClient = generateClient; const rpc = __importStar(require("vscode-jsonrpc/node")); const __1 = require(".."); const connect_1 = __importDefault(require("../connect")); /** * Generates a client based on the provided client generation options. * * @param {ClientGenerationOptions} clientGenerationOptions - The options for generating the client. * * Options for generating a client. * * @param {string} clientGenerationOptions.openAPIFilePath - The file path to the OpenAPI specification. * @param {string} clientGenerationOptions.clientClassName - The name of the client class to generate. * @param {string} clientGenerationOptions.clientNamespaceName - The namespace name for the generated client. * @param {KiotaGenerationLanguage} clientGenerationOptions.language - The programming language for the generated client. * @param {string} clientGenerationOptions.outputPath - The output path for the generated client. * @param {ConsumerOperation} clientGenerationOptions.operation - The consumer operation to perform. * @param {string} clientGenerationOptions.workingDirectory - The working directory for the generation process. * @param {boolean} [clientGenerationOptions.clearCache] - Whether to clear the cache before generating the client. * @param {boolean} [clientGenerationOptions.cleanOutput] - Whether to clean the output directory before generating the client. * @param {string[]} [clientGenerationOptions.deserializers] - The list of deserializers to use. * @param {string[]} [clientGenerationOptions.disabledValidationRules] - The list of validation rules to disable. * @param {boolean} [clientGenerationOptions.excludeBackwardCompatible] - Whether to exclude backward-compatible changes. * @param {string[]} [clientGenerationOptions.excludePatterns] - The list of patterns to exclude from generation. * @param {boolean} [clientGenerationOptions.includeAdditionalData] - Whether to include additional data in the generated client. * @param {string[]} [clientGenerationOptions.includePatterns] - The list of patterns to include in generation. * @param {string[]} [clientGenerationOptions.serializers] - The list of serializers to use. * @param {string[]} [clientGenerationOptions.structuredMimeTypes] - The list of structured MIME types to support. * @param {boolean} [clientGenerationOptions.usesBackingStore] - Whether the generated client uses a backing store. * @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. */ async function generateClient(clientGenerationOptions) { const result = await (0, connect_1.default)(async (connection) => { const request = new rpc.RequestType1("Generate"); 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, }); }, clientGenerationOptions.workingDirectory); if (result instanceof Error) { throw result; } if (result) { return { isSuccess: (0, __1.checkForSuccess)(result), logs: result }; } return undefined; } ; //# sourceMappingURL=generateClient.js.map