{"version":3,"file":"shared-aggregator.ddbdcedb4bd6a26c.js","mappings":"8JAMO,gBAAyBA,IAChCC,eACAC,SACAC,uBAOAC,iBACA,8BACA,iBAmEA,gBACA,cACAC,UAEAC,WACAC,sBAAiCC,kBACjCF,iBAEAA,EA3EAG,cACAC,EAEAC,iBACA,8BACA,cAIA,gBACAC,iBAGAL,mBAA6BC,YAE7B,eACA,YACAK,OAGAA,QACAD,cAGAA,KAuFA,gBACA,UACAN,MAEAA,UAEAA,4BACAA,4BACAA,SACAA,aACAA,SACAA,GAVAQ,EAxFAC,WAjBA,MADAL,WAkBA,CAIAM,qBACA,4BACA,4BACAC,EAEAC,mBACAf,oDACA,gCACA,WACAc,6BACAE,cAEAC,IACAH,aAGAA,EAEAI,SAEA,2DAEAlB,uBAIAmB,QAIA,QAHAC,KACAC,KACAJ,KACAH,IAAoBA,WAAkBA,IAEtCM,EADAC,QACAjB,0CACAgB,2BACApB,uBAEA,iBAaA,gBAEA,eAsBA,cACA,SAKAW,MAJAA,GACAF,KAKAE,EA7BAW,IAIAnB,GAKAA,MACAA,UAIAA,OACAA,OACAA,WACAQ,mBACAA,mBACAR,GAfA,CACAA,KAyCA,cACA,OACAA,IACAoB,MACAC,MACAC,QACAhB,qDCrJA,SACAiB,mBACAC,WAEO,QACP7B,eACA,IACA,6BAA8C,OAAI,GAClDE,sBACAI,oCACAA,oCACAA,uDAGU,CAHV,MAEMQ,IACA,OAAI","names":["o","constructor","super","this","store","count","t","Object","forEach","C","g","merge","c","O","a","f","storeMetric","r","getBucket","params","s","get","take","e","n","b","min","max","sos","agentIdentifier","ee"],"sourceRoot":"webpack:///","sources":["./node_modules/@newrelic/browser-agent/dist/esm/common/aggregate/aggregator.js","./node_modules/@newrelic/browser-agent/dist/esm/common/context/shared-context.js"],"sourcesContent":["/*\n * Copyright 2020 New Relic Corporation. All rights reserved.\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { SharedContext } from '../context/shared-context';\nexport class Aggregator extends SharedContext {\n constructor(parent) {\n super(parent);\n this.aggregatedData = {};\n }\n\n // Items with the same type and name get aggregated together\n // params are example data from the aggregated items\n // metrics are the numeric values to be aggregated\n\n store(type, name, params, newMetrics, customParams) {\n var bucket = this.getBucket(type, name, params, customParams);\n bucket.metrics = aggregateMetrics(newMetrics, bucket.metrics);\n return bucket;\n }\n merge(type, name, metrics, params, customParams) {\n var bucket = this.getBucket(type, name, params, customParams);\n if (!bucket.metrics) {\n bucket.metrics = metrics;\n return;\n }\n var oldMetrics = bucket.metrics;\n oldMetrics.count += metrics.count;\n\n // iterate through each new metric and merge\n Object.keys(metrics || {}).forEach(key => {\n // count is a special case handled above\n if (key === 'count') return;\n var oldMetric = oldMetrics[key];\n var newMetric = metrics[key];\n\n // handling the case where newMetric is a single-value first\n if (newMetric && !newMetric.c) {\n oldMetrics[key] = updateMetric(newMetric.t, oldMetric);\n } else {\n // newMetric is a metric object\n oldMetrics[key] = mergeMetric(newMetric, oldMetrics[key]);\n }\n });\n }\n storeMetric(type, name, params, value) {\n var bucket = this.getBucket(type, name, params);\n bucket.stats = updateMetric(value, bucket.stats);\n return bucket;\n }\n getBucket(type, name, params, customParams) {\n if (!this.aggregatedData[type]) this.aggregatedData[type] = {};\n var bucket = this.aggregatedData[type][name];\n if (!bucket) {\n bucket = this.aggregatedData[type][name] = {\n params: params || {}\n };\n if (customParams) {\n bucket.custom = customParams;\n }\n }\n return bucket;\n }\n get(type, name) {\n // if name is passed, get a single bucket\n if (name) return this.aggregatedData[type] && this.aggregatedData[type][name];\n // else, get all buckets of that type\n return this.aggregatedData[type];\n }\n\n // Like get, but for many types and it deletes the retrieved content from the aggregatedData\n take(types) {\n var results = {};\n var type = '';\n var hasData = false;\n for (var i = 0; i < types.length; i++) {\n type = types[i];\n results[type] = Object.values(this.aggregatedData[type] || {});\n if (results[type].length) hasData = true;\n delete this.aggregatedData[type];\n }\n return hasData ? results : null;\n }\n}\nfunction aggregateMetrics(newMetrics, oldMetrics) {\n if (!oldMetrics) oldMetrics = {\n count: 0\n };\n oldMetrics.count += 1;\n Object.entries(newMetrics || {}).forEach(([key, value]) => {\n oldMetrics[key] = updateMetric(value, oldMetrics[key]);\n });\n return oldMetrics;\n}\nfunction updateMetric(value, metric) {\n // when there is no value, then send only count\n if (value == null) {\n return updateCounterMetric(metric);\n }\n\n // When there is only one data point, the c (count), min, max, and sos (sum of squares) params are superfluous.\n if (!metric) return {\n t: value\n };\n\n // but on the second data point, we need to calculate the other values before aggregating in new values\n if (!metric.c) {\n metric = createMetricObject(metric.t);\n }\n\n // at this point, metric is always uncondensed\n metric.c += 1;\n metric.t += value;\n metric.sos += value * value;\n if (value > metric.max) metric.max = value;\n if (value < metric.min) metric.min = value;\n return metric;\n}\nfunction updateCounterMetric(metric) {\n if (!metric) {\n metric = {\n c: 1\n };\n } else {\n metric.c++;\n }\n return metric;\n}\nfunction mergeMetric(newMetric, oldMetric) {\n if (!oldMetric) return newMetric;\n if (!oldMetric.c) {\n // oldMetric is a single-value\n oldMetric = createMetricObject(oldMetric.t);\n }\n oldMetric.min = Math.min(newMetric.min, oldMetric.min);\n oldMetric.max = Math.max(newMetric.max, oldMetric.max);\n oldMetric.t += newMetric.t;\n oldMetric.sos += newMetric.sos;\n oldMetric.c += newMetric.c;\n return oldMetric;\n}\n\n// take a value and create a metric object\nfunction createMetricObject(value) {\n return {\n t: value,\n min: value,\n max: value,\n sos: value * value,\n c: 1\n };\n}","import { warn } from '../util/console';\nconst model = {\n agentIdentifier: '',\n ee: undefined\n};\nexport class SharedContext {\n constructor(context) {\n try {\n if (typeof context !== 'object') return warn(8);\n this.sharedContext = {};\n Object.assign(this.sharedContext, model);\n Object.entries(context).forEach(([key, value]) => {\n if (Object.keys(model).includes(key)) this.sharedContext[key] = value;\n });\n } catch (err) {\n warn(9, err);\n }\n }\n}"]}