dt-toolbox 5.0.0 → 7.0.0

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.
Files changed (83) hide show
  1. package/Changelog.md +15 -10
  2. package/LICENSE +1 -1
  3. package/Migration.guide.md +63 -1
  4. package/README.md +996 -346
  5. package/README_v.2.x.x.md +0 -1
  6. package/README_v.4.x.x.md +532 -0
  7. package/README_v.6.x.x.md +1158 -0
  8. package/package.json +21 -24
  9. package/src/convertors/index.js +43 -34
  10. package/src/convertors/midflat.js +76 -132
  11. package/src/convertors/standard.js +61 -86
  12. package/src/convertors/tuples.js +171 -0
  13. package/src/flatData/connect.js +50 -0
  14. package/src/flatData/export.js +46 -0
  15. package/src/flatData/filters/list.js +11 -0
  16. package/src/flatData/filters/listObject.js +13 -0
  17. package/src/flatData/filters/object.js +12 -0
  18. package/src/flatData/filters/root.js +12 -0
  19. package/src/flatData/find.js +20 -0
  20. package/src/flatData/from.js +33 -0
  21. package/src/flatData/get.js +29 -0
  22. package/src/flatData/index.js +101 -0
  23. package/src/flatData/insert.js +24 -0
  24. package/src/flatData/like.js +24 -0
  25. package/src/flatData/look.js +56 -0
  26. package/src/flatData/push.js +19 -0
  27. package/src/flatData/save.js +17 -0
  28. package/src/flatData/set.js +26 -0
  29. package/src/flatData/setupFilter.js +21 -0
  30. package/src/flatData/use.js +16 -0
  31. package/src/flatObject/copy.js +19 -0
  32. package/src/flatObject/export.js +13 -0
  33. package/src/flatObject/index.js +55 -0
  34. package/src/flatObject/insert.js +38 -0
  35. package/src/flatObject/model.js +32 -0
  36. package/src/flatObject/query.js +24 -0
  37. package/src/flatObject/setupFilter.js +12 -0
  38. package/src/main.js +21 -689
  39. package/src/mainLib.js +114 -0
  40. package/src/compareMethod/change.js +0 -21
  41. package/src/compareMethod/different.js +0 -18
  42. package/src/compareMethod/identical.js +0 -21
  43. package/src/compareMethod/index.js +0 -13
  44. package/src/compareMethod/missing.js +0 -18
  45. package/src/compareMethod/same.js +0 -18
  46. package/src/convertors/breadcrumbs.js +0 -148
  47. package/src/help/extractSelection.js +0 -12
  48. package/src/help/filterObject.js +0 -25
  49. package/src/help/hasNumbers.js +0 -14
  50. package/src/help/index.js +0 -35
  51. package/src/help/isItPrimitive.js +0 -10
  52. package/src/help/objectsByLevel.js +0 -16
  53. package/src/help/reduceTuples.js +0 -29
  54. package/src/help/sanitizeFlatKeys.js +0 -30
  55. package/src/help/toBreadcrumbsKeys.js +0 -28
  56. package/src/help/tuplesToBreadcrumbs.js +0 -25
  57. package/src/help/updateSelection.js +0 -12
  58. package/src/help/zipObject.js +0 -24
  59. package/src/lib/assemble.js +0 -45
  60. package/src/lib/attach.js +0 -20
  61. package/src/lib/block.js +0 -33
  62. package/src/lib/combine.js +0 -38
  63. package/src/lib/deep.js +0 -23
  64. package/src/lib/find.js +0 -36
  65. package/src/lib/folder.js +0 -42
  66. package/src/lib/index.js +0 -56
  67. package/src/lib/modify.js +0 -22
  68. package/src/lib/parent.js +0 -51
  69. package/src/lib/purify.js +0 -37
  70. package/src/lib/transform.js +0 -55
  71. package/src/modifiers/add.js +0 -18
  72. package/src/modifiers/append.js +0 -18
  73. package/src/modifiers/combineShallow.js +0 -119
  74. package/src/modifiers/flatten.js +0 -38
  75. package/src/modifiers/index.js +0 -34
  76. package/src/modifiers/insert.js +0 -21
  77. package/src/modifiers/keyPrefix.js +0 -27
  78. package/src/modifiers/mix.js +0 -25
  79. package/src/modifiers/overwrite.js +0 -18
  80. package/src/modifiers/prepend.js +0 -19
  81. package/src/modifiers/reverse.js +0 -23
  82. package/src/modifiers/update.js +0 -18
  83. package/src/simple.js +0 -49
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ function setupFilter ( flatStorage, filterFn, filtering, getFilterNames ) {
4
+ return function setupFilter ( name, fn ) {
5
+ const
6
+ filterNames = getFilterNames ()
7
+ , [,, flatData ] = flatStorage
8
+ ;
9
+ if ( filterNames.includes( name )) {
10
+ console.error ( `Filter name "${name}" is already defined` )
11
+ return this
12
+ }
13
+ filterFn[name] = fn
14
+ flatData.forEach ( line => filtering ( name, line ))
15
+ }} // setupFilter func.
16
+
17
+
18
+
19
+ export default setupFilter
20
+
21
+
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+
4
+
5
+ function use ( flatIO ) {
6
+ return function use ( name ) {
7
+ const filter = flatIO.getFilters()[name];
8
+ if ( filter ) flatIO.setupScanList ( filter )
9
+ return this
10
+ }} // use func.
11
+
12
+
13
+
14
+ export default use
15
+
16
+
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+
4
+
5
+ function copy ( dependencies, flatIO ) {
6
+ return function copy ( name = 'root' ) {
7
+ const
8
+ c = flatIO.getCopy (name)
9
+ , { walk } = dependencies ()
10
+ ;
11
+ if ( !c ) return null
12
+ return walk ({ data : c })
13
+ }} // copy func.
14
+
15
+
16
+
17
+ export default copy
18
+
19
+
@@ -0,0 +1,13 @@
1
+ 'use strict'
2
+
3
+
4
+
5
+ function ex ( dependencies, flatIO ) {
6
+ return name => flatIO.export ( name )
7
+ }
8
+
9
+
10
+
11
+ export default ex
12
+
13
+
@@ -0,0 +1,55 @@
1
+ 'use strict'
2
+
3
+
4
+
5
+ import insert from './insert.js'
6
+ import ex from './export.js'
7
+ import copy from './copy.js'
8
+ import model from './model.js'
9
+ import query from './query.js'
10
+ import setupFilter from './setupFilter.js'
11
+
12
+
13
+
14
+ function flatObject ( dependencies, d ) {
15
+ const
16
+ { flatData } = dependencies ()
17
+ , [ flatIO, flatStore ] = flatData ( dependencies, d )
18
+ , objectAPI = {
19
+ // I/O Operations
20
+ insertSegment : insert ( dependencies, flatIO ) // Extends available data with new data segment;
21
+ , export : ex ( dependencies, flatIO ) // Returns flat data;
22
+ , copy : copy ( dependencies, flatIO ) // Creates deep copy of original data
23
+ , model : model ( dependencies, flatIO, flatStore ) // Arrange data according specific data-model. Model should come as a function;
24
+ , query : query ( dependencies, flatIO, flatStore ) // Request, and evaluate data. Returns a new flat object;
25
+ , setupFilter : setupFilter ( flatIO ) // Functions should filter content according some criteria. Generated indexes will help for data search in
26
+ , listSegments : () => {
27
+ const ix = Object.keys ( flatIO.getIndexes() );
28
+ return ix.reduce ( (res,item) => {
29
+ if ( item.includes('/') ) return res
30
+ res.push ( item )
31
+ return res
32
+ }, [] )
33
+ }
34
+ , index : n => {
35
+ if ( n == null ) return null
36
+ let r = flatIO.getLine(n)
37
+ if ( r ) {
38
+ let [ name, d, breadcrumbs, links ] = r;
39
+ let copy;
40
+ if ( d instanceof Array ) copy = [...d ]
41
+ else copy = {...d }
42
+ return [ name, copy, breadcrumbs, [...links] ]
43
+ }
44
+ else return null
45
+ } // index
46
+ }
47
+ ;
48
+ return objectAPI
49
+ } // flatObject func.
50
+
51
+
52
+
53
+ export default flatObject
54
+
55
+
@@ -0,0 +1,38 @@
1
+ 'use strict'
2
+
3
+ function insert ( dependencies, flatIO ) {
4
+ return function insert ( name, inData ) {
5
+ const { convert, isDTO, isDTM, walk } = dependencies();
6
+ let d, copy;
7
+
8
+ if ( isDTO(inData) ) {
9
+ d = inData.export ()
10
+ copy = inData.copy ()
11
+
12
+ }
13
+ else if ( isDTM(inData) ) {
14
+ d = walk ({ data : inData })
15
+ copy = walk ({ data : inData })
16
+ }
17
+ else {
18
+ [ copy,, d ] = convert.from ( 'std' ).toFlat ( dependencies, inData )
19
+ console.warn ( 'A non "dt-object" data segment was inserted. Autoconverted to "dt-object".' )
20
+ }
21
+
22
+ const search = new RegExp ( `^root\/` );
23
+ d.forEach ( line => { // Word 'root' should be changed to the argument 'name'.
24
+ if ( line[0] === line[2] ) {
25
+ line[0] = name
26
+ line[2] = name
27
+ }
28
+ line[2] = line[2].replace ( search, `${name}/` )
29
+ line[3].forEach ( (edge,i) => line[3][i] = edge.replace ( search, `${name}/` ) )
30
+ })
31
+ flatIO.insert ( [copy,,d])
32
+ }} // insert func.
33
+
34
+
35
+
36
+ export default insert
37
+
38
+
@@ -0,0 +1,32 @@
1
+ 'use strict'
2
+
3
+
4
+
5
+ function model ( dependencies, flatIO ,flatStore ) {
6
+ return function model () {
7
+ const
8
+ [ fn, ...args ] = arguments
9
+ , { as } = fn ( flatStore, ...args ) || {}
10
+ , { convert } = dependencies ()
11
+ , selection = flatIO.getSelection ()
12
+ , data = ( selection.length === 0 ) ? flatIO.export() : selection
13
+ , CONVERTOR_NAMES = [ 'standard', 'std', 'midFlat', 'tuple', 'tuples', 'breadcrumb', 'breadcrumbs' ]
14
+ , hasConvertor = as ? CONVERTOR_NAMES.includes ( as ) : false
15
+ ;
16
+
17
+ let result;
18
+ if ( as && !hasConvertor ) {
19
+ console.error ( `Model '${as}' is unknown data-model.` )
20
+ return null
21
+ }
22
+ if ( as ) result = convert.to ( as, dependencies, data )
23
+ else result = data
24
+ flatIO.reset ()
25
+ return result
26
+ }} // model func.
27
+
28
+
29
+
30
+ export default model
31
+
32
+
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+
3
+
4
+
5
+ function query ( dependencies, flatIO ,flatStore ) {
6
+ return function query () {
7
+ const
8
+ { main } = dependencies ()
9
+ , { load } = main ()
10
+ , [ fn, ...args ] = arguments
11
+ ;
12
+
13
+ fn ( flatStore, ...args )
14
+ const result = flatIO.getSelection ();
15
+ flatIO.reset ()
16
+ if ( result.length === 0 ) return this
17
+ return load ( result )
18
+ }} // query func.
19
+
20
+
21
+
22
+ export default query
23
+
24
+
@@ -0,0 +1,12 @@
1
+ 'use strict'
2
+
3
+
4
+ function setupFilter ( flatIO ) {
5
+ return ( name, filterFn ) => flatIO.setupFilter ( name, filterFn )
6
+ } // setupFilter func.
7
+
8
+
9
+
10
+ export default setupFilter
11
+
12
+