theprogrammablemind 9.8.0-beta.16 → 9.8.0-beta.18

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 CHANGED
@@ -18,9 +18,11 @@
18
18
  "test:debug": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
19
19
  "td": "node inspect node_modules/.bin/jest --runInBand --config ./jest.config.json",
20
20
  "tod": "node inspect node_modules/.bin/jest --runInBand -t NEO23",
21
+ "toda": "node inspect node_modules/.bin/jest --runInBand -t NEO23A",
21
22
  "lint:fix": "eslint \"**/*.js\" --fix",
22
23
  "lint": "eslint \"**/*.js\"",
23
24
  "to": "node node_modules/.bin/jest --runInBand -t NEO23",
25
+ "toa": "node node_modules/.bin/jest --runInBand -t NEO23A",
24
26
  "tos": "node node_modules/.bin/jest --runInBand -t NEOS23",
25
27
  "test": "jest --config ./jest.config.json",
26
28
  "test:python": "node node_modules/.bin/jest --runInBand -t PYTHON",
@@ -73,6 +75,6 @@
73
75
  "scriptjs": "^2.5.9",
74
76
  "uuid": "^8.3.2"
75
77
  },
76
- "version": "9.8.0-beta.16",
78
+ "version": "9.8.0-beta.18",
77
79
  "license": "UNLICENSED"
78
80
  }
package/src/helpers.js CHANGED
@@ -22,12 +22,30 @@ class OverrideCheck {
22
22
  }
23
23
  }
24
24
 
25
- function pathEquals (p1, p2) {
25
+ function pathEquals (p1, p2, n) {
26
+ if (n !== undefined) {
27
+ if (n < 0) {
28
+ p1 = p1.slice(n)
29
+ p2 = p2.slice(n)
30
+ } else {
31
+ p1 = p1.slice(0, n)
32
+ p2 = p2.slice(0, n)
33
+ }
34
+ }
35
+
26
36
  if (p1.length !== p2.length) {
27
37
  return false
28
38
  }
29
39
  for (let i = 0; i < p1.length; ++i) {
30
- if (typeof p2[i] == 'function') {
40
+ if (p1[i].integer) {
41
+ if (!Number.isInteger(p2[i])) {
42
+ return false
43
+ }
44
+ } else if (p2[i].integer) {
45
+ if (!Number.isInteger(p1[i])) {
46
+ return false
47
+ }
48
+ } else if (typeof p2[i] == 'function') {
31
49
  if (!p2[i](p1[i])) {
32
50
  return false
33
51
  }
package/src/project2.js CHANGED
@@ -1,18 +1,6 @@
1
1
  const debug = require('./debug')
2
2
  const helpers = require('./helpers')
3
3
 
4
- function areFirstNEqual(arr1, arr2, n) {
5
- if (n <= 0) return true;
6
- if (arr1.length < n || arr2.length < n) return false;
7
-
8
- for (let i = 0; i < n; i++) {
9
- if (arr1[i] !== arr2[i]) {
10
- return false;
11
- }
12
- }
13
- return true;
14
- }
15
-
16
4
  function project(source, filters, path=[]) {
17
5
  if (['boolean', 'string', 'number'].includes(typeof source)) {
18
6
  return source
@@ -49,12 +37,16 @@ function project(source, filters, path=[]) {
49
37
  let properties = []
50
38
  for (const filter of selectedFilters) {
51
39
  for (const property of filter.apply(source)) {
52
- properties.push(property)
40
+ if (!properties.includes(property)) {
41
+ properties.push(property)
42
+ }
53
43
  }
54
44
  }
55
45
  if (source?.checks) {
56
46
  for (const check of source.checks) {
57
- properties.push(check)
47
+ if (!properties.includes(check)) {
48
+ properties.push(check)
49
+ }
58
50
  }
59
51
  }
60
52
 
@@ -64,10 +56,14 @@ function project(source, filters, path=[]) {
64
56
  // property that contains a list of properties to be checked
65
57
  if (property.properties) {
66
58
  for (const moreProperty of source[property.properties] || []) {
67
- updatedProperties.push(moreProperty)
59
+ if (!updatedProperties.includes(property)) {
60
+ updatedProperties.push(moreProperty)
61
+ }
68
62
  }
69
63
  } else {
70
- updatedProperties.push(property)
64
+ if (!updatedProperties.includes(property)) {
65
+ updatedProperties.push(property)
66
+ }
71
67
  }
72
68
  }
73
69
  properties = updatedProperties
@@ -75,7 +71,7 @@ function project(source, filters, path=[]) {
75
71
  // Build the result object
76
72
  const result = {};
77
73
  properties.forEach(prop => {
78
- if (prop.path && (prop.path.length === path.length + 1) && areFirstNEqual(path, prop.path, path.length) && source.hasOwnProperty(prop.path[path.length])) {
74
+ if (prop.path && (prop.path.length === path.length + 1) && helpers.pathEquals(path, prop.path, path.length) && source.hasOwnProperty(prop.path[path.length])) {
79
75
  const endProp = prop.path[path.length]
80
76
  if (['boolean', 'string', 'number'].includes(typeof source[endProp])) {
81
77
  result[endProp] = source[endProp]
@@ -109,8 +105,18 @@ function project(source, filters, path=[]) {
109
105
  const instantiatedCheck = []
110
106
  for (const check of prop.check) {
111
107
  if (typeof check.property == 'function') {
112
- for (const sourceKey of source[prop.property].keys()) {
108
+ const keys = (value) => {
109
+ if (Array.isArray(value)) {
110
+ return value.keys()
111
+ } else {
112
+ return Object.keys(value)
113
+ }
114
+ }
115
+ for (const sourceKey of keys(source[prop.property])) {
113
116
  if (check.property(sourceKey)) {
117
+ if (!check.check) {
118
+ throw new Error(`For the property check of the property '${check.property.toString()}', the 'check' (singular) property is missing.`)
119
+ }
114
120
  instantiatedCheck.push({ property: sourceKey, check: check.check })
115
121
  }
116
122
  }