theprogrammablemind 7.5.0-beta.33 → 7.5.0-beta.35

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/config.js +272 -13
package/package.json CHANGED
@@ -61,6 +61,6 @@
61
61
  "json-stable-stringify": "^1.0.1",
62
62
  "node-fetch": "^2.6.1"
63
63
  },
64
- "version": "7.5.0-beta.33",
64
+ "version": "7.5.0-beta.35",
65
65
  "license": "ISC"
66
66
  }
package/src/config.js CHANGED
@@ -542,9 +542,23 @@ class Config {
542
542
  client.build({ config: this, target: this.name, beforeQuery: () => {}, template, ...options })
543
543
  } else {
544
544
  // no change
545
- this.initInstances.push(instance)
546
- this.instances.push(instance)
547
- client.processInstance(this, instance)
545
+ // this.initInstances.push({ ...instance, name: config.name })
546
+ const isEmpty = ( instance ) => {
547
+ const properties = [
548
+ "queries",
549
+ "resultss",
550
+ "fragments",
551
+ "semantics",
552
+ "associations",
553
+ ]
554
+ return !properties.find( (property) => instance[property].length > 0 )
555
+ }
556
+ if (!isEmpty(instance)) {
557
+ instance.name = this.name
558
+ this.initInstances.push(instance)
559
+ this.instances.push(instance)
560
+ client.processInstance(this, instance)
561
+ }
548
562
  }
549
563
  }
550
564
 
@@ -1533,7 +1547,8 @@ class Config {
1533
1547
  }
1534
1548
 
