@loadmill/mcp
Version:
Loadmill mcp library
45 lines • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.schemaTypeToSchemaURL = exports.getSchema = void 0;
const constants_1 = require("../constants");
const http_request_1 = require("../http-request");
const schemaCache = new Map();
async function getSchema(schemaType) {
try {
console.log('Getting schema with type:', schemaType);
const schemaUrl = getSchemaURLByType(schemaType);
const cached = schemaCache.get(schemaUrl);
if (cached) {
if (!cached.expiresAt || Date.now() < cached.expiresAt) {
return cached.text;
}
schemaCache.delete(schemaUrl);
}
const resp = await (0, http_request_1.sendHttpRequest)({ method: http_request_1.HttpMethods.GET, url: schemaUrl });
const text = resp.text;
const entry = {
text,
expiresAt: Date.now() + 60 * 60 * 1000, // Cache for 60 minutes
};
console.log('Cached schema:', entry);
schemaCache.set(schemaUrl, entry);
return entry.text;
}
catch (error) {
console.error(`Failed to fetch schema for ${schemaType}:`, error);
throw error;
}
}
exports.getSchema = getSchema;
exports.schemaTypeToSchemaURL = {
[constants_1.SCHEMA_TYPE.TEST_SUITE]: `${constants_1.ASSETS_URL}/schema/loadmill-test-suite.schema.v1.json`,
};
function getSchemaURLByType(schemaType) {
const schemaUrl = exports.schemaTypeToSchemaURL[schemaType];
//console.log('Resolved schema URL:', schemaUrl);
if (!schemaUrl) {
throw new Error(`Unknown schema type: ${schemaType}`);
}
return schemaUrl;
}
//# sourceMappingURL=shared.js.map