theprogrammablemind 9.7.1-beta.5 → 9.7.1-beta.6

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.7.1-beta.5",
76
+ "version": "9.7.1-beta.6",
77
77
  "license": "UNLICENSED"
78
78
  }
package/src/config.js CHANGED
@@ -1655,6 +1655,7 @@ class Config {
1655
1655
  }
1656
1656
  }
1657
1657
 
1658
+ // handler/listener
1658
1659
  updateBridge(id, updater) {
1659
1660
  const bridge = this.config.bridges.find((b) => b.id === id)
1660
1661
  updater({ config: this, bridge })
package/src/debug.js CHANGED
@@ -27,6 +27,18 @@ const unhit = (name) => {
27
27
  hits[name] = false
28
28
  }
29
29
 
30
+ const hitScoped = async (name, call) => {
31
+ hit(name)
32
+ try {
33
+ const result = await call()
34
+ unhit(name)
35
+ return result
36
+ } catch( e ) {
37
+ unhit(name)
38
+ throw e
39
+ }
40
+ }
41
+
30
42
  const wasHit = (name) => {
31
43
  return hits[name]
32
44
  }
@@ -64,16 +76,19 @@ const _break = (name) => {
64
76
  }
65
77
  }
66
78
 
79
+ const breakAt = _break;
80
+
67
81
  module.exports = {
68
82
  counter,
69
83
  get,
70
84
  _break, // break is a keyword
71
-
85
+ breakAt,
72
86
  // used for tests
73
87
  reset,
74
88
  hit,
75
89
  unhit,
76
90
  wasHit,
77
91
  getDb,
78
- setDb
92
+ setDb,
93
+ hitScoped,
79
94
  }
package/src/fragments.js CHANGED
@@ -1,6 +1,29 @@
1
1
  const _ = require('lodash')
2
2
  const helpers = require('./helpers')
3
3
 
