const knownExtensionParameters = ["attachTo", "disabled", "config"]; function readAppExtensionsConfig(rootConfig) { const arr = rootConfig.getOptional("app.extensions"); if (!Array.isArray(arr)) { if (arr === void 0) { return []; } rootConfig.getConfigArray("app.extensions"); return []; } return arr.map( (arrayEntry, arrayIndex) => expandShorthandExtensionParameters(arrayEntry, arrayIndex) ); } function expandShorthandExtensionParameters(arrayEntry, arrayIndex) { function errorMsg(msg, key, prop) { return `Invalid extension configuration at app.extensions[${arrayIndex}]${key ? `[${key}]` : ""}${prop ? `.${prop}` : ""}, ${msg}`; } function assertValidId(id2) { if (!id2 || id2 !== id2.trim()) { throw new Error( errorMsg("extension ID must not be empty or contain whitespace") ); } } if (typeof arrayEntry === "string") { assertValidId(arrayEntry); return { id: arrayEntry, disabled: false }; } if (typeof arrayEntry !== "object" || arrayEntry === null || Array.isArray(arrayEntry)) { throw new Error(errorMsg("must be a string or an object")); } const keys = Object.keys(arrayEntry); if (keys.length !== 1) { const joinedKeys = keys.length ? `'${keys.join("', '")}'` : "none"; throw new Error(errorMsg(`must have exactly one key, got ${joinedKeys}`)); } const id = String(keys[0]); const value = arrayEntry[id]; assertValidId(id); if (value === null) { return { id, disabled: false }; } if (typeof value === "boolean") { return { id, disabled: !value }; } if (typeof value !== "object" || Array.isArray(value)) { throw new Error(errorMsg("value must be a boolean or object", id)); } const attachTo = value.attachTo; const disabled = value.disabled; const config = value.config; if (attachTo !== void 0) { if (attachTo === null || typeof attachTo !== "object" || Array.isArray(attachTo)) { throw new Error(errorMsg("must be an object", id, "attachTo")); } if (typeof attachTo.id !== "string" || attachTo.id === "") { throw new Error( errorMsg("must be a non-empty string", id, "attachTo.id") ); } if (typeof attachTo.input !== "string" || attachTo.input === "") { throw new Error( errorMsg("must be a non-empty string", id, "attachTo.input") ); } } if (disabled !== void 0 && typeof disabled !== "boolean") { throw new Error(errorMsg("must be a boolean", id, "disabled")); } if (config !== void 0 && (typeof config !== "object" || config === null || Array.isArray(config))) { throw new Error(errorMsg("must be an object", id, "config")); } const unknownKeys = Object.keys(value).filter( (k) => !knownExtensionParameters.includes(k) ); if (unknownKeys.length > 0) { throw new Error( errorMsg( `unknown parameter; expected one of '${knownExtensionParameters.join( "', '" )}'`, id, unknownKeys.join(", ") ) ); } return { id, attachTo, disabled, config }; } export { expandShorthandExtensionParameters, readAppExtensionsConfig }; //# sourceMappingURL=readAppExtensionsConfig.esm.js.map