Skip to content

Commit

Permalink
Allowing to have array like field names in schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Alena Khineika authored and Alena Khineika committed Feb 16, 2018
1 parent 1eddb48 commit f1d3608
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,17 @@ module.exports = function parse(options) {
* @param {Object} schema the updated schema object
*/
addToField = function(path, value, schema) {
var field = schema[path] = _.get(schema, path, {
var defaults = {};

defaults[path] = {
name: _.last(path.split('.')),
path: path,
count: 0,
types: {}
});
};
_.defaultsDeep(schema, defaults);
var field = schema[path];

field.count++;
// debug('added to field', field);
addToType(path, value, field.types);
Expand Down
6 changes: 4 additions & 2 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ describe('using only basic fields', function() {
'last_address_latitude': null,
'last_address_longitude': null,
'created_at': new Date(),
'length': 29
'length': 29,
'name[]': 'Annabeth Frankie'
}
];

Expand All @@ -36,7 +37,8 @@ describe('using only basic fields', function() {
'length',
'name',
'stats_friends',
'twitter_username'
'twitter_username',
'name[]'
];
assert.deepEqual(_.pluck(users.fields, 'name').sort(), field_names.sort());
});
Expand Down

0 comments on commit f1d3608

Please sign in to comment.