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

@atombender/hydrant-api

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atombender/hydrant-api - npm Package Compare versions

Comparing version 0.0.25 to 0.0.26

90

dist/json.js

@@ -9,2 +9,4 @@ 'use strict';

exports.serializeTableQuery = serializeTableQuery;
exports.deserializeTableQuery = deserializeTableQuery;
exports.serializeQuery = serializeQuery;

@@ -14,5 +16,6 @@ exports.deserializeQuery = deserializeQuery;

exports.deserializeTopKQuery = deserializeTopKQuery;
exports.serializeResults = serializeResults;
exports.serializeTable = serializeTable;
exports.deserializeTable = deserializeTable;
exports.serializeResultSet = serializeResultSet;
exports.serializeTableResultSet = serializeTableResultSet;
exports.serializeSchema = serializeSchema;

@@ -79,2 +82,58 @@ exports.parseSchema = parseSchema;

function serializeTableQuery(query) {
var raw = {};
raw.groupings = query.groupings.map(function (g) {
return {
id: g.dimension.id,
mode: g.mode
};
});
raw.query = serializeQuery(query.query);
if (query.sortDimension) {
raw.sortDimension = query.sortDimension.id;
}
if (query.sortDirection) {
raw.sortDirection = query.sortDirection;
}
return raw;
}
function deserializeTableQuery(rawQuery, schema) {
var query = new _queries.TableQuery();
query.setGroupings((rawQuery.groupings || []).map(function (raw) {
return parseTableGrouping(raw, schema);
}));
query.setQuery(deserializeQuery(rawQuery.query, schema));
if (rawQuery.sortDimension) {
query.sortDimension = (0, _underscore.find)(schema.dimensions, function (d) {
return d.id == rawQuery.sortDimension;
});
}
if (rawQuery.sortDirection == _queries.SORT_DIRECTION_ASCENDING || rawQuery.sortDirection == _queries.SORT_DIRECTION_DESCENDING) {
query.sortDirection = rawQuery.sortDirection;
}
return query;
function parseTableGrouping(raw) {
if (raw) {
var _ret = (function () {
var id = raw.id;
var dimension = (0, _underscore.find)(schema.dimensions, function (d) {
return d.id === id;
});
if (!dimension) {
throw new Error('Unknown dimension ' + id);
}
return {
v: new _queries.TableGrouping(dimension, raw.mode)
};
})();
if (typeof _ret === 'object') return _ret.v;
} else {
return null;
}
}
}
function serializeQuery(query) {

@@ -92,6 +151,5 @@ var raw = {};

});
raw.groupBy = query.groupByItems.map(function (g) {
raw.groupings = query.groupings.map(function (g) {
return {
id: g.dimension.id,
mode: g.mode
id: g.dimension.id
};

@@ -125,4 +183,4 @@ });

}));
query.setGroupByItems((rawQuery.groupBy || []).map(function (raw) {
return parseGroupBy(raw, schema);
query.setGroupings((rawQuery.groupings || []).map(function (raw) {
return parseGrouping(raw, schema);
}));

@@ -169,3 +227,3 @@ query.setTimeInterval(parseTimeInterval(rawQuery.timeInterval));

if (raw) {
var _ret = (function () {
var _ret2 = (function () {
var id = raw.id;

@@ -183,3 +241,3 @@ var dimension = (0, _underscore.find)(schema.dimensions, function (d) {

if (typeof _ret === 'object') return _ret.v;
if (typeof _ret2 === 'object') return _ret2.v;
} else {

@@ -190,5 +248,5 @@ return null;

function parseGroupBy(raw) {
function parseGrouping(raw) {
if (raw) {
var _ret2 = (function () {
var _ret3 = (function () {
var id = raw.id;

@@ -202,7 +260,7 @@ var dimension = (0, _underscore.find)(schema.dimensions, function (d) {

return {
v: new _queries.GroupBy(dimension, raw.mode)
v: new _queries.Grouping(dimension)
};
})();
if (typeof _ret2 === 'object') return _ret2.v;
if (typeof _ret3 === 'object') return _ret3.v;
} else {

@@ -264,3 +322,3 @@ return null;

if (!dimension) {
throw new Error('Unknown dimension ' + id);
throw new Error('Unknown dimension ' + raw.id);
}

@@ -274,2 +332,6 @@ return new _queries.Filter(dimension, raw.operator, raw.value);

function serializeResults(results) {
return results;
}
function serializeTable(table) {

@@ -418,3 +480,3 @@ return {

function serializeResultSet(results) {
function serializeTableResultSet(results) {
return {

@@ -421,0 +483,0 @@ rows: results.rows.map(function (row) {

212

dist/queries.js

@@ -17,7 +17,26 @@ 'use strict';

var GroupBy = (function () {
function GroupBy(dimension) {
var Grouping = (function () {
function Grouping(dimension) {
_classCallCheck(this, Grouping);
this.dimension = dimension;
}
_createClass(Grouping, [{
key: 'equals',
value: function equals(other) {
return other instanceof Grouping && other.dimension.equals(this.dimension);
}
}]);
return Grouping;
})();
exports.Grouping = Grouping;
var TableGrouping = (function () {
function TableGrouping(dimension) {
var mode = arguments[1] === undefined ? null : arguments[1];
_classCallCheck(this, GroupBy);
_classCallCheck(this, TableGrouping);

@@ -34,13 +53,13 @@ if (!mode) {

_createClass(GroupBy, [{
_createClass(TableGrouping, [{
key: 'equals',
value: function equals(other) {
return other instanceof GroupBy && other.dimension.equals(this.dimension) && (0, _underscore.isEqual)(this.mode, other.mode);
return other instanceof TableGrouping && other.dimension.equals(this.dimension) && (0, _underscore.isEqual)(this.mode, other.mode);
}
}]);
return GroupBy;
return TableGrouping;
})();
exports.GroupBy = GroupBy;
exports.TableGrouping = TableGrouping;

@@ -75,8 +94,6 @@ var Filter = (function () {

this.filters = [];
this.groupByItems = [];
this.groupings = [];
this.timeframe = null;
this.timeRange = null;
this.timeInterval = null;
this.sortDimension = null;
this.sortDirection = null;
this.limit = null;

@@ -88,17 +105,17 @@ this.timeZone = null;

_createClass(Query, [{
key: 'mayGroupItemBeNested',
key: 'mayGroupingBeNested',
// A group item can only be nested if it comes after a "row" or a "nest", and
// we only permit one parent.
value: function mayGroupItemBeNested(groupByItem) {
return this._mayGroupItemBeNested(groupByItem, this.groupByItems);
value: function mayGroupingBeNested(grouping) {
return this._mayGroupingBeNested(grouping, this.groupings);
}
}, {
key: '_mayGroupItemBeNested',
key: '_mayGroupingBeNested',
// A group item can only be nested if it comes after a "row" or a "nest", and
// we only permit one parent.
value: function _mayGroupItemBeNested(groupByItem, items) {
value: function _mayGroupingBeNested(grouping, items) {
var idx = (0, _atombenderUtils.findIndex)(items, function (g) {
return g.dimension.id === groupByItem.dimension.id;
return g.dimension.id === grouping.dimension.id;
});

@@ -130,5 +147,3 @@ if (idx > 0 && items.length > 1) {

this.filters = [];
this.groupByItems = [];
this.sortDimension = null;
this.sortDirection = null;
this.groupings = [];
}

@@ -186,14 +201,6 @@ return this;

}, {
key: 'setGroupByItems',
value: function setGroupByItems(groupByItems) {
var _this = this;
this.groupByItems = groupByItems.map(function (g, idx) {
if (idx === 0 && g.mode !== 'pivot') {
return new GroupBy(g.dimension, 'row');
} else if (g.mode === 'pivot' || _this._mayGroupItemBeNested(g, groupByItems)) {
return g;
} else {
return new GroupBy(g.dimension, 'row');
}
key: 'setGroupings',
value: function setGroupings(groupings) {
this.groupings = groupings.map(function (g) {
return new Grouping(g.dimension);
});

@@ -209,5 +216,3 @@ return this;

query.eventTypes = (0, _underscore.clone)(this.eventTypes);
query.groupByItems = (0, _underscore.clone)(this.groupByItems);
query.sortDimension = this.sortDimension;
query.sortDirection = this.sortDirection;
query.groupings = (0, _underscore.clone)(this.groupings);
query.timeInterval = this.timeInterval;

@@ -224,14 +229,2 @@ query.timeRange = this.timeRange;

value: function equals(other) {
return this._equals(other);
}
}, {
key: 'equalsIgnoringSorting',
value: function equalsIgnoringSorting(other) {
return this._equals(other, true);
}
}, {
key: '_equals',
value: function _equals(other) {
var ignoreSorting = arguments[1] === undefined ? false : arguments[1];
if (!other instanceof Query) {

@@ -265,5 +258,5 @@ return false;

}
if (!(0, _underscore.isEqual)(this.groupByItems.map(function (g) {
if (!(0, _underscore.isEqual)(this.groupings.map(function (g) {
return [g.dimension.id, g.mode];
}), other.groupByItems.map(function (g) {
}), other.groupings.map(function (g) {
return [g.dimension.id, g.mode];

@@ -285,10 +278,119 @@ }))) {

}
if (ignoreSorting !== true) {
if ((this.sortDimension && this.sortDimension.id) !== (other.sortDimension && other.sortDimension.id)) {
return false;
return true;
}
}]);
return Query;
})();
exports.Query = Query;
// Ascending sort direction
var SORT_DIRECTION_ASCENDING = 'asc';
exports.SORT_DIRECTION_ASCENDING = SORT_DIRECTION_ASCENDING;
// Descending sort direction
var SORT_DIRECTION_DESCENDING = 'desc';
exports.SORT_DIRECTION_DESCENDING = SORT_DIRECTION_DESCENDING;
var TableQuery = (function () {
function TableQuery() {
_classCallCheck(this, TableQuery);
this.query = null;
this.groupings = [];
this.sortDimension = null;
this.sortDirection = null;
}
_createClass(TableQuery, [{
key: 'mayGroupingBeNested',
// A group item can only be nested if it comes after a "row" or a "nest", and
// we only permit one parent.
value: function mayGroupingBeNested(grouping) {
return this._mayGroupingBeNested(grouping, this.groupings);
}
}, {
key: '_mayGroupingBeNested',
// A group item can only be nested if it comes after a "row" or a "nest", and
// we only permit one parent.
value: function _mayGroupingBeNested(grouping, items) {
var idx = (0, _atombenderUtils.findIndex)(items, function (g) {
return g.dimension.id === grouping.dimension.id;
});
if (idx > 0 && items.length > 1) {
for (var i = idx - 1; i >= 0; i--) {
if (items[i].mode === 'nest') {
return true;
} else if (items[i].mode === 'row') {
var j = (0, _atombenderUtils.findIndex)(items, function (g) {
return g.mode === 'nest';
});
if (j === -1 || j > i) {
return true;
}
} else {
break;
}
}
if (this.sortDirection !== other.sortDirection) {
return false;
}
return false;
}
}, {
key: 'setQuery',
value: function setQuery(query) {
this.query = query;
return this;
}
}, {
key: 'setGroupings',
value: function setGroupings(groupings) {
var _this = this;
this.groupings = groupings.map(function (g, idx) {
if (idx === 0 && g.mode !== 'pivot') {
return new TableGrouping(g.dimension, 'row');
} else if (g.mode === 'pivot' || _this._mayGroupingBeNested(g, groupings)) {
return g;
} else {
return new TableGrouping(g.dimension, 'row');
}
});
return this;
}
}, {
key: 'clone',
value: function clone() {
var result = new TableQuery();
result.query = (0, _underscore.clone)(this.query);
result.groupings = (0, _underscore.clone)(this.groupings);
result.sortDimension = this.sortDimension;
result.sortDirection = this.sortDirection;
return result;
}
}, {
key: 'equals',
value: function equals(other) {
if (!other instanceof TableQuery) {
return false;
}
if (this.query && other.query && !this.query.equals(other.query)) {
return false;
}
if (!(0, _underscore.isEqual)(this.groupings.map(function (g) {
return [g.dimension.id, g.mode];
}), other.groupings.map(function (g) {
return [g.dimension.id, g.mode];
}))) {
return false;
}
if ((this.sortDimension && this.sortDimension.id) !== (other.sortDimension && other.sortDimension.id)) {
return false;
}
if (this.sortDirection !== other.sortDirection) {
return false;
}
return true;

@@ -298,6 +400,6 @@ }

return Query;
return TableQuery;
})();
exports.Query = Query;
exports.TableQuery = TableQuery;

@@ -304,0 +406,0 @@ var TopKQuery = (function () {

@@ -17,10 +17,10 @@ 'use strict';

// A result row is a map of dimensions to raw values (eg., strings,
// A table row is a map of dimensions to raw values (eg., strings,
// epoch integers, etc.).
var ResultRow = (function () {
function ResultRow() {
var TableRow = (function () {
function TableRow() {
var values = arguments[0] === undefined ? null : arguments[0];
_classCallCheck(this, ResultRow);
_classCallCheck(this, TableRow);

@@ -30,24 +30,66 @@ this.values = values ? _immutable2['default'].Map(values) : _immutable2['default'].Map();

_createClass(ResultRow, [{
_createClass(TableRow, [{
key: 'toString',
value: function toString() {
return 'ResultRow values={this.values.toString()}';
return 'TableRow values={this.values.toString()}';
}
}]);
return ResultRow;
return TableRow;
})();
exports.ResultRow = ResultRow;
exports.TableRow = TableRow;
// A result set is a very basic set of result rows (pairs of dimensions and
// A table result set is a very basic set of result rows (pairs of dimensions and
// raw values) that is the raw output of a search.
var TableResultSet = (function () {
function TableResultSet() {
var rows = arguments[0] === undefined ? null : arguments[0];
_classCallCheck(this, TableResultSet);
this.rows = rows ? _immutable2['default'].List(rows) : _immutable2['default'].List();
}
_createClass(TableResultSet, [{
key: 'toString',
value: function toString() {
return 'TableResultSet rows={this.rows.toString()}';
}
}]);
return TableResultSet;
})();
exports.TableResultSet = TableResultSet;
var ResultBucket = (function () {
function ResultBucket(key) {
_classCallCheck(this, ResultBucket);
this.key = key;
this.count = 0;
this.buckets = _immutable2['default'].Set();
}
_createClass(ResultBucket, [{
key: 'toString',
value: function toString() {
return 'ResultBucket key={this.key.toString()}';
}
}]);
return ResultBucket;
})();
exports.ResultBucket = ResultBucket;
var ResultSet = (function () {
function ResultSet() {
var rows = arguments[0] === undefined ? null : arguments[0];
var buckets = arguments[0] === undefined ? null : arguments[0];
_classCallCheck(this, ResultSet);
this.rows = rows ? _immutable2['default'].List(rows) : _immutable2['default'].List();
this.buckets = buckets ? _immutable2['default'].Set(buckets) : _immutable2['default'].Set();
}

@@ -58,3 +100,3 @@

value: function toString() {
return 'ResultSet rows={this.rows.toString()}';
return 'ResultSet buckets={this.buckets.toString()}';
}

@@ -61,0 +103,0 @@ }]);

@@ -11,3 +11,3 @@ 'use strict';

exports.resultSetToTable = resultSetToTable;
exports.tableResultSetToTable = tableResultSetToTable;

@@ -28,5 +28,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var _queries = require('./queries');
function numericValueFrom(value) {
if (value instanceof TableRow) {
return value.valueMap.map(function (v, k) {
return value.valueMap.map(function (v, _) {
return numericValueFrom(v);

@@ -65,10 +67,2 @@ });

// Ascending sort direction
var DIRECTION_ASCENDING = 1;
exports.DIRECTION_ASCENDING = DIRECTION_ASCENDING;
// Descending sort direction
var DIRECTION_DESCENDING = -1;
exports.DIRECTION_DESCENDING = DIRECTION_DESCENDING;
/**

@@ -506,5 +500,6 @@ * Returned by `Table.computeColumnTree()` for any columns that reference

var grouped = groupings.groupBy(function (_ref3) {
var _ref32 = _slicedToArray(_ref3, 1);
var _ref32 = _slicedToArray(_ref3, 2);
var grouping = _ref32[0];
var _ = _ref32[1];
return grouping;

@@ -549,5 +544,6 @@ }).map(function (v, k) {

var merged = grouped.map(function (_ref4, k) {
var _ref42 = _slicedToArray(_ref4, 1);
var _ref42 = _slicedToArray(_ref4, 2);
var values = _ref42[0];
var _ = _ref42[1];

@@ -687,3 +683,3 @@ // Backwill row with zeroes

function isRowNestedOrPivoted(row) {
return row.valueMap.some(function (value, key) {
return row.valueMap.some(function (value, _) {
return value instanceof TableRow;

@@ -717,3 +713,3 @@ });

value: function sort(column, direction) {
var mul = direction === DIRECTION_DESCENDING ? -1 : 1;
var mul = direction === _queries.SORT_DIRECTION_DESCENDING ? -1 : 1;

@@ -725,3 +721,3 @@ var findValueFromColumn = function findValueFromColumn(row) {

if (value === undefined || value === null) {
var zz = row.valueMap.findEntry(function (v, k) {
var zz = row.valueMap.findEntry(function (v, _) {
return findValueFromColumn(v);

@@ -785,10 +781,9 @@ });

function resultSetToTable(query, resultSet) {
var schema = query.schema;
var groupByItems = query.groupByItems;
var timeInterval = query.timeInterval;
function tableResultSetToTable(query, results) {
var groupings = query.groupings;
var schema = query.query.schema;
var tableRows = _immutable2['default'].List(resultSet.rows.map(function (resultRow) {
var tableRows = _immutable2['default'].List(results.rows.map(function (row) {
var valueMap = _immutable2['default'].OrderedMap();
resultRow.values.forEach(function (value, dimension) {
row.values.forEach(function (value, dimension) {
valueMap = valueMap.set(dimension, dimension.parseRawValue(value));

@@ -801,3 +796,3 @@ });

var pivotDimensions = (0, _underscore.filter)(groupByItems, function (g) {
var pivotDimensions = (0, _underscore.filter)(groupings, function (g) {
return g.mode === 'pivot';

@@ -832,3 +827,3 @@ }).map(function (g) {

var parentIdx = groupByItems.length > 1 ? (0, _atombenderUtils.findIndex)(groupByItems, function (g) {
var parentIdx = groupings.length > 1 ? (0, _atombenderUtils.findIndex)(groupings, function (g) {
return g.mode === 'nest';

@@ -838,3 +833,3 @@ }) - 1 : -1;

(function () {
var nestables = groupByItems.slice(parentIdx, parentIdx + 1).concat((0, _underscore.filter)(groupByItems, function (g) {
var nestables = groupings.slice(parentIdx, parentIdx + 1).concat((0, _underscore.filter)(groupings, function (g) {
return g.mode === 'nest';

@@ -845,3 +840,3 @@ })).map(function (g) {

var unnestables = (0, _underscore.filter)(groupByItems.map(function (g) {
var unnestables = (0, _underscore.filter)(groupings.map(function (g) {
return g.dimension;

@@ -848,0 +843,0 @@ }), function (d) {

{
"name": "@atombender/hydrant-api",
"version": "0.0.25",
"version": "0.0.26",
"repository": {

@@ -5,0 +5,0 @@ "type": "git",

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