dt-toolbox 7.1.0 → 7.1.2
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 +19 -5
- package/README.md +0 -2
- package/package.json +1 -1
- package/src/draft/connect.js +50 -0
- package/src/draft/index.js +17 -0
- package/src/flatData/from.js +4 -1
- package/src/flatData/get.js +1 -1
- package/src/flatData/index.js +12 -32
- package/src/flatObject/extractList.js +1 -2
- package/src/flatObject/insert.js +0 -1
- package/src/flatObject/model.js +15 -5
- package/src/flatObject/query.js +17 -8
- package/src/mainLib.js +8 -10
- /package/src/{flatData → draft}/push.js +0 -0
- /package/src/{flatData → draft}/save.js +0 -0
- /package/src/{flatData → draft}/set.js +0 -0
package/Changelog.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
## Release History
|
|
2
2
|
|
|
3
|
+
### 7.1.2 (2023-09-12)
|
|
4
|
+
- [x] Fix: Dt-Storage method 'from' is not filtering the list if requested 'breadcrumbs' does not exist;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### 7.1.1 (2023-09-05 )
|
|
9
|
+
- [x] Fix: Multiple queries in same programming scope;
|
|
10
|
+
- [ ] Bug: Dt-Storage method 'from' is not filtering the list if requested 'breadcrumbs' does not exist;
|
|
11
|
+
|
|
12
|
+
|
|
3
13
|
|
|
4
14
|
### 7.1.0 (2023-08-28)
|
|
5
15
|
- [x] Method `extractList` was added;
|
|
@@ -7,6 +17,8 @@
|
|
|
7
17
|
- [x] Fix: Tuple model if data is just an array is wrong;
|
|
8
18
|
- [x] Fix: Convertor to files shows 'root' in the beginning of the path;
|
|
9
19
|
- [x] Fix: Convertor to breadcrumbs shows 'root' in the beginning of the path;
|
|
20
|
+
- [ ] Bug: Multiple queries in same programming scope;
|
|
21
|
+
- [ ] Bug: Dt-Storage method 'from' is not filtering the list if requested 'breadcrumbs' does not exist;
|
|
10
22
|
|
|
11
23
|
|
|
12
24
|
|
|
@@ -17,11 +29,13 @@
|
|
|
17
29
|
- [x] Method `insert` was renamed to `insertSegment`;
|
|
18
30
|
- [x] Method `listSegments` was added to show list of all segments in dt-object;
|
|
19
31
|
- [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;
|
|
32
|
+
- [ ] Method `insertSegment` can recognize a dt model object.
|
|
33
|
+
- [ ] Bug: Method `model` doesn't recognize '**files**' as a model;
|
|
34
|
+
- [ ] Bug: Tuple model if data is just an array is wrong;
|
|
35
|
+
- [ ] Bug: Convertor to files shows 'root' in the beginning of the path;
|
|
36
|
+
- [ ] Bug: Convertor to breadcrumbs shows 'root' in the beginning of the path;
|
|
37
|
+
- [ ] Bug: Multiple queries in same programming scope;
|
|
38
|
+
- [ ] Bug: Dt-Storage method 'from' is not filtering the list if requested 'breadcrumbs' does not exist;
|
|
25
39
|
|
|
26
40
|
|
|
27
41
|
|
package/README.md
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|

|
|
4
4
|

|
|
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
|
@@ -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
|
+
|
package/src/flatData/from.js
CHANGED
package/src/flatData/get.js
CHANGED
package/src/flatData/index.js
CHANGED
|
@@ -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
|
-
,
|
|
72
|
-
, resetScan : () => { scanList = flatData }
|
|
61
|
+
, resetScan : () => { scanList = flatData } // Reset the scanList to use all flatData;
|
|
73
62
|
}
|
|
74
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
,
|
|
84
|
-
,
|
|
85
|
-
|
|
86
|
-
,
|
|
87
|
-
,
|
|
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
|
package/src/flatObject/insert.js
CHANGED
package/src/flatObject/model.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
,
|
|
10
|
-
|
|
11
|
-
|
|
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.
|
|
34
|
+
flatIO.resetScan ()
|
|
25
35
|
return result
|
|
26
36
|
}} // model func.
|
|
27
37
|
|
package/src/flatObject/query.js
CHANGED
|
@@ -2,19 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
function query ( dependencies, flatIO
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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'
|
|
8
|
-
import flatData from './flatData/index.js'
|
|
9
|
-
import convert from './convertors/index.js'
|
|
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 :
|
|
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
|
-
|
|
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
|