1535
1549
  initializeFromConfigs () {
1536
- this.configs.forEach(({ config, namespace, uuid }) => {
1550
+ // [...this.configs].reverse().forEach(({ config, namespace, uuid }) => {
1551
+ [...this.configs].reverse().forEach(({ config, namespace, uuid }) => {
1537
1552
  /*
1538
1553
  let objects = this.get('objects')
1539
1554
  if (namespace) {
@@ -1785,8 +1800,17 @@ class Config {
1785
1800
  this.configs = [...oconfigs]
1786
1801
  }
1787
1802
 
1803
+ const addInternals = []
1788
1804
  const inits = []
1789
1805
  const initAfterApis = []
1806
+ if (false && this.config.hierarchy.find( (pair) => JSON.stringify(pair) === JSON.stringify(["equipable2","property"]))) {
1807
+ debugger // happened
1808
+ }
1809
+ if (false && this.name == 'countable') {
1810
+ debugger // in rebuild
1811
+ }
1812
+ const reverseIt = true
1813
+ const interleaved = true
1790
1814
  this.configs.forEach((km) => {
1791
1815
  const namespace = km.namespace
1792
1816
  this.config.objects.namespaced[km._uuid] = {}
@@ -1819,7 +1843,12 @@ class Config {
1819
1843
  const args = { isModule, addWord: aw, km: kmFn, hierarchy: this.hierarchy, config, baseConfig: this, currentConfig: config, uuid: config._uuid, objects: namespacedObjects, namespace, api: config.api }
1820
1844
  config.initializerFn(args)
1821
1845
  if (config.initAfterApi) {
1822
- initAfterApis.push({ config, args })
1846
+ // reverse the list
1847
+ initAfterApis.unshift({ config, args })
1848
+ } else {
1849
+ if (interleaved) {
1850
+ initAfterApis.unshift(null)
1851
+ }
1823
1852
  }
1824
1853
  // greg
1825
1854
  if (config._api) {
@@ -1827,27 +1856,124 @@ class Config {
1827
1856
  // reverse the list
1828
1857
  inits.unshift( () => config._api.initialize({ config: this, km: kmFn, api: config._api }) )
1829
1858
  // config._api.initialize({ config, api: config._api })
1859
+ } else {
1860
+ if (interleaved) {
1861
+ inits.unshift(null)
1862
+ }
1830
1863
  }
1831
1864
  config._api.objects = namespacedObjects
1832
1865
  config._api.config = () => this
1833
1866
  config._api.uuid = config._uuid
1867
+ } else {
1868
+ if (interleaved) {
1869
+ inits.unshift(null)
1870
+ }
1834
1871
  }
1835
1872
  config.setUUIDs()
1836
1873
  config.applyNamespace(config.config, namespace, config.uuid)
1837
1874
  if (!isSelf) {
1838
- this.addInternal(config, true, false, false, true)
1875
+ if (!reverseIt) {
1876
+ addInternals.push(config)
1877
+ } else {
1878
+ addInternals.unshift(config)
1879
+ }
1880
+ // this.addInternal(config, true, false, false, true)
1881
+ } else {
1882
+ if (interleaved) {
1883
+ addInternals.unshift(null)
1884
+ }
1839
1885
  }
1840
1886
  km.valid()
1841
1887
  })
1842
- // console.log('inits from config', inits)
1843
- for (const init of inits) {
1844
- init()
1888
+
1889
+ if (this.name == 'time') {
1890
+ debugger
1845
1891
  }
1846
- for (let init of initAfterApis) {
1847
- // init.args.isAfterApi = true
1848
- init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
1892
+
1893
+ if (addInternals.length !== inits.length || addInternals.length !== initAfterApis.length) {
1894
+ debugger // bug
1895
+ }
1896
+
1897
+ const generators = this.config.generators
1898
+ const semantics = this.config.semantics
1899
+ if (reverseIt) {
1900
+ this.config.generators = []
1901
+ this.config.semantics = []
1902
+ }
1903
+
1904
+ if (!interleaved) {
1905
+ for (const config of addInternals) {
1906
+ if (!reverseIt) {
1907
+ this.addInternal(config, true, false, false, true)
1908
+ } else {
1909
+ this.addInternalR(config, true, false, false, true)
1910
+ }
1911
+ }
1912
+ // console.log('inits from config', inits)
1913
+ for (const init of inits) {
1914
+ init()
1915
+ }
1916
+ for (let init of initAfterApis) {
1917
+ // init.args.isAfterApi = true
1918
+ init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
1919
+ }
1920
+ this.instances.forEach((instance) => client.processInstance(this, instance))
1921
+ } else {
1922
+ const base = {
1923
+ operators: this.config.operators,
1924
+ bridges: this.config.bridges,
1925
+ hierarchy: this.config.hierarchy,
1926
+ priorities: this.config.priorities,
1927
+ associations: this.config.associations,
1928
+ words: this.config.words
1929
+ }
1930
+
1931
+ this.config.operators = []
1932
+ this.config.bridges = []
1933
+ this.config.hierarchy = []
1934
+ this.config.priorities = []
1935
+ this.config.associations = { positive: [], negative: [] }
1936
+ this.config.words = {}
1937
+
1938
+ for (let i = 0; i < addInternals.length; ++i) {
1939
+ let name;
1940
+ if (addInternals[i]) {
1941
+ this.addInternalR(addInternals[i], true, false, false, true)
1942
+ name = addInternals[i].name
1943
+ } else{
1944
+ this.addInternalR(base, true, false, false, true)
1945
+ name = this.name
1946
+ }
1947
+ // console.log('name -------------', name)
1948
+ if (inits[i]) {
1949
+ inits[i]()
1950
+ }
1951
+ if (initAfterApis[i]) {
1952
+ const init = initAfterApis[i]
1953
+ init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
1954
+ }
1955
+ if (this.name == 'pipboy') {
1956
+ debugger
1957
+ }
1958
+ const instance = this.instances.find((instance) => instance.name == name)
1959
+ if (instance) {
1960
+ // console.log('-------- instance')
1961
+ if (name == 'pipboyTemplate') {
1962
+ debugger
1963
+ }
1964
+ client.processInstance(this, instance)
1965
+ }
1966
+ }
1967
+ // this.instances.forEach((instance) => client.processInstance(this, instance))
1968
+ }
1969
+
1970
+ if (reverseIt) {
1971
+ this.config.generators = generators.concat(this.config.generators)
1972
+ this.config.semantics = semantics.concat(this.config.semantics)
1973
+ }
1974
+ if (this.name == 'pipboy') {
1975
+ debugger // instance
1849
1976
  }
1850
- this.instances.forEach((instance) => client.processInstance(this, instance))
1851
1977
  this.valid()
1852
1978
  this.checkBridges()
1853
1979
  }
@@ -2173,6 +2299,10 @@ class Config {
2173
2299
  more = new Config(more)
2174
2300
  }
2175
2301
 
2302
+ if (this.name == 'pipboy') {
2303
+ debugger // in add
2304
+ // .config.hierarchy.find( (pair) => JSON.stringify(pair) == JSON.stringify(["equipable","isEder"]) )
2305
+ }
2176
2306
  this.valid()
2177
2307
  more.valid()
2178
2308
  // copy so i don't have to copy later
@@ -2214,6 +2344,13 @@ class Config {
2214
2344
  this.configs.forEach((km) => {
2215
2345
  this.instances = (km._config.instances || this.initInstances.slice()).concat(this.instances)
2216
2346
  })
2347
+ let noDups = []
2348
+ for (let instance of this.instances) {
2349
+ if (!noDups.find( (existing) => existing.name == instance.name )) {
2350
+ noDups.push(instance)
2351
+ }
2352
+ }
2353
+ this.instances = noDups
2217
2354
 
2218
2355
  this.rebuild()
2219
2356
  this.valid()
@@ -2331,6 +2468,128 @@ class Config {
2331
2468
  }
2332
2469
  return this
2333
2470
  }
2471
+
2472
+ // assumes this is called in reverse order
2473
+ addInternalR (more, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false) {
2474
+ if (more instanceof Config) {
2475
+ more.initialize({ force: false })
2476
+ if (useOldVersion) {
2477
+ more = more.config
2478
+ } else {
2479
+ // more = more.initConfig
2480
+ more = _.cloneDeep(more.initConfig)
2481
+ }
2482
+ }
2483
+ for (const key of Object.keys(more)) {
2484
+ const value = more[key]
2485
+ // TODO remove name and description on the config bag
2486
+ const noOverwrite = ['name', 'namespaced']
2487
+ if (!this.config[key]) {
2488
+ if (allowNameToBeNull) {
2489
+ if (noOverwrite.includes(key)) {
2490
+ continue
2491
+ }
2492
+ } else if (this.config[key] && noOverwrite.includes(key)) {
2493
+ continue
2494
+ }
2495
+ this.config[key] = value
2496
+ continue
2497
+ }
2498
+ if (key === 'words') {
2499
+ const configWords = this.config.words
2500
+ const moreWords = more.words
2501
+ for (const word of Object.keys(moreWords)) {
2502
+ if (!configWords[word]) {
2503
+ configWords[word] = []
2504
+ }
2505
+ // configWords[word] = configWords[word].concat(moreWords[word])
2506
+ configWords[word] = moreWords[word].concat(configWords[word])
2507
+ }
2508
+ } else if (key === 'name') {
2509
+ /*
2510
+ if (this.config[key] === '') {
2511
+ this.config[key] = more[key]
2512
+ }
2513
+ */
2514
+ } else if (key === 'namespaces') {
2515
+ if (includeNamespaces) {
2516
+ Object.assign(this.config[key], more[key])
2517
+ }
2518
+ } else if (key === 'debug') {
2519
+ this.config[key] = this.config[key] || more[key]
2520
+ } else if (key === 'description') {
2521
+ // this.config[key] += ' ' + more[key].trim()
2522
+ this.config[key] = more[key].trim() + ' ' + this.config[key]
2523
+ } else if (key === 'objects') {
2524
+ if (!skipObjects) {
2525
+ // namespaced is special
2526
+ const namespaced = this.config.objects.namespaced
2527
+ Object.assign(this.config[key], more[key])
2528
+ this.config.objects.namespaced = namespaced
2529
+ }
2530
+ } else if (key === 'associations') {
2531
+ const configAssociations = this.config.associations
2532
+ const moreAssociations = more.associations
2533
+ if (moreAssociations.positive) {
2534
+ // configAssociations.positive = configAssociations.positive.concat(moreAssociations.positive)
2535
+ configAssociations.positive = moreAssociations.positive.concat(configAssociations.positive)
2536
+ }
2537
+ if (moreAssociations.negative) {
2538
+ // configAssociations.negative = configAssociations.negative.concat(moreAssociations.negative)
2539
+ configAssociations.negative = moreAssociations.negative.concat(configAssociations.negative)
2540
+ }
2541
+ } else if (Array.isArray(value)) {
2542
+ // handle allowDups
2543
+ if (key == 'operators') {
2544
+ // TODO what about other props
2545
+ const isDup = (op1, op2) => op1.pattern == op2.pattern
2546
+ for (const newOne of more[key]) {
2547
+ for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
2548
+ const oldOne = this.config[key][iOldOne];
2549
+ if (isDup(newOne, oldOne)) {
2550
+ if (oldOne.allowDups) {
2551
+ // the old one takes precedence to match what would happen during the original load
2552
+ debugger
2553
+ this.config[key].splice(iOldOne, 1)
2554
+ break;
2555
+ }
2556
+ }
2557
+ }
2558
+ }
2559
+ }
2560
+ if (key == 'bridges') {
2561
+ // TODO what about other props
2562
+ const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
2563
+ for (const newOne of more[key]) {
2564
+ for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
2565
+ const oldOne = this.config[key][iOldOne];
2566
+ if (newOne.id == oldOne.id) {
2567
+ if (oldOne.allowDups) {
2568
+ // the old one takes precedence to match what would happen during the original load
2569
+ this.config[key].splice(iOldOne, 1)
2570
+ break;
2571
+ }
2572
+ }
2573
+ }
2574
+ }
2575
+ }
2576
+ // console.log('key', key, 'XXX')
2577
+ // console.log('more', JSON.stringify(more, null, 2))
2578
+ // this.config[key] = this.config[key].concat(more[key])
2579
+ if (key == '2enerators') {
2580
+ debugger
2581
+ }
2582
+ // this.config[key] = this.config[key].concat(more[key])
2583
+ this.config[key] = more[key].concat(this.config[key])
2584
+ } else {
2585
+ if (!(key in this.config)) {
2586
+ throw `Unexpected property in config ${key}`
2587
+ }
2588
+ this.config[key] = more[key]
2589
+ }
2590
+ }
2591
+ return this
2592
+ }
2334
2593
  }
2335
2594
 
2336
2595
  module.exports = {