theprogrammablemind 8.0.0-beta.49 → 8.0.0-beta.50

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
@@ -65,6 +65,6 @@
65
65
  "sort-json": "^2.0.0",
66
66
  "uuid": "^8.3.2"
67
67
  },
68
- "version": "8.0.0-beta.49",
68
+ "version": "8.0.0-beta.50",
69
69
  "license": "UNLICENSED"
70
70
  }
package/src/config.js CHANGED
@@ -1012,7 +1012,7 @@ class Config {
1012
1012
  return instance
1013
1013
  }
1014
1014
 
1015
- fragmentInstantiator (contexts) {
1015
+ fragmentInstantiator (args, contexts) {
1016
1016
  return new Object({
1017
1017
  contexts: () => contexts,
1018
1018
  instantiate: async (mappings) => {
@@ -1020,11 +1020,13 @@ class Config {
1020
1020
  // const todo = [...instantiated]
1021
1021
  // const todo = [...instantiated]
1022
1022
  const todo = _.clone(instantiated)
1023
+ args = {...args}
1023
1024
  while (todo.length > 0) {
1024
1025
  const context = todo.pop()
1026
+ args.context = context
1025
1027
  for (const mapping of mappings) {
1026
- if (await mapping.match({ context })) {
1027
- await mapping.apply({ context })
1028
+ if (await mapping.match(args)) {
1029
+ await mapping.apply(args)
1028
1030
  }
1029
1031
  }
1030
1032
  for (const key of Object.keys(context)) {
@@ -1043,21 +1045,21 @@ class Config {
1043
1045
  })
1044
1046
  }
1045
1047
 
1046
- fragment (query) {
1048
+ fragment (args, query) {
1047
1049
  for (const instance of (this.instances || [])) {
1048
1050
  for (const fragment of (instance.fragments || [])) {
1049
1051
  if (fragment.query === query) {
1050
- return this.fragmentInstantiator(fragment.contexts)
1052
+ return this.fragmentInstantiator(args, fragment.contexts)
1051
1053
  }
1052
1054
  }
1053
1055
  for (const fragment of (instance.resultss || [])) {
1054
1056
  if (fragment.isFragment && fragment.query === query) {
1055
- return this.fragmentInstantiator(fragment.contexts)
1057
+ return this.fragmentInstantiator(args, fragment.contexts)
1056
1058
  }
1057
1059
  }
1058
1060
  for (const fragment of (this.fragmentsBeingBuilt || [])) {
1059
1061
  if (fragment.query === query) {
1060
- return this.fragmentInstantiator(fragment.contexts)
1062
+ return this.fragmentInstantiator(args, fragment.contexts)
1061
1063
  }
1062
1064
  }
1063
1065
  }
@@ -77,6 +77,22 @@ const listable = (hierarchy) => (c, type) => {
77
77
  return false
78
78
  }
79
79
 
80
+ const cleanAssign = (dest, ...srcs) => {
81
+ for (const key in dest) {
82
+ let found = false
83
+ for (const src of srcs) {
84
+ if (src[key]) {
85
+ found = true
86
+ break
87
+ }
88
+ }
89
+ if (!found) {
90
+ delete dest[key]
91
+ }
92
+ }
93
+ Object.assign(dest, ...srcs)
94
+ }
95
+
80
96
  const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
81
97
 
82
98
  // callId
@@ -84,6 +100,7 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
84
100
  if (global.theprogrammablemind && global.theprogrammablemind.loadForTesting) {
85
101
  args.calls = new InitCalls(Object.keys(global.theprogrammablemind.loadForTesting)[0])
86
102
  }
103
+ args.cleanAssign = cleanAssign
87
104
  args.km = (name) => config.getConfig(name)
88
105
  args.api = (name) => config.getConfig(name).api
89
106
  args.error = (context) => {
@@ -96,7 +113,9 @@ const setupArgs = (args, config, logs, hierarchy, uuidForScoping) => {
96
113
  args.listable = listable(hierarchy)
97
114
  args.asList = asList
98
115
  args.retry = () => { throw new RetryError() }
99
- args.fragments = (query) => config.fragment(query)
116
+ args.fragments = (query) => {
117
+ return config.fragment(args, query)
118
+ }
100
119
  args.breakOnSemantics = false
101
120
  args.theDebugger = {
102
121
  breakOnSemantics: (value) => args.breakOnSemantics = value