theprogrammablemind 7.5.4-beta.4 → 7.5.4-beta.5
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 +2 -2
- package/package.json +1 -1
- package/src/config.js +6 -6
- 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
|
|
@@ -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
|
|
@@ -646,12 +645,13 @@ class Config {
|
|
646
645
|
}
|
647
646
|
const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map( toCanonical )
|
648
647
|
const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map( toCanonical )
|
649
|
-
const sameFragments =
|
650
|
-
const sameQueries =
|
648
|
+
const sameFragments = helpers.safeEquals(templateFragments, instanceFragments)
|
649
|
+
const sameQueries = helpers.safeEquals((template.queries || []).map(helpers.updateQueries), (instance.queries || []))
|
651
650
|
return !(instance && sameQueries && sameFragments)
|
652
651
|
}
|
653
652
|
|
654
653
|
load (template, instance, options = { rebuild: false } ) {
|
654
|
+
this.template = template
|
655
655
|
this.logs.push(`loading template for ${this.name}`)
|
656
656
|
if (instance && instance.associations && !options.rebuild) {
|
657
657
|
this.addAssociations(instance.associations)
|
@@ -713,7 +713,7 @@ class Config {
|
|
713
713
|
}
|
714
714
|
}
|
715
715
|
if (global.entodictonDebugAssociation) {
|
716
|
-
if (
|
716
|
+
if (helpers.safeEquals(global.entodictonDebugAssociation, association)) {
|
717
717
|
debugger; // debug association hit
|
718
718
|
}
|
719
719
|
}
|
@@ -748,7 +748,7 @@ class Config {
|
|
748
748
|
throw `addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`
|
749
749
|
}
|
750
750
|
if (global.entodictonDebugHierarchy) {
|
751
|
-
if (
|
751
|
+
if ((helpers.safeEquals.entodictonDebugHierarchy, [child, parent])) {
|
752
752
|
debugger; // debug hierarchy hit
|
753
753
|
}
|
754
754
|
}
|
@@ -766,7 +766,7 @@ class Config {
|
|
766
766
|
}
|
767
767
|
|
768
768
|
if (global.entodictonDebugHierarchy) {
|
769
|
-
if (
|
769
|
+
if (helpers.safeEquals(global.entodictonDebugHierarchy, [child, parent])) {
|
770
770
|
debugger; // debug hierarchy hit
|
771
771
|
}
|
772
772
|
}
|
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,
|