theprogrammablemind_4wp 9.6.3-beta.23 → 9.6.3-beta.25

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
@@ -73,6 +73,6 @@
73
73
  "scriptjs": "^2.5.9",
74
74
  "uuid": "^8.3.2"
75
75
  },
76
- "version": "9.6.3-beta.23",
76
+ "version": "9.6.3-beta.25",
77
77
  "license": "UNLICENSED"
78
78
  }
@@ -86,6 +86,30 @@ const cleanAssign = (dest, ...srcs) => {
86
86
  Object.assign(dest, ...srcs)
87
87
  }
88
88
 
89
+ // handler is a semantic or a generator
90
+ class HandlerStack {
91
+ constructor(handlers = []) {
92
+ this.handlers = [...handlers]
93
+ }
94
+
95
+ push(handler) {
96
+ this.handlers.push(handler)
97
+ }
98
+
99
+ pop() {
100
+ this.handlers.pop()
101
+ }
102
+
103
+ toString() {
104
+ let str = ''
105
+ for (let i = this.handlers.length - 1; i >= 0; --i) {
106
+ str += this.handlers[i].toLabel() + '\n'
107
+ str += this.handlers[i].toString() + '\n\n'
108
+ }
109
+ return str
110
+ }
111
+ }
112
+
89
113
  class ContextHierarchy {
90
114
  constructor(contexts = []) {
91
115
  this.contexts = [...contexts]
@@ -139,6 +163,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
139
163
  }
140
164
  }
141
165
  args.contextHierarchy = new ContextHierarchy()
166
+ args.handlerStack = new HandlerStack()
142
167
  args.cleanAssign = cleanAssign
143
168
  args.km = (name) => config.getConfig(name)
144
169
  args.api = (name) => config.getConfig(name).api
@@ -591,4 +616,5 @@ module.exports = {
591
616
  loadInstance,
592
617
  isA,
593
618
  ContextHierarchy,
619
+ HandlerStack,
594
620
  }
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 filter = filters.find(f => f.match({ context: source }));
40
- if (!filter) {
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 = filter.apply(source);
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 in source[endProp]) {
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
- for (const key of prop.check) {
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 {
package/src/semantics.js CHANGED
@@ -103,7 +103,13 @@ class Semantic {
103
103
  if (args.breakOnSemantics) {
104
104
  debugger // eslint-disable-line no-debugger
105
105
  }
106
- await this._apply(args)
106
+ try {
107
+ args.handlerStack.push(this)
108
+ await this._apply(args)
109
+ args.handlerStack.pop()
110
+ } catch( e ) {
111
+ args.handlerStack.pop()
112
+ }
107
113
  return contextPrime
108
114
  }
109
115
  }