theprogrammablemind_4wp 7.5.6 → 7.5.7-beta.0
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/client.js +72 -21
 - package/package.json +2 -1
 - package/src/config.js +5 -5
 - package/src/digraph.js +32 -0
 - package/src/digraph_internal.js +131 -0
 - package/src/generators.js +4 -1
 
    
        package/client.js
    CHANGED
    
    | 
         @@ -1,5 +1,6 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            const { Semantics, Semantic } = require('./src/semantics')
         
     | 
| 
       2 
2 
     | 
    
         
             
            const { Generators, Generator } = require('./src/generators')
         
     | 
| 
      
 3 
     | 
    
         
            +
            const DigraphInternal = require('./src/digraph_internal')
         
     | 
| 
       3 
4 
     | 
    
         
             
            const Digraph = require('./src/digraph')
         
     | 
| 
       4 
5 
     | 
    
         
             
            const fetch = require('node-fetch')
         
     | 
| 
       5 
6 
     | 
    
         
             
            const base64 = require('base-64')
         
     | 
| 
         @@ -228,7 +229,7 @@ const processContext = (context, { objects = {}, config, logs = [] }) => { 
     | 
|
| 
       228 
229 
     | 
    
         
             
              const response = {} // NA but passed in
         
     | 
| 
       229 
230 
     | 
    
         
             
              // generators = new Generators(generators.map((g) => new Generator(normalizeGenerator(g))))
         
     | 
| 
       230 
231 
     | 
    
         
             
              // semantics = new Semantics(semantics.map((g) => new Semantic(normalizeSemantic(g))))
         
     | 
| 
       231 
     | 
    
         
            -
              const hierarchy = new  
     | 
| 
      
 232 
     | 
    
         
            +
              const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
         
     | 
| 
       232 
233 
     | 
    
         | 
| 
       233 
234 
     | 
    
         
             
              const args = { objects, response, getObjects: getObjects(objects) }
         
     | 
| 
       234 
235 
     | 
    
         
             
              setupArgs(args, config, logs, hierarchy)
         
     | 
| 
         @@ -244,14 +245,18 @@ const processContext = (context, { objects = {}, config, logs = [] }) => { 
     | 
|
| 
       244 
245 
     | 
    
         
             
            }
         
     | 
| 
       245 
246 
     | 
    
         | 
| 
       246 
247 
     | 
    
         
             
            const convertToStable = (objects) => {
         
     | 
| 
       247 
     | 
    
         
            -
               
     | 
| 
       248 
     | 
    
         
            -
             
     | 
| 
       249 
     | 
    
         
            -
               
     | 
| 
       250 
     | 
    
         
            -
             
     | 
| 
       251 
     | 
    
         
            -
                stableObjects.namespaced 
     | 
| 
       252 
     | 
    
         
            -
                counter  
     | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
       254 
     | 
    
         
            -
             
     | 
| 
      
 248 
     | 
    
         
            +
              if (true) {
         
     | 
| 
      
 249 
     | 
    
         
            +
                return objects
         
     | 
| 
      
 250 
     | 
    
         
            +
              } else {
         
     | 
| 
      
 251 
     | 
    
         
            +
                const stableObjects = Object.assign({}, objects)
         
     | 
| 
      
 252 
     | 
    
         
            +
                stableObjects.namespaced = {}
         
     | 
| 
      
 253 
     | 
    
         
            +
                let counter = 0
         
     | 
| 
      
 254 
     | 
    
         
            +
                Object.keys(((objects || {}).namespaced || {})).forEach((uuid) => {
         
     | 
| 
      
 255 
     | 
    
         
            +
                  stableObjects.namespaced[`${counter}`] = objects.namespaced[uuid]
         
     | 
| 
      
 256 
     | 
    
         
            +
                  counter += 1
         
     | 
| 
      
 257 
     | 
    
         
            +
                })
         
     | 
| 
      
 258 
     | 
    
         
            +
                return stableObjects
         
     | 
| 
      
 259 
     | 
    
         
            +
              }
         
     | 
| 
       255 
260 
     | 
    
         
             
            }
         
     | 
| 
       256 
261 
     | 
    
         | 
| 
       257 
262 
     | 
    
         
             
            const writeTestFile = (fn, tests) => {
         
     | 
| 
         @@ -378,7 +383,7 @@ const processContextsB = ({ config, hierarchy, semantics, generators, json, isTe 
     | 
|
| 
       378 
383 
     | 
    
         
             
                context.topLevel = true
         
     | 
| 
       379 
384 
     | 
    
         
             
                try {
         
     | 
| 
       380 
385 
     | 
    
         
             
                  if (json.has_errors) {
         
     | 
| 
       381 
     | 
    
         
            -
                    throw new Error('There are errors in the logs')
         
     | 
| 
      
 386 
     | 
    
         
            +
                    throw new Error('There are errors in the logs. Run with the -d flag and grep for Error')
         
     | 
| 
       382 
387 
     | 
    
         
             
                  }
         
     | 
| 
       383 
388 
     | 
    
         
             
                  if (!config.get('skipSemantics')) {
         
     | 
| 
       384 
389 
     | 
    
         
             
                    if (!config.doMotivations(args, context)) {
         
     | 
| 
         @@ -505,7 +510,7 @@ const setupProcessB = ({ config, initializer, allowDelta=false } = {}) => { 
     | 
|
| 
       505 
510 
     | 
    
         
             
              delete data.generators
         
     | 
| 
       506 
511 
     | 
    
         
             
              // const semantics = new Semantics((data.semantics || []).map((g) => new Semantic(normalizeSemantic(g))))
         
     | 
| 
       507 
512 
     | 
    
         
             
              delete data.semantics
         
     | 
| 
       508 
     | 
    
         
            -
              const hierarchy = new  
     | 
| 
      
 513 
     | 
    
         
            +
              const hierarchy = new DigraphInternal((config.config || {}).hierarchy || [])
         
     | 
| 
       509 
514 
     | 
    
         | 
| 
       510 
515 
     | 
    
         
             
              return {
         
     | 
| 
       511 
516 
     | 
    
         
             
                data,
         
     | 
| 
         @@ -690,8 +695,10 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug 
     | 
|
| 
       690 
695 
     | 
    
         
             
              }
         
     | 
| 
       691 
696 
     | 
    
         | 
| 
       692 
697 
     | 
    
         
             
              let objects = getObjects(config.config.objects)(config.uuid)
         
     | 
| 
      
 698 
     | 
    
         
            +
              let testConfigName = config.name
         
     | 
| 
       693 
699 
     | 
    
         
             
              if (testConfig.testModuleName) {
         
     | 
| 
       694 
700 
     | 
    
         
             
                objects = getObjects(config.config.objects)(config.getConfigs()[testConfig.testModuleName].uuid)
         
     | 
| 
      
 701 
     | 
    
         
            +
                testConfigName = testConfig.testModuleName
         
     | 
| 
       695 
702 
     | 
    
         
             
              }
         
     | 
| 
       696 
703 
     | 
    
         
             
              config.beforeQuery({ query: test, isModule: false, objects })
         
     | 
| 
       697 
704 
     | 
    
         
             
              // config.resetMotivations()
         
     | 
| 
         @@ -715,15 +722,40 @@ const runTest = async (config, expected, { verbose, afterTest, testConfig, debug 
     | 
|
| 
       715 
722 
     | 
    
         
             
                  const failed_contexts = !matching(result.contexts, expected.contexts)
         
     | 
| 
       716 
723 
     | 
    
         
             
                  const failed_objects = !matching(actual_objects, expected_objects)
         
     | 
| 
       717 
724 
     | 
    
         | 
| 
       718 
     | 
    
         
            -
                  const pickEm = ( 
     | 
| 
      
 725 
     | 
    
         
            +
                  const pickEm = (getObjects) => {
         
     | 
| 
       719 
726 
     | 
    
         
             
                    const picked = {}
         
     | 
| 
       720 
727 
     | 
    
         
             
                    for (let prop of (testConfig.check || [])) {
         
     | 
| 
       721 
     | 
    
         
            -
                       
     | 
| 
      
 728 
     | 
    
         
            +
                      if (prop.km) {
         
     | 
| 
      
 729 
     | 
    
         
            +
                        c = config.getConfig(prop.km)
         
     | 
| 
      
 730 
     | 
    
         
            +
                        o = getObjects(prop.km)
         
     | 
| 
      
 731 
     | 
    
         
            +
                        picked[prop.km] = {}
         
     | 
| 
      
 732 
     | 
    
         
            +
                        for (let p of c.testConfig.check) {
         
     | 
| 
      
 733 
     | 
    
         
            +
                          if (p.km) {
         
     | 
| 
      
 734 
     | 
    
         
            +
                            continue
         
     | 
| 
      
 735 
     | 
    
         
            +
                          }
         
     | 
| 
      
 736 
     | 
    
         
            +
                          picked[p] = o[p]
         
     | 
| 
      
 737 
     | 
    
         
            +
                        }
         
     | 
| 
      
 738 
     | 
    
         
            +
                      } else {
         
     | 
| 
      
 739 
     | 
    
         
            +
                        picked[prop] = getObjects(testConfigName)[prop]
         
     | 
| 
      
 740 
     | 
    
         
            +
                      }
         
     | 
| 
       722 
741 
     | 
    
         
             
                    }
         
     | 
| 
       723 
742 
     | 
    
         
             
                    return picked
         
     | 
| 
       724 
743 
     | 
    
         
             
                  }
         
     | 
| 
       725 
     | 
    
         
            -
                  const  
     | 
| 
       726 
     | 
    
         
            -
             
     | 
| 
      
 744 
     | 
    
         
            +
                  const expectedGetObjects = (name) => {
         
     | 
| 
      
 745 
     | 
    
         
            +
                    if (!name) {
         
     | 
| 
      
 746 
     | 
    
         
            +
                      name = config.name
         
     | 
| 
      
 747 
     | 
    
         
            +
                    }
         
     | 
| 
      
 748 
     | 
    
         
            +
                    return expected.objects.namespaced[expected.objects.nameToUUID[name]]
         
     | 
| 
      
 749 
     | 
    
         
            +
                  }
         
     | 
| 
      
 750 
     | 
    
         
            +
                  const expected_checked = sortJson(pickEm(expectedGetObjects), { depth: 25 })
         
     | 
| 
      
 751 
     | 
    
         
            +
                  const actualGetObjects = (name) => {
         
     | 
| 
      
 752 
     | 
    
         
            +
                    if (!name) {
         
     | 
| 
      
 753 
     | 
    
         
            +
                      name = config.name
         
     | 
| 
      
 754 
     | 
    
         
            +
                    }
         
     | 
| 
      
 755 
     | 
    
         
            +
                    const km = config.configs.find( (km) => km.name == name )
         
     | 
| 
      
 756 
     | 
    
         
            +
                    return config.config.objects.namespaced[km.uuid]
         
     | 
| 
      
 757 
     | 
    
         
            +
                  }
         
     | 
| 
      
 758 
     | 
    
         
            +
                  const actual_checked = sortJson(pickEm(actualGetObjects), { depth: 25 })
         
     | 
| 
       727 
759 
     | 
    
         
             
                  const failed_checked = !matching(actual_objects, expected_objects)
         
     | 
| 
       728 
760 
     | 
    
         | 
| 
       729 
761 
     | 
    
         
             
                  const failed_checks = !matching(actual_objects, expected_objects)
         
     | 
| 
         @@ -811,7 +843,14 @@ const saveTest = async (testFile, config, test, expected, testConfig, saveDevelo 
     | 
|
| 
       811 
843 
     | 
    
         
             
              const result = await _process(config, test, { isTest: true })
         
     | 
| 
       812 
844 
     | 
    
         
             
              // const actualObjects = config.config.objects
         
     | 
| 
       813 
845 
     | 
    
         
             
              const actualConfig = getConfigForTest(config, testConfig)
         
     | 
| 
       814 
     | 
    
         
            -
               
     | 
| 
      
 846 
     | 
    
         
            +
              const args = {
         
     | 
| 
      
 847 
     | 
    
         
            +
              }
         
     | 
| 
      
 848 
     | 
    
         
            +
              const saveObjects = {...config.config.objects}
         
     | 
| 
      
 849 
     | 
    
         
            +
              saveObjects.nameToUUID = {}
         
     | 
| 
      
 850 
     | 
    
         
            +
              for (let km of config.configs) {
         
     | 
| 
      
 851 
     | 
    
         
            +
                saveObjects.nameToUUID[km.name] = km.uuid
         
     | 
| 
      
 852 
     | 
    
         
            +
              }
         
     | 
| 
      
 853 
     | 
    
         
            +
              writeTest(testFile, test, saveObjects, result.generated, result.paraphrases, result.responses, result.contexts, result.associations, result.metadata, actualConfig, saveDeveloper)
         
     | 
| 
       815 
854 
     | 
    
         
             
            }
         
     | 
| 
       816 
855 
     | 
    
         | 
| 
       817 
856 
     | 
    
         
             
            const saveTestsHelper = async (testFile, config, tests, todo, testConfig, saveDeveloper) => {
         
     | 
| 
         @@ -849,12 +888,22 @@ const showInfo = (description, section, config) => { 
     | 
|
| 
       849 
888 
     | 
    
         
             
                  visibleExamples.push(test.query)
         
     | 
| 
       850 
889 
     | 
    
         
             
                }
         
     | 
| 
       851 
890 
     | 
    
         
             
              }
         
     | 
| 
       852 
     | 
    
         
            -
              const  
     | 
| 
      
 891 
     | 
    
         
            +
              const templateQueries = []
         
     | 
| 
      
 892 
     | 
    
         
            +
              if (config.instances && config.instances.length > 0) {
         
     | 
| 
      
 893 
     | 
    
         
            +
                for (let query of config.instances.slice(-1)[0].queries) {
         
     | 
| 
      
 894 
     | 
    
         
            +
                  if (typeof query == 'string') {
         
     | 
| 
      
 895 
     | 
    
         
            +
                    templateQueries.push(query)
         
     | 
| 
      
 896 
     | 
    
         
            +
                  }
         
     | 
| 
      
 897 
     | 
    
         
            +
                }
         
     | 
| 
      
 898 
     | 
    
         
            +
              }
         
     | 
| 
      
 899 
     | 
    
         
            +
              const info = { name, description, examples: visibleExamples, template: templateQueries, section, includes, demo: config.demo }
         
     | 
| 
      
 900 
     | 
    
         
            +
              /*
         
     | 
| 
       853 
901 
     | 
    
         
             
              if (config.instances.length > 0) {
         
     | 
| 
       854 
902 
     | 
    
         
             
                info.template = {
         
     | 
| 
       855 
903 
     | 
    
         
             
                  base: config.instances[0].base
         
     | 
| 
       856 
904 
     | 
    
         
             
                }
         
     | 
| 
       857 
905 
     | 
    
         
             
              }
         
     | 
| 
      
 906 
     | 
    
         
            +
              */
         
     | 
| 
       858 
907 
     | 
    
         
             
              console.log(JSON.stringify(info, null, 2))
         
     | 
| 
       859 
908 
     | 
    
         
             
            }
         
     | 
| 
       860 
909 
     | 
    
         | 
| 
         @@ -1265,9 +1314,11 @@ const knowledgeModule = async ({ 
     | 
|
| 
       1265 
1314 
     | 
    
         
             
              processResults = processResults({ config, errorHandler })
         
     | 
| 
       1266 
1315 
     | 
    
         
             
              config.description = description
         
     | 
| 
       1267 
1316 
     | 
    
         
             
              config.demo = demo
         
     | 
| 
       1268 
     | 
    
         
            -
              if (typeof test === 'object' 
     | 
| 
       1269 
     | 
    
         
            -
                 
     | 
| 
       1270 
     | 
    
         
            -
             
     | 
| 
      
 1317 
     | 
    
         
            +
              if (typeof test === 'object') {
         
     | 
| 
      
 1318 
     | 
    
         
            +
                if (test.contents) {
         
     | 
| 
      
 1319 
     | 
    
         
            +
                  config.tests = test.contents
         
     | 
| 
      
 1320 
     | 
    
         
            +
                  test = test.name
         
     | 
| 
      
 1321 
     | 
    
         
            +
                }
         
     | 
| 
       1271 
1322 
     | 
    
         
             
              } else {
         
     | 
| 
       1272 
1323 
     | 
    
         
             
                if (runtime.fs && runtime.fs.existsSync(test)) {
         
     | 
| 
       1273 
1324 
     | 
    
         
             
                  config.tests = JSON.parse(runtime.fs.readFileSync(test))
         
     | 
| 
         @@ -1275,6 +1326,7 @@ const knowledgeModule = async ({ 
     | 
|
| 
       1275 
1326 
     | 
    
         
             
                  config.tests = {}
         
     | 
| 
       1276 
1327 
     | 
    
         
             
                }
         
     | 
| 
       1277 
1328 
     | 
    
         
             
              }
         
     | 
| 
      
 1329 
     | 
    
         
            +
              config.setTestConfig(testConfig)
         
     | 
| 
       1278 
1330 
     | 
    
         | 
| 
       1279 
1331 
     | 
    
         
             
              if (!isProcess) {
         
     | 
| 
       1280 
1332 
     | 
    
         
             
                if (template) {
         
     | 
| 
         @@ -1652,7 +1704,6 @@ const knowledgeModule = async ({ 
     | 
|
| 
       1652 
1704 
     | 
    
         
             
                }
         
     | 
| 
       1653 
1705 
     | 
    
         
             
              } else {
         
     | 
| 
       1654 
1706 
     | 
    
         
             
                config.addAssociationsFromTests(config.tests);
         
     | 
| 
       1655 
     | 
    
         
            -
                config.setTestConfig(testConfig)
         
     | 
| 
       1656 
1707 
     | 
    
         
             
                //for (let query in config.tests) {
         
     | 
| 
       1657 
1708 
     | 
    
         
             
                //  config.addAssociations(config.tests[query].associations || []);
         
     | 
| 
       1658 
1709 
     | 
    
         
             
                //}
         
     | 
    
        package/package.json
    CHANGED
    
    | 
         @@ -44,6 +44,7 @@ 
     | 
|
| 
       44 
44 
     | 
    
         
             
                "src/config.js",
         
     | 
| 
       45 
45 
     | 
    
         
             
                "src/copy.js",
         
     | 
| 
       46 
46 
     | 
    
         
             
                "src/digraph.js",
         
     | 
| 
      
 47 
     | 
    
         
            +
                "src/digraph_internal.js",
         
     | 
| 
       47 
48 
     | 
    
         
             
                "src/generators.js",
         
     | 
| 
       48 
49 
     | 
    
         
             
                "src/semantics.js"
         
     | 
| 
       49 
50 
     | 
    
         
             
              ],
         
     | 
| 
         @@ -62,6 +63,6 @@ 
     | 
|
| 
       62 
63 
     | 
    
         
             
                "json-stable-stringify": "^1.0.1",
         
     | 
| 
       63 
64 
     | 
    
         
             
                "node-fetch": "^2.6.1"
         
     | 
| 
       64 
65 
     | 
    
         
             
              },
         
     | 
| 
       65 
     | 
    
         
            -
              "version": "7.5. 
     | 
| 
      
 66 
     | 
    
         
            +
              "version": "7.5.7-beta.0",
         
     | 
| 
       66 
67 
     | 
    
         
             
              "license": "ISC"
         
     | 
| 
       67 
68 
     | 
    
         
             
            }
         
     | 
    
        package/src/config.js
    CHANGED
    
    | 
         @@ -3,7 +3,7 @@ const { Semantics, normalizeGenerator } = require('./semantics') 
     | 
|
| 
       3 
3 
     | 
    
         
             
            const { Generators } = require('./generators')
         
     | 
| 
       4 
4 
     | 
    
         
             
            // const { uuid: uuidv4 } = require('uuidv4')
         
     | 
| 
       5 
5 
     | 
    
         
             
            const client = require('../client')
         
     | 
| 
       6 
     | 
    
         
            -
            const  
     | 
| 
      
 6 
     | 
    
         
            +
            const DigraphInternal = require('./digraph_internal')
         
     | 
| 
       7 
7 
     | 
    
         
             
            const helpers = require('./helpers')
         
     | 
| 
       8 
8 
     | 
    
         
             
            const runtime = require('../runtime')
         
     | 
| 
       9 
9 
     | 
    
         
             
            const _ = require('lodash')
         
     | 
| 
         @@ -1287,7 +1287,7 @@ class Config { 
     | 
|
| 
       1287 
1287 
     | 
    
         
             
                  this.name = config.name
         
     | 
| 
       1288 
1288 
     | 
    
         
             
                }
         
     | 
| 
       1289 
1289 
     | 
    
         
             
                this.motivations = []
         
     | 
| 
       1290 
     | 
    
         
            -
                this.loadOrder = new  
     | 
| 
      
 1290 
     | 
    
         
            +
                this.loadOrder = new DigraphInternal()
         
     | 
| 
       1291 
1291 
     | 
    
         
             
                this.wasInitialized = false
         
     | 
| 
       1292 
1292 
     | 
    
         
             
                this.configs = []
         
     | 
| 
       1293 
1293 
     | 
    
         
             
                this._api = undefined
         
     | 
| 
         @@ -1300,7 +1300,7 @@ class Config { 
     | 
|
| 
       1300 
1300 
     | 
    
         
             
                  this.config = config
         
     | 
| 
       1301 
1301 
     | 
    
         
             
                  handleCalculatedProps(this, config)
         
     | 
| 
       1302 
1302 
     | 
    
         
             
                }
         
     | 
| 
       1303 
     | 
    
         
            -
                this.hierarchy = new  
     | 
| 
      
 1303 
     | 
    
         
            +
                this.hierarchy = new DigraphInternal(this.config.hierarchy)
         
     | 
| 
       1304 
1304 
     | 
    
         
             
                this.initConfig = _.cloneDeep(this.config)
         
     | 
| 
       1305 
1305 
     | 
    
         
             
                this.configs.push(new KM({ config: this.config, getCounter: (name) => this.config.getCounter(name), uuid: this._uuid }))
         
     | 
| 
       1306 
1306 
     | 
    
         | 
| 
         @@ -1854,7 +1854,7 @@ class Config { 
     | 
|
| 
       1854 
1854 
     | 
    
         
             
                this.resetDelta()
         
     | 
| 
       1855 
1855 
     | 
    
         
             
                const debug = this.config.debug;
         
     | 
| 
       1856 
1856 
     | 
    
         
             
                this.config = _.cloneDeep(this.initConfig)
         
     | 
| 
       1857 
     | 
    
         
            -
                this.hierarchy = new  
     | 
| 
      
 1857 
     | 
    
         
            +
                this.hierarchy = new DigraphInternal(this.config.hierarchy)
         
     | 
| 
       1858 
1858 
     | 
    
         
             
                if (debug) {
         
     | 
| 
       1859 
1859 
     | 
    
         
             
                  this.config.debug = debug
         
     | 
| 
       1860 
1860 
     | 
    
         
             
                }
         
     | 
| 
         @@ -1918,7 +1918,7 @@ class Config { 
     | 
|
| 
       1918 
1918 
     | 
    
         
             
                  config.wasInitialized = false
         
     | 
| 
       1919 
1919 
     | 
    
         
             
                  // TODO change name of config: to baseConfig:
         
     | 
| 
       1920 
1920 
     | 
    
         
             
                  const kmFn = (name) => this.getConfig(name)
         
     | 
| 
       1921 
     | 
    
         
            -
                  // const hierarchy = new  
     | 
| 
      
 1921 
     | 
    
         
            +
                  // const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
         
     | 
| 
       1922 
1922 
     | 
    
         
             
                  const args = { isModule, addWord: aw, km: kmFn, hierarchy: this.hierarchy, config, baseConfig: this, currentConfig: config, uuid: config._uuid, objects: namespacedObjects, namespace, api: config.api }
         
     | 
| 
       1923 
1923 
     | 
    
         
             
                  config.initializerFn(args)
         
     | 
| 
       1924 
1924 
     | 
    
         
             
                  if (config.initAfterApi) {
         
     | 
    
        package/src/digraph.js
    CHANGED
    
    | 
         @@ -13,6 +13,38 @@ class Digraph { 
     | 
|
| 
       13 
13 
     | 
    
         
             
                this._edges = edges
         
     | 
| 
       14 
14 
     | 
    
         
             
              }
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
      
 16 
     | 
    
         
            +
              // BFS
         
     | 
| 
      
 17 
     | 
    
         
            +
              path(from, to) {
         
     | 
| 
      
 18 
     | 
    
         
            +
                debugger
         
     | 
| 
      
 19 
     | 
    
         
            +
                const frontier = { [from]: [[]] }
         
     | 
| 
      
 20 
     | 
    
         
            +
                const done = new Set()
         
     | 
| 
      
 21 
     | 
    
         
            +
                while (Object.keys(frontier).length > 0) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                  const n = Object.keys(frontier)[0]
         
     | 
| 
      
 23 
     | 
    
         
            +
                  const ps = frontier[n]
         
     | 
| 
      
 24 
     | 
    
         
            +
                  if (to == n) {
         
     | 
| 
      
 25 
     | 
    
         
            +
                    return ps[0]
         
     | 
| 
      
 26 
     | 
    
         
            +
                  }
         
     | 
| 
      
 27 
     | 
    
         
            +
                  if (done.has(n)) {
         
     | 
| 
      
 28 
     | 
    
         
            +
                    delete frontier[n]
         
     | 
| 
      
 29 
     | 
    
         
            +
                    continue
         
     | 
| 
      
 30 
     | 
    
         
            +
                  }
         
     | 
| 
      
 31 
     | 
    
         
            +
                  done.add(n)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  for (let edge of this._edges) {
         
     | 
| 
      
 33 
     | 
    
         
            +
                    if (edge.child == n) {
         
     | 
| 
      
 34 
     | 
    
         
            +
                      if (!frontier[edge.parent]) {
         
     | 
| 
      
 35 
     | 
    
         
            +
                        frontier[edge.parent] = []
         
     | 
| 
      
 36 
     | 
    
         
            +
                      }
         
     | 
| 
      
 37 
     | 
    
         
            +
                      for (let path of ps) {
         
     | 
| 
      
 38 
     | 
    
         
            +
                        if (edge.parent == to) {
         
     | 
| 
      
 39 
     | 
    
         
            +
                          return [...path, edge]
         
     | 
| 
      
 40 
     | 
    
         
            +
                        }
         
     | 
| 
      
 41 
     | 
    
         
            +
                        frontier[edge.parent].push([...path, edge])
         
     | 
| 
      
 42 
     | 
    
         
            +
                      }
         
     | 
| 
      
 43 
     | 
    
         
            +
                    }
         
     | 
| 
      
 44 
     | 
    
         
            +
                  }
         
     | 
| 
      
 45 
     | 
    
         
            +
                }
         
     | 
| 
      
 46 
     | 
    
         
            +
              }
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       16 
48 
     | 
    
         
             
              addEdges(edges) {
         
     | 
| 
       17 
49 
     | 
    
         
             
                for (let edge of edges) {
         
     | 
| 
       18 
50 
     | 
    
         
             
                  this.addEdge(edge)
         
     | 
| 
         @@ -0,0 +1,131 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            const toA = (edge) => {
         
     | 
| 
      
 2 
     | 
    
         
            +
              if (Array.isArray(edge)) {
         
     | 
| 
      
 3 
     | 
    
         
            +
                return edge
         
     | 
| 
      
 4 
     | 
    
         
            +
              } else {
         
     | 
| 
      
 5 
     | 
    
         
            +
                return [edge.child, edge.parent]
         
     | 
| 
      
 6 
     | 
    
         
            +
              }
         
     | 
| 
      
 7 
     | 
    
         
            +
            }
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            class DigraphInternal {
         
     | 
| 
      
 10 
     | 
    
         
            +
              // edges maybe either [child, parent] or { child, parent }
         
     | 
| 
      
 11 
     | 
    
         
            +
              constructor (edges = []) {
         
     | 
| 
      
 12 
     | 
    
         
            +
                // dont make a copy of edges. this is shared and that breaks stuff. TODO fix this
         
     | 
| 
      
 13 
     | 
    
         
            +
                this._edges = edges
         
     | 
| 
      
 14 
     | 
    
         
            +
              }
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              addEdges(edges) {
         
     | 
| 
      
 17 
     | 
    
         
            +
                for (let edge of edges) {
         
     | 
| 
      
 18 
     | 
    
         
            +
                  this.addEdge(edge)
         
     | 
| 
      
 19 
     | 
    
         
            +
                }
         
     | 
| 
      
 20 
     | 
    
         
            +
              }
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              addEdge(edge) {
         
     | 
| 
      
 23 
     | 
    
         
            +
                edge = toA(edge)
         
     | 
| 
      
 24 
     | 
    
         
            +
                this._edges.push(edge)
         
     | 
| 
      
 25 
     | 
    
         
            +
              }
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              get edges() {
         
     | 
| 
      
 28 
     | 
    
         
            +
                return this._edges
         
     | 
| 
      
 29 
     | 
    
         
            +
              }
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
              set edges(edges) {
         
     | 
| 
      
 32 
     | 
    
         
            +
                this._edges = edges
         
     | 
| 
      
 33 
     | 
    
         
            +
              }
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            /*
         
     | 
| 
      
 36 
     | 
    
         
            +
              set edges(edges) {
         
     | 
| 
      
 37 
     | 
    
         
            +
                this._edges = edges.map( toA )
         
     | 
| 
      
 38 
     | 
    
         
            +
              }
         
     | 
| 
      
 39 
     | 
    
         
            +
            */
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              acdcs (s, from, to) {
         
     | 
| 
      
 42 
     | 
    
         
            +
                const todo = [s]
         
     | 
| 
      
 43 
     | 
    
         
            +
                const seen = new Set([s])
         
     | 
| 
      
 44 
     | 
    
         
            +
                const acdcs = new Set([])
         
     | 
| 
      
 45 
     | 
    
         
            +
                while (todo.length > 0) {
         
     | 
| 
      
 46 
     | 
    
         
            +
                  const n = todo.pop()
         
     | 
| 
      
 47 
     | 
    
         
            +
                  this._edges.forEach((e) => {
         
     | 
| 
      
 48 
     | 
    
         
            +
                    e = toA(e)
         
     | 
| 
      
 49 
     | 
    
         
            +
                    if (e[from] === n) {
         
     | 
| 
      
 50 
     | 
    
         
            +
                      acdcs.add(e[to])
         
     | 
| 
      
 51 
     | 
    
         
            +
                      if (!seen.has(e[to])) {
         
     | 
| 
      
 52 
     | 
    
         
            +
                        todo.push(e[to])
         
     | 
| 
      
 53 
     | 
    
         
            +
                        seen.add(e[to])
         
     | 
| 
      
 54 
     | 
    
         
            +
                      }
         
     | 
| 
      
 55 
     | 
    
         
            +
                    }
         
     | 
| 
      
 56 
     | 
    
         
            +
                  })
         
     | 
| 
      
 57 
     | 
    
         
            +
                }
         
     | 
| 
      
 58 
     | 
    
         
            +
                return acdcs
         
     | 
| 
      
 59 
     | 
    
         
            +
              }
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              isA (low, high) {
         
     | 
| 
      
 62 
     | 
    
         
            +
                if (low === high) {
         
     | 
| 
      
 63 
     | 
    
         
            +
                  return true
         
     | 
| 
      
 64 
     | 
    
         
            +
                }
         
     | 
| 
      
 65 
     | 
    
         
            +
                return this.ancestors(low).has(high)
         
     | 
| 
      
 66 
     | 
    
         
            +
              }
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
              lessThan (low, high) {
         
     | 
| 
      
 69 
     | 
    
         
            +
                if (low === high) {
         
     | 
| 
      
 70 
     | 
    
         
            +
                  return false
         
     | 
| 
      
 71 
     | 
    
         
            +
                }
         
     | 
| 
      
 72 
     | 
    
         
            +
                return this.ancestors(low).has(high)
         
     | 
| 
      
 73 
     | 
    
         
            +
              }
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
              descendants (s) {
         
     | 
| 
      
 76 
     | 
    
         
            +
                return this.acdcs(s, 1, 0)
         
     | 
| 
      
 77 
     | 
    
         
            +
              }
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
              ancestors (s) {
         
     | 
| 
      
 80 
     | 
    
         
            +
                return this.acdcs(s, 0, 1)
         
     | 
| 
      
 81 
     | 
    
         
            +
              }
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
              minima (nodes) {
         
     | 
| 
      
 84 
     | 
    
         
            +
                let minima = new Set(nodes)
         
     | 
| 
      
 85 
     | 
    
         
            +
                const ancestors = new Set([])
         
     | 
| 
      
 86 
     | 
    
         
            +
                nodes.forEach((node) => {
         
     | 
| 
      
 87 
     | 
    
         
            +
                  this.ancestors(node).forEach((n) => ancestors.add(n))
         
     | 
| 
      
 88 
     | 
    
         
            +
                })
         
     | 
| 
      
 89 
     | 
    
         
            +
                ancestors.forEach((n) => minima.delete(n))
         
     | 
| 
      
 90 
     | 
    
         
            +
                if (minima.size === 0) {
         
     | 
| 
      
 91 
     | 
    
         
            +
                  // all unrelated
         
     | 
| 
      
 92 
     | 
    
         
            +
                  minima = new Set(nodes)
         
     | 
| 
      
 93 
     | 
    
         
            +
                }
         
     | 
| 
      
 94 
     | 
    
         
            +
                return minima
         
     | 
| 
      
 95 
     | 
    
         
            +
              }
         
     | 
| 
      
 96 
     | 
    
         
            +
             
     | 
| 
      
 97 
     | 
    
         
            +
              maxima (nodes) {
         
     | 
| 
      
 98 
     | 
    
         
            +
                const maxima = new Set(nodes)
         
     | 
| 
      
 99 
     | 
    
         
            +
                const descendants = new Set([])
         
     | 
| 
      
 100 
     | 
    
         
            +
                nodes.forEach((node) => {
         
     | 
| 
      
 101 
     | 
    
         
            +
                  this.descendants(node).forEach((n) => descendants.add(n))
         
     | 
| 
      
 102 
     | 
    
         
            +
                })
         
     | 
| 
      
 103 
     | 
    
         
            +
                descendants.forEach((n) => maxima.delete(n))
         
     | 
| 
      
 104 
     | 
    
         
            +
                return maxima
         
     | 
| 
      
 105 
     | 
    
         
            +
              }
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
              add (child, parent) {
         
     | 
| 
      
 108 
     | 
    
         
            +
                this._edges.push([child, parent])
         
     | 
| 
      
 109 
     | 
    
         
            +
              }
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
              addList (l) {
         
     | 
| 
      
 112 
     | 
    
         
            +
                for (let i = 1; i < l.length; ++i) {
         
     | 
| 
      
 113 
     | 
    
         
            +
                  this._edges.push([l[i - 1], l[i]])
         
     | 
| 
      
 114 
     | 
    
         
            +
                }
         
     | 
| 
      
 115 
     | 
    
         
            +
              }
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
              order (todo) {
         
     | 
| 
      
 118 
     | 
    
         
            +
                const ordered = []
         
     | 
| 
      
 119 
     | 
    
         
            +
                while (todo.length > 0) {
         
     | 
| 
      
 120 
     | 
    
         
            +
                  const nodes = this.minima(todo)
         
     | 
| 
      
 121 
     | 
    
         
            +
                  todo = todo.filter((e) => !nodes.has(e))
         
     | 
| 
      
 122 
     | 
    
         
            +
                  for (const node of nodes) {
         
     | 
| 
      
 123 
     | 
    
         
            +
                    ordered.push(node)
         
     | 
| 
      
 124 
     | 
    
         
            +
                  }
         
     | 
| 
      
 125 
     | 
    
         
            +
                  // ordered = ordered.concat([...nodes])
         
     | 
| 
      
 126 
     | 
    
         
            +
                }
         
     | 
| 
      
 127 
     | 
    
         
            +
                return ordered
         
     | 
| 
      
 128 
     | 
    
         
            +
              }
         
     | 
| 
      
 129 
     | 
    
         
            +
            }
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
            module.exports = DigraphInternal
         
     | 
    
        package/src/generators.js
    CHANGED
    
    | 
         @@ -115,6 +115,9 @@ class Generator { 
     | 
|
| 
       115 
115 
     | 
    
         
             
                        apis: this.getAPIs(config) 
         
     | 
| 
       116 
116 
     | 
    
         
             
                      }
         
     | 
| 
       117 
117 
     | 
    
         
             
                const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
         
     | 
| 
      
 118 
     | 
    
         
            +
                if (this.property == 'generatorp') {
         
     | 
| 
      
 119 
     | 
    
         
            +
                  args.g = args.gp
         
     | 
| 
      
 120 
     | 
    
         
            +
                }
         
     | 
| 
       118 
121 
     | 
    
         
             
                // if (this.callId) {
         
     | 
| 
       119 
122 
     | 
    
         
             
                // greg
         
     | 
| 
       120 
123 
     | 
    
         
             
                /*
         
     | 
| 
         @@ -262,10 +265,10 @@ class Generators { 
     | 
|
| 
       262 
265 
     | 
    
         
             
                        lines.newRow()
         
     | 
| 
       263 
266 
     | 
    
         
             
                        lines.setElement(0, 1, 'STACK')
         
     | 
| 
       264 
267 
     | 
    
         
             
                        lines.setElement(0, 2, stack)
         
     | 
| 
       265 
     | 
    
         
            -
                        lines.newRow()
         
     | 
| 
       266 
268 
     | 
    
         
             
            						lines.newRow()
         
     | 
| 
       267 
269 
     | 
    
         
             
            						lines.setElement(0, 1, 'DEBUG')
         
     | 
| 
       268 
270 
     | 
    
         
             
            						lines.setElement(0, 2, `To debug this use args.callId == '${args.calls.current()}'`)
         
     | 
| 
      
 271 
     | 
    
         
            +
            						lines.newRow()
         
     | 
| 
       269 
272 
     | 
    
         
             
                        lines.setElement(0, 1, 'TO')
         
     | 
| 
       270 
273 
     | 
    
         
             
                        lines.setElement(0, 2, `(HASHCODE ${helpers.hashCode(JSON.stringify(helpers.sortJson(context, { depth: 25 })))})`)
         
     | 
| 
       271 
274 
     | 
    
         
             
                        lines.setElement(1, 2, JSON.stringify(helpers.sortJson(context, { depth: 25 }), null, 2))
         
     |