theprogrammablemind_4wp 9.6.3-beta.23 → 9.6.3-beta.24
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/package.json +1 -1
- package/src/fragments.js +1 -13
- package/src/helpers.js +17 -0
- package/src/project2.js +24 -6
package/package.json
CHANGED
package/src/fragments.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
const _ = require('lodash')
|
|
2
2
|
const helpers = require('./helpers')
|
|
3
3
|
|
|
4
|
-
function pathEquals (p1, p2) {
|
|
5
|
-
if (p1.length !== p2.length) {
|
|
6
|
-
return false
|
|
7
|
-
}
|
|
8
|
-
for (let i = 0; i < p1.length; ++i) {
|
|
9
|
-
if (p1[i] !== p2[i]) {
|
|
10
|
-
return false
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
|
|
16
4
|
function fragmentInstantiator (args, contexts) {
|
|
17
5
|
return new Object({
|
|
18
6
|
contexts: () => {
|
|
@@ -22,7 +10,7 @@ function fragmentInstantiator (args, contexts) {
|
|
|
22
10
|
const instantiated = _.cloneDeep(contexts)
|
|
23
11
|
const todo = [{ context: instantiated, path: [] }]
|
|
24
12
|
args = { ...args }
|
|
25
|
-
args.pathEquals = pathEquals
|
|
13
|
+
args.pathEquals = helpers.pathEquals
|
|
26
14
|
while (todo.length > 0) {
|
|
27
15
|
const { context, path } = todo.pop()
|
|
28
16
|
args.context = context
|
package/src/helpers.js
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
const deepEqual = require('deep-equal')
|
|
2
2
|
const stringify = require('json-stable-stringify')
|
|
3
3
|
|
|
4
|
+
function pathEquals (p1, p2) {
|
|
5
|
+
if (p1.length !== p2.length) {
|
|
6
|
+
return false
|
|
7
|
+
}
|
|
8
|
+
for (let i = 0; i < p1.length; ++i) {
|
|
9
|
+
if (typeof p2[i] == 'function') {
|
|
10
|
+
if (!p2[i](p1[i])) {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
} else if (p1[i] !== p2[i]) {
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return true
|
|
18
|
+
}
|
|
19
|
+
|
|
4
20
|
function watchProperty(obj, propName) {
|
|
5
21
|
let value = obj[propName];
|
|
6
22
|
|
|
@@ -594,4 +610,5 @@ module.exports = {
|
|
|
594
610
|
setByPath,
|
|
595
611
|
assignAssumed,
|
|
596
612
|
watchProperty,
|
|
613
|
+
pathEquals,
|
|
597
614
|
}
|
package/src/project2.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const debug = require('./debug')
|
|
2
|
+
const helpers = require('./helpers')
|
|
2
3
|
|
|
3
4
|
function areFirstNEqual(arr1, arr2, n) {
|
|
4
5
|
if (n <= 0) return true;
|
|
@@ -36,8 +37,8 @@ function project(source, filters, path=[]) {
|
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// Find the applicable filter for the current context
|
|
39
|
-
const
|
|
40
|
-
if (
|
|
40
|
+
const selectedFilters = filters.filter(f => f.match({ context: source, path, pathEquals: helpers.pathEquals }));
|
|
41
|
+
if (filters.length == 0) {
|
|
41
42
|
if (Array.isArray(source)) {
|
|
42
43
|
return source.map((element) => project(element, filters, [...path, '*']))
|
|
43
44
|
}
|
|
@@ -45,7 +46,12 @@ function project(source, filters, path=[]) {
|
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
// Get the properties to include from the apply function
|
|
48
|
-
let properties =
|
|
49
|
+
let properties = []
|
|
50
|
+
for (const filter of selectedFilters) {
|
|
51
|
+
for (const property of filter.apply(source)) {
|
|
52
|
+
properties.push(property)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
49
55
|
if (source?.checks) {
|
|
50
56
|
for (const check of source.checks) {
|
|
51
57
|
properties.push(check)
|
|
@@ -75,7 +81,7 @@ function project(source, filters, path=[]) {
|
|
|
75
81
|
result[endProp] = source[endProp]
|
|
76
82
|
} else if (Array.isArray(source[endProp])) {
|
|
77
83
|
result[endProp] = []
|
|
78
|
-
for (const key
|
|
84
|
+
for (const key of source[endProp].keys()) {
|
|
79
85
|
result[endProp].push(project(source[endProp][key], filters, [...path, endProp, key]))
|
|
80
86
|
}
|
|
81
87
|
} else {
|
|
@@ -96,7 +102,19 @@ function project(source, filters, path=[]) {
|
|
|
96
102
|
// If the property is an object and not null, recursively project it
|
|
97
103
|
if (typeof source[prop.property] === 'object' && source[prop.property] !== null) {
|
|
98
104
|
result[prop.property] = {}
|
|
99
|
-
|
|
105
|
+
const instantiatedCheck = []
|
|
106
|
+
for (const check of prop.check) {
|
|
107
|
+
if (typeof check.property == 'function') {
|
|
108
|
+
for (const sourceKey of source[prop.property].keys()) {
|
|
109
|
+
if (check.property(sourceKey)) {
|
|
110
|
+
instantiatedCheck.push({ property: sourceKey, check: check.check })
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
instantiatedCheck.push(check)
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
for (const key of instantiatedCheck) {
|
|
100
118
|
if (typeof key == 'string') {
|
|
101
119
|
result[prop.property][key] = project(source[prop.property][key], filters, [...path, prop.property, key]);
|
|
102
120
|
} else {
|
|
@@ -104,7 +122,7 @@ function project(source, filters, path=[]) {
|
|
|
104
122
|
match: () => true,
|
|
105
123
|
apply: () => key.check
|
|
106
124
|
}
|
|
107
|
-
result[prop.property][key.property] = project(source[prop.property][key.property], [f], [...path, prop.property, key.property]);
|
|
125
|
+
result[prop.property][key.property] = project(source[prop.property][key.property], [...filters, f], [...path, prop.property, key.property]);
|
|
108
126
|
}
|
|
109
127
|
}
|
|
110
128
|
} else {
|