dt-toolbox 7.1.0 → 7.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Changelog.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## Release History
2
2
 
3
+ ### 7.1.1 (2023-09-05 )
4
+ - [x] Fix: Multiple queries in same programming scope;
5
+
6
+
3
7
 
4
8
  ### 7.1.0 (2023-08-28)
5
9
  - [x] Method `extractList` was added;
@@ -7,6 +11,7 @@
7
11
  - [x] Fix: Tuple model if data is just an array is wrong;
8
12
  - [x] Fix: Convertor to files shows 'root' in the beginning of the path;
9
13
  - [x] Fix: Convertor to breadcrumbs shows 'root' in the beginning of the path;
14
+ - [ ] Bug: Multiple queries in same programming scope;
10
15
 
11
16
 
12
17
 
@@ -17,11 +22,12 @@
17
22
  - [x] Method `insert` was renamed to `insertSegment`;
18
23
  - [x] Method `listSegments` was added to show list of all segments in dt-object;
19
24
  - [x] Method `insertSegment` expect the incoming data as dt-object, but if is not - will assume it as a standard javascript object and will convert it to dt-object automatically;
20
- - [] Method `insertSegment` can recognize a dt model object.
21
- - [] Bug: Method `model` doesn't recognize '**files**' as a model;
22
- - [] Bug: Tuple model if data is just an array is wrong;
23
- - [] Bug: Convertor to files shows 'root' in the beginning of the path;
24
- - [] Bug: Convertor to breadcrumbs shows 'root' in the beginning of the path;
25
+ - [ ] Method `insertSegment` can recognize a dt model object.
26
+ - [ ] Bug: Method `model` doesn't recognize '**files**' as a model;
27
+ - [ ] Bug: Tuple model if data is just an array is wrong;
28
+ - [ ] Bug: Convertor to files shows 'root' in the beginning of the path;
29
+ - [ ] Bug: Convertor to breadcrumbs shows 'root' in the beginning of the path;
30
+ - [ ] Bug: Multiple queries in same programming scope;
25
31
 
26
32
 
27
33
 
