{ "version": 3, "sources": ["../ui/app/mn.collections.service.js"], "sourcesContent": ["/*\nCopyright 2020-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*/\nimport {Injectable} from '@angular/core';\nimport {HttpClient} from '@angular/common/http';\nimport {BehaviorSubject} from 'rxjs';\nimport {map, shareReplay} from 'rxjs/operators';\n\nimport {MnHttpRequest} from './mn.http.request.js';\nimport {MnBucketsService} from './mn.buckets.service.js';\nimport {MnPermissions} from './ajs.upgraded.providers.js';\nimport {singletonGuard} from './mn.core.js';\n\nconst restApiBase = \"/pools/default/buckets\";\n\nexport {MnCollectionsService}\n\nclass MnCollectionsService {\n static get annotations() { return [\n new Injectable()\n ]}\n\n static get parameters() { return [\n HttpClient,\n MnBucketsService,\n MnPermissions\n ]}\n\n constructor(http, mnBucketsService, mnPermissions) {\n singletonGuard(MnCollectionsService);\n\n this.http = http;\n this.stream = {};\n\n this.stream.updateManifest =\n new BehaviorSubject();\n\n this.stream.addScopeHttp =\n new MnHttpRequest(this.addScope.bind(this))\n .addSuccess()\n .addError(map(error => {\n if (error.status === 404) {\n return {errors: {bucketName: \"This bucket doesn't exist\"}};\n }\n if (typeof error === \"string\") {\n //hanlde \"Scope with this name already exists\" error\n return {errors: {name: error}};\n }\n return error;\n }));\n\n this.stream.deleteScopeHttp =\n new MnHttpRequest(this.deleteScope.bind(this))\n .addSuccess()\n .addError();\n\n this.stream.addCollectionHttp =\n new MnHttpRequest(this.addCollection.bind(this))\n .addSuccess()\n .addError();\n\n this.stream.deleteCollectionHttp =\n new MnHttpRequest(this.deleteCollection.bind(this))\n .addSuccess()\n .addError();\n\n this.stream.collectionBuckets = mnBucketsService.stream.bucketsMembaseEphemeral\n .pipe(map(buckets => buckets\n .filter(bucket => {\n let scope = mnPermissions.export.cluster.collection[bucket.name + ':.:.'];\n return scope && scope.collections.read;\n })),\n shareReplay({refCount: true, bufferSize: 1}));\n }\n\n extractInterestingStatsPipe(statsStream) {\n return statsStream.pipe(\n map(stats => Object.keys(stats).reduce((acc, statName) => {\n if (stats[statName] && stats[statName][\"aggregate\"]) {\n acc[statName] = stats[statName][\"aggregate\"].values\n .slice()\n .reverse()\n .find(stat => stat != null)[1];\n }\n return acc;\n }, {})),\n shareReplay({refCount: true, bufferSize: 1}));\n }\n\n getManifest(bucket) {\n bucket = encodeURIComponent(bucket);\n return this.http.get(`${restApiBase}/${bucket}/scopes`);\n }\n\n addScope({name, bucketName}) {\n bucketName = encodeURIComponent(bucketName);\n return this.http.post(`${restApiBase}/${bucketName}/scopes`, {\n name: name\n });\n }\n\n addCollection([bucket, scope, name, ttl]) {\n bucket = encodeURIComponent(bucket);\n scope = encodeURIComponent(scope);\n return this.http.post(`${restApiBase}/${bucket}/scopes/${scope}/collections`, {name: name, maxTTL: ttl || 0});\n }\n\n deleteScope([bucket, scope]) {\n bucket = encodeURIComponent(bucket);\n scope = encodeURIComponent(scope);\n return this.http.delete(`${restApiBase}/${bucket}/scopes/${scope}`);\n }\n\n deleteCollection([bucket, scope, collection]) {\n bucket = encodeURIComponent(bucket);\n scope = encodeURIComponent(scope);\n collection = encodeURIComponent(collection);\n return this.http.delete(`${restApiBase}/${bucket}/scopes/${scope}/collections/${collection}`);\n }\n}\n"], "mappings": "gWAmBA,GAAM,aAAc,yBAIpB,8BAA2B,WACd,cAAc,CAAE,MAAO,CAChC,GAAI,uBAGK,aAAa,CAAE,MAAO,CAC/B,WACA,iBACA,eAGF,YAAY,KAAM,iBAAkB,cAAe,CACjD,eAAe,sBAEf,KAAK,KAAO,KACZ,KAAK,OAAS,GAEd,KAAK,OAAO,eACV,GAAI,iBAEN,KAAK,OAAO,aACV,GAAI,eAAc,KAAK,SAAS,KAAK,OACpC,aACA,SAAS,IAAI,OACR,MAAM,SAAW,IACZ,CAAC,OAAQ,CAAC,WAAY,8BA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