UNPKG

armpit

Version:

Another resource manager programming interface toolkit.

66 lines 2.48 kB
export function ensureAzPrefix(templates) { if (templates.length > 0 && !/^\s*az\s/i.test(templates[0])) { const [firstCookedTemplate, ...remainingCookedTemplates] = templates; const [firstRawTemplate, ...remainingRawTemplates] = templates.raw; templates = Object.assign([`az ${firstCookedTemplate}`, ...remainingCookedTemplates], { raw: [`az ${firstRawTemplate}`, ...remainingRawTemplates], }); } return templates; } function extractSinglePropertyNameOrNull(obj) { let propName = null; for (const key in obj) { if (Object.hasOwn(obj, key)) { if (propName == null) { propName = key; } else { // If there are multiple properties then it doesn't fit the shape of a wrapped response return null; } } } return propName; } function findWrappedResultPropertyName(response) { const propName = extractSinglePropertyNameOrNull(response); if (propName) { if (propName === "publicIp") { return propName; } // Some create responses have {NewX:{}} or {newX:{}} wrappers // around the actual response. This will detect if the if (/^[Nn]ew[A-Za-z0-9]+$/.test(propName)) { return propName; } } return null; } function hasTypeProperty(obj) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return typeof obj.type === "string"; } function hasPropertiesProperty(obj) { // eslint-disable-next-line @typescript-eslint/no-explicit-any const properties = obj?.properties; return properties != null && typeof properties === "object"; } function isContainerAppResultWithProperties(result) { return hasPropertiesProperty(result) && hasTypeProperty(result) && /Microsoft.App\//i.test(result.type); } export function adjustCliResultObject(results, opt) { if (opt.unwrapResults) { const wrapperPropertyName = findWrappedResultPropertyName(results); if (wrapperPropertyName != null) { // eslint-disable-next-line @typescript-eslint/no-explicit-any return results[wrapperPropertyName]; } } if (opt.simplifyContainerAppResults && isContainerAppResultWithProperties(results)) { const { properties, ...rest } = results; return { ...rest, ...properties }; } return results; } //# sourceMappingURL=azCliInvoker.js.map