UNPKG

@cloud-copilot/iam-data

Version:
79 lines 2.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.readDataFile = readDataFile; exports.readActionData = readActionData; exports.readConditionKeys = readConditionKeys; exports.readResourceTypes = readResourceTypes; exports.readConditionPatterns = readConditionPatterns; exports.readUnassociatedConditions = readUnassociatedConditions; const readRelativeFile_js_1 = require("./readRelativeFile.js"); const dataCache = {}; const requestCache = {}; async function readDataFile(...pathParts) { pathParts.unshift('data'); const file = pathParts.join('/'); // If the data is already cached, return it immediately. if (dataCache[file]) { return dataCache[file]; } // If there's an ongoing request, return the existing Promise. if (requestCache[file] !== undefined) { return requestCache[file]; } // Create a new Promise and store it in dataQueues synchronously. requestCache[file] = (async () => { try { const data = await (0, readRelativeFile_js_1.readRelativeFile)(pathParts); dataCache[file] = data; // Cache the fetched data. return data; } finally { delete requestCache[file]; // Clean up the queue regardless of success or failure. } })(); return requestCache[file]; } /** * Read the action data for a service * * @param serviceKey the service key to read the action data for * @returns the action data for the service */ async function readActionData(serviceKey) { return readDataFile('actions', `${serviceKey}.json`); } /** * Read the condition key data for a service * * @param serviceKey the service key to read the condition key data for * @returns the condition key data */ async function readConditionKeys(serviceKey) { return readDataFile('conditionKeys', `${serviceKey}.json`); } /** * Read the resource type data for a service * * @param serviceKey the service key to read the resource type data for * @returns the resource type data */ async function readResourceTypes(serviceKey) { return readDataFile('resourceTypes', `${serviceKey}.json`); } /** * Read the condition patterns data * * @returns the condition patterns data */ async function readConditionPatterns() { return readDataFile('conditionPatterns.json'); } /** * Read the unassociated conditions data * * @returns the unassociated conditions data */ async function readUnassociatedConditions() { return readDataFile('unassociatedConditions.json'); } //# sourceMappingURL=data.js.map