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,EAAE,GAAI,EAAE,GAAG,GAEpF,CACJ,CACA,MAAO,GACC,GACA,QAAQ,MAAM,4BAA6B,EAEnD,CACJ,CACA,OAAO,EAAQ,GAAW,KAAI,IAC1B,QAAc,IAAV,EAAqB,CACrB,IACI,GAAI,EAAc,CACd,MAAM,EAAU,aAA6C,EAAS,EAAU,cACxE,UAAU,QAAE,IAAe,EAC7B,EAAQ,EAAQ,IAAI,GACtB,GACI,GACA,UAAU,QAAQ,IAAI,YAAc,EAAe,WAAa,GAEpE,SAA8C,EAAM,aAAa,EAAc,IAG3E,GACA,QAAQ,KAAK,eAAiB,EAAe,aAGzD,CACJ,CACA,MAAO,GACC,GACA,QAAQ,MAAM,oCAAqC,EAE3D,CACA,IACI,EAAM,OACN,OAAQ,CACZ,CACA,MAAO,GACC,GACA,QAAQ,MAAM,2BAA4B,EAElD,CACJ,CACA,GAAI,EAAO,CACP,MAAM,GAAW,IAAI,MAAO,UAAY,EAClC,EAAQ,gBAAgB,QAAQ,EAAe,EAAW,GAChE,UAAU,QAAQ,kBAAkB,GACpC,UAAU,QAAQ,IAAI,MAAO,GAC7B,UAAU,QAAQ,IAAI,MAAO,GAC7B,UAAU,QAAQ,IAAI,OAAQ,GAC9B,UAAU,QAAQ,YAAY,EAClC,CACA,OAAO,CAAM,GACf,IAGV,QAAQ,QAAU","file":"/npm/react-native-firebase-perf-apollo-link@1.2.2/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/react-native-firebase-perf-apollo-link@1.2.2/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nvar __importDefault = (this && this.__importDefault) || function (mod) {\n    return (mod && mod.__esModule) ? mod : { \"default\": mod };\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nconst client_1 = require(\"@apollo/client\");\nconst formatMessage_1 = __importDefault(require(\"./formatMessage\"));\nconst logging_1 = __importDefault(require(\"./logging\"));\nconst createFPMLink = (perf, attributes, headersByKey, debug = false) => {\n    return new client_1.ApolloLink((operation, forward) => {\n        if (!forward) {\n            return null;\n        }\n        const def = operation.query.definitions.length > 0 ? operation.query.definitions[0] : undefined;\n        let operationType;\n        if (def) {\n            const operationTypeString = typeof def.operation === 'string' ? def.operation : undefined;\n            operationType = operationTypeString.length > 0 ? operationTypeString : 'req';\n        }\n        else {\n            operationType = 'req';\n        }\n        const perfObj = perf();\n        const startTime = new Date().getTime();\n        let trace;\n        if (perfObj && operationType !== 'subscription') {\n            let traceName = `${operation.operationName}`.trim();\n            if (traceName.length > 32) {\n                traceName = traceName.substr(0, 32);\n            }\n            else if (traceName.length === 0) {\n                traceName = 'unknown';\n            }\n            if (traceName.charAt(0) === '_') {\n                traceName = traceName.substr(1, traceName.length - 1).trim();\n                if (traceName.length === 0) {\n                    traceName = 'unknown';\n                }\n            }\n            if (traceName.charAt(traceName.length - 1) === '_') {\n                traceName = traceName.substr(0, traceName.length - 1).trim();\n                if (traceName.length === 0 || traceName === '_') {\n                    traceName = 'unknown';\n                }\n            }\n            try {\n                trace = perfObj.newTrace(traceName);\n                trace.start();\n                if (attributes) {\n                    const convertedAttributes = Object.entries(attributes);\n                    convertedAttributes.map(v => {\n                        trace === null || trace === void 0 ? void 0 : trace.putAttribute(v[0], v[1]);\n                    });\n                }\n            }\n            catch (e) {\n                if (debug) {\n                    console.error('Unable to start FPM trace', e);\n                }\n            }\n        }\n        return forward(operation).map(result => {\n            if (trace !== undefined) {\n                try {\n                    if (headersByKey) {\n                        const context = operation === null || operation === void 0 ? void 0 : operation.getContext();\n                        const { response: { headers }, } = context;\n                        const value = headers.get(headersByKey);\n                        if (value) {\n                            if (debug) {\n                                logging_1.default.log('HEADERS: ' + headersByKey + ' value: ' + value);\n                            }\n                            trace === null || trace === void 0 ? void 0 : trace.putAttribute(headersByKey, value);\n                        }\n                        else {\n                            if (debug) {\n                                console.warn('Header Key: ' + headersByKey + ' not exist');\n                            }\n                        }\n                    }\n                }\n                catch (e) {\n                    if (debug) {\n                        console.error('Error when getting headers by key', e);\n                    }\n                }\n                try {\n                    trace.stop();\n                    trace = undefined;\n                }\n                catch (e) {\n                    if (debug) {\n                        console.error('Unable to stop FPM trace', e);\n                    }\n                }\n            }\n            if (debug) {\n                const ellapsed = new Date().getTime() - startTime;\n                const group = formatMessage_1.default(operationType, operation, ellapsed);\n                logging_1.default.groupCollapsed(...group);\n                logging_1.default.log('REQ', operation);\n                logging_1.default.log('RES', result);\n                logging_1.default.log('ATTR', attributes);\n                logging_1.default.groupEnd(...group);\n            }\n            return result;\n        });\n    });\n};\nexports.default = createFPMLink;\n"]}