theprogrammablemind 7.5.4-beta.4 → 7.5.4-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/client.js +3 -3
- package/package.json +1 -1
- package/src/config.js +32 -132
- package/src/helpers.js +74 -2
package/client.js
CHANGED
@@ -8,7 +8,7 @@ const _ = require('lodash')
|
|
8
8
|
const stringify = require('json-stable-stringify')
|
9
9
|
const Lines = require('./lines')
|
10
10
|
const flattens = require('./src/flatten')
|
11
|
-
const { appendNoDups, InitCalls } = require('./src/helpers')
|
11
|
+
const { appendNoDups, InitCalls, updateQueries } = require('./src/helpers')
|
12
12
|
const runtime = require('./runtime')
|
13
13
|
const sortJson = runtime.sortJson
|
14
14
|
|
@@ -518,7 +518,7 @@ const processInstance = (config, instance) => {
|
|
518
518
|
for (const results of (instance.resultss || [])) {
|
519
519
|
if (results.extraConfig) {
|
520
520
|
// config.addInternal(results, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false)
|
521
|
-
config.addInternal(results)
|
521
|
+
config.addInternal(results, { handleCalculatedProps: true } )
|
522
522
|
} else {
|
523
523
|
processContextsB({ config, hierarchy, json: results/*, generators, semantics */ })
|
524
524
|
}
|
@@ -1143,7 +1143,7 @@ const build = async ({ config, target, template, errorHandler = defaultErrorHand
|
|
1143
1143
|
return template
|
1144
1144
|
};
|
1145
1145
|
stabilizeOutput(accumulators)
|
1146
|
-
runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries }, accumulators), 0, 2))
|
1146
|
+
runtime.fs.writeFileSync(instanceName, JSON.stringify(Object.assign({ queries: template.queries.map(updateQueries) }, accumulators), 0, 2))
|
1147
1147
|
|
1148
1148
|
// km tests file
|
1149
1149
|
const testsName = `./${target}.test.json`
|
package/package.json
CHANGED
package/src/config.js
CHANGED
@@ -5,7 +5,6 @@ const { Generators } = require('./generators')
|
|
5
5
|
const client = require('../client')
|
6
6
|
const Digraph = require('./digraph')
|
7
7
|
const helpers = require('./helpers')
|
8
|
-
const deepEqual = require('deep-equal')
|
9
8
|
const runtime = require('../runtime')
|
10
9
|
const _ = require('lodash')
|
11
10
|
|
@@ -104,6 +103,24 @@ const handleBridgeProps = (config, bridge) => {
|
|
104
103
|
}
|
105
104
|
}
|
106
105
|
|
106
|
+
const handleCalculatedProps = (baseConfig, moreConfig) => {
|
107
|
+
for (let bridge of moreConfig.bridges) {
|
108
|
+
const valid = [ 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
|
109
|
+
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy' ]
|
110
|
+
helpers.validProps(valid, bridge, 'bridge')
|
111
|
+
handleBridgeProps(baseConfig, bridge)
|
112
|
+
}
|
113
|
+
if (moreConfig.operators) {
|
114
|
+
moreConfig.operators = moreConfig.operators.map((operator) => {
|
115
|
+
if (typeof operator === 'string') {
|
116
|
+
return { pattern: operator }
|
117
|
+
} else {
|
118
|
+
return operator
|
119
|
+
}
|
120
|
+
})
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
107
124
|
if (runtime.process.env.DEBUG_HIERARCHY) {
|
108
125
|
global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
|
109
126
|
}
|
@@ -646,12 +663,13 @@ class Config {
|
|
646
663
|
}
|
647
664
|
const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map( toCanonical )
|
648
665
|
const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map( toCanonical )
|
649
|
-
const sameFragments =
|
650
|
-
const sameQueries =
|
666
|
+
const sameFragments = helpers.safeEquals(templateFragments, instanceFragments)
|
667
|
+
const sameQueries = helpers.safeEquals((template.queries || []).map(helpers.updateQueries), (instance.queries || []))
|
651
668
|
return !(instance && sameQueries && sameFragments)
|
652
669
|
}
|
653
670
|
|
654
671
|
load (template, instance, options = { rebuild: false } ) {
|
672
|
+
this.template = template
|
655
673
|
this.logs.push(`loading template for ${this.name}`)
|
656
674
|
if (instance && instance.associations && !options.rebuild) {
|
657
675
|
this.addAssociations(instance.associations)
|
@@ -713,7 +731,7 @@ class Config {
|
|
713
731
|
}
|
714
732
|
}
|
715
733
|
if (global.entodictonDebugAssociation) {
|
716
|
-
if (
|
734
|
+
if (helpers.safeEquals(global.entodictonDebugAssociation, association)) {
|
717
735
|
debugger; // debug association hit
|
718
736
|
}
|
719
737
|
}
|
@@ -748,7 +766,7 @@ class Config {
|
|
748
766
|
throw `addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`
|
749
767
|
}
|
750
768
|
if (global.entodictonDebugHierarchy) {
|
751
|
-
if (
|
769
|
+
if ((helpers.safeEquals.entodictonDebugHierarchy, [child, parent])) {
|
752
770
|
debugger; // debug hierarchy hit
|
753
771
|
}
|
754
772
|
}
|
@@ -766,7 +784,7 @@ class Config {
|
|
766
784
|
}
|
767
785
|
|
768
786
|
if (global.entodictonDebugHierarchy) {
|
769
|
-
if (
|
787
|
+
if (helpers.safeEquals(global.entodictonDebugHierarchy, [child, parent])) {
|
770
788
|
debugger; // debug hierarchy hit
|
771
789
|
}
|
772
790
|
}
|
@@ -1244,133 +1262,12 @@ class Config {
|
|
1244
1262
|
if (config) {
|
1245
1263
|
config = _.cloneDeep(config)
|
1246
1264
|
this.config = config
|
1247
|
-
|
1248
|
-
const valid = [ 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
|
1249
|
-
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy' ]
|
1250
|
-
helpers.validProps(valid, bridge, 'bridge')
|
1251
|
-
/* moved
|
1252
|
-
if (!bridge.bridge) {
|
1253
|
-
bridge.bridge = "{ ...next(operator) }"
|
1254
|
-
}
|
1255
|
-
*/
|
1256
|
-
handleBridgeProps(this, bridge)
|
1257
|
-
|
1258
|
-
/* moved
|
1259
|
-
if (!bridge.level) {
|
1260
|
-
bridge.level = 0
|
1261
|
-
}
|
1262
|
-
*/
|
1263
|
-
/*
|
1264
|
-
if (bridge.generator) {
|
1265
|
-
this.config.generators.push({
|
1266
|
-
match: ({context}) => bridge.id == context.marker,
|
1267
|
-
apply: (args) => bridge.generator(args),
|
1268
|
-
})
|
1269
|
-
}
|
1270
|
-
*/
|
1271
|
-
/* moved
|
1272
|
-
if (bridge.children) {
|
1273
|
-
for (let child of bridge.children) {
|
1274
|
-
this.addHierarchy(child, bridge.id)
|
1275
|
-
}
|
1276
|
-
}
|
1277
|
-
if (bridge.parents) {
|
1278
|
-
for (let parent of bridge.parents) {
|
1279
|
-
this.addHierarchy(bridge.id, parent)
|
1280
|
-
}
|
1281
|
-
}
|
1282
|
-
if (bridge.isA) {
|
1283
|
-
for (let parent of bridge.isA) {
|
1284
|
-
this.addHierarchy(bridge.id, parent)
|
1285
|
-
}
|
1286
|
-
}
|
1287
|
-
*/
|
1288
|
-
/* moved
|
1289
|
-
if (bridge.before) {
|
1290
|
-
for (let after of bridge.before) {
|
1291
|
-
if (typeof after == 'string') {
|
1292
|
-
after = [after, 0]
|
1293
|
-
}
|
1294
|
-
this.addPriorities([after, [bridge.id, bridge.level]])
|
1295
|
-
}
|
1296
|
-
}
|
1297
|
-
if (bridge.words) {
|
1298
|
-
for (let def of bridge.words) {
|
1299
|
-
if (typeof def == 'string') {
|
1300
|
-
this.addWordInternal(def, {"id": bridge.id, "initial": `{ value: "${def}"}` })
|
1301
|
-
} else {
|
1302
|
-
const word = def.word
|
1303
|
-
def = { initial: JSON.stringify(def), id: bridge.id, word: undefined }
|
1304
|
-
this.addWordInternal(word, def)
|
1305
|
-
}
|
1306
|
-
}
|
1307
|
-
}
|
1308
|
-
if (bridge.generator) {
|
1309
|
-
this.config.generators.unshift(bridge.generator)
|
1310
|
-
}
|
1311
|
-
*/
|
1312
|
-
/* moved
|
1313
|
-
if (bridge.generators) {
|
1314
|
-
const generators = [...bridge.generators]
|
1315
|
-
generators.reverse()
|
1316
|
-
for (let generator of generators) {
|
1317
|
-
this.config.generators.unshift(generator)
|
1318
|
-
}
|
1319
|
-
}
|
1320
|
-
if (bridge.generatorp) {
|
1321
|
-
this.config.generators.unshift({
|
1322
|
-
where: bridge.generatorp.where || client.where(3),
|
1323
|
-
match: ({context}) => bridge.id == context.marker && context.paraphrase,
|
1324
|
-
apply: (args) => bridge.generatorp(args),
|
1325
|
-
})
|
1326
|
-
}
|
1327
|
-
if (bridge.generatorr) {
|
1328
|
-
this.config.generators.unshift({
|
1329
|
-
// TODO merge response and isResponse
|
1330
|
-
where: bridge.generatorr.where || client.where(3),
|
1331
|
-
match: ({context}) => bridge.id == context.marker && !context.paraphrase && (context.response || context.isResponse),
|
1332
|
-
apply: (args) => bridge.generatorr(args),
|
1333
|
-
})
|
1334
|
-
}
|
1335
|
-
if (bridge.evaluator) {
|
1336
|
-
this.config.semantics.unshift({
|
1337
|
-
where: bridge.evaluator.where || client.where(3),
|
1338
|
-
match: ({context}) => bridge.id == context.marker && context.evaluate,
|
1339
|
-
apply: (args) => bridge.evaluator(args),
|
1340
|
-
})
|
1341
|
-
}
|
1342
|
-
if (bridge.semantic) {
|
1343
|
-
this.config.semantics.unshift({
|
1344
|
-
where: bridge.semantic.where || client.where(3),
|
1345
|
-
match: ({context}) => bridge.id == context.marker,
|
1346
|
-
apply: (args) => bridge.semantic(args),
|
1347
|
-
})
|
1348
|
-
}
|
1349
|
-
*/
|
1350
|
-
}
|
1351
|
-
if (config.operators) {
|
1352
|
-
config.operators = config.operators.map((operator) => {
|
1353
|
-
if (typeof operator === 'string') {
|
1354
|
-
return { pattern: operator }
|
1355
|
-
} else {
|
1356
|
-
return operator
|
1357
|
-
}
|
1358
|
-
})
|
1359
|
-
}
|
1265
|
+
handleCalculatedProps(this, config)
|
1360
1266
|
}
|
1361
1267
|
this.hierarchy = new Digraph(this.config.hierarchy)
|
1362
1268
|
this.initConfig = _.cloneDeep(this.config)
|
1363
1269
|
this.configs.push(new KM({ config: this.config, getCounter: (name) => this.config.getCounter(name), uuid: this._uuid }))
|
1364
1270
|
|
1365
|
-
/*
|
1366
|
-
if (config) {
|
1367
|
-
this.configs.push(new KM({config, isSelf: true}))
|
1368
|
-
this.addInternal(Object.assign({}, config), false)
|
1369
|
-
} else {
|
1370
|
-
this.configs.push( new KM({config: this.config, isSelf: true}) )
|
1371
|
-
}
|
1372
|
-
*/
|
1373
|
-
|
1374
1271
|
this.setUUIDs()
|
1375
1272
|
this.initDefaults()
|
1376
1273
|
if (!this.config.objects.namespaced) {
|
@@ -2026,7 +1923,6 @@ class Config {
|
|
2026
1923
|
} else {
|
2027
1924
|
addInternals.unshift(config)
|
2028
1925
|
}
|
2029
|
-
// this.addInternal(config, true, false, false, true)
|
2030
1926
|
} else {
|
2031
1927
|
if (interleaved) {
|
2032
1928
|
addInternals.unshift(null)
|
@@ -2049,7 +1945,7 @@ class Config {
|
|
2049
1945
|
if (!interleaved) {
|
2050
1946
|
for (const config of addInternals) {
|
2051
1947
|
if (!reverseIt) {
|
2052
|
-
this.addInternal(config,
|
1948
|
+
this.addInternal(config, { includeNamespace: false, allowNameToBeNull: true })
|
2053
1949
|
} else {
|
2054
1950
|
this.addInternalR(config, true, false, false, true)
|
2055
1951
|
}
|
@@ -2201,7 +2097,7 @@ class Config {
|
|
2201
2097
|
|
2202
2098
|
this.applyNamespace(configPrime, km.namespace, km.uuid)
|
2203
2099
|
first = false
|
2204
|
-
this.addInternal(configPrime, false, true)
|
2100
|
+
this.addInternal(configPrime, { useOldVersion: false, skipObjects: true })
|
2205
2101
|
applyUUID(configPrime, km.uuid)
|
2206
2102
|
})
|
2207
2103
|
|
@@ -2491,7 +2387,7 @@ class Config {
|
|
2491
2387
|
}
|
2492
2388
|
|
2493
2389
|
// TODO get rid of useOldVersion arg
|
2494
|
-
addInternal (more, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false) {
|
2390
|
+
addInternal (more, { useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
|
2495
2391
|
if (more instanceof Config) {
|
2496
2392
|
more.initialize({ force: false })
|
2497
2393
|
if (useOldVersion) {
|
@@ -2501,6 +2397,10 @@ class Config {
|
|
2501
2397
|
more = _.cloneDeep(more.initConfig)
|
2502
2398
|
}
|
2503
2399
|
}
|
2400
|
+
if (hcps) {
|
2401
|
+
handleCalculatedProps(this, more)
|
2402
|
+
applyUUID(more, this._uuid)
|
2403
|
+
}
|
2504
2404
|
for (const key of Object.keys(more)) {
|
2505
2405
|
const value = more[key]
|
2506
2406
|
// TODO remove name and description on the config bag
|
package/src/helpers.js
CHANGED
@@ -44,10 +44,23 @@ const appendNoDups = (l1, l2) => {
|
|
44
44
|
}
|
45
45
|
|
46
46
|
const safeEquals = (v1, v2) => {
|
47
|
-
if (
|
47
|
+
if (typeof v1 !== typeof v2) {
|
48
48
|
return false
|
49
49
|
}
|
50
|
-
|
50
|
+
|
51
|
+
const type = typeof v1
|
52
|
+
if (type == 'number' || type == 'string') {
|
53
|
+
return v1 == v2
|
54
|
+
} else if (type == 'function') {
|
55
|
+
return v1.toString() == v2.toString()
|
56
|
+
} else {
|
57
|
+
for (let key in v1) {
|
58
|
+
if (!safeEquals(v1[key], v2[key])) {
|
59
|
+
return false
|
60
|
+
}
|
61
|
+
}
|
62
|
+
return true
|
63
|
+
}
|
51
64
|
}
|
52
65
|
|
53
66
|
/*
|
@@ -238,7 +251,66 @@ const mapInPlace = (list, fn) => {
|
|
238
251
|
}
|
239
252
|
}
|
240
253
|
|
254
|
+
const updateQueries = (queryOrConfig) => {
|
255
|
+
if (typeof queryOrConfig == 'string' || queryOrConfig.query) {
|
256
|
+
return queryOrConfig
|
257
|
+
} else {
|
258
|
+
const config = queryOrConfig
|
259
|
+
return functionsToStrings(config)
|
260
|
+
}
|
261
|
+
}
|
262
|
+
|
263
|
+
const functionsToStrings = (config) => {
|
264
|
+
config = {...config}
|
265
|
+
const mapGenerator = (generator) => {
|
266
|
+
if (generator.apply) {
|
267
|
+
return { ...generator, match: generator.match.toString(), apply: generator.apply.toString() }
|
268
|
+
} else {
|
269
|
+
return [ generator[0].toString(), generator[1].toString() ]
|
270
|
+
}
|
271
|
+
}
|
272
|
+
if (config.generators) {
|
273
|
+
config.generators = config.generators.map( mapGenerator )
|
274
|
+
}
|
275
|
+
if (config.semantics) {
|
276
|
+
config.semantics = config.semantics.map( (semantic) => {
|
277
|
+
if (semantic.apply) {
|
278
|
+
return { ...semantic, match: semantic.match.toString(), apply: semantic.apply.toString() }
|
279
|
+
} else {
|
280
|
+
return [ semantic[0].toString(), semantic[1].toString() ]
|
281
|
+
}
|
282
|
+
})
|
283
|
+
}
|
284
|
+
if (config.bridges) {
|
285
|
+
config.bridges = config.bridges.map( (bridge) => {
|
286
|
+
bridge = {...bridge}
|
287
|
+
if (bridge.generator) {
|
288
|
+
bridge.generator = bridge.generator.toString()
|
289
|
+
}
|
290
|
+
if (bridge.generators) {
|
291
|
+
bridge.generators = bridge.generators.map( mapGenerator )
|
292
|
+
}
|
293
|
+
if (bridge.generatorp) {
|
294
|
+
bridge.generatorp = bridge.generatorp.toString()
|
295
|
+
}
|
296
|
+
if (bridge.generatorr) {
|
297
|
+
bridge.generatorr = bridge.generatorr.toString()
|
298
|
+
}
|
299
|
+
if (bridge.semantic) {
|
300
|
+
bridge.semantic = bridge.semantic.toString()
|
301
|
+
}
|
302
|
+
if (bridge.evaluator) {
|
303
|
+
bridge.evaluator = bridge.evaluator.toString()
|
304
|
+
}
|
305
|
+
return bridge
|
306
|
+
})
|
307
|
+
}
|
308
|
+
return config
|
309
|
+
}
|
310
|
+
|
241
311
|
module.exports = {
|
312
|
+
functionsToStrings,
|
313
|
+
updateQueries,
|
242
314
|
mapInPlace,
|
243
315
|
validProps,
|
244
316
|
args,
|