4
+ function createChangeTracker(obj) {
5
+ const changes = new Set();
6
+
7
+ const handler = {
8
+ set(target, prop, value) {
9
+ changes.add(prop);
10
+ target[prop] = value;
11
+ return true;
12
+ },
13
+ deleteProperty(target, prop) {
14
+ changes.add(prop);
15
+ delete target[prop];
16
+ return true;
17
+ }
18
+ };
19
+
20
+ return {
21
+ proxy: new Proxy(obj, handler),
22
+ getChanges: () => Array.from(changes)
23
+ };
24
+ }
25
+
26
+
4
27
  function fragmentInstantiator (args, contexts) {
5
28
  return new Object({
6
29
  contexts: () => {
@@ -13,13 +36,15 @@ function fragmentInstantiator (args, contexts) {
13
36
  args.pathEquals = helpers.pathEquals
14
37
  while (todo.length > 0) {
15
38
  const { context, path } = todo.pop()
16
- args.context = context
39
+ const { proxy, getChanges } = createChangeTracker(context);
40
+ args.context = proxy
17
41
  args.path = path
18
42
  for (const mapping of mappings) {
19
43
  if (await mapping.match(args)) {
20
44
  await mapping.apply(args)
21
45
  }
22
46
  }
47
+ const ignore = getChanges()
23
48
  for (const key of Object.keys(context)) {
24
49
  // if (['number', 'string', 'boolean'].includes(typeof (context[key]))) {
25
50
  if (!helpers.isCompound(context[key])) {
@@ -28,7 +53,9 @@ function fragmentInstantiator (args, contexts) {
28
53
  if (context[key].instantiated) {
29
54
  continue
30
55
  }
31
- todo.push({ context: context[key], path: [...path, key] })
56
+ if (!ignore.includes(key)) {
57
+ todo.push({ context: context[key], path: [...path, key] })
58
+ }
32
59
  }
33
60
  }
34
61
  if (contexts.length == 1 && instantiated.length == 1) {
package/src/generators.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const { args: contextArgs, normalizeGenerator } = require('./helpers')
2
2
  const Lines = require('../lines')
3
3
  const helpers = require('./helpers')
4
+ const debug = require('./debug')
4
5
 
5
6
  class Generator {
6
7
  // constructor ({ match, apply, uuid, index, km, priority, notes }) {
@@ -65,14 +66,16 @@ class Generator {
65
66
  }
66
67
  const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
67
68
  // return this.match(args)
68
- const matches = await this.match(args)
69
- if ((matches && (options.debug || {}).match) ||
70
- callId === this.callId) {
71
- // next line is the matcher
72
- debugger // eslint-disable-line no-debugger
73
- await this.match(args)
74
- }
75
- return matches
69
+ return await debug.hitScoped(args.callId, async () => {
70
+ const matches = await this.match(args)
71
+ if ((matches && (options.debug || {}).match) ||
72
+ callId === this.callId) {
73
+ // next line is the matcher
74
+ debugger // eslint-disable-line no-debugger
75
+ await this.match(args)
76
+ }
77
+ return matches
78
+ })
76
79
  }
77
80
 
78
81
  // apply (baseArgs, objects, g, gs, context, hierarchy, config, response, log, options = {}) {
@@ -121,11 +124,13 @@ class Generator {
121
124
  if (this.property === 'generatorp') {
122
125
  args.g = args.gp
123
126
  }
124
- if ((options.debug || {}).apply ||
125
- callId === this.callId) {
126
- debugger // eslint-disable-line no-debugger
127
- }
128
- return await this._apply(args)
127
+ return await debug.hitScoped(args.callId, async () => {
128
+ if ((options.debug || {}).apply ||
129
+ callId === this.callId) {
130
+ debugger // eslint-disable-line no-debugger
131
+ }
132
+ return await this._apply(args)
133
+ })
129
134
  }
130
135
  }
131
136
 
@@ -220,7 +225,7 @@ class Generators {
220
225
  lines.setElement(0, 2, stack)
221
226
  lines.newRow()
222
227
  lines.setElement(0, 1, 'DEBUG')
223
- lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
228
+ lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
224
229
  lines.newRow()
225
230
  lines.setElement(0, 1, 'ERROR')
226
231
  lines.setElement(0, 2, errorMessage)
@@ -252,7 +257,7 @@ class Generators {
252
257
  lines.setElement(0, 2, stack)
253
258
  lines.newRow()
254
259
  lines.setElement(0, 1, 'DEBUG')
255
- lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
260
+ lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
256
261
  lines.newRow()
257
262
  lines.setElement(0, 1, 'TO')
258
263
  lines.setElement(0, 2, `context_id: ${context.context_id}`)
package/src/semantics.js CHANGED
@@ -75,13 +75,15 @@ class Semantic {
75
75
  async matches (args, context, options = {}) {
76
76
  args = {...args}
77
77
  this.fixUpArgs(args, context)
78
- const matches = await this.matcher(args)
79
- if (matches && (options.debug || {}).match || args.callId === this.callId) {
80
- // next line is the matcher
81
- debugger // eslint-disable-line no-debugger
82
- await this.matcher(args)
83
- }
84
- return matches
78
+ return await debug.hitScoped(args.callId, async () => {
79
+ const matches = await this.matcher(args)
80
+ if (matches && (options.debug || {}).match || args.callId === this.callId) {
81
+ // next line is the matcher
82
+ debugger // eslint-disable-line no-debugger
83
+ await this.matcher(args)
84
+ }
85
+ return matches
86
+ })
85
87
  }
86
88
 
87
89
  async apply (args, context, s, options = {}) {
@@ -97,21 +99,24 @@ class Semantic {
97
99
  const contextPrime = Object.assign({}, context)
98
100
  this.fixUpArgs(args, contextPrime)
99
101
 
100
- if ((options.debug || {}).apply || args.callId === this.callId) {
101
- debugger // eslint-disable-line no-debugger
102
- }
103
- if (args.breakOnSemantics) {
104
- debugger // eslint-disable-line no-debugger
105
- }
106
- try {
107
- args.handlerStack.push(this)
108
- await this._apply(args)
109
- args.handlerStack.pop()
110
- } catch( e ) {
111
- args.handlerStack.pop()
112
- throw e
113
- }
114
- return contextPrime
102
+ return await debug.hitScoped(args.callId, async () => {
103
+ if ((options.debug || {}).apply || args.callId === this.callId) {
104
+ debugger // eslint-disable-line no-debugger
105
+ }
106
+ if (args.breakOnSemantics) {
107
+ debugger // eslint-disable-line no-debugger
108
+ }
109
+
110
+ try {
111
+ args.handlerStack.push(this)
112
+ await this._apply(args)
113
+ args.handlerStack.pop()
114
+ } catch( e ) {
115
+ args.handlerStack.pop()
116
+ throw e
117
+ }
118
+ return contextPrime
119
+ })
115
120
  }
116
121
  }
117
122
 
@@ -253,7 +258,7 @@ class Semantics {
253
258
  lines.setElement(0, 2, semantic.toString())
254
259
  lines.newRow()
255
260
  lines.setElement(0, 1, 'DEBUG')
256
- lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
261
+ lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
257
262
  lines.newRow()
258
263
  lines.setElement(0, 1, 'TO')
259
264
  lines.setElement(0, 2, `context_id: ${context.context_id}`)
@@ -288,7 +293,7 @@ class Semantics {
288
293
  lines.setElement(0, 2, semantic.toString())
289
294
  lines.newRow()
290
295
  lines.setElement(0, 1, 'DEBUG')
291
- lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
296
+ lines.setElement(0, 2, `To debug this use debug.breakAt('${args.calls.current()}')`)
292
297
  lines.newRow()
293
298
  lines.setElement(0, 1, 'TO')
294
299
  lines.setElement(0, 2, `context_id: ${context.context_id}`)