UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

90 lines (89 loc) 3.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoreTransformOrchestrator = void 0; exports.createCoreOrchestrator = createCoreOrchestrator; const path_1 = __importDefault(require("path")); const config_loader_impl_1 = require("./core/impl/config-loader.impl"); const transformer_orchestrator_abstract_impl_1 = require("./core/impl/transformer-orchestrator.abstract.impl"); /** * Core implementation of the Transform Orchestrator * Provides basic transformation capabilities with minimal configuration */ class CoreTransformOrchestrator extends transformer_orchestrator_abstract_impl_1.AbstractTransformerOrchestrator { /** * Create a new core transform orchestrator * @param configRegistry Configuration registry * @param transformerRegistry Transformer registry * @param targetVersion Target gateway version */ constructor(configRegistry, transformerRegistry, configLoader, targetVersion = '10.1.0') { super(configRegistry, transformerRegistry, configLoader, targetVersion); } /** * Check if an API and its assets are valid for transformation * Core implementation always returns true * @param api The API asset * @param relatedAssets Related assets * @returns True if the API is valid for transformation */ isApiValid(api, relatedAssets) { return true; } /** * Filter assets to include only those needed for the target gateway * Core implementation includes all assets by default * @param assets Array of assets to filter * @returns Filtered array of assets */ filterAssets(assets) { return assets; } /** * Post-transformation hook that runs after all assets have been transformed * Core implementation extracts the outputAsset from each wrapped asset * @param transformedAssets Array of wrapped transformed assets * @param resources Resources extracted from the ZIP file * @param apiName Name of the API being processed * @param apiMetadata Metadata of the API * @returns Final processed output */ async postTransform(allAssets, transformedAssets, resources, apiName, apiMetadata) { return transformedAssets .filter(asset => asset.outputAsset) .map(asset => asset.outputAsset); } /** * Pre-transformation hook that runs before individual asset transformations * Core implementation simply wraps each asset with its metadata * @param inputAssets Array of assets extracted from ZIP * @returns Processed assets ready for transformation */ async preTransform(inputAssets) { return inputAssets.map(asset => ({ inputSchema: asset, metadata: asset.metadata })); } } exports.CoreTransformOrchestrator = CoreTransformOrchestrator; /** * Factory function to create a core transform orchestrator with default registries * @returns A new core transform orchestrator */ function createCoreOrchestrator() { const configLoader = new config_loader_impl_1.ConfigLoader(path_1.default.resolve(__dirname, '../src')); const configRegistry = { getConfigPath: (_sourceVersion, _targetVersion, _kind) => { return '/configs/skip-transform.json'; } }; const transformerRegistry = { getTransformer: (_name) => { return undefined; } }; return new CoreTransformOrchestrator(configRegistry, transformerRegistry, configLoader); }