kwhitley / treeize

Converts row data (in JSON/associative array format) to tree structure based on column naming conventions.
MIT License
189 stars 24 forks source link

Deep node collections (perhaps when triggered with modifiers) failing to process #27

Closed kwhitley closed 9 years ago

kwhitley commented 9 years ago
var tree = new Treeize();

tree.setOptions({ log: true }).grow([
  { 'foo': 'bar', 'log+:id': 'abc', 'log+:a:b': 1 },
  { 'foo': 'bar', 'log+:id': 'abc', 'log+:a:b': 2 },
  { 'foo': 'baz', 'log+:id': 'abc', 'log+:a:b': 3 },
]);

fails with output:

SIGNATURE> { nodes: 
   [ { path: '',
       attributes: [ { name: 'foo', key: 'foo' } ],
       blueprint: [ { name: 'foo', key: 'foo' } ],
       isCollection: true,
       name: undefined,
       depth: 0,
       parent: '' },
     { path: 'log',
       attributes: [ { name: 'id', key: 'log+:id' } ],
       blueprint: [ { name: 'id', key: 'log+:id' } ],
       isCollection: [ '+' ],
       flags: true,
       name: 'log',
       depth: 1,
       parent: '' },
     { path: 'log+:a',
       attributes: [ { name: 'b', key: 'log+:a:b' } ],
       blueprint: [ { name: 'b', key: 'log+:a:b' } ],
       isCollection: false,
       name: 'a',
       depth: 2,
       parent: 'log+' } ],
  type: 'object',
  isFixed: false }
PROCESSING NODE> { path: '',
  attributes: [ { name: 'foo', key: 'foo' } ],
  blueprint: [ { name: 'foo', key: 'foo' } ],
  isCollection: true,
  name: undefined,
  depth: 0,
  parent: '' }
creating attribute "foo" within blueprint baz
creating attribute "foo" within extended blueprint baz
EXTENDED BLUEPRINT> { foo: 'baz' }
BLUEPRINT> { foo: 'baz' }
PARENT TRAIL NOT FOUND (ROOT?)
PROCESSING NODE> { path: 'log',
  attributes: [ { name: 'id', key: 'log+:id' } ],
  blueprint: [ { name: 'id', key: 'log+:id' } ],
  isCollection: [ '+' ],
  flags: true,
  name: 'log',
  depth: 1,
  parent: '' }
creating attribute "id" within blueprint abc
creating attribute "id" within extended blueprint abc
EXTENDED BLUEPRINT> { id: 'abc' }
BLUEPRINT> { id: 'abc' }
inserting into collection node { foo: 'baz' }
PROCESSING NODE> { path: 'log+:a',
  attributes: [ { name: 'b', key: 'log+:a:b' } ],
  blueprint: [ { name: 'b', key: 'log+:a:b' } ],
  isCollection: false,
  name: 'a',
  depth: 2,
  parent: 'log+' }
creating attribute "b" within blueprint 3
creating attribute "b" within extended blueprint 3
EXTENDED BLUEPRINT> { b: 3 }
BLUEPRINT> { b: 3 }
path MISSING for location "log+"
..attempting path location for ""
path FOUND for location for "" after removing 1 segments
create path for segment "log"
inserting into non-collection node
create object
BASE> [ { foo: 'bar', log: [ { id: 'abc' }, a: { b: 2 } ] },
  { foo: 'baz', log: [ { id: 'abc' }, a: { b: 3 } ] } ]
STATS> { time: { total: 19, signatures: 4 }, rows: 3, sources: 1 } 
kwhitley commented 9 years ago

Compared to (working):

tree.setOptions({ log: true }).grow([
  { 'foo': 'bar', 'logs:id': 'abc', 'logs:a:b': 1 },
  { 'foo': 'bar', 'logs:id': 'abc', 'logs:a:b': 2 },
  { 'foo': 'baz', 'logs:id': 'abc', 'logs:a:b': 3 },
]);
SIGNATURE> { nodes: 
   [ { path: '',
       attributes: [ { name: 'foo', key: 'foo' } ],
       blueprint: [ { name: 'foo', key: 'foo' } ],
       isCollection: true,
       name: undefined,
       depth: 0,
       parent: '' },
     { path: 'logs',
       attributes: [ { name: 'id', key: 'logs:id' } ],
       blueprint: [ { name: 'id', key: 'logs:id' } ],
       isCollection: true,
       name: 'logs',
       depth: 1,
       parent: '' },
     { path: 'logs:a',
       attributes: [ { name: 'b', key: 'logs:a:b' } ],
       blueprint: [ { name: 'b', key: 'logs:a:b' } ],
       isCollection: false,
       name: 'a',
       depth: 2,
       parent: 'logs' } ],
  type: 'object',
  isFixed: false }
PROCESSING NODE> { path: '',
  attributes: [ { name: 'foo', key: 'foo' } ],
  blueprint: [ { name: 'foo', key: 'foo' } ],
  isCollection: true,
  name: undefined,
  depth: 0,
  parent: '' }
creating attribute "foo" within blueprint baz
creating attribute "foo" within extended blueprint baz
EXTENDED BLUEPRINT> { foo: 'baz' }
BLUEPRINT> { foo: 'baz' }
PARENT TRAIL NOT FOUND (ROOT?)
PROCESSING NODE> { path: 'logs',
  attributes: [ { name: 'id', key: 'logs:id' } ],
  blueprint: [ { name: 'id', key: 'logs:id' } ],
  isCollection: true,
  name: 'logs',
  depth: 1,
  parent: '' }
creating attribute "id" within blueprint abc
creating attribute "id" within extended blueprint abc
EXTENDED BLUEPRINT> { id: 'abc' }
BLUEPRINT> { id: 'abc' }
inserting into collection node { foo: 'baz' }
PROCESSING NODE> { path: 'logs:a',
  attributes: [ { name: 'b', key: 'logs:a:b' } ],
  blueprint: [ { name: 'b', key: 'logs:a:b' } ],
  isCollection: false,
  name: 'a',
  depth: 2,
  parent: 'logs' }
creating attribute "b" within blueprint 3
creating attribute "b" within extended blueprint 3
EXTENDED BLUEPRINT> { b: 3 }
BLUEPRINT> { b: 3 }
inserting into non-collection node
create object
BASE> [ { foo: 'bar', logs: [ { id: 'abc', a: { b: 2 } } ] },
  { foo: 'baz', logs: [ { id: 'abc', a: { b: 3 } } ] } ]
STATS> { time: { total: 18, signatures: 2 }, rows: 3, sources: 1 }