UNPKG

@azure/app-configuration

Version:
77 lines (76 loc) 3.23 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var snapshotReference_exports = {}; __export(snapshotReference_exports, { SnapshotReferenceHelper: () => SnapshotReferenceHelper, isSnapshotReference: () => isSnapshotReference, parseSnapshotReference: () => parseSnapshotReference, snapshotReferenceContentType: () => snapshotReferenceContentType }); module.exports = __toCommonJS(snapshotReference_exports); var import_logger = require("./logger.js"); const snapshotReferenceContentType = 'application/json; profile="https://azconfig.io/mime-profiles/snapshot-ref"; charset=utf-8'; const SnapshotReferenceHelper = { /** * Takes the SnapshotReference (JSON) and returns a ConfigurationSetting (with the props encoded in the value). */ toConfigurationSettingParam: (snapshotReference) => { import_logger.logger.info("Encoding SnapshotReference value in a ConfigurationSetting:", snapshotReference); if (!snapshotReference.value) { import_logger.logger.error(`SnapshotReference has an unexpected value`, snapshotReference); throw new TypeError(`SnapshotReference has an unexpected value - ${snapshotReference.value}`); } const jsonSnapshotReferenceValue = { snapshot_name: snapshotReference.value.snapshotName }; const configSetting = { ...snapshotReference, value: JSON.stringify(jsonSnapshotReferenceValue) }; return configSetting; } }; function parseSnapshotReference(setting) { import_logger.logger.info( "[parseSnapshotReference] Parsing the value to return the SnapshotReferenceValue", setting ); if (!isSnapshotReference(setting)) { import_logger.logger.error("Invalid SnapshotReference input", setting); throw TypeError( `Setting with key ${setting.key} is not a valid SnapshotReference, make sure to have the correct content-type and a valid non-null value.` ); } const jsonSnapshotReferenceValue = JSON.parse(setting.value); const snapshotReference = { ...setting, value: { snapshotName: jsonSnapshotReferenceValue.snapshot_name } }; return snapshotReference; } function isSnapshotReference(setting) { return setting && setting.contentType === snapshotReferenceContentType && typeof setting.value === "string"; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { SnapshotReferenceHelper, isSnapshotReference, parseSnapshotReference, snapshotReferenceContentType }); //# sourceMappingURL=snapshotReference.js.map