theprogrammablemind 7.5.8-beta.9 → 7.5.8-beta.90
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 +367 -280
- package/index.js +1 -0
- package/lines.js +2 -2
- package/package.json +2 -1
- package/src/config.js +559 -262
- package/src/flatten.js +9 -1
- package/src/helpers.js +16 -5
- package/src/project.js +81 -0
- package/src/semantics.js +6 -1
package/src/config.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// lookup = (name) => returns <config>
|
2
2
|
const { Semantics, normalizeGenerator } = require('./semantics')
|
3
3
|
const { Generators } = require('./generators')
|
4
|
-
|
4
|
+
const { v4 : uuidv4 } = require('uuid');
|
5
5
|
const client = require('../client')
|
6
6
|
const DigraphInternal = require('./digraph_internal')
|
7
7
|
const helpers = require('./helpers')
|
@@ -22,7 +22,184 @@ const indent = (string, indent) => {
|
|
22
22
|
return string.replace(/^/gm, ' '.repeat(indent));
|
23
23
|
}
|
24
24
|
|
25
|
-
const
|
25
|
+
const config_toServer = (config) => {
|
26
|
+
}
|
27
|
+
|
28
|
+
const debugPriority = (priority) => {
|
29
|
+
if (global.entodictonDebugPriority) {
|
30
|
+
if (helpers.safeEquals(entodictonDebugPriority, priority)) {
|
31
|
+
debugger; // debug hierarchy hit
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
const debugAssociation = (association) => {
|
37
|
+
if (global.entodictonDebugAssociation) {
|
38
|
+
if (helpers.safeEquals(global.entodictonDebugAssociation, association)) {
|
39
|
+
debugger; // debug association hit
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
const debugHierarchy = (pair) => {
|
45
|
+
if (global.entodictonDebugHierarchy) {
|
46
|
+
if (helpers.safeEquals(global.entodictonDebugHierarchy, pair)) {
|
47
|
+
debugger; // debug hierarchy hit
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
const debugBridge = (bridge) => {
|
53
|
+
if (global.entodictonDebugBridge) {
|
54
|
+
if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
|
55
|
+
debugger; // debug hierarchy hit
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
const debugOperator = (operator) => {
|
61
|
+
if (global.entodictonDebugOperator) {
|
62
|
+
if ((operator.pattern || operator) === global.entodictonDebugOperator) {
|
63
|
+
debugger; // debug operator hit
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
const debugConfigProps = (config) => {
|
69
|
+
if (!config) {
|
70
|
+
return
|
71
|
+
}
|
72
|
+
const checkProps = [
|
73
|
+
{ property: 'priorities', check: (v) => debugPriority(v) },
|
74
|
+
{ property: 'association', check: (v) => debugAssociation(v) },
|
75
|
+
{ property: 'hierarchy', check: (v) => debugHierarchy(v) },
|
76
|
+
{ property: 'operators', check: (v) => debugOperator(v) },
|
77
|
+
{ property: 'bridges', check: (v) => debugBridge(v) },
|
78
|
+
]
|
79
|
+
for (const { property, check } of checkProps) {
|
80
|
+
if (config[property]) {
|
81
|
+
for (const value of config[property]) {
|
82
|
+
check(value)
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
const validConfigProps = (config) => {
|
89
|
+
const valid = [
|
90
|
+
'hierarchy',
|
91
|
+
'objects',
|
92
|
+
'bridges',
|
93
|
+
'operators',
|
94
|
+
'words',
|
95
|
+
'priorities',
|
96
|
+
'associations',
|
97
|
+
'name',
|
98
|
+
'version',
|
99
|
+
'generatorp',
|
100
|
+
'generators',
|
101
|
+
'semantics',
|
102
|
+
'where',
|
103
|
+
'floaters',
|
104
|
+
'debug',
|
105
|
+
|
106
|
+
// TODO Fix these from the test app
|
107
|
+
'implicits',
|
108
|
+
'convolution',
|
109
|
+
'expected_generated',
|
110
|
+
'expected_results',
|
111
|
+
'skipSemantics',
|
112
|
+
'description',
|
113
|
+
'contexts',
|
114
|
+
'utterances',
|
115
|
+
'flatten',
|
116
|
+
|
117
|
+
'namespaces',
|
118
|
+
'eqClasses',
|
119
|
+
]
|
120
|
+
helpers.validProps(valid, config, 'config')
|
121
|
+
}
|
122
|
+
|
123
|
+
const setupInitializerFNArgs = (config, args) => {
|
124
|
+
const aw = (word, def) => config.addWord(word, def, args.uuid)
|
125
|
+
const ag = (generator) => config.addGenerator(generator, args.uuid, config.name)
|
126
|
+
const km = (name) => config.getConfig(name)
|
127
|
+
const apis = (name) => config.getConfig(name).api
|
128
|
+
|
129
|
+
return {
|
130
|
+
...args,
|
131
|
+
addWord: aw,
|
132
|
+
addGenerator: ag,
|
133
|
+
config: config.getPseudoConfig(args.uuid, args.currentConfig),
|
134
|
+
km,
|
135
|
+
baseConfig: config,
|
136
|
+
apis,
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
const operatorKey_valid = (key) => {
|
141
|
+
if (
|
142
|
+
!_.isArray(key) ||
|
143
|
+
key.length != 2 ||
|
144
|
+
!_.isString(key[0]) ||
|
145
|
+
!_.isInteger(key[1]) ||
|
146
|
+
key[1] < 0
|
147
|
+
) {
|
148
|
+
|
149
|
+
let details = ''
|
150
|
+
if (!_.isArray(key)) {
|
151
|
+
details = "Expected an array."
|
152
|
+
} else if (key.length != 2) {
|
153
|
+
details = "Expected an array of length two."
|
154
|
+
} else if (!_.isString(key[0])) {
|
155
|
+
details = "Expected element zero to be a string that is an operator id."
|
156
|
+
} else if (!_.isInteger(key[1])) {
|
157
|
+
details = "Expected element one to be a number that is an operator level."
|
158
|
+
} else if (key[1] < 0) {
|
159
|
+
details = "Expected element one to be a number that is an operator level which is greater than zero."
|
160
|
+
}
|
161
|
+
throw new Error(`${JSON.stringify(key)} is not a valid operator key. Values are of the form [<operatorId>, <operatorLevel>]. ${details}`)
|
162
|
+
}
|
163
|
+
}
|
164
|
+
|
165
|
+
const elist = (list, check, prefix) => {
|
166
|
+
for ([index, element] of list.entries()) {
|
167
|
+
try {
|
168
|
+
check(element)
|
169
|
+
} catch( e ) {
|
170
|
+
throw new Error(prefix(index, e))
|
171
|
+
}
|
172
|
+
}
|
173
|
+
}
|
174
|
+
const priorities_valid = (cps) => {
|
175
|
+
elist(cps, (cp) => priority_valid(cp), (index, e) => `priorities has an invalid priority at position ${index}. ${e}`)
|
176
|
+
}
|
177
|
+
|
178
|
+
const priority_valid = (cp) => {
|
179
|
+
if (!cp.context) {
|
180
|
+
throw new Error(`The priority ${JSON.stringify(cp)} is missing the "context" property. That is a list of the operator keys that are to be prioritized differently.`)
|
181
|
+
}
|
182
|
+
if (!_.isArray(cp.context)) {
|
183
|
+
throw new Error(`The priority ${JSON.stringify(cp)} has an invalid "context" value. That is a list of the operator keys that are to be prioritized differently.`)
|
184
|
+
}
|
185
|
+
elist(cp.context, (element) => operatorKey_valid(element), (index, e) => `The priority ${JSON.stringify(cp)} has an invalid operator key at position ${index}. ${e}`)
|
186
|
+
if (!_.isArray(cp.choose)) {
|
187
|
+
throw new Error(`The priority ${JSON.stringify(cp)} has an invalid "choose" value. The value should be a list of the operators in the context to consider for prioritization.`)
|
188
|
+
}
|
189
|
+
elist(cp.choose,
|
190
|
+
(element) => {
|
191
|
+
if (!element && element !== 0) {
|
192
|
+
throw new Error(`The value should be an index into the "context" property of the operator that is to be considered for prioritization.`)
|
193
|
+
}
|
194
|
+
if (!_.isInteger(element) || element < 0 || element >= cp.context.length) {
|
195
|
+
throw new Error(`The value should be an index into the "context" property of the operator that is to be considered for prioritization. Valid values are between 0 and ${cp.context.length-1}.`)
|
196
|
+
}
|
197
|
+
},
|
198
|
+
(index, e) => `The choose property in the priority ${JSON.stringify(cp)} has an invalid index at position ${index}. ${e}`
|
199
|
+
)
|
200
|
+
}
|
201
|
+
|
202
|
+
const handleBridgeProps = (config, bridge, addFirst) => {
|
26
203
|
ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
|
27
204
|
() => {
|
28
205
|
if (!bridge.bridge) {
|
@@ -51,7 +228,7 @@ const handleBridgeProps = (config, bridge) => {
|
|
51
228
|
if (typeof after == 'string') {
|
52
229
|
after = [after, 0]
|
53
230
|
}
|
54
|
-
config.
|
231
|
+
config.addPriority({ context: [[bridge.id, bridge.level], after], choose: [0] })
|
55
232
|
}
|
56
233
|
}
|
57
234
|
if (bridge.after) {
|
@@ -59,7 +236,7 @@ const handleBridgeProps = (config, bridge) => {
|
|
59
236
|
if (typeof before == 'string') {
|
60
237
|
before = [before, 0]
|
61
238
|
}
|
62
|
-
config.
|
239
|
+
config.addPriority({ context: [before, [bridge.id, bridge.level]], choose: [0] })
|
63
240
|
}
|
64
241
|
}
|
65
242
|
if (bridge.words) {
|
@@ -68,19 +245,29 @@ const handleBridgeProps = (config, bridge) => {
|
|
68
245
|
config.addWordInternal(def, {"id": bridge.id, "initial": `{ value: "${def}"}` })
|
69
246
|
} else {
|
70
247
|
const word = def.word
|
71
|
-
def = { initial: JSON.stringify(def), id: bridge.id, word
|
248
|
+
def = { initial: JSON.stringify(def), id: bridge.id, word }
|
72
249
|
config.addWordInternal(word, def)
|
73
250
|
}
|
74
251
|
}
|
75
252
|
}
|
253
|
+
/*
|
76
254
|
if (bridge.generator) {
|
77
|
-
|
255
|
+
if (addFirst) {
|
256
|
+
config.config.generators.unshift(bridge.generator)
|
257
|
+
} else {
|
258
|
+
config.config.generators.push(bridge.generator)
|
259
|
+
}
|
78
260
|
}
|
261
|
+
*/
|
79
262
|
if (bridge.generators) {
|
80
263
|
const generators = [...bridge.generators]
|
81
264
|
generators.reverse()
|
82
265
|
for (let generator of generators) {
|
83
|
-
|
266
|
+
if (addFirst) {
|
267
|
+
config.config.generators.unshift(generator)
|
268
|
+
} else {
|
269
|
+
config.config.generators.push(generator)
|
270
|
+
}
|
84
271
|
}
|
85
272
|
}
|
86
273
|
if (bridge.generatorpr) {
|
@@ -91,66 +278,76 @@ const handleBridgeProps = (config, bridge) => {
|
|
91
278
|
const match = bridge.generatorp.match || (() => true)
|
92
279
|
const apply = typeof bridge.generatorp == 'function' ? bridge.generatorp : bridge.generatorp.apply || bridge.generatorp
|
93
280
|
const level = bridge.generatorp.level >= 0 ? bridge.generatorp.level : bridge.level + 1
|
94
|
-
|
281
|
+
|
282
|
+
const generator = {
|
95
283
|
where: bridge.generatorp.where || bridge.where || client.where(4),
|
96
284
|
match: (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && match(args),
|
97
285
|
apply: (args) => apply(args),
|
98
286
|
applyWrapped: apply,
|
99
287
|
property: 'generatorp',
|
100
|
-
}
|
288
|
+
}
|
289
|
+
if (addFirst) {
|
290
|
+
config.config.generators.unshift(generator)
|
291
|
+
} else {
|
292
|
+
config.config.generators.push(generator)
|
293
|
+
}
|
294
|
+
|
101
295
|
}
|
102
296
|
if (bridge.generatorr) {
|
103
297
|
const match = bridge.generatorr.match || (() => true)
|
104
298
|
const apply = typeof bridge.generatorr == 'function' ? bridge.generatorr : bridge.generatorr.apply || bridge.generatorr
|
105
299
|
const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
|
106
|
-
|
300
|
+
const generator = {
|
107
301
|
where: bridge.generatorr.where || bridge.where || client.where(4),
|
108
302
|
match: (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && match(args),
|
109
303
|
apply: (args) => apply(args),
|
110
304
|
applyWrapped: apply,
|
111
305
|
property: 'generatorr',
|
112
|
-
}
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
where: bridge.generatorr.where || bridge.where || client.where(3),
|
119
|
-
match: ({context}) => bridge.id == context.marker && !context.paraphrase && (context.response || context.isResponse),
|
120
|
-
apply: (args) => bridge.generatorr(args),
|
121
|
-
applyWrapped: bridge.generatorr,
|
122
|
-
property: 'generatorr',
|
123
|
-
})
|
306
|
+
}
|
307
|
+
if (addFirst) {
|
308
|
+
config.config.generators.unshift(generator)
|
309
|
+
} else {
|
310
|
+
config.config.generators.push(generator)
|
311
|
+
}
|
124
312
|
}
|
125
|
-
*/
|
126
313
|
if (bridge.evaluator) {
|
127
|
-
|
314
|
+
const semantic = {
|
128
315
|
where: bridge.evaluator.where || bridge.where || client.where(3),
|
129
316
|
match: ({context}) => bridge.id == context.marker && context.evaluate,
|
130
317
|
apply: (args) => bridge.evaluator(args),
|
131
318
|
applyWrapped: bridge.evaluator,
|
132
319
|
property: 'evaluator',
|
133
|
-
}
|
320
|
+
}
|
321
|
+
if (addFirst) {
|
322
|
+
config.config.semantics.unshift(semantic)
|
323
|
+
} else {
|
324
|
+
config.config.semantics.push(semantic)
|
325
|
+
}
|
134
326
|
}
|
135
327
|
if (bridge.semantic) {
|
136
|
-
|
328
|
+
const semantic = {
|
137
329
|
where: bridge.semantic.where || bridge.where || client.where(3),
|
138
330
|
match: ({context}) => bridge.id == context.marker,
|
139
331
|
apply: (args) => bridge.semantic(args),
|
140
332
|
applyWrapped: bridge.semantic,
|
141
333
|
property: 'semantic',
|
142
|
-
}
|
334
|
+
}
|
335
|
+
if (addFirst) {
|
336
|
+
config.config.semantics.unshift(semantic)
|
337
|
+
} else {
|
338
|
+
config.config.semantics.push(semantic)
|
339
|
+
}
|
143
340
|
}
|
144
341
|
}
|
145
342
|
)
|
146
343
|
}
|
147
344
|
|
148
|
-
const handleCalculatedProps = (baseConfig, moreConfig) => {
|
149
|
-
for (let bridge of moreConfig.bridges) {
|
345
|
+
const handleCalculatedProps = (baseConfig, moreConfig, addFirst) => {
|
346
|
+
for (let bridge of (moreConfig.bridges || [])) {
|
150
347
|
const valid = [ 'after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
|
151
|
-
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where' ]
|
348
|
+
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid' ]
|
152
349
|
helpers.validProps(valid, bridge, 'bridge')
|
153
|
-
handleBridgeProps(baseConfig, bridge)
|
350
|
+
handleBridgeProps(baseConfig, bridge, addFirst)
|
154
351
|
}
|
155
352
|
if (moreConfig.operators) {
|
156
353
|
moreConfig.operators = moreConfig.operators.map((operator) => {
|
@@ -167,10 +364,19 @@ if (runtime.process.env.DEBUG_HIERARCHY) {
|
|
167
364
|
global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
|
168
365
|
}
|
169
366
|
|
367
|
+
|
368
|
+
// i keep randomly doing one of the other so I will just make both work the same way
|
369
|
+
if (runtime.process.env.DEBUG_PRIORITIES) {
|
370
|
+
global.entodictonDebugPriority = JSON.parse(runtime.process.env.DEBUG_PRIORITIES)
|
371
|
+
}
|
170
372
|
if (runtime.process.env.DEBUG_PRIORITY) {
|
171
373
|
global.entodictonDebugPriority = JSON.parse(runtime.process.env.DEBUG_PRIORITY)
|
172
374
|
}
|
173
375
|
|
376
|
+
if (runtime.process.env.DEBUG_CONTEXTUAL_PRIORITY) {
|
377
|
+
global.entodictonDebugContextualPriority = JSON.parse(runtime.process.env.DEBUG_CONTEXTUAL_PRIORITY)
|
378
|
+
}
|
379
|
+
|
174
380
|
if (runtime.process.env.DEBUG_ASSOCIATION) {
|
175
381
|
global.entodictonDebugAssociation = JSON.parse(runtime.process.env.DEBUG_ASSOCIATION)
|
176
382
|
}
|
@@ -180,6 +386,7 @@ if (runtime.process.env.DEBUG_BRIDGE) {
|
|
180
386
|
global.entodictonDebugBridge = runtime.process.env.DEBUG_BRIDGE.split('/')
|
181
387
|
if (global.entodictonDebugBridge.length !== 2) {
|
182
388
|
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"');
|
389
|
+
process.exit(-1)
|
183
390
|
}
|
184
391
|
global.entodictonDebugBridge[1] = parseInt(global.entodictonDebugBridge[1])
|
185
392
|
}
|
@@ -252,6 +459,14 @@ const normalizeConfig = (config) => {
|
|
252
459
|
}
|
253
460
|
}
|
254
461
|
}
|
462
|
+
|
463
|
+
if (config.semantics) {
|
464
|
+
for (let semantic of config.semantics) {
|
465
|
+
if (semantic.oneShot) {
|
466
|
+
semantic.id = uuid()
|
467
|
+
}
|
468
|
+
}
|
469
|
+
}
|
255
470
|
}
|
256
471
|
}
|
257
472
|
|
@@ -459,8 +674,8 @@ const multiApiImpl = (initializer) => {
|
|
459
674
|
initializer(config, api)
|
460
675
|
const name = api.getName()
|
461
676
|
multiApi.apis[name] = api
|
462
|
-
api.objects = config.get('objects')
|
463
|
-
api.config = () => config
|
677
|
+
// api.objects = config.get('objects')
|
678
|
+
// api.config = () => config
|
464
679
|
multiApi.current = name
|
465
680
|
},
|
466
681
|
|
@@ -471,11 +686,13 @@ const multiApiImpl = (initializer) => {
|
|
471
686
|
}
|
472
687
|
},
|
473
688
|
|
689
|
+
/*
|
474
690
|
set objects (value) {
|
475
691
|
for (const key in Object.keys(this.apis)) {
|
476
692
|
this.apis[key].objects = value
|
477
693
|
}
|
478
694
|
},
|
695
|
+
*/
|
479
696
|
|
480
697
|
// "product1": apiInstance(testData1),
|
481
698
|
apis: {
|
@@ -489,6 +706,47 @@ const multiApiImpl = (initializer) => {
|
|
489
706
|
|
490
707
|
class Config {
|
491
708
|
|
709
|
+
toServer (config) {
|
710
|
+
return config_toServer(config)
|
711
|
+
}
|
712
|
+
|
713
|
+
base () {
|
714
|
+
const base = new Config()
|
715
|
+
for (let km of this.configs.reverse()) {
|
716
|
+
if (km.isSelf) {
|
717
|
+
continue
|
718
|
+
}
|
719
|
+
base.add(km.config)
|
720
|
+
}
|
721
|
+
return base
|
722
|
+
}
|
723
|
+
|
724
|
+
getPseudoConfig (uuid, config) {
|
725
|
+
return {
|
726
|
+
description: "this is a pseudo config that has limited functionality due to being available in the initializer function context",
|
727
|
+
addAssociation: (...args) => this.addAssociation(...args),
|
728
|
+
addAssociations: (...args) => this.addAssociations(...args),
|
729
|
+
addBridge: (...args) => this.addBridge(...args, uuid),
|
730
|
+
addGenerator: (...args) => this.addGenerator(...args, uuid, config.name),
|
731
|
+
addHierarchy: (...args) => this.addHierarchy(...args),
|
732
|
+
addOperator: (...args) => this.addOperator(...args, uuid),
|
733
|
+
addPriority: (...args) => this.addPriority(...args),
|
734
|
+
addPriorities: (...args) => this.addPriorities(...args),
|
735
|
+
addSemantic: (...args) => this.addSemantic(...args, uuid, config.name),
|
736
|
+
removeSemantic: (...args) => this.removeSemantic(...args, uuid, config.name),
|
737
|
+
addWord: (...args) => this.addWord(...args, uuid),
|
738
|
+
|
739
|
+
getHierarchy: (...args) => this.config.hierarchy,
|
740
|
+
getBridges: (...args) => this.config.bridges,
|
741
|
+
|
742
|
+
addArgs: (...args) => this.addArgs(...args),
|
743
|
+
getBridge: (...args) => this.getBridge(...args),
|
744
|
+
fragment: (...args) => this.fragment(...args),
|
745
|
+
exists: (...args) => this.exists(...args),
|
746
|
+
addAPI: (...args) => this.addAPI(...args),
|
747
|
+
}
|
748
|
+
}
|
749
|
+
|
492
750
|
inDevelopmentMode (call) {
|
493
751
|
config.developmentModeOn += 1
|
494
752
|
try {
|
@@ -527,9 +785,6 @@ class Config {
|
|
527
785
|
}
|
528
786
|
|
529
787
|
setTestConfig(testConfig) {
|
530
|
-
if (this.name == 'ui') {
|
531
|
-
console.log('ui setting testConfig')
|
532
|
-
}
|
533
788
|
this.testConfig = testConfig
|
534
789
|
}
|
535
790
|
|
@@ -709,7 +964,8 @@ class Config {
|
|
709
964
|
}
|
710
965
|
}
|
711
966
|
|
712
|
-
|
967
|
+
// { rebuild: false, isModule: false }
|
968
|
+
needsRebuild(template, instance, options) {
|
713
969
|
if (options.rebuild) {
|
714
970
|
return true
|
715
971
|
}
|
@@ -723,7 +979,83 @@ class Config {
|
|
723
979
|
const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map( toCanonical )
|
724
980
|
const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map( toCanonical )
|
725
981
|
const sameFragments = helpers.safeEquals(templateFragments, instanceFragments)
|
726
|
-
const
|
982
|
+
const toCanonicalQuery = (queryOrConfig) => {
|
983
|
+
if (typeof queryOrConfig == 'string') {
|
984
|
+
const query = queryOrConfig
|
985
|
+
return query
|
986
|
+
} else {
|
987
|
+
const config = { ...queryOrConfig }
|
988
|
+
delete config.where
|
989
|
+
if (options.isModule) {
|
990
|
+
// things like webpack rewrite the functions if there are constants so this compare does not work
|
991
|
+
delete config.generators;
|
992
|
+
delete config.semantics;
|
993
|
+
(config.bridges || []).forEach((bridge) => {
|
994
|
+
delete bridge.generatorp
|
995
|
+
delete bridge.generatorr
|
996
|
+
delete bridge.generatorpr
|
997
|
+
delete bridge.evaluator
|
998
|
+
delete bridge.semantic
|
999
|
+
});
|
1000
|
+
} else {
|
1001
|
+
config.generators = (config.generators || []).map((generator) => {
|
1002
|
+
generator = {...generator}
|
1003
|
+
delete generator.where
|
1004
|
+
generator.match = generator.match.toString()
|
1005
|
+
generator.apply = generator.apply.toString()
|
1006
|
+
return generator
|
1007
|
+
})
|
1008
|
+
config.semantics = (config.semantics || []).map((semantic) => {
|
1009
|
+
semantic = {...semantic}
|
1010
|
+
delete semantic.where
|
1011
|
+
semantic.match = semantic.match.toString()
|
1012
|
+
semantic.apply = semantic.apply.toString()
|
1013
|
+
return semantic
|
1014
|
+
})
|
1015
|
+
config.bridges = (config.bridges || []).map((bridge) => {
|
1016
|
+
bridge = {...bridge}
|
1017
|
+
delete bridge.where
|
1018
|
+
if (bridge.generatorp) {
|
1019
|
+
bridge.generatorp = bridge.generatorp.toString()
|
1020
|
+
}
|
1021
|
+
if (bridge.generatorr) {
|
1022
|
+
bridge.generatorr = bridge.generatorr.toString()
|
1023
|
+
}
|
1024
|
+
if (bridge.generatorpr) {
|
1025
|
+
bridge.generatorpr = bridge.generatorpr.toString()
|
1026
|
+
}
|
1027
|
+
if (bridge.evaluator) {
|
1028
|
+
bridge.evaluator = bridge.evaluator.toString()
|
1029
|
+
}
|
1030
|
+
if (bridge.semantic) {
|
1031
|
+
bridge.semantic = bridge.semantic.toString()
|
1032
|
+
}
|
1033
|
+
return bridge
|
1034
|
+
})
|
1035
|
+
}
|
1036
|
+
return config
|
1037
|
+
}
|
1038
|
+
}
|
1039
|
+
const toCanonicalQueries = (elements) => {
|
1040
|
+
return elements.map( toCanonicalQuery )
|
1041
|
+
}
|
1042
|
+
|
1043
|
+
const sameQueries = helpers.safeEquals(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), toCanonicalQueries(instance.queries || []))
|
1044
|
+
|
1045
|
+
const debug = false
|
1046
|
+
if (debug) {
|
1047
|
+
if (!sameQueries) {
|
1048
|
+
debugger
|
1049
|
+
debugger
|
1050
|
+
}
|
1051
|
+
console.log("instance", instance)
|
1052
|
+
console.log("sameQueries", sameQueries)
|
1053
|
+
console.log("sameFragments", sameFragments)
|
1054
|
+
console.log("templateFragments", templateFragments)
|
1055
|
+
console.log("instanceFragments", instanceFragments)
|
1056
|
+
console.log('template.queries', toCanonicalQueries(template.queries || []).map(helpers.updateQueries))
|
1057
|
+
console.log("instance.queries", toCanonicalQueries(instance.queries || []))
|
1058
|
+
}
|
727
1059
|
return !(instance && sameQueries && sameFragments)
|
728
1060
|
}
|
729
1061
|
|
@@ -739,18 +1071,21 @@ class Config {
|
|
739
1071
|
}
|
740
1072
|
}
|
741
1073
|
|
1074
|
+
toData (data) {
|
1075
|
+
Object.assign(data, this.config)
|
1076
|
+
config_toServer(data)
|
1077
|
+
}
|
1078
|
+
|
1079
|
+
// loadTemplate
|
742
1080
|
load (template, instance, options = { rebuild: false } ) {
|
743
1081
|
this.validifyTemplate(template)
|
744
1082
|
instance.template = template
|
745
1083
|
this.logs.push(`loading template for ${this.name}`)
|
746
|
-
if (instance && instance.associations && !options.rebuild) {
|
747
|
-
this.addAssociations(instance.associations)
|
748
|
-
}
|
749
1084
|
if (options.rebuild) {
|
750
1085
|
// TODO fix beforeQuery
|
751
1086
|
template = { fragments: [], queries: [], ...template }
|
752
1087
|
template.fragments = template.fragments.concat(this.dynamicFragments)
|
753
|
-
client.
|
1088
|
+
client.rebuildTemplate({ config: this, target: this.name, beforeQuery: () => {}, template, ...options })
|
754
1089
|
} else {
|
755
1090
|
// no change
|
756
1091
|
// this.initInstances.push({ ...instance, name: config.name })
|
@@ -768,7 +1103,7 @@ class Config {
|
|
768
1103
|
instance.name = this.name
|
769
1104
|
this.initInstances.push(instance)
|
770
1105
|
this.instances.push(instance)
|
771
|
-
client.
|
1106
|
+
client.loadInstance(this, instance)
|
772
1107
|
}
|
773
1108
|
}
|
774
1109
|
}
|
@@ -788,13 +1123,15 @@ class Config {
|
|
788
1123
|
}
|
789
1124
|
}
|
790
1125
|
|
791
|
-
|
792
1126
|
addAssociations (associations) {
|
793
1127
|
for (let association of associations) {
|
794
1128
|
this.addAssociation(association)
|
795
1129
|
}
|
796
1130
|
}
|
797
1131
|
|
1132
|
+
debugConfig() {
|
1133
|
+
}
|
1134
|
+
|
798
1135
|
addAssociation (association) {
|
799
1136
|
if (!this.config.associations) {
|
800
1137
|
this.config.associations = {
|
@@ -802,27 +1139,28 @@ class Config {
|
|
802
1139
|
positive: []
|
803
1140
|
}
|
804
1141
|
}
|
805
|
-
|
806
|
-
if (helpers.safeEquals(global.entodictonDebugAssociation, association)) {
|
807
|
-
debugger; // debug association hit
|
808
|
-
}
|
809
|
-
}
|
1142
|
+
debugAssociation(association)
|
810
1143
|
this.config.associations.positive.push(association)
|
811
1144
|
this._delta.json.associations.push({ action: 'add', association })
|
812
1145
|
}
|
813
1146
|
|
814
1147
|
// TODO add more error checking to these like addHierarchy has
|
815
|
-
|
1148
|
+
// TODO change name from priorities to priority
|
1149
|
+
// [ context: <list of [id, level]>, choose: [<indexes of prioritized operator>], [ordered: [true|false]] ]
|
1150
|
+
addPriority (priority) {
|
816
1151
|
if (!this.config.priorities) {
|
817
1152
|
this.config.priorities = []
|
818
1153
|
}
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
1154
|
+
debugPriority(priority)
|
1155
|
+
priority_valid(priority)
|
1156
|
+
this.config.priorities.push(priority)
|
1157
|
+
this._delta.json.priorities.push({ action: 'add', priority })
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
addPriorities (priorities) {
|
1161
|
+
for (let priority of priorities) {
|
1162
|
+
this.addPriority(priority)
|
823
1163
|
}
|
824
|
-
this.config.priorities.push(priorities)
|
825
|
-
this._delta.json.priorities.push({ action: 'add', priorities })
|
826
1164
|
}
|
827
1165
|
|
828
1166
|
addHierarchy (child, parent) {
|
@@ -842,11 +1180,7 @@ class Config {
|
|
842
1180
|
if (typeof parent !== 'string') {
|
843
1181
|
throw new Error(`addHierarchy expected parent property to be a string. got ${JSON.stringify(parent)}`)
|
844
1182
|
}
|
845
|
-
|
846
|
-
if (helpers.safeEquals(entodictonDebugHierarchy, [child, parent])) {
|
847
|
-
debugger; // debug hierarchy hit
|
848
|
-
}
|
849
|
-
}
|
1183
|
+
debugHierarchy([child, parent])
|
850
1184
|
this.config.hierarchy.push(edge)
|
851
1185
|
// TODO greg11 this.hierarchy.addEdge(edge)
|
852
1186
|
this._delta.json.hierarchy.push([child, parent])
|
@@ -859,13 +1193,7 @@ class Config {
|
|
859
1193
|
if (typeof parent !== 'string') {
|
860
1194
|
throw new Error(`addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`)
|
861
1195
|
}
|
862
|
-
|
863
|
-
if (global.entodictonDebugHierarchy) {
|
864
|
-
if (helpers.safeEquals(global.entodictonDebugHierarchy, [child, parent])) {
|
865
|
-
debugger; // debug hierarchy hit
|
866
|
-
}
|
867
|
-
}
|
868
|
-
|
1196
|
+
debugHierarchy([child, parent])
|
869
1197
|
if (this.config.hierarchy.find( (element) => {
|
870
1198
|
const hc = hierarchyCanonical(element)
|
871
1199
|
if (child == hc.child && parent == hc.parent) {
|
@@ -881,24 +1209,24 @@ class Config {
|
|
881
1209
|
}
|
882
1210
|
|
883
1211
|
getBridge (id, level) {
|
884
|
-
|
1212
|
+
if (level) {
|
1213
|
+
return this.config.bridges.find( (bridge) => bridge.id == id && bridge.level == level )
|
1214
|
+
} else {
|
1215
|
+
return this.config.bridges.find( (bridge) => bridge.id == id)
|
1216
|
+
}
|
885
1217
|
}
|
886
1218
|
|
887
|
-
addBridge (bridge) {
|
1219
|
+
addBridge (bridge, uuid) {
|
888
1220
|
if (!this.config.bridges) {
|
889
1221
|
this.config.bridges = []
|
890
1222
|
}
|
891
1223
|
const bridges = this.config.bridges
|
892
|
-
const def = Object.assign({}, bridge, { uuid: this._uuid })
|
893
|
-
|
894
|
-
|
895
|
-
if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
|
896
|
-
debugger; // debug hierarchy hit
|
897
|
-
}
|
898
|
-
}
|
899
|
-
|
1224
|
+
const def = Object.assign({}, bridge, { uuid: uuid || this._uuid })
|
1225
|
+
|
1226
|
+
debugBridge(bridge)
|
900
1227
|
if (bridge.allowDups) {
|
901
|
-
if (bridges.find( (b) => b.id == bridge.id && b.level == bridge.level && b.bridge == bridge.bridge )) {
|
1228
|
+
// if (bridges.find( (b) => b.id == bridge.id && b.level == bridge.level && b.bridge == bridge.bridge )) {
|
1229
|
+
if (bridges.find( (b) => b.id == bridge.id && b.level == bridge.level)) {
|
902
1230
|
return;
|
903
1231
|
}
|
904
1232
|
}
|
@@ -911,12 +1239,7 @@ class Config {
|
|
911
1239
|
this._delta.json.bridges.push({ action: 'add', bridge: def })
|
912
1240
|
}
|
913
1241
|
|
914
|
-
addGenerator (
|
915
|
-
let generator = match
|
916
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
917
|
-
generator = { match, apply }
|
918
|
-
}
|
919
|
-
|
1242
|
+
addGenerator (generator, uuid, name) {
|
920
1243
|
if (!(typeof generator.match === 'function')) {
|
921
1244
|
throw new Error('addGenerator: Expected matcher to be a function')
|
922
1245
|
}
|
@@ -933,20 +1256,16 @@ class Config {
|
|
933
1256
|
}
|
934
1257
|
|
935
1258
|
const generators = this.config.generators
|
936
|
-
Object.assign(generator, { uuid: this._uuid, km: this.name, index: generators.length })
|
1259
|
+
Object.assign(generator, { uuid: uuid || this._uuid, km: name || this.name, index: generators.length })
|
937
1260
|
// used to be unshift
|
938
1261
|
generators.unshift(generator)
|
939
1262
|
}
|
940
1263
|
|
941
|
-
addSemantic (
|
942
|
-
let semantic = match
|
943
|
-
if ((typeof match === 'function') && (typeof apply === 'function')) {
|
944
|
-
semantic = { match, apply }
|
945
|
-
}
|
946
|
-
|
1264
|
+
addSemantic (semantic, uuid, name) {
|
947
1265
|
if (!(typeof semantic.match === 'function')) {
|
948
1266
|
throw new Error('addSemantic: Expected match to be a function')
|
949
1267
|
}
|
1268
|
+
|
950
1269
|
if (!(typeof semantic.apply === 'function')) {
|
951
1270
|
throw new Error('addSemantic: Expected apply to be a function')
|
952
1271
|
}
|
@@ -960,11 +1279,18 @@ class Config {
|
|
960
1279
|
}
|
961
1280
|
|
962
1281
|
const semantics = this.config.semantics
|
963
|
-
Object.assign(semantic, { uuid: this._uuid, km: this.name, index: semantics.length })
|
1282
|
+
Object.assign(semantic, { uuid: uuid || semantic.uuid || this._uuid, km: name || this.name, index: semantics.length, id: semantic.id || uuidv4() })
|
964
1283
|
semantics.unshift(semantic)
|
965
1284
|
}
|
966
1285
|
|
967
|
-
|
1286
|
+
removeSemantic(deleteSemantic) {
|
1287
|
+
const index = this.config.semantics.findIndex( (semantic) => semantic.id === deleteSemantic.id )
|
1288
|
+
if (index >= 0) {
|
1289
|
+
this.config.semantics.splice(index, 1)
|
1290
|
+
}
|
1291
|
+
}
|
1292
|
+
|
1293
|
+
addOperator (objectOrPattern, uuid) {
|
968
1294
|
if (!this.config.operators) {
|
969
1295
|
this.config.operators = []
|
970
1296
|
}
|
@@ -973,16 +1299,12 @@ class Config {
|
|
973
1299
|
|
974
1300
|
let operator;
|
975
1301
|
if (typeof objectOrPattern === 'string') {
|
976
|
-
operator = { pattern: objectOrPattern, uuid: this._uuid }
|
1302
|
+
operator = { pattern: objectOrPattern, uuid: uuid || this._uuid }
|
977
1303
|
} else {
|
978
|
-
operator = Object.assign({}, objectOrPattern, { uuid: this._uuid })
|
1304
|
+
operator = Object.assign({}, objectOrPattern, { uuid: uuid || this._uuid })
|
979
1305
|
}
|
980
1306
|
|
981
|
-
|
982
|
-
if (operator.pattern === global.entodictonDebugOperator) {
|
983
|
-
debugger; // debug operator hit
|
984
|
-
}
|
985
|
-
}
|
1307
|
+
debugOperator(operator)
|
986
1308
|
|
987
1309
|
if (operator.allowDups) {
|
988
1310
|
if (operators.find( (o) => o.pattern == operator.pattern )) {
|
@@ -996,16 +1318,16 @@ class Config {
|
|
996
1318
|
this._delta.json.operators.push({ action: 'add', operator })
|
997
1319
|
}
|
998
1320
|
|
999
|
-
addWord (word, def) {
|
1000
|
-
this.addWordInternal(word, def)
|
1321
|
+
addWord (word, def, uuid) {
|
1322
|
+
this.addWordInternal(word, def, uuid)
|
1001
1323
|
}
|
1002
1324
|
|
1003
|
-
addWordInternal (word, def) {
|
1325
|
+
addWordInternal (word, def, uuid) {
|
1004
1326
|
if (!this.config.words) {
|
1005
1327
|
this.config.words = {}
|
1006
1328
|
}
|
1007
1329
|
const words = this.config.words
|
1008
|
-
def = Object.assign({}, def, { uuid: this._uuid })
|
1330
|
+
def = Object.assign({}, def, { uuid: uuid || this._uuid })
|
1009
1331
|
if (words[word]) {
|
1010
1332
|
if (!words[word].some((e) => helpers.safeEquals(e, def))) {
|
1011
1333
|
words[word].unshift(def)
|
@@ -1226,33 +1548,7 @@ class Config {
|
|
1226
1548
|
}
|
1227
1549
|
|
1228
1550
|
if (config) {
|
1229
|
-
|
1230
|
-
'hierarchy',
|
1231
|
-
'objects',
|
1232
|
-
'bridges',
|
1233
|
-
'operators',
|
1234
|
-
'words',
|
1235
|
-
'priorities',
|
1236
|
-
'associations',
|
1237
|
-
'name',
|
1238
|
-
'version',
|
1239
|
-
'generators',
|
1240
|
-
'semantics',
|
1241
|
-
'floaters',
|
1242
|
-
'debug',
|
1243
|
-
|
1244
|
-
// TODO Fix these from the test app
|
1245
|
-
'implicits',
|
1246
|
-
'convolution',
|
1247
|
-
'expected_generated',
|
1248
|
-
'expected_results',
|
1249
|
-
'skipSemantics',
|
1250
|
-
'description',
|
1251
|
-
'contexts',
|
1252
|
-
'utterances',
|
1253
|
-
'flatten',
|
1254
|
-
]
|
1255
|
-
helpers.validProps(valid, config, 'config')
|
1551
|
+
validConfigProps(config)
|
1256
1552
|
|
1257
1553
|
config.operators = config.operators || []
|
1258
1554
|
config.bridges = config.bridges || []
|
@@ -1315,6 +1611,10 @@ class Config {
|
|
1315
1611
|
}
|
1316
1612
|
}
|
1317
1613
|
|
1614
|
+
if (config && config.priorities) {
|
1615
|
+
priorities_valid(config.priorities)
|
1616
|
+
}
|
1617
|
+
|
1318
1618
|
normalizeConfig(config)
|
1319
1619
|
|
1320
1620
|
// set the default server so stuff just works
|
@@ -1330,7 +1630,6 @@ class Config {
|
|
1330
1630
|
if (config) {
|
1331
1631
|
this.name = config.name
|
1332
1632
|
}
|
1333
|
-
this.motivations = []
|
1334
1633
|
this.loadOrder = new DigraphInternal()
|
1335
1634
|
this.wasInitialized = false
|
1336
1635
|
this.configs = []
|
@@ -1355,6 +1654,7 @@ class Config {
|
|
1355
1654
|
}
|
1356
1655
|
this.get('objects').namespaced[this._uuid] = {}
|
1357
1656
|
this.valid()
|
1657
|
+
debugConfigProps(this.config)
|
1358
1658
|
}
|
1359
1659
|
|
1360
1660
|
addArgs(moreArgs) {
|
@@ -1385,7 +1685,10 @@ class Config {
|
|
1385
1685
|
}
|
1386
1686
|
|
1387
1687
|
delta () {
|
1388
|
-
return {
|
1688
|
+
return {
|
1689
|
+
cacheKey: this._delta.cacheKey,
|
1690
|
+
json: this._delta.json
|
1691
|
+
}
|
1389
1692
|
}
|
1390
1693
|
|
1391
1694
|
resetDelta (cacheKey) {
|
@@ -1431,11 +1734,13 @@ class Config {
|
|
1431
1734
|
this._api.add(this, this._api, value)
|
1432
1735
|
} else {
|
1433
1736
|
this._api = _.cloneDeep(value)
|
1737
|
+
/*
|
1434
1738
|
if (this._api) {
|
1435
|
-
this._api.objects = this.config.objects
|
1436
|
-
this._api.config = () => this
|
1437
|
-
this._api.uuid = this._uuid
|
1739
|
+
// this._api.objects = this.config.objects
|
1740
|
+
// this._api.config = () => this
|
1741
|
+
// this._api.uuid = this._uuid
|
1438
1742
|
}
|
1743
|
+
*/
|
1439
1744
|
this.rebuild()
|
1440
1745
|
}
|
1441
1746
|
}
|
@@ -1478,40 +1783,6 @@ class Config {
|
|
1478
1783
|
// this.valid() init was not run because the kms are not all setup yet
|
1479
1784
|
}
|
1480
1785
|
|
1481
|
-
// motivation === { match, apply, uuid }
|
1482
|
-
addMotivation (motivation) {
|
1483
|
-
if (!motivation.uuid) {
|
1484
|
-
motivation.uuid = this.uuid
|
1485
|
-
}
|
1486
|
-
this.motivations.push(motivation)
|
1487
|
-
}
|
1488
|
-
|
1489
|
-
resetMotivations () {
|
1490
|
-
this.motivations = []
|
1491
|
-
}
|
1492
|
-
|
1493
|
-
doMotivations (args, context) {
|
1494
|
-
args = Object.assign({}, args, { context, api: this.api })
|
1495
|
-
// console.log('src/config doMotivations this.uuid', this.uuid)
|
1496
|
-
// args.objects = args.getObjects(this.uuid)
|
1497
|
-
const motivations = this.motivations
|
1498
|
-
this.motivations = []
|
1499
|
-
let done = false
|
1500
|
-
for (const motivation of motivations) {
|
1501
|
-
args.objects = args.getObjects(motivation.uuid)
|
1502
|
-
if (!done && motivation.match(args)) {
|
1503
|
-
motivation.apply(args)
|
1504
|
-
if (args.context.controlKeepMotivation || motivation.repeat) {
|
1505
|
-
this.motivations.push(motivation)
|
1506
|
-
}
|
1507
|
-
done = true
|
1508
|
-
} else {
|
1509
|
-
this.motivations.push(motivation)
|
1510
|
-
}
|
1511
|
-
}
|
1512
|
-
return done
|
1513
|
-
}
|
1514
|
-
|
1515
1786
|
// TODO add more details
|
1516
1787
|
equal(config) {
|
1517
1788
|
if (JSON.stringify(this.config) != JSON.stringify(config.config)) {
|
@@ -1525,6 +1796,9 @@ class Config {
|
|
1525
1796
|
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1526
1797
|
}
|
1527
1798
|
|
1799
|
+
copy (options = { callInitializers: true }) {
|
1800
|
+
}
|
1801
|
+
|
1528
1802
|
copy (options = { callInitializers: true }) {
|
1529
1803
|
this.valid()
|
1530
1804
|
const cp = new Config()
|
@@ -1534,15 +1808,14 @@ class Config {
|
|
1534
1808
|
cp.transitoryMode = this.transitoryMode
|
1535
1809
|
cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
1536
1810
|
cp._uuid = cp.configs[0]._uuid
|
1811
|
+
// update uuid here set the uuid in the objects and add error checking
|
1537
1812
|
cp.initializerFn = this.initializerFn
|
1538
|
-
cp.initAfterApi = this.initAfterApi
|
1539
1813
|
cp._api = _.cloneDeep(this._api)
|
1540
1814
|
cp._namespace = this._namespace
|
1541
1815
|
cp._eqClasses = this._eqClasses
|
1542
1816
|
cp.name = this.name
|
1543
1817
|
cp.description = this.description
|
1544
1818
|
cp.tests = this.tests
|
1545
|
-
cp.motivations = [...this.motivations]
|
1546
1819
|
cp.isModule = this.isModule
|
1547
1820
|
cp.loadedForTesting = this.loadedForTesting
|
1548
1821
|
cp.initInstances = this.initInstances.slice()
|
@@ -1567,25 +1840,38 @@ class Config {
|
|
1567
1840
|
}
|
1568
1841
|
cp.mapUUIDs(map)
|
1569
1842
|
|
1843
|
+
if (cp._uuid == 'concept2') {
|
1844
|
+
// debugger
|
1845
|
+
}
|
1570
1846
|
if (options.callInitializers) {
|
1571
1847
|
cp.rebuild(options)
|
1572
|
-
}
|
1573
|
-
|
1574
|
-
|
1575
|
-
cp._api
|
1576
|
-
|
1577
|
-
|
1848
|
+
} else {
|
1849
|
+
// this mess is for duplicate into a KM after resetToOne was called
|
1850
|
+
/*
|
1851
|
+
if (cp._api) {
|
1852
|
+
// cp._api.objects = cp.config.objects
|
1853
|
+
// cp._api.config = () => (cp instanceof Config) ? cp : cp.config
|
1854
|
+
// cp._api.uuid = cp._uuid
|
1855
|
+
}
|
1856
|
+
*/
|
1578
1857
|
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1858
|
+
if (!cp.config.objects) {
|
1859
|
+
cp.config.objects = { namespaced: {} }
|
1860
|
+
} else if (!cp.config.objects.namespaced) {
|
1861
|
+
cp.config.objects.namespaced = {}
|
1862
|
+
}
|
1863
|
+
cp.configs.forEach((km) => {
|
1864
|
+
// const namespace = km.namespace
|
1865
|
+
cp.config.objects.namespaced[km._uuid] = {}
|
1866
|
+
})
|
1867
|
+
/*
|
1868
|
+
if (cp._uuid == 'concept2') {
|
1869
|
+
if (!cp.api.objects.defaultTypesForHierarchy) {
|
1870
|
+
debugger
|
1871
|
+
}
|
1872
|
+
}
|
1873
|
+
*/
|
1583
1874
|
}
|
1584
|
-
cp.configs.forEach((km) => {
|
1585
|
-
// const namespace = km.namespace
|
1586
|
-
cp.config.objects.namespaced[km._uuid] = {}
|
1587
|
-
})
|
1588
|
-
|
1589
1875
|
cp.valid()
|
1590
1876
|
return cp
|
1591
1877
|
}
|
@@ -1685,38 +1971,33 @@ class Config {
|
|
1685
1971
|
}
|
1686
1972
|
*/
|
1687
1973
|
const objects = {}
|
1688
|
-
const km = (name) => this.getConfig(name)
|
1689
1974
|
if (config instanceof Config) {
|
1690
|
-
// const aw = addWord(this.config, config.uuid)
|
1691
|
-
const aw = (word, def) => this.addWord(word, def)
|
1692
1975
|
this.get('objects').namespaced[config._uuid] = objects
|
1976
|
+
/*
|
1693
1977
|
if (config._api) {
|
1694
|
-
config._api.objects = objects
|
1695
|
-
config._api.config = () => this
|
1978
|
+
// config._api.objects = objects
|
1979
|
+
// config._api.config = () => this
|
1696
1980
|
}
|
1697
|
-
|
1981
|
+
*/
|
1982
|
+
config.initializerFn(setupInitializerFNArgs(this, { testConfig: config, currentConfig: config, objects, namespace, uuid }))
|
1698
1983
|
} else {
|
1699
|
-
// const aw = addWord(this.config, this.uuid)
|
1700
|
-
const aw = (word, def) => this.addWord(word, def)
|
1701
1984
|
this.get('objects').namespaced[this._uuid] = objects
|
1985
|
+
/*
|
1702
1986
|
if (config._api) {
|
1703
|
-
config._api.objects = objects
|
1704
|
-
config._api.config = () => this
|
1987
|
+
// config._api.objects = objects
|
1988
|
+
// config._api.config = () => this
|
1705
1989
|
}
|
1706
|
-
|
1990
|
+
*/
|
1991
|
+
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, namespace, uuid }))
|
1707
1992
|
}
|
1708
1993
|
})
|
1709
|
-
this.instances.forEach((instance) => client.
|
1994
|
+
this.instances.forEach((instance) => client.loadInstance(this, instance))
|
1710
1995
|
}
|
1711
1996
|
|
1712
1997
|
initialize ({ force = true } = {}) {
|
1713
1998
|
if (force || !this.wasInitialized) {
|
1714
|
-
// const aw = addWord(this.config, this.uuid)
|
1715
|
-
const aw = (word, def) => this.addWord(word, def)
|
1716
|
-
const km = (name) => this.getConfig(name)
|
1717
|
-
// this.initializerFn({ addWord: aw, km, config: this, baseConfig: this, currentConfig: this, objects: this.get('objects'), uuid: this._uuid, namespace: '', api: this.api })
|
1718
1999
|
const objects = this.config.objects.namespaced[this._uuid]
|
1719
|
-
this.initializerFn(
|
2000
|
+
this.initializerFn(setupInitializerFNArgs(this, { testConfig: this, currentConfig: this, objects, uuid: this._uuid, namespace: '' }))
|
1720
2001
|
this.wasInitialized = true
|
1721
2002
|
}
|
1722
2003
|
}
|
@@ -1724,29 +2005,22 @@ class Config {
|
|
1724
2005
|
initializer (fn, options = {}) {
|
1725
2006
|
if (options) {
|
1726
2007
|
for (let option of Object.keys(options)) {
|
1727
|
-
const validOptions = [
|
1728
|
-
if (!
|
2008
|
+
const validOptions = []
|
2009
|
+
if (!validOptions.includes(option)) {
|
1729
2010
|
throw new Error(`For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`)
|
1730
2011
|
}
|
1731
2012
|
}
|
1732
2013
|
}
|
1733
|
-
const { initAfterApi = false } = options;
|
1734
2014
|
this.wasInitialized = false
|
1735
|
-
this.
|
1736
|
-
this.initializerFn = (args) => {
|
2015
|
+
this.initializerFn = (args, { dontCallFn } = {}) => {
|
1737
2016
|
const transitoryMode = global.transitoryMode
|
1738
2017
|
global.transitoryMode = false
|
1739
2018
|
// const baseConfig = args.baseConfig
|
1740
2019
|
const currentConfig = args.currentConfig
|
1741
2020
|
|
1742
|
-
if (
|
1743
|
-
|
1744
|
-
// GREG42 currentConfig.api.config = () => this
|
1745
|
-
currentConfig.api.config = () => args.baseConfig
|
1746
|
-
currentConfig.api.uuid = currentConfig._uuid
|
2021
|
+
if (args.isAfterApi) {
|
2022
|
+
fn(args)
|
1747
2023
|
}
|
1748
|
-
// this.instances.forEach( (instance) => client.processInstance(this, instance) )
|
1749
|
-
fn(args)
|
1750
2024
|
currentConfig.wasInitialized = true
|
1751
2025
|
global.transitoryMode = transitoryMode
|
1752
2026
|
}
|
@@ -1913,7 +2187,6 @@ class Config {
|
|
1913
2187
|
}
|
1914
2188
|
this.config.objects.namespaced = {}
|
1915
2189
|
this.resetWasInitialized()
|
1916
|
-
this.resetMotivations()
|
1917
2190
|
|
1918
2191
|
// reorder configs base on load ordering
|
1919
2192
|
{
|
@@ -1939,8 +2212,8 @@ class Config {
|
|
1939
2212
|
this.config.objects.namespaced[km._uuid] = {}
|
1940
2213
|
const namespacedObjects = this.config.objects.namespaced[km._uuid]
|
1941
2214
|
this.setupNamespace(km)
|
1942
|
-
// const aw =
|
1943
|
-
const
|
2215
|
+
// const aw = (word, def) => this.addWord(word, def)
|
2216
|
+
// const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
1944
2217
|
let config = km.config
|
1945
2218
|
|
1946
2219
|
if (config.addedArgss) {
|
@@ -1961,45 +2234,51 @@ class Config {
|
|
1961
2234
|
}
|
1962
2235
|
config.wasInitialized = false
|
1963
2236
|
// TODO change name of config: to baseConfig:
|
1964
|
-
const kmFn = (name) =>
|
2237
|
+
const kmFn = (name) => {
|
2238
|
+
const config = this.getConfig(name)
|
2239
|
+
return config
|
2240
|
+
}
|
1965
2241
|
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
|
1966
|
-
const args = {
|
2242
|
+
const args = new Object(setupInitializerFNArgs(this, {
|
1967
2243
|
isModule,
|
1968
|
-
addWord: aw,
|
1969
|
-
km: kmFn,
|
1970
2244
|
hierarchy: this.hierarchy,
|
1971
|
-
config,
|
1972
|
-
baseConfig: this,
|
2245
|
+
testConfig: config,
|
1973
2246
|
currentConfig: config,
|
1974
2247
|
uuid: config._uuid,
|
1975
2248
|
objects: namespacedObjects,
|
1976
2249
|
namespace,
|
1977
|
-
|
1978
|
-
|
2250
|
+
api: config.api,
|
2251
|
+
}))
|
2252
|
+
|
2253
|
+
const currentConfig = args.currentConfig
|
2254
|
+
|
2255
|
+
/*
|
2256
|
+
if (args.currentConfig.api) {
|
2257
|
+
// args.currentConfig.api.objects = args.objects
|
2258
|
+
// TODO assign pseudo config?
|
2259
|
+
// args.currentConfig.api.config = () => args.baseConfig
|
2260
|
+
// args.currentConfig.api.uuid = args.currentConfig._uuid
|
2261
|
+
args.currentConfig.wasInitialized = true
|
1979
2262
|
}
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
2263
|
+
*/
|
2264
|
+
// debugger
|
2265
|
+
// greg55
|
2266
|
+
config.initializerFn(args, { dontCallFn: true })
|
1983
2267
|
initAfterApis.unshift({ config, args })
|
1984
|
-
} else {
|
1985
|
-
if (interleaved) {
|
1986
|
-
initAfterApis.unshift(null)
|
1987
|
-
}
|
1988
|
-
}
|
1989
|
-
// greg
|
1990
2268
|
if (config._api) {
|
1991
2269
|
if (config._api.initialize) {
|
1992
2270
|
// reverse the list
|
1993
|
-
|
2271
|
+
// TODO sync up the args with initialize of config
|
2272
|
+
inits.unshift( () => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }) )
|
1994
2273
|
// config._api.initialize({ config, api: config._api })
|
1995
2274
|
} else {
|
1996
2275
|
if (interleaved) {
|
1997
2276
|
inits.unshift(null)
|
1998
2277
|
}
|
1999
2278
|
}
|
2000
|
-
config._api.objects = namespacedObjects
|
2001
|
-
config._api.config = () => this
|
2002
|
-
config._api.uuid = config._uuid
|
2279
|
+
// config._api.objects = namespacedObjects
|
2280
|
+
// config._api.config = () => this
|
2281
|
+
// config._api.uuid = config._uuid
|
2003
2282
|
} else {
|
2004
2283
|
if (interleaved) {
|
2005
2284
|
inits.unshift(null)
|
@@ -2041,10 +2320,9 @@ class Config {
|
|
2041
2320
|
init()
|
2042
2321
|
}
|
2043
2322
|
for (let init of initAfterApis) {
|
2044
|
-
// init.args.isAfterApi = true
|
2045
2323
|
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2046
2324
|
}
|
2047
|
-
this.instances.forEach((instance) => client.
|
2325
|
+
this.instances.forEach((instance) => client.loadInstance(this, instance))
|
2048
2326
|
} else {
|
2049
2327
|
const base = {
|
2050
2328
|
operators: this.config.operators,
|
@@ -2073,19 +2351,19 @@ class Config {
|
|
2073
2351
|
}
|
2074
2352
|
// console.log('name -------------', name)
|
2075
2353
|
if (inits[i]) {
|
2354
|
+
// greg55
|
2076
2355
|
inits[i]()
|
2077
2356
|
}
|
2078
2357
|
if (initAfterApis[i]) {
|
2079
2358
|
const init = initAfterApis[i]
|
2080
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true
|
2359
|
+
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true})
|
2081
2360
|
}
|
2082
2361
|
const instance = this.instances.find((instance) => instance.name == name)
|
2083
2362
|
if (instance) {
|
2084
|
-
client.
|
2363
|
+
client.loadInstance(this, instance)
|
2085
2364
|
}
|
2086
2365
|
this.hierarchy.edges = this.config.hierarchy
|
2087
2366
|
}
|
2088
|
-
// this.instances.forEach((instance) => client.processInstance(this, instance))
|
2089
2367
|
}
|
2090
2368
|
|
2091
2369
|
if (reverseIt) {
|
@@ -2208,13 +2486,9 @@ class Config {
|
|
2208
2486
|
}
|
2209
2487
|
const km = (name) => this.getConfig(name)
|
2210
2488
|
if (config instanceof Config) {
|
2211
|
-
|
2212
|
-
const aw = (word, def) => this.addWord(word, def)
|
2213
|
-
config.initializerFn({ isModule: this.isModule, addWord: aw, baseConfig: this, km, currentConfig: config, config, objects: nsobjects, namespace, uuid, api: config.api })
|
2489
|
+
config.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: config, testConfig: config, objects: nsobjects, namespace, uuid }))
|
2214
2490
|
} else {
|
2215
|
-
|
2216
|
-
const aw = (word, def) => this.addWord(word, def)
|
2217
|
-
this.initializerFn({ isModule: this.isModule, addWord: aw, baseConfig: this, km, currentConfig: this, config: this, objects: nsobjects, namespace, uuid, api: this.api })
|
2491
|
+
this.initializerFn(setupInitializerFNArgs(this, { isModule: this.isModule, currentConfig: this, testConfig: this, objects: nsobjects, namespace, uuid }))
|
2218
2492
|
}
|
2219
2493
|
})
|
2220
2494
|
}
|
@@ -2271,10 +2545,18 @@ class Config {
|
|
2271
2545
|
|
2272
2546
|
if (config.priorities) {
|
2273
2547
|
let priorities = config.priorities
|
2274
|
-
priorities = priorities.map((
|
2275
|
-
|
2276
|
-
|
2277
|
-
|
2548
|
+
priorities = priorities.map((cp) => {
|
2549
|
+
const { context, choose, ordered } = cp
|
2550
|
+
const priority = {
|
2551
|
+
context: context.map((id) => {
|
2552
|
+
return [toNS(id[0]), id[1]]
|
2553
|
+
}),
|
2554
|
+
choose,
|
2555
|
+
}
|
2556
|
+
if (ordered) {
|
2557
|
+
priority.ordered = ordered
|
2558
|
+
}
|
2559
|
+
return priority
|
2278
2560
|
})
|
2279
2561
|
config.priorities = priorities
|
2280
2562
|
}
|
@@ -2473,7 +2755,8 @@ class Config {
|
|
2473
2755
|
}
|
2474
2756
|
|
2475
2757
|
// TODO get rid of useOldVersion arg
|
2476
|
-
addInternal (more, { useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
|
2758
|
+
addInternal (more, { addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps : hcps = false } = {}) {
|
2759
|
+
validConfigProps(more)
|
2477
2760
|
if (more instanceof Config) {
|
2478
2761
|
more.initialize({ force: false })
|
2479
2762
|
if (useOldVersion) {
|
@@ -2483,8 +2766,10 @@ class Config {
|
|
2483
2766
|
more = _.cloneDeep(more.initConfig)
|
2484
2767
|
}
|
2485
2768
|
}
|
2769
|
+
debugConfigProps(more)
|
2770
|
+
|
2486
2771
|
if (hcps) {
|
2487
|
-
handleCalculatedProps(this, more)
|
2772
|
+
handleCalculatedProps(this, more, addFirst)
|
2488
2773
|
applyUUID(more, this._uuid)
|
2489
2774
|
}
|
2490
2775
|
for (const key of Object.keys(more)) {
|
@@ -2509,7 +2794,11 @@ class Config {
|
|
2509
2794
|
if (!configWords[word]) {
|
2510
2795
|
configWords[word] = []
|
2511
2796
|
}
|
2512
|
-
|
2797
|
+
if (addFirst) {
|
2798
|
+
configWords[word] = moreWords[word].concat(configWords[word])
|
2799
|
+
} else {
|
2800
|
+
configWords[word] = configWords[word].concat(moreWords[word])
|
2801
|
+
}
|
2513
2802
|
}
|
2514
2803
|
} else if (key === 'name') {
|
2515
2804
|
/*
|
@@ -2571,13 +2860,18 @@ class Config {
|
|
2571
2860
|
this.config[key].splice(iOldOne, 1)
|
2572
2861
|
break;
|
2573
2862
|
}
|
2574
|
-
}
|
2863
|
+
}
|
2575
2864
|
}
|
2576
2865
|
}
|
2577
2866
|
}
|
2867
|
+
|
2578
2868
|
// console.log('key', key, 'XXX')
|
2579
2869
|
// console.log('more', JSON.stringify(more, null, 2))
|
2580
|
-
|
2870
|
+
if (addFirst) {
|
2871
|
+
this.config[key] = more[key].concat(this.config[key])
|
2872
|
+
} else {
|
2873
|
+
this.config[key] = this.config[key].concat(more[key])
|
2874
|
+
}
|
2581
2875
|
} else {
|
2582
2876
|
if (!(key in this.config)) {
|
2583
2877
|
throw new Error(`Unexpected property in config ${key}`)
|
@@ -2708,5 +3002,8 @@ class Config {
|
|
2708
3002
|
}
|
2709
3003
|
|
2710
3004
|
module.exports = {
|
2711
|
-
Config
|
3005
|
+
Config,
|
3006
|
+
config_toServer,
|
3007
|
+
operatorKey_valid,
|
3008
|
+
handleBridgeProps,
|
2712
3009
|
}
|