{ "version": 3, "sources": ["../ui/app/mn.settings.auto.compaction.service.js"], "sourcesContent": ["/*\nCopyright 2021-Present Couchbase, Inc.\n\nUse of this software is governed by the Business Source License included in\nthe file licenses/BSL-Couchbase.txt. As of the Change Date specified in that\nfile, in accordance with the Business Source License, use of this software will\nbe governed by the Apache License, Version 2.0, included in the file\nlicenses/APL2.txt.\n*/\n\nimport {Injectable} from '@angular/core';\nimport {HttpClient, HttpParams} from '@angular/common/http';\nimport {NEVER} from 'rxjs';\nimport {switchMap, shareReplay, map} from 'rxjs/operators';\nimport {clone, is} from 'ramda';\n\nimport {MnPermissions} from './ajs.upgraded.providers.js';\nimport {MnHelperService} from './mn.helper.service.js';\nimport {MnHttpRequest} from './mn.http.request.js';\nimport {singletonGuard} from './mn.core.js';\n\nexport {MnSettingsAutoCompactionService}\n\nclass MnSettingsAutoCompactionService {\n static get annotations() { return [\n new Injectable()\n ]}\n\n static get parameters() { return [\n HttpClient,\n MnHelperService,\n MnPermissions\n ]}\n\n constructor(http, mnHelperService, permissions) {\n singletonGuard(MnSettingsAutoCompactionService);\n this.http = http;\n this.stream = {};\n this.mnHelperService = mnHelperService;\n this.permissions = permissions.stream;\n this.flattenData = this.flattenData.bind(this);\n\n this.stream.getAutoCompaction = this.permissions\n .pipe(switchMap(permissions =>\n permissions.cluster.settings.autocompaction.read ? this.getAutoCompaction() : NEVER),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.getIndexSettings = this.permissions\n .pipe(switchMap(permissions =>\n permissions.cluster.settings.indexes.read ? this.getIndexSettings() : NEVER),\n shareReplay({refCount: true, bufferSize: 1}));\n\n this.stream.isMemoryOptimized = this.stream.getIndexSettings\n .pipe(map(value => value.storageMode === \"memory_optimized\"));\n\n this.stream.postAutoCompaction =\n new MnHttpRequest(this.postAutoCompaction(false).bind(this))\n .addSuccess()\n .addError();\n\n this.stream.postAutoCompactionValidation =\n new MnHttpRequest(this.postAutoCompaction(true).bind(this))\n .addSuccess()\n .addError();\n\n this.stream.settingsSource = this.stream.getAutoCompaction\n .pipe(map(this.getSettingsSource.bind(this)));\n }\n\n getAutoCompaction() {\n return this.http.get('/settings/autoCompaction');\n }\n\n postAutoCompaction(validate) {\n return (data) => {\n return this.http.post('/controller/setAutoCompaction', data, {\n params: new HttpParams().set(\"just_validate\", validate ? 1 : 0)\n });\n }\n }\n\n getIndexSettings() {\n return this.http.get('/settings/indexes');\n }\n\n flattenData(obj, path = [], result = {}) {\n Object.keys(obj).forEach(k => {\n if (is(Object, obj[k])) {\n this.flattenData(obj[k], [...path, k], result);\n } else {\n let resultKey = [...path, k].reduce((acc, s, i) => acc + (i ? `[${s}]`: s));\n result[resultKey] = obj[k];\n }\n })\n\n return result;\n }\n\n /**\n * Sets the initial values of the auto compaction settings form.\n * Fragmentation and AllowedTimePeriod keys are added on the basis\n * they are present in the payload of the request.\n */\n getSettingsSource(settings) {\n let data = settings.autoCompactionSettings;\n\n let source = {\n indexCompactionMode: data.indexCompactionMode,\n timePeriodFlag: !!data.allowedTimePeriod,\n parallelDBAndViewCompaction: data.parallelDBAndViewCompaction,\n purgeInterval: settings.purgeInterval,\n };\n\n if (data.databaseFragmentationThreshold) {\n source.databaseFragmentationThreshold = this.setThresholdGroup(data.databaseFragmentationThreshold);\n }\n\n if (data.viewFragmentationThreshold) {\n source.viewFragmentationThreshold = this.setThresholdGroup(data.viewFragmentationThreshold);\n }\n\n if (data.indexFragmentationThreshold) {\n source.indexFragmentationThreshold = data.indexFragmentationThreshold;\n }\n\n if (data.indexCircularCompaction) {\n source.indexCircularCompaction = {\n daysOfWeek: this.mnHelperService.stringToObject(data.indexCircularCompaction.daysOfWeek),\n interval: data.indexCircularCompaction.interval\n }\n }\n\n if (data.allowedTimePeriod) {\n source.allowedTimePeriod = data.allowedTimePeriod;\n }\n\n source.magmaFragmentationPercentage = data.magmaFragmentationPercentage;\n\n return source;\n }\n\n getAutoCompactionData(group) {\n let values = clone(group.value);\n\n if (values.databaseFragmentationThreshold) {\n values.databaseFragmentationThreshold.size = values.databaseFragmentationThreshold.size ?\n this.mnHelperService.transformMBToBytes(values.databaseFragmentationThreshold.size) :\n \"undefined\";\n\n values.databaseFragmentationThreshold.percentage = values.databaseFragmentationThreshold.percentage ?\n values.databaseFragmentationThreshold.percentage :\n \"undefined\";\n\n delete values.databaseFragmentationThreshold.sizeFlag;\n delete values.databaseFragmentationThreshold.percentageFlag;\n }\n\n if (values.viewFragmentationThreshold) {\n values.viewFragmentationThreshold.size = values.viewFragmentationThreshold.size ?\n this.mnHelperService.transformMBToBytes(values.viewFragmentationThreshold.size) :\n \"undefined\";\n\n values.viewFragmentationThreshold.percentage = values.viewFragmentationThreshold.percentage ?\n values.viewFragmentationThreshold.percentage :\n \"undefined\";\n\n delete values.viewFragmentationThreshold.sizeFlag;\n delete values.viewFragmentationThreshold.percentageFlag;\n }\n\n values.purgeInterval = Number(values.purgeInterval);\n values.magmaFragmentationPercentage = Number(values.magmaFragmentationPercentage);\n\n delete values.timePeriodFlag;\n\n return this.flattenData(values);\n }\n\n isFlagEnabled(value) {\n return Number.isInteger(value);\n }\n\n maybeDefaultPercentage(value) {\n return Number.isInteger(value) ? value : \"\";\n }\n\n maybeDefaultSize(value) {\n return Number.isInteger(value) ? this.mnHelperService.transformBytesToMB(value) : \"\";\n }\n\n setThresholdGroup(threshold) {\n return {\n percentage: this.maybeDefaultPercentage(threshold.percentage),\n percentageFlag: this.isFlagEnabled(threshold.percentage),\n size: this.maybeDefaultSize(threshold.size),\n sizeFlag: this.isFlagEnabled(threshold.size)\n };\n }\n}\n"], "mappings": "oZAuBA,yCAAsC,WACzB,cAAc,CAAE,MAAO,CAChC,GAAI,uBAGK,aAAa,CAAE,MAAO,CAC/B,WACA,gBACA,eAGF,YAAY,KAAM,gBAAiB,YAAa,CAC9C,eAAe,iCACf,KAAK,KAAO,KACZ,KAAK,OAAS,GACd,KAAK,gBAAkB,gBACvB,KAAK,YAAc,YAAY,OAC/B,KAAK,YAAc,KAAK,YAAY,KAAK,M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