Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@nodeswork/utils

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nodeswork/utils - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

18

dist/metrics/built-in.operators.js

@@ -7,3 +7,3 @@ "use strict";

function Sum(val) {
return { operand: exports.SUM, value: val };
return { oper: exports.SUM, val, };
}

@@ -14,3 +14,3 @@ exports.Sum = Sum;

function Count(val) {
return { operand: exports.COUNT, value: val };
return { oper: exports.COUNT, val, };
}

@@ -21,3 +21,3 @@ exports.Count = Count;

function Average(val, weight = 1) {
return { operand: exports.AVERAGE, value: { v: val, w: weight } };
return { oper: exports.AVERAGE, val: { v: val, w: weight } };
}

@@ -33,3 +33,3 @@ exports.Average = Average;

function Max(val) {
return { operand: exports.MAX, value: val };
return { oper: exports.MAX, val, };
}

@@ -40,3 +40,3 @@ exports.Max = Max;

function Min(val) {
return { operand: exports.MIN, value: val };
return { oper: exports.MIN, val, };
}

@@ -47,3 +47,3 @@ exports.Min = Min;

function Last(val) {
return { operand: exports.LAST, value: val };
return { oper: exports.LAST, val, };
}

@@ -54,3 +54,3 @@ exports.Last = Last;

function First(val) {
return { operand: exports.FIRST, value: val };
return { oper: exports.FIRST, val, };
}

@@ -61,3 +61,3 @@ exports.First = First;

function Collect(val) {
return { operand: exports.COLLECT, value: [val] };
return { oper: exports.COLLECT, val: [val] };
}

@@ -68,5 +68,5 @@ exports.Collect = Collect;

function Union(val) {
return { operand: exports.UNION, value: [val] };
return { oper: exports.UNION, val: [val] };
}
exports.Union = Union;
operators_1.operator.registerAggregator(exports.UNION, (v1, v2) => _.union(v1, v2));
export interface MetricsValue<V> {
operand: string;
value: V;
oper: string;
val: V;
}

@@ -5,0 +5,0 @@ export interface Operator<T> {

@@ -8,6 +8,10 @@ import { MetricsData, MetricsDimensions, MetricsValue, Operator } from './def';

updateMetricsData(dimensions: MetricsDimensions, name: string, value: MetricsValue<any>, target?: MetricsData): MetricsData;
projectMetricsData(data: MetricsData, metricsNames: string[]): MetricsData;
projectMetricsData(data: MetricsData, options: MetricsProjectOptions): MetricsData;
mergeMetricsData(...datas: (MetricsData | MetricsData[])[]): MetricsData;
mergeMetricsDataInternal(data: MetricsData[], low: number, high: number): MetricsData;
private mergeMetricsDataInternal(data, low, high);
}
export interface MetricsProjectOptions {
metrics?: string[];
dimensions?: string[];
}
export declare const operator: MetricsOperator;

@@ -24,11 +24,14 @@ "use strict";

else {
const oper = this.operators[value.operand];
const oper = this.operators[value.oper];
if (oper == null) {
throw error_1.NodesworkError.internalServerError(`Unknown operator ${value.operand}`);
throw error_1.NodesworkError.internalServerError(`Unknown operator ${value.oper}`);
}
else if (value.operand != res.operand) {
throw error_1.NodesworkError.internalServerError(`Inconsistent operands ${value.operand} vs ${res.operand}`);
else if (value.oper != res.oper) {
throw error_1.NodesworkError.internalServerError(`Inconsistent operands ${value.oper} vs ${res.oper}`);
}
else {
res = oper(res, value);
res = {
oper: res.oper,
val: oper(res.val, value.val),
};
}

@@ -39,3 +42,3 @@ }

}
updateMetricsData(dimensions, name, value, target) {
updateMetricsData(dimensions = {}, name, value, target) {
const dhash = utils_1.hashDimensions(dimensions);

@@ -61,3 +64,8 @@ if (target == null) {

}
projectMetricsData(data, metricsNames) {
projectMetricsData(data, options) {
let metricsNames = options.metrics || [];
const dimensionNames = options.dimensions || [];
if (metricsNames.length === 0) {
metricsNames = Object.keys(data.metrics);
}
const dhashes = _

@@ -68,6 +76,17 @@ .chain(metricsNames)

.value();
return {
dimensions: _.pick(data.dimensions, dhashes),
metrics: _.pick(data.metrics, metricsNames),
};
const diff = _.difference(dhashes, dimensionNames);
if (dimensionNames.length === 0 || diff.length === 0) {
return {
dimensions: _.pick(data.dimensions, dhashes),
metrics: _.pick(data.metrics, metricsNames),
};
}
const result = { dimensions: {}, metrics: {} };
for (const mName of metricsNames) {
_.each(data.metrics[mName], (metricsValue, dhash) => {
const newDimensions = _.pick(data.dimensions[dhash], dimensionNames);
this.updateMetricsData(newDimensions, mName, metricsValue, result);
});
}
return result;
}

@@ -85,5 +104,5 @@ mergeMetricsData(...datas) {

}
const mid = (low + high) / 2;
const mid = Math.floor((low + high) / 2);
const left = this.mergeMetricsDataInternal(data, low, mid);
const right = this.mergeMetricsDataInternal(data, mid + 1, high);
const right = this.mergeMetricsDataInternal(data, mid, high);
const metricsNames = _.union(Object.keys(left.metrics), Object.keys(right.metrics));

@@ -90,0 +109,0 @@ const metrics = {};

{
"name": "@nodeswork/utils",
"version": "0.0.13",
"version": "0.0.14",
"description": "Utilities used across nodeswork repos.",

@@ -12,3 +12,4 @@ "main": "dist/index.js",

"start": "node dist/index.js",
"test": "./node_modules/.bin/gulp && NODE_ENV=test node_modules/.bin/mocha --timeout=10000 --trace-warnings"
"test": "./node_modules/.bin/gulp && NODE_ENV=test node_modules/.bin/mocha --timeout=10000 --trace-warnings --compilers coffee:coffeescript/register",
"test2": "NODE_ENV=test node_modules/.bin/mocha --timeout=10000 --trace-warnings --compilers ts:ts-node/register"
},

@@ -30,3 +31,5 @@ "repository": {

"devDependencies": {
"@types/mocha": "^2.2.43",
"@types/node": "^8.0.8",
"@types/should": "^11.2.0",
"chai": "^4.0.2",

@@ -36,5 +39,7 @@ "coffeescript": "^2.0.0-beta3",

"gulp-typedoc": "^2.0.2",
"gulp-typescript": "^3.2.1",
"gulp-typescript": "^3.2.2",
"mocha": "^3.4.2",
"should": "^11.2.1",
"source-map-support": "^0.5.0",
"ts-node": "^3.3.0",
"typedoc": "^0.7.1",

@@ -41,0 +46,0 @@ "typescript": "^2.4.2"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc