{ "version": 3, "sources": ["../_p/ui/query/angular-services/qw.query.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*/\n\nimport { HttpClient, HttpHeaders } from '@angular/common/http';\n\nexport {QwQueryService};\n\nclass QwQueryService {\n static get annotations() {\n return [\n new Injectable()\n ]\n }\n\n static get parameters() {\n return [\n HttpClient,\n ]\n }\n\n constructor(http) {\n this.http = http;\n\n /**\n * Fast UUID generator, RFC4122 version 4 compliant.\n * @author Jeff Ward (jcward.com).\n * @license MIT license\n * @link http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136\n **/\n this.UUID = (function () {\n var self = {};\n var lut = [];\n for (var i = 0; i < 256; i++) {\n lut[i] = (i < 16 ? '0' : '') + (i).toString(16);\n }\n self.generate = function () {\n var d0 = Math.random() * 0xffffffff | 0;\n var d1 = Math.random() * 0xffffffff | 0;\n var d2 = Math.random() * 0xffffffff | 0;\n var d3 = Math.random() * 0xffffffff | 0;\n return lut[d0 & 0xff] + lut[d0 >> 8 & 0xff] + lut[d0 >> 16 & 0xff] + lut[d0 >> 24 & 0xff] + '-' +\n lut[d1 & 0xff] + lut[d1 >> 8 & 0xff] + '-' + lut[d1 >> 16 & 0x0f | 0x40] + lut[d1 >> 24 & 0xff] + '-' +\n lut[d2 & 0x3f | 0x80] + lut[d2 >> 8 & 0xff] + '-' + lut[d2 >> 16 & 0xff] + lut[d2 >> 24 & 0xff] +\n lut[d3 & 0xff] + lut[d3 >> 8 & 0xff] + lut[d3 >> 16 & 0xff] + lut[d3 >> 24 & 0xff];\n }\n return self;\n })();\n }\n\n // create a query request object for internal queries (no user options)\n // timeout should be an integer number of seconds\n buildQueryRequest(queryText, timeout) {\n\n var queryRequest = {\n url: '../_p/query/query/service',\n method: \"POST\",\n headers: {\n 'Content-Type': 'application/json',\n 'ignore-401': 'true',\n 'CB-User-Agent': 'Couchbase Query Workbench',\n 'isNotForm': 'true'\n },\n data: {\n statement: queryText,\n pretty: false,\n timeout: (timeout || 0) + 's',\n client_context_id: \"INTERNAL-\" + this.UUID.generate(),\n },\n mnHttp: {\n isNotForm: true,\n group: \"global\"\n }\n };\n\n // our queries run through a ns_server proxy, so it needs a timeout at least\n // as long as that for the query service.\n if (timeout)\n queryRequest.headers['ns-server-proxy-timeout'] = (timeout + 1) * 1000;\n\n return(queryRequest);\n }\n\n //\n // run an internal UI query against the query service. For user queries, use\n // the QwQueryWorkbenchService, which includes user options and puts the result\n // in the query history.\n //\n // we run queries many places, some of them are still written to expect a Promise\n // (as was returned by the old $http). This function builds the query request, uses\n // the new HttpClient, and converts the response from an Observable to a Promise.\n //\n\n executeQueryUtil(queryText) {\n return(this.executeQueryUtilNew(queryText))\n .toPromise().then(this.handleSuccess,this.handleFailure);\n }\n\n //\n // query utility for new HttpClient with observables\n //\n\n executeQueryUtilNew(queryText) {\n var request = this.buildQueryRequest(queryText);\n return this.http.post(request.url,request.data,this.configToOptions(request));\n }\n\n // convenience functions for interacting with HttpClient\n\n // convert the $http config to an HttpClient options object\n\n configToOptions(config) {\n var options = {observe: 'response'};\n if (config.headers) {\n // can't pass options to HttpHeaders constructor, because it can't\n // handle headers with numeric values\n options.headers = new HttpHeaders();\n Object.keys(config.headers).forEach(key =>\n options.headers = options.headers.set(key,config.headers[key]));\n }\n\n if (config.params)\n options.params = config.params;\n return(options);\n }\n\n handleSuccess(resp) {\n if (resp && resp.status == 200 && resp.body) {\n if (typeof resp.body == 'string') try {\n resp.data = JSON.parse(resp.body);\n } catch (e) {}\n else\n resp.data = resp.body;\n }\n return(resp);\n }\n\n handleFailure(resp) {\n if (typeof resp.error == 'string') try {\n resp.data = JSON.parse(resp.error);\n } catch (e) {}\n\n return(Promise.reject(resp));\n }\n\n}\n\n"], "mappings": "gGA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