package/README.md CHANGED
@@ -3,8 +3,6 @@
3
3
  ![version](https://img.shields.io/github/package-json/v/peterNaydenov/dt-toolbox)
4
4
  ![license](https://img.shields.io/github/license/peterNaydenov/dt-toolbox)
5
5
 
6
- - [Documentatation for v.6.x.x is here](htts://github.com/PeterNaydenov/dt-toolbox/blob/master/README_v.6.x.x.md)
7
- - [Migration guide from v.6.x.x to v.7.x.x](htts://github.com/PeterNaydenov/dt-toolbox/blob/master/MIGRATION.md)
8
6
 
9
7
 
10
8
  ## Last Updates
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dt-toolbox",
3
3
  "description": "Data manipulation tool",
4
- "version": "7.1.0",
4
+ "version": "7.1.1",
5
5
  "license": "MIT",
6
6
  "author": "Peter Naydenov",
7
7
  "keywords": [
@@ -0,0 +1,50 @@
1
+ 'use strict'
2
+
3
+
4
+ function connect ( selectionIx ) {
5
+ return function connect ( list ) {
6
+ list.forEach ( item => {
7
+ let arr = item.split ( '/' )
8
+ const
9
+ child = arr.pop ()
10
+ , parent = arr.pop ()
11
+ , line = selectionIx[parent]
12
+ , childLine = selectionIx[child]
13
+ ;
14
+
15
+ if ( !childLine ) return this
16
+ if ( !line ) return this
17
+ if ( line[1][child] ) return this
18
+
19
+ let breadcrumbs = `${line[2]}/${child}`;
20
+
21
+ updateBreadcrumbs ( selectionIx , child, breadcrumbs )
22
+ if ( line[3].includes(breadcrumbs) ) return this
23
+ line[3].push ( breadcrumbs )
24
+ return this
25
+ })
26
+ }} // connect func.
27
+
28
+
29
+
30
+ function updateBreadcrumbs ( selectionIx, child, bread ) {
31
+ const
32
+ childLine = selectionIx[child]
33
+ , oldBread = childLine [2]
34
+ ;
35
+
36
+ childLine[2] = bread
37
+ selectionIx[oldBread] = childLine
38
+
39
+ childLine[3].forEach ( (br,i) => {
40
+ const search = new RegExp (`^${oldBread}\/`);
41
+ const brUpdate = br.replace ( search, `${bread}/` );
42
+ updateBreadcrumbs ( selectionIx[br], br, brUpdate )
43
+ })
44
+ } // updateBreadcrumbs func.
45
+
46
+
47
+
48
+ export default connect
49
+
50
+
@@ -0,0 +1,13 @@
1
+ import push from './push.js'
2
+ import set from './set.js'
3
+ import connect from './connect.js'
4
+ import save from './save.js'
5
+
6
+
7
+
8
+ export default {
9
+ push
10
+ , set
11
+ , connect
12
+ , save
13
+ }
@@ -8,7 +8,7 @@
8
8
 
9
9
 
10
10
  function get ( flatIO ) {
11
- return function find ( name ) {
11
+ return function get ( name ) {
12
12
  const list = [];
13
13
  flatIO.getScanList().every ( line => {
14
14
  const loc = line[2];
@@ -4,11 +4,6 @@ import insert from './insert.js'
4
4
  import ex from './export.js'
5
5
  import setupFilter from './setupFilter.js'
6
6
 
7
- import set from './set.js'
8
- import connect from './connect.js'
9
- import save from './save.js'
10
- import push from './push.js'
11
-
12
7
  import fr from './from.js'
13
8
  import use from './use.js'
14
9
  import find from './find.js'
@@ -16,13 +11,14 @@ import like from './like.js'
16
11
  import look from './look.js'
17
12
  import get from './get.js'
18
13
 
19
-
20
14
  // Default filters
21
15
  import list from './filters/list.js'
22
16
  import listObject from './filters/listObject.js'
23
17
  import object from './filters/object.js'
24
18
  import root from './filters/root.js'
25
19
 
20
+
21
+
26
22
  function flatData ( dependencies, d ) {
27
23
  const
28
24
  [ copy, indexes, flatData ] = d
@@ -31,11 +27,7 @@ function flatData ( dependencies, d ) {
31
27
  , filterFn = { list, listObject, object, root } // { filter functions}
32
28
  ;
33
29
 
34
- let
35
- selection = [] // Place for building a query/model result;
36
- , selectionIx = {}
37
- , scanList = flatData // Where 'look' function will be executed;
38
- ;
30
+ let scanList = flatData; // Where 'look' function will be executed;
39
31
 
40
32
  const
41
33
  getFilterNames = () => Object.keys ( filterFn )
@@ -60,35 +52,23 @@ function flatData ( dependencies, d ) {
60
52
  insert : insert ( flatStorage, filtering, getFilterNames ) // Insert a new rows to existing flatData;
61
53
  , export : ex ( flatStorage ) // Exports a copy of flatData;
62
54
  , getCopy : name => ( copy[name] ) ? copy[name] : null
63
- , getSelection : () => selection
64
- , getSelectionIx : () => selectionIx
65
55
  , getIndexes : () => indexes
66
56
  , getLine : k => indexes[k] ? indexes[k] : null
67
57
  , getFilters : () => filters
68
58
  , getScanList : () => scanList
69
59
  , setupScanList : l => scanList = l
70
60
  , setupFilter : setupFilter ( flatStorage, filterFn, filtering, getFilterNames ) // Add and apply a new filter function to flatData;
71
- , reset : () => { selection = [], scanList = flatData } // Removes 'selection' and reset the scanList to use all flatData;
72
- , resetScan : () => { scanList = flatData }
61
+ , resetScan : () => { scanList = flatData } // Reset the scanList to use all flatData;
73
62
  }
74
- , flatStoreSelection_API = {
75
- set : set ( selection, selectionIx ) // Selection: Creates a new row;
76
- , connect : connect ( selectionIx ) // Selection: Creates an edges among rows;
77
- , save : save ( selectionIx ) // Selection: Sets property+value in specified selection row;
78
- , push : push ( selectionIx ) // Selection: Adds a new value to selection row if data is an array structure;
79
- }
63
+
80
64
  , flatStore_API = {
81
- set : flatStoreSelection_API.set
82
- , connect : flatStoreSelection_API.connect
83
- , save : flatStoreSelection_API.save
84
- , push : flatStoreSelection_API.push
85
-
86
- , from : fr ( flatIO_API ) // Scan: Scan deeper from object;
87
- , use : use ( flatIO_API ) // Scan: Use filter to select objects to scan;
88
- , get : get ( flatIO_API ) // Scan: Take a single object with specific breadcrumbs;
89
- , find : find ( flatIO_API ) // Scan: String search for exact object name;
90
- , like : like ( flatIO_API ) // Scan: String search in object name;
91
- , look : look ( flatIO_API ) // Scan: Executes on each object property in the selection list;
65
+ // Query and Model functions will add methods related to new structure: set, connect, save, push;
66
+ from : fr ( flatIO_API ) // Scan: Scan deeper from object;
67
+ , use : use ( flatIO_API ) // Scan: Use filter to select objects to scan;
68
+ , get : get ( flatIO_API ) // Scan: Take a single object with specific breadcrumbs;
69
+ , find : find ( flatIO_API ) // Scan: String search for exact object name;
70
+ , like : like ( flatIO_API ) // Scan: String search in object name;
71
+ , look : look ( flatIO_API ) // Scan: Executes on each object property in the selection list;
92
72
  }
93
73
  ;
94
74
  return [ flatIO_API , flatStore_API ]
@@ -6,8 +6,7 @@ function extractList ( dependencies, flatIO, indexFn ) {
6
6
  return function exportList ( list, options={} ) {
7
7
  const
8
8
  root = indexFn ( 'root' )
9
- , { main } = dependencies ()
10
- , { load } = main ()
9
+ , { main:{load} } = dependencies ()
11
10
  , possibleAs = ['standard', 'std', 'midFlat', 'tuple', 'tuples', 'breadcrumb', 'breadcrumbs', 'files', 'file' ]
12
11
  ;
13
12
  let
@@ -8,7 +8,6 @@ return function insert ( name, inData ) {
8
8
  if ( isDTO(inData) ) {
9
9
  d = inData.export ()
10
10
  copy = inData.copy ()
11
-
12
11
  }
13
12
  else if ( isDTM(inData) ) {
14
13
  d = walk ({ data : inData })
@@ -4,11 +4,20 @@
4
4
 
5
5
  function model ( dependencies, flatIO ,flatStore ) {
6
6
  return function model () {
7
+ let
8
+ selection = [] // Place for building a query/model result;
9
+ , selectionIx = {}
10
+ ;
7
11
  const
8
- [ fn, ...args ] = arguments
9
- , { as } = fn ( flatStore, ...args ) || {}
10
- , { convert } = dependencies ()
11
- , selection = flatIO.getSelection ()
12
+ { convert, draft } = dependencies ()
13
+ , draft_API = {
14
+ set : draft.set ( selection, selectionIx ) // Selection: Creates a new row;
15
+ , connect : draft.connect ( selectionIx ) // Selection: Creates an edges among rows;
16
+ , save : draft.save ( selectionIx ) // Selection: Sets property+value in specified selection row;
17
+ , push : draft.push ( selectionIx ) // Selection: Adds a new value to selection row if data is an array structure;
18
+ }
19
+ , [ fn, ...args ] = arguments
20
+ , { as } = fn ( {...flatStore,...draft_API}, ...args ) || {}
12
21
  , data = ( selection.length === 0 ) ? flatIO.export() : selection
13
22
  , CONVERTOR_NAMES = [ 'standard', 'std', 'midFlat', 'tuple', 'tuples', 'breadcrumb', 'breadcrumbs', 'files', 'file' ]
14
23
  , hasConvertor = as ? CONVERTOR_NAMES.includes ( as ) : false
@@ -19,9 +28,10 @@ return function model () {
19
28
  console.error ( `Model '${as}' is unknown data-model.` )
20
29
  return null
21
30
  }
31
+
22
32
  if ( as ) result = convert.to ( as, dependencies, data )
23
33
  else result = data
24
- flatIO.reset ()
34
+ flatIO.resetScan ()
25
35
  return result
26
36
  }} // model func.
27
37
 
@@ -2,19 +2,28 @@
2
2
 
3
3
 
4
4
 
5
- function query ( dependencies, flatIO ,flatStore ) {
5
+ function query ( dependencies, flatIO, flatStore ) {
6
6
  return function query () {
7
7
  const
8
- { main } = dependencies ()
9
- , { load } = main ()
8
+ { main:{load}, draft } = dependencies ()
10
9
  , [ fn, ...args ] = arguments
11
10
  ;
11
+ let
12
+ selection = [] // Place for building a query/model result;
13
+ , selectionIx = {}
14
+ ;
15
+
16
+ const draft_API = {
17
+ set : draft.set ( selection, selectionIx ) // Selection: Creates a new row;
18
+ , connect : draft.connect ( selectionIx ) // Selection: Creates an edges among rows;
19
+ , save : draft.save ( selectionIx ) // Selection: Sets property+value in specified selection row;
20
+ , push : draft.push ( selectionIx ) // Selection: Adds a new value to selection row if data is an array structure;
21
+ }
12
22
 
13
- fn ( flatStore, ...args )
14
- const result = flatIO.getSelection ();
15
- flatIO.reset ()
16
- if ( result.length === 0 ) return this
17
- return load ( result )
23
+ fn ( {...flatStore, ...draft_API}, ...args )
24
+ flatIO.resetScan ()
25
+ if ( selection.length === 0 ) return this
26
+ return load ( selection )
18
27
  }} // query func.
19
28
 
20
29
 
package/src/mainLib.js CHANGED
@@ -4,9 +4,10 @@
4
4
 
5
5
  import walk from '@peter.naydenov/walk'
6
6
 
7
- import flatObject from './flatObject/index.js' // Flat data api.
8
- import flatData from './flatData/index.js' // Query data api. Used in model functions
9
- import convert from './convertors/index.js' // Convertors
7
+ import flatObject from './flatObject/index.js' // Flat data api.
8
+ import flatData from './flatData/index.js' // Query data api. Used in model functions
9
+ import convert from './convertors/index.js' // Convertors
10
+ import draft from './draft/index.js' // Build a dt-model api
10
11
 
11
12
 
12
13
 
@@ -31,7 +32,7 @@ const mainLib = {
31
32
  , flatObject
32
33
  , convert
33
34
  , INIT_DATA_TYPES
34
- , main : () => ({ load : mainLib.load })
35
+ , main : { load : mainLib.load }
35
36
  , isDTO : d => typeof d.insertSegment === 'function'
36
37
  , isDTM : d => {
37
38
  if ( !(d instanceof Array)) return false
@@ -40,7 +41,7 @@ const mainLib = {
40
41
  if ( d[0][0] !== 'root' ) return false
41
42
  return true
42
43
  }
43
- ,
44
+ , draft
44
45
  }
45
46
  } // dependencies func.
46
47
 
@@ -56,11 +57,8 @@ const mainLib = {
56
57
  console.error ( `Can't understand your data-model: ${model}. Please, find what is possible on https://github.com/PeterNaydenov/dt-toolbox` )
57
58
  return null
58
59
  }
59
- const
60
- d = convert.from(model).toFlat ( dependencies, inData )
61
- , flat = flatObject ( dependencies, d )
62
- ;
63
- return flat
60
+ const d = convert.from(model).toFlat ( dependencies, inData );
61
+ return flatObject ( dependencies, d )
64
62
  } // init func.
65
63
 
66
64
 
File without changes
File without changes
File without changes