theprogrammablemind 9.6.0-beta.24 → 9.6.0-beta.26

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.0-beta.24",
76
+ "version": "9.6.0-beta.26",
77
77
  "license": "UNLICENSED"
78
78
  }
@@ -86,6 +86,28 @@ const cleanAssign = (dest, ...srcs) => {
86
86
  Object.assign(dest, ...srcs)
87
87
  }
88
88
 
89
+ class ContextHierarchy {
90
+ constructor(contexts = []) {
91
+ this.contexts = [...contexts]
92
+ }
93
+
94
+ push(context) {
95
+ this.contexts.push(context)
96
+ }
97
+
98
+ pop() {
99
+ this.contexts.pop()
100
+ }
101
+
102
+ under(marker) {
103
+ for (let i = this.contexts.length - 1; i >= 0; --i) {
104
+ if (this.contexts[i].marker == marker) {
105
+ return true
106
+ }
107
+ }
108
+ }
109
+ }
110
+
89
111
  const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
90
112
  if (!args.objects) {
91
113
  args.objects = config.get('objects')
@@ -105,6 +127,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
105
127
  if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
106
128
  args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
107
129
  }
130
+ args.contextHierarchy = new ContextHierarchy()
108
131
  args.cleanAssign = cleanAssign
109
132
  args.km = (name) => config.getConfig(name)
110
133
  args.api = (name) => config.getConfig(name).api
package/src/semantics.js CHANGED
@@ -156,11 +156,21 @@ class Semantics {
156
156
  }
157
157
 
158
158
  async applyToContext (args, context, options) {
159
+ args.contextHierarchy.push(context)
160
+ try {
161
+ return await this.applyToContextHelper(args, context, options)
162
+ } finally {
163
+ args.contextHierarchy.pop()
164
+ }
165
+ }
166
+
167
+ async applyToContextHelper (args, context, options) {
159
168
  // let context_prime = {}
160
169
  if (!(context instanceof Array || context instanceof Object)) {
161
170
  return context
162
171
  }
163
172
  args = { ...args }
173
+
164
174
  const config = args.config
165
175
  const debug = config.getDebug()
166
176
  let contextPrime = Object.assign({}, context)