theprogrammablemind_4wp 7.10.0-beta.9 → 7.10.1-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/client.js +273 -273
- package/demo.js +24 -24
- package/lines.js +2 -2
- package/package.json +1 -1
- package/runtime.js +12 -12
- package/src/config.js +239 -241
- package/src/digraph.js +9 -9
- package/src/digraph_internal.js +6 -6
- package/src/flatten.js +1 -1
- package/src/generators.js +41 -43
- package/src/helpers.js +57 -58
- package/src/project.js +6 -8
- package/src/semantics.js +40 -42
- package/src/unflatten.js +7 -7
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
|
-
const { v4
|
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')
|
@@ -19,7 +19,7 @@ const bags = [
|
|
19
19
|
]
|
20
20
|
|
21
21
|
const indent = (string, indent) => {
|
22
|
-
|
22
|
+
return string.replace(/^/gm, ' '.repeat(indent))
|
23
23
|
}
|
24
24
|
|
25
25
|
const config_toServer = (config) => {
|
@@ -29,7 +29,7 @@ const config_toServer = (config) => {
|
|
29
29
|
const debugPriority = (priority) => {
|
30
30
|
if (global.entodictonDebugPriority) {
|
31
31
|
if (helpers.subPriority(entodictonDebugPriority, priority)) {
|
32
|
-
debugger
|
32
|
+
debugger // debug hierarchy hit
|
33
33
|
}
|
34
34
|
}
|
35
35
|
}
|
@@ -37,7 +37,7 @@ const debugPriority = (priority) => {
|
|
37
37
|
const debugAssociation = (association) => {
|
38
38
|
if (global.entodictonDebugAssociation) {
|
39
39
|
if (helpers.safeEquals(global.entodictonDebugAssociation, association)) {
|
40
|
-
debugger
|
40
|
+
debugger // debug association hit
|
41
41
|
}
|
42
42
|
}
|
43
43
|
}
|
@@ -45,15 +45,15 @@ const debugAssociation = (association) => {
|
|
45
45
|
const debugHierarchy = (pair) => {
|
46
46
|
if (global.entodictonDebugHierarchy) {
|
47
47
|
if (helpers.safeEquals(global.entodictonDebugHierarchy, pair)) {
|
48
|
-
debugger
|
48
|
+
debugger // debug hierarchy hit
|
49
49
|
}
|
50
50
|
}
|
51
51
|
}
|
52
52
|
|
53
|
-
const debugBridge = (bridge) => {
|
53
|
+
const debugBridge = (bridge) => {
|
54
54
|
if (global.entodictonDebugBridge) {
|
55
55
|
if (global.entodictonDebugBridge[0] == bridge.id && global.entodictonDebugBridge[1] == bridge.level) {
|
56
|
-
debugger
|
56
|
+
debugger // debug hierarchy hit
|
57
57
|
}
|
58
58
|
}
|
59
59
|
}
|
@@ -61,7 +61,7 @@ const debugBridge = (bridge) => {
|
|
61
61
|
const debugOperator = (operator) => {
|
62
62
|
if (global.entodictonDebugOperator) {
|
63
63
|
if ((operator.pattern || operator) === global.entodictonDebugOperator) {
|
64
|
-
debugger
|
64
|
+
debugger // debug operator hit
|
65
65
|
}
|
66
66
|
}
|
67
67
|
}
|
@@ -75,7 +75,7 @@ const debugConfigProps = (config) => {
|
|
75
75
|
{ property: 'association', check: (v) => debugAssociation(v) },
|
76
76
|
{ property: 'hierarchy', check: (v) => debugHierarchy(v) },
|
77
77
|
{ property: 'operators', check: (v) => debugOperator(v) },
|
78
|
-
{ property: 'bridges', check: (v) => debugBridge(v) }
|
78
|
+
{ property: 'bridges', check: (v) => debugBridge(v) }
|
79
79
|
]
|
80
80
|
for (const { property, check } of checkProps) {
|
81
81
|
if (config[property]) {
|
@@ -87,21 +87,21 @@ const debugConfigProps = (config) => {
|
|
87
87
|
}
|
88
88
|
|
89
89
|
const validConfigProps = (config) => {
|
90
|
-
const valid = [
|
91
|
-
'hierarchy',
|
92
|
-
'objects',
|
93
|
-
'bridges',
|
94
|
-
'operators',
|
95
|
-
'words',
|
96
|
-
'priorities',
|
97
|
-
'associations',
|
98
|
-
'name',
|
99
|
-
'version',
|
100
|
-
'generatorp',
|
101
|
-
'generators',
|
102
|
-
'semantics',
|
103
|
-
'where',
|
104
|
-
'floaters',
|
90
|
+
const valid = [
|
91
|
+
'hierarchy',
|
92
|
+
'objects',
|
93
|
+
'bridges',
|
94
|
+
'operators',
|
95
|
+
'words',
|
96
|
+
'priorities',
|
97
|
+
'associations',
|
98
|
+
'name',
|
99
|
+
'version',
|
100
|
+
'generatorp',
|
101
|
+
'generators',
|
102
|
+
'semantics',
|
103
|
+
'where',
|
104
|
+
'floaters',
|
105
105
|
'debug',
|
106
106
|
|
107
107
|
// TODO Fix these from the test app
|
@@ -116,7 +116,7 @@ const validConfigProps = (config) => {
|
|
116
116
|
'flatten',
|
117
117
|
|
118
118
|
'namespaces',
|
119
|
-
'eqClasses'
|
119
|
+
'eqClasses'
|
120
120
|
]
|
121
121
|
helpers.validProps(valid, config, 'config')
|
122
122
|
}
|
@@ -134,30 +134,29 @@ const setupInitializerFNArgs = (config, args) => {
|
|
134
134
|
config: config.getPseudoConfig(args.uuid, args.currentConfig),
|
135
135
|
km,
|
136
136
|
baseConfig: config,
|
137
|
-
apis
|
137
|
+
apis
|
138
138
|
}
|
139
139
|
}
|
140
140
|
|
141
141
|
const operatorKey_valid = (key) => {
|
142
142
|
if (
|
143
|
-
|
143
|
+
!_.isArray(key) ||
|
144
144
|
key.length != 2 ||
|
145
145
|
!_.isString(key[0]) ||
|
146
146
|
!_.isInteger(key[1]) ||
|
147
147
|
key[1] < 0
|
148
|
-
|
149
|
-
|
148
|
+
) {
|
150
149
|
let details = ''
|
151
150
|
if (!_.isArray(key)) {
|
152
|
-
details =
|
151
|
+
details = 'Expected an array.'
|
153
152
|
} else if (key.length != 2) {
|
154
|
-
details =
|
153
|
+
details = 'Expected an array of length two.'
|
155
154
|
} else if (!_.isString(key[0])) {
|
156
|
-
details =
|
155
|
+
details = 'Expected element zero to be a string that is an operator id.'
|
157
156
|
} else if (!_.isInteger(key[1])) {
|
158
|
-
details =
|
157
|
+
details = 'Expected element one to be a number that is an operator level.'
|
159
158
|
} else if (key[1] < 0) {
|
160
|
-
details =
|
159
|
+
details = 'Expected element one to be a number that is an operator level which is greater than zero.'
|
161
160
|
}
|
162
161
|
throw new Error(`${JSON.stringify(key)} is not a valid operator key. Values are of the form [<operatorId>, <operatorLevel>]. ${details}`)
|
163
162
|
}
|
@@ -167,13 +166,13 @@ const elist = (list, check, prefix) => {
|
|
167
166
|
for ([index, element] of list.entries()) {
|
168
167
|
try {
|
169
168
|
check(element)
|
170
|
-
} catch(
|
169
|
+
} catch (e) {
|
171
170
|
throw new Error(prefix(index, e))
|
172
171
|
}
|
173
172
|
}
|
174
173
|
}
|
175
174
|
const priorities_valid = (cps) => {
|
176
|
-
elist(cps, (cp) => priority_valid(cp),
|
175
|
+
elist(cps, (cp) => priority_valid(cp), (index, e) => `priorities has an invalid priority at position ${index}. ${e}`)
|
177
176
|
}
|
178
177
|
|
179
178
|
const priority_valid = (cp) => {
|
@@ -187,16 +186,16 @@ const priority_valid = (cp) => {
|
|
187
186
|
if (!_.isArray(cp.choose)) {
|
188
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.`)
|
189
188
|
}
|
190
|
-
elist(cp.choose,
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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}`
|
200
199
|
)
|
201
200
|
}
|
202
201
|
|
@@ -204,29 +203,29 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
204
203
|
ecatch(`While processing the bridge for ${bridge.id}#${bridge.level}`,
|
205
204
|
() => {
|
206
205
|
if (!bridge.bridge) {
|
207
|
-
bridge.bridge =
|
206
|
+
bridge.bridge = '{ ...next(operator) }'
|
208
207
|
}
|
209
208
|
if (!bridge.level) {
|
210
209
|
bridge.level = 0
|
211
210
|
}
|
212
211
|
if (bridge.children) {
|
213
|
-
for (
|
212
|
+
for (const child of bridge.children) {
|
214
213
|
config.addHierarchy(child, bridge.id)
|
215
214
|
}
|
216
215
|
}
|
217
216
|
if (bridge.parents) {
|
218
|
-
for (
|
217
|
+
for (const parent of bridge.parents) {
|
219
218
|
config.addHierarchy(bridge.id, parent)
|
220
219
|
}
|
221
220
|
}
|
222
221
|
if (bridge.isA) {
|
223
|
-
for (
|
222
|
+
for (const parent of bridge.isA) {
|
224
223
|
config.addHierarchy(bridge.id, parent)
|
225
224
|
}
|
226
225
|
}
|
227
226
|
if (bridge.before) {
|
228
227
|
for (let after of bridge.before) {
|
229
|
-
if (typeof after
|
228
|
+
if (typeof after === 'string') {
|
230
229
|
after = [after, 0]
|
231
230
|
}
|
232
231
|
config.addPriority({ context: [[bridge.id, bridge.level], after], choose: [0] })
|
@@ -234,7 +233,7 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
234
233
|
}
|
235
234
|
if (bridge.after) {
|
236
235
|
for (let before of bridge.after) {
|
237
|
-
if (typeof before
|
236
|
+
if (typeof before === 'string') {
|
238
237
|
before = [before, 0]
|
239
238
|
}
|
240
239
|
config.addPriority({ context: [before, [bridge.id, bridge.level]], choose: [0] })
|
@@ -242,8 +241,8 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
242
241
|
}
|
243
242
|
if (bridge.words) {
|
244
243
|
for (let def of bridge.words) {
|
245
|
-
if (typeof def
|
246
|
-
config.addWordInternal(def, {
|
244
|
+
if (typeof def === 'string') {
|
245
|
+
config.addWordInternal(def, { id: bridge.id, initial: `{ value: "${def}"}` })
|
247
246
|
} else {
|
248
247
|
const word = def.word
|
249
248
|
def = { initial: JSON.stringify(def), id: bridge.id, word }
|
@@ -263,7 +262,7 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
263
262
|
if (bridge.generators) {
|
264
263
|
const generators = [...bridge.generators]
|
265
264
|
generators.reverse()
|
266
|
-
for (
|
265
|
+
for (const generator of generators) {
|
267
266
|
if (addFirst) {
|
268
267
|
config.config.generators.unshift(generator)
|
269
268
|
} else {
|
@@ -277,33 +276,32 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
277
276
|
}
|
278
277
|
if (bridge.generatorp) {
|
279
278
|
const match = bridge.generatorp.match || (() => true)
|
280
|
-
const apply = typeof bridge.generatorp
|
279
|
+
const apply = typeof bridge.generatorp === 'function' ? bridge.generatorp : bridge.generatorp.apply || bridge.generatorp
|
281
280
|
const level = bridge.generatorp.level >= 0 ? bridge.generatorp.level : bridge.level + 1
|
282
|
-
|
281
|
+
|
283
282
|
const generator = {
|
284
283
|
where: bridge.generatorp.where || bridge.where || client.where(4),
|
285
284
|
match: (args) => bridge.id == args.context.marker && args.context.level == level && args.context.paraphrase && match(args),
|
286
285
|
apply: (args) => apply(args),
|
287
286
|
applyWrapped: apply,
|
288
|
-
property: 'generatorp'
|
287
|
+
property: 'generatorp'
|
289
288
|
}
|
290
289
|
if (addFirst) {
|
291
290
|
config.config.generators.unshift(generator)
|
292
291
|
} else {
|
293
292
|
config.config.generators.push(generator)
|
294
293
|
}
|
295
|
-
|
296
294
|
}
|
297
295
|
if (bridge.generatorr) {
|
298
296
|
const match = bridge.generatorr.match || (() => true)
|
299
|
-
const apply = typeof bridge.generatorr
|
297
|
+
const apply = typeof bridge.generatorr === 'function' ? bridge.generatorr : bridge.generatorr.apply || bridge.generatorr
|
300
298
|
const level = bridge.generatorr.level >= 0 ? bridge.generatorr.level : bridge.level + 1
|
301
299
|
const generator = {
|
302
300
|
where: bridge.generatorr.where || bridge.where || client.where(4),
|
303
301
|
match: (args) => bridge.id == args.context.marker && args.context.level == level && !args.context.paraphrase && (args.context.response || args.context.isResponse) && match(args),
|
304
302
|
apply: (args) => apply(args),
|
305
303
|
applyWrapped: apply,
|
306
|
-
property: 'generatorr'
|
304
|
+
property: 'generatorr'
|
307
305
|
}
|
308
306
|
if (addFirst) {
|
309
307
|
config.config.generators.unshift(generator)
|
@@ -314,10 +312,10 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
314
312
|
if (bridge.evaluator) {
|
315
313
|
const semantic = {
|
316
314
|
where: bridge.evaluator.where || bridge.where || client.where(3),
|
317
|
-
match: ({context}) => bridge.id == context.marker && context.evaluate,
|
315
|
+
match: ({ context }) => bridge.id == context.marker && context.evaluate,
|
318
316
|
apply: (args) => bridge.evaluator(args),
|
319
317
|
applyWrapped: bridge.evaluator,
|
320
|
-
property: 'evaluator'
|
318
|
+
property: 'evaluator'
|
321
319
|
}
|
322
320
|
if (addFirst) {
|
323
321
|
config.config.semantics.unshift(semantic)
|
@@ -328,10 +326,10 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
328
326
|
if (bridge.semantic) {
|
329
327
|
const semantic = {
|
330
328
|
where: bridge.semantic.where || bridge.where || client.where(3),
|
331
|
-
match: ({context}) => bridge.id == context.marker,
|
329
|
+
match: ({ context }) => bridge.id == context.marker,
|
332
330
|
apply: (args) => bridge.semantic(args),
|
333
331
|
applyWrapped: bridge.semantic,
|
334
|
-
property: 'semantic'
|
332
|
+
property: 'semantic'
|
335
333
|
}
|
336
334
|
if (addFirst) {
|
337
335
|
config.config.semantics.unshift(semantic)
|
@@ -344,11 +342,15 @@ const handleBridgeProps = (config, bridge, addFirst) => {
|
|
344
342
|
}
|
345
343
|
|
346
344
|
const handleCalculatedProps = (baseConfig, moreConfig, addFirst) => {
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
345
|
+
if (moreConfig.bridges) {
|
346
|
+
moreConfig.bridges = moreConfig.bridges.map((bridge) => {
|
347
|
+
bridge = { ...bridge }
|
348
|
+
const valid = ['after', 'before', 'bridge', 'development', 'evaluator', 'generatorp', 'generatorr', 'generatorpr', 'generators', 'id', 'convolution', 'inverted', 'isA', 'children', 'parents',
|
349
|
+
'level', 'optional', 'selector', 'semantic', 'words', /Bridge$/, 'localHierarchy', 'levelSpecificHierarchy', 'where', 'uuid']
|
350
|
+
helpers.validProps(valid, bridge, 'bridge')
|
351
|
+
handleBridgeProps(baseConfig, bridge, addFirst)
|
352
|
+
return bridge
|
353
|
+
})
|
352
354
|
}
|
353
355
|
if (moreConfig.operators) {
|
354
356
|
moreConfig.operators = moreConfig.operators.map((operator) => {
|
@@ -365,7 +367,6 @@ if (runtime.process.env.DEBUG_HIERARCHY) {
|
|
365
367
|
global.entodictonDebugHierarchy = JSON.parse(runtime.process.env.DEBUG_HIERARCHY)
|
366
368
|
}
|
367
369
|
|
368
|
-
|
369
370
|
// i keep randomly doing one of the other so I will just make both work the same way
|
370
371
|
if (runtime.process.env.DEBUG_PRIORITIES) {
|
371
372
|
global.entodictonDebugPriority = JSON.parse(runtime.process.env.DEBUG_PRIORITIES)
|
@@ -386,7 +387,7 @@ if (runtime.process.env.DEBUG_BRIDGE) {
|
|
386
387
|
// id/level
|
387
388
|
global.entodictonDebugBridge = runtime.process.env.DEBUG_BRIDGE.split('/')
|
388
389
|
if (global.entodictonDebugBridge.length !== 2) {
|
389
|
-
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"')
|
390
|
+
console.log('Expected DEBUG_BRIDGE to be of the form "id/level"')
|
390
391
|
process.exit(-1)
|
391
392
|
}
|
392
393
|
global.entodictonDebugBridge[1] = parseInt(global.entodictonDebugBridge[1])
|
@@ -398,12 +399,12 @@ if (runtime.process.env.DEBUG_OPERATOR) {
|
|
398
399
|
}
|
399
400
|
|
400
401
|
const hierarchyCanonical = (element) => {
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
}
|
402
|
+
if (element.child && element.parent) {
|
403
|
+
return element
|
404
|
+
} else {
|
405
|
+
return { child: element[0], parent: element[1] }
|
406
406
|
}
|
407
|
+
}
|
407
408
|
|
408
409
|
const isValidDef = (word, def, config) => {
|
409
410
|
if (!def.id) {
|
@@ -448,21 +449,20 @@ const normalizeConfig = (config) => {
|
|
448
449
|
config[bag][i].km = config.name
|
449
450
|
}
|
450
451
|
}
|
451
|
-
|
452
452
|
}
|
453
|
-
if (config
|
454
|
-
for (
|
453
|
+
if (config.bridges) {
|
454
|
+
for (const bridge of config.bridges) {
|
455
455
|
if (!bridge.level) {
|
456
456
|
bridge.level = 0
|
457
457
|
}
|
458
458
|
if (!bridge.bridge) {
|
459
|
-
bridge.bridge =
|
459
|
+
bridge.bridge = '{ ...next(operator) }'
|
460
460
|
}
|
461
461
|
}
|
462
462
|
}
|
463
463
|
|
464
464
|
if (config.semantics) {
|
465
|
-
for (
|
465
|
+
for (const semantic of config.semantics) {
|
466
466
|
if (semantic.oneShot) {
|
467
467
|
semantic.id = uuid()
|
468
468
|
}
|
@@ -607,7 +607,7 @@ class KM {
|
|
607
607
|
const config = configDup(this._config, options)
|
608
608
|
const km = new KM({
|
609
609
|
config,
|
610
|
-
getCounter: options.getCounter,
|
610
|
+
getCounter: options.getCounter,
|
611
611
|
name: this._name,
|
612
612
|
_uuid: config._uuid,
|
613
613
|
namespace: this._namespace,
|
@@ -704,16 +704,14 @@ const multiApiImpl = (initializer) => {
|
|
704
704
|
})
|
705
705
|
}
|
706
706
|
|
707
|
-
|
708
707
|
class Config {
|
709
|
-
|
710
708
|
toServer (config) {
|
711
709
|
return config_toServer(config)
|
712
710
|
}
|
713
711
|
|
714
712
|
base () {
|
715
713
|
const base = new Config()
|
716
|
-
for (
|
714
|
+
for (const km of this.configs.reverse()) {
|
717
715
|
if (km.isSelf) {
|
718
716
|
continue
|
719
717
|
}
|
@@ -733,8 +731,8 @@ class Config {
|
|
733
731
|
}
|
734
732
|
const templateQueries = []
|
735
733
|
if (this.instances && this.instances.length > 0) {
|
736
|
-
for (
|
737
|
-
if (typeof query
|
734
|
+
for (const query of this.instances.slice(-1)[0].queries) {
|
735
|
+
if (typeof query === 'string') {
|
738
736
|
templateQueries.push(query)
|
739
737
|
}
|
740
738
|
}
|
@@ -745,7 +743,7 @@ class Config {
|
|
745
743
|
|
746
744
|
getPseudoConfig (uuid, config) {
|
747
745
|
return {
|
748
|
-
description:
|
746
|
+
description: 'this is a pseudo config that has limited functionality due to being available in the initializer function context',
|
749
747
|
addAssociation: (...args) => this.addAssociation(...args),
|
750
748
|
addAssociations: (...args) => this.addAssociations(...args),
|
751
749
|
addBridge: (...args) => this.addBridge(...args, uuid),
|
@@ -765,7 +763,7 @@ class Config {
|
|
765
763
|
getBridge: (...args) => this.getBridge(...args),
|
766
764
|
fragment: (...args) => this.fragment(...args),
|
767
765
|
exists: (...args) => this.exists(...args),
|
768
|
-
addAPI: (...args) => this.addAPI(...args)
|
766
|
+
addAPI: (...args) => this.addAPI(...args)
|
769
767
|
}
|
770
768
|
}
|
771
769
|
|
@@ -779,7 +777,7 @@ class Config {
|
|
779
777
|
}
|
780
778
|
|
781
779
|
// return the config with just the elements from the included KM's
|
782
|
-
baseConfig() {
|
780
|
+
baseConfig () {
|
783
781
|
const operators = this.config.operators.filter((operator) => {
|
784
782
|
return operator.uuid !== this.uuid
|
785
783
|
})
|
@@ -787,8 +785,8 @@ class Config {
|
|
787
785
|
return bridge.uuid !== this.uuid
|
788
786
|
})
|
789
787
|
const words = {}
|
790
|
-
for (
|
791
|
-
const defs = this.config.words[word].filter(
|
788
|
+
for (const word in this.config.words) {
|
789
|
+
const defs = this.config.words[word].filter((def) => def.uuid !== this.uuid)
|
792
790
|
if (defs.length > 0) {
|
793
791
|
words[word] = defs
|
794
792
|
}
|
@@ -806,11 +804,11 @@ class Config {
|
|
806
804
|
return `${maybeName}${counter}`
|
807
805
|
}
|
808
806
|
|
809
|
-
setTestConfig(testConfig) {
|
807
|
+
setTestConfig (testConfig) {
|
810
808
|
this.testConfig = testConfig
|
811
809
|
}
|
812
810
|
|
813
|
-
getTestConfig() {
|
811
|
+
getTestConfig () {
|
814
812
|
return this.testConfig
|
815
813
|
}
|
816
814
|
|
@@ -855,44 +853,44 @@ class Config {
|
|
855
853
|
|
856
854
|
// applies only to config sent to the server
|
857
855
|
|
858
|
-
watching() {
|
856
|
+
watching () {
|
859
857
|
const props = [
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
]
|
858
|
+
'operators',
|
859
|
+
'bridges',
|
860
|
+
'hierarchy',
|
861
|
+
'namespaces',
|
862
|
+
'eqClasses',
|
863
|
+
'priorities',
|
864
|
+
'associations',
|
865
|
+
'words',
|
866
|
+
'floaters',
|
867
|
+
'implicits',
|
868
|
+
'flatten'
|
869
|
+
]
|
872
870
|
const watching = {}
|
873
|
-
for (
|
871
|
+
for (const prop of props) {
|
874
872
|
watching[prop] = this.config[prop]
|
875
873
|
}
|
876
874
|
return JSON.stringify(watching)
|
877
875
|
}
|
878
876
|
|
879
|
-
watch() {
|
880
|
-
this.watchStart = this.watching()
|
877
|
+
watch () {
|
878
|
+
this.watchStart = this.watching()
|
881
879
|
}
|
882
880
|
|
883
|
-
wasChanged() {
|
881
|
+
wasChanged () {
|
884
882
|
if (!this.watchStart) {
|
885
|
-
return false
|
883
|
+
return false
|
886
884
|
}
|
887
885
|
return this.watchStart !== this.watching()
|
888
886
|
}
|
889
887
|
|
890
|
-
|
891
|
-
for (
|
888
|
+
exists (marker) {
|
889
|
+
for (const bridge of this.config.bridges) {
|
892
890
|
if (bridge.id == marker) {
|
893
|
-
return true
|
891
|
+
return true
|
894
892
|
}
|
895
|
-
|
893
|
+
}
|
896
894
|
}
|
897
895
|
|
898
896
|
getSemantics (logs = []) {
|
@@ -906,7 +904,7 @@ class Config {
|
|
906
904
|
warningNotEvaluated (log, value) {
|
907
905
|
const description = 'WARNING: for semantics, implement an evaluations handler, set "value" property of the operator to the value.'
|
908
906
|
const match = `({context}) => context.marker == '${value.marker}' && context.evaluate && <other conditions as you like>`
|
909
|
-
const apply =
|
907
|
+
const apply = '({context}) => <do stuff...>; context.value = <value>'
|
910
908
|
const input = indent(JSON.stringify(value, null, 2), 2)
|
911
909
|
const message = `${description}\nThe semantic would be\n match: ${match}\n apply: ${apply}\nThe input context would be:\n${input}\n`
|
912
910
|
log.push(indent(message, 4))
|
@@ -933,18 +931,17 @@ class Config {
|
|
933
931
|
const instance = s({ ...context, evaluate: true })
|
934
932
|
calls.touch(instance)
|
935
933
|
if (!instance.evalue && !instance.verbatim && !instance.value) {
|
936
|
-
this.warningNotEvaluated(log, context)
|
934
|
+
this.warningNotEvaluated(log, context)
|
937
935
|
}
|
938
936
|
if (!instance.evalue) {
|
939
937
|
instance.evalue = instance.value
|
940
938
|
instance.edefault = true
|
941
939
|
}
|
942
940
|
delete instance.evaluate
|
943
|
-
instance.instance = true
|
941
|
+
instance.instance = true
|
944
942
|
return instance
|
945
943
|
}
|
946
944
|
|
947
|
-
|
948
945
|
fragmentInstantiator (contexts) {
|
949
946
|
return new Object({
|
950
947
|
contexts: () => contexts,
|
@@ -966,7 +963,7 @@ class Config {
|
|
966
963
|
continue
|
967
964
|
}
|
968
965
|
if (context[key].instantiated) {
|
969
|
-
continue
|
966
|
+
continue
|
970
967
|
}
|
971
968
|
todo.push(context[key])
|
972
969
|
}
|
@@ -992,20 +989,20 @@ class Config {
|
|
992
989
|
return true
|
993
990
|
}
|
994
991
|
const toCanonical = (f) => {
|
995
|
-
if (typeof f
|
992
|
+
if (typeof f === 'string') {
|
996
993
|
return { query: f }
|
997
994
|
} else {
|
998
995
|
return f
|
999
996
|
}
|
1000
997
|
}
|
1001
|
-
const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map(
|
1002
|
-
const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map(
|
998
|
+
const instanceFragments = (instance.fragments || []).map((fragment) => fragment.key || fragment.query).map(toCanonical)
|
999
|
+
const templateFragments = (template.fragments || []).concat(this.dynamicFragments).map(toCanonical)
|
1003
1000
|
const sameFragments = helpers.safeEquals(templateFragments, instanceFragments)
|
1004
1001
|
const toCanonicalQuery = (queryOrConfig) => {
|
1005
|
-
if (typeof queryOrConfig
|
1002
|
+
if (typeof queryOrConfig === 'string') {
|
1006
1003
|
const query = queryOrConfig
|
1007
1004
|
return query
|
1008
|
-
} else if (typeof queryOrConfig
|
1005
|
+
} else if (typeof queryOrConfig === 'function') {
|
1009
1006
|
if (options.isModule) {
|
1010
1007
|
return { apply: 'function in the browser has webpack rewrites so can not be compared' }
|
1011
1008
|
} else {
|
@@ -1020,8 +1017,8 @@ class Config {
|
|
1020
1017
|
} else {
|
1021
1018
|
const config = { ...queryOrConfig }
|
1022
1019
|
delete config.where
|
1023
|
-
config.operators = (config.operators || []).map(
|
1024
|
-
if (typeof operator
|
1020
|
+
config.operators = (config.operators || []).map((operator) => {
|
1021
|
+
if (typeof operator === 'string') {
|
1025
1022
|
return { pattern: operator }
|
1026
1023
|
} else {
|
1027
1024
|
operator = { ...operator }
|
@@ -1029,7 +1026,7 @@ class Config {
|
|
1029
1026
|
return operator
|
1030
1027
|
}
|
1031
1028
|
})
|
1032
|
-
config.bridges = (config.bridges || []).map(
|
1029
|
+
config.bridges = (config.bridges || []).map((bridge) => {
|
1033
1030
|
bridge = { ...bridge },
|
1034
1031
|
bridge.level = bridge.level || 0
|
1035
1032
|
delete bridge.uuid
|
@@ -1037,10 +1034,10 @@ class Config {
|
|
1037
1034
|
})
|
1038
1035
|
if (options.isModule) {
|
1039
1036
|
// things like webpack rewrite the functions if there are constants so this compare does not work
|
1040
|
-
delete config.generators
|
1041
|
-
delete config.semantics
|
1037
|
+
delete config.generators
|
1038
|
+
delete config.semantics
|
1042
1039
|
config.bridges = (config.bridges || []).map((bridge) => {
|
1043
|
-
bridge = {...bridge}
|
1040
|
+
bridge = { ...bridge }
|
1044
1041
|
delete bridge.where
|
1045
1042
|
delete bridge.generatorp
|
1046
1043
|
delete bridge.generatorr
|
@@ -1048,24 +1045,24 @@ class Config {
|
|
1048
1045
|
delete bridge.evaluator
|
1049
1046
|
delete bridge.semantic
|
1050
1047
|
return bridge
|
1051
|
-
})
|
1048
|
+
})
|
1052
1049
|
} else {
|
1053
1050
|
config.generators = (config.generators || []).map((generator) => {
|
1054
|
-
generator = {...generator}
|
1051
|
+
generator = { ...generator }
|
1055
1052
|
delete generator.where
|
1056
1053
|
generator.match = generator.match.toString()
|
1057
1054
|
generator.apply = generator.apply.toString()
|
1058
1055
|
return generator
|
1059
1056
|
})
|
1060
1057
|
config.semantics = (config.semantics || []).map((semantic) => {
|
1061
|
-
semantic = {...semantic}
|
1058
|
+
semantic = { ...semantic }
|
1062
1059
|
delete semantic.where
|
1063
1060
|
semantic.match = semantic.match.toString()
|
1064
1061
|
semantic.apply = semantic.apply.toString()
|
1065
1062
|
return semantic
|
1066
1063
|
})
|
1067
1064
|
config.bridges = (config.bridges || []).map((bridge) => {
|
1068
|
-
bridge = {...bridge}
|
1065
|
+
bridge = { ...bridge }
|
1069
1066
|
delete bridge.where
|
1070
1067
|
if (bridge.generatorp) {
|
1071
1068
|
bridge.generatorp = bridge.generatorp.toString()
|
@@ -1089,13 +1086,13 @@ class Config {
|
|
1089
1086
|
}
|
1090
1087
|
}
|
1091
1088
|
const toCanonicalQueries = (elements) => {
|
1092
|
-
return elements.map(
|
1089
|
+
return elements.map(toCanonicalQuery)
|
1093
1090
|
}
|
1094
1091
|
|
1095
1092
|
const templateQueries = toCanonicalQueries(template.queries || []).map(helpers.updateQueries)
|
1096
1093
|
const instanceQueries = toCanonicalQueries(instance.queries || [])
|
1097
1094
|
let sameQueries = true
|
1098
|
-
let startOfChanges
|
1095
|
+
let startOfChanges
|
1099
1096
|
for (let iq = 0; iq < templateQueries.length; ++iq) {
|
1100
1097
|
if (!helpers.safeEquals(templateQueries[iq], instanceQueries[iq])) {
|
1101
1098
|
sameQueries = false
|
@@ -1105,8 +1102,8 @@ class Config {
|
|
1105
1102
|
|
1106
1103
|
const debug = true
|
1107
1104
|
if (debug && startOfChanges) {
|
1108
|
-
console.log('templateQueries[startOfChanges]', templateQueries[startOfChanges])
|
1109
|
-
console.log('instanceQueries[startOfChanges]', instanceQueries[startOfChanges])
|
1105
|
+
console.log('templateQueries[startOfChanges]', templateQueries[startOfChanges])
|
1106
|
+
console.log('instanceQueries[startOfChanges]', instanceQueries[startOfChanges])
|
1110
1107
|
}
|
1111
1108
|
|
1112
1109
|
// things were deleted case
|
@@ -1122,8 +1119,8 @@ class Config {
|
|
1122
1119
|
debugger
|
1123
1120
|
}
|
1124
1121
|
// console.log("instance", instance)
|
1125
|
-
console.log(
|
1126
|
-
console.log(
|
1122
|
+
console.log('sameQueries', sameQueries)
|
1123
|
+
console.log('sameFragments', sameFragments)
|
1127
1124
|
// console.log("templateFragments", templateFragments)
|
1128
1125
|
// console.log("instanceFragments", instanceFragments)
|
1129
1126
|
// console.log('template.queries', JSON.stringify(toCanonicalQueries(template.queries || []).map(helpers.updateQueries), null, 2))
|
@@ -1141,8 +1138,8 @@ class Config {
|
|
1141
1138
|
if (!template.queries && !template.fragments) {
|
1142
1139
|
throw new Error(`Expected the template for ${this.name} to be an object that can have the properties: queries and fragments`)
|
1143
1140
|
}
|
1144
|
-
for (
|
1145
|
-
if (typeof query
|
1141
|
+
for (const query of template.queries || []) {
|
1142
|
+
if (typeof query === 'string') {
|
1146
1143
|
} else if (query instanceof Config) {
|
1147
1144
|
throw new Error(`For the template for ${this.name}, each element in queries should be either a string or a structure with a config (not a Config object).`)
|
1148
1145
|
}
|
@@ -1155,7 +1152,7 @@ class Config {
|
|
1155
1152
|
}
|
1156
1153
|
|
1157
1154
|
// loadTemplate
|
1158
|
-
load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined }
|
1155
|
+
load (template, instance, options = { rebuild: false, previousResultss: undefined, startOfChanges: undefined }) {
|
1159
1156
|
this.validifyTemplate(template)
|
1160
1157
|
instance.template = template
|
1161
1158
|
this.logs.push(`loading template for ${this.name}`)
|
@@ -1167,15 +1164,15 @@ class Config {
|
|
1167
1164
|
} else {
|
1168
1165
|
// no change
|
1169
1166
|
// this.initInstances.push({ ...instance, name: config.name })
|
1170
|
-
const isEmpty = (
|
1167
|
+
const isEmpty = (instance) => {
|
1171
1168
|
const properties = [
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1169
|
+
'queries',
|
1170
|
+
'resultss',
|
1171
|
+
'fragments',
|
1172
|
+
'semantics',
|
1173
|
+
'associations'
|
1177
1174
|
]
|
1178
|
-
return !properties.find(
|
1175
|
+
return !properties.find((property) => instance[property] && instance[property].length > 0)
|
1179
1176
|
}
|
1180
1177
|
if (!isEmpty(instance)) {
|
1181
1178
|
// fix up apply functions
|
@@ -1193,7 +1190,7 @@ class Config {
|
|
1193
1190
|
}
|
1194
1191
|
}
|
1195
1192
|
|
1196
|
-
addFragments(fragments) {
|
1193
|
+
addFragments (fragments) {
|
1197
1194
|
// only run this if not loading as module write error if loading as module and different
|
1198
1195
|
this.dynamicFragments = this.dynamicFragments.concat(fragments)
|
1199
1196
|
}
|
@@ -1203,12 +1200,12 @@ class Config {
|
|
1203
1200
|
}
|
1204
1201
|
|
1205
1202
|
addAssociations (associations) {
|
1206
|
-
for (
|
1203
|
+
for (const association of associations) {
|
1207
1204
|
this.addAssociation(association)
|
1208
1205
|
}
|
1209
1206
|
}
|
1210
1207
|
|
1211
|
-
debugConfig() {
|
1208
|
+
debugConfig () {
|
1212
1209
|
}
|
1213
1210
|
|
1214
1211
|
addAssociation (association) {
|
@@ -1237,17 +1234,17 @@ class Config {
|
|
1237
1234
|
}
|
1238
1235
|
|
1239
1236
|
addPriorities (priorities) {
|
1240
|
-
for (
|
1237
|
+
for (const priority of priorities) {
|
1241
1238
|
this.addPriority(priority)
|
1242
1239
|
}
|
1243
1240
|
}
|
1244
1241
|
|
1245
1242
|
addHierarchy (child, parent) {
|
1246
|
-
if (child && parent || !child || Array.isArray(child) || (typeof child
|
1243
|
+
if (child && parent || !child || Array.isArray(child) || (typeof child === 'string' && !parent)) {
|
1247
1244
|
this.addHierarchyChildParent(child, parent)
|
1248
1245
|
// this.addHierarchyProperties ({ child, parent })
|
1249
1246
|
} else {
|
1250
|
-
this.addHierarchyProperties
|
1247
|
+
this.addHierarchyProperties(child)
|
1251
1248
|
}
|
1252
1249
|
}
|
1253
1250
|
|
@@ -1273,8 +1270,8 @@ class Config {
|
|
1273
1270
|
throw new Error(`addHierarchy expected parent to be a string. got ${JSON.stringify(parent)}`)
|
1274
1271
|
}
|
1275
1272
|
debugHierarchy([child, parent])
|
1276
|
-
if (this.config.hierarchy.find(
|
1277
|
-
const hc = hierarchyCanonical(element)
|
1273
|
+
if (this.config.hierarchy.find((element) => {
|
1274
|
+
const hc = hierarchyCanonical(element)
|
1278
1275
|
if (child == hc.child && parent == hc.parent) {
|
1279
1276
|
return true
|
1280
1277
|
}
|
@@ -1289,9 +1286,9 @@ class Config {
|
|
1289
1286
|
|
1290
1287
|
getBridge (id, level) {
|
1291
1288
|
if (level) {
|
1292
|
-
return this.config.bridges.find(
|
1289
|
+
return this.config.bridges.find((bridge) => bridge.id == id && bridge.level == level)
|
1293
1290
|
} else {
|
1294
|
-
return this.config.bridges.find(
|
1291
|
+
return this.config.bridges.find((bridge) => bridge.id == id)
|
1295
1292
|
}
|
1296
1293
|
}
|
1297
1294
|
|
@@ -1301,12 +1298,12 @@ class Config {
|
|
1301
1298
|
}
|
1302
1299
|
const bridges = this.config.bridges
|
1303
1300
|
const def = Object.assign({}, bridge, { uuid: uuid || this._uuid })
|
1304
|
-
|
1301
|
+
|
1305
1302
|
debugBridge(bridge)
|
1306
1303
|
if (bridge.allowDups) {
|
1307
1304
|
// if (bridges.find( (b) => b.id == bridge.id && b.level == bridge.level && b.bridge == bridge.bridge )) {
|
1308
|
-
if (bridges.find(
|
1309
|
-
return
|
1305
|
+
if (bridges.find((b) => b.id == bridge.id && b.level == bridge.level)) {
|
1306
|
+
return
|
1310
1307
|
}
|
1311
1308
|
}
|
1312
1309
|
if (global.transitoryMode) {
|
@@ -1314,7 +1311,7 @@ class Config {
|
|
1314
1311
|
}
|
1315
1312
|
handleBridgeProps(this, def)
|
1316
1313
|
bridges.push(def)
|
1317
|
-
this.checkBridges()
|
1314
|
+
this.checkBridges()
|
1318
1315
|
this._delta.json.bridges.push({ action: 'add', bridge: def })
|
1319
1316
|
}
|
1320
1317
|
|
@@ -1362,8 +1359,8 @@ class Config {
|
|
1362
1359
|
semantics.unshift(semantic)
|
1363
1360
|
}
|
1364
1361
|
|
1365
|
-
removeSemantic(deleteSemantic) {
|
1366
|
-
const index = this.config.semantics.findIndex(
|
1362
|
+
removeSemantic (deleteSemantic) {
|
1363
|
+
const index = this.config.semantics.findIndex((semantic) => semantic.id === deleteSemantic.id)
|
1367
1364
|
if (index >= 0) {
|
1368
1365
|
this.config.semantics.splice(index, 1)
|
1369
1366
|
}
|
@@ -1376,7 +1373,7 @@ class Config {
|
|
1376
1373
|
|
1377
1374
|
const operators = this.config.operators
|
1378
1375
|
|
1379
|
-
let operator
|
1376
|
+
let operator
|
1380
1377
|
if (typeof objectOrPattern === 'string') {
|
1381
1378
|
operator = { pattern: objectOrPattern, uuid: uuid || this._uuid }
|
1382
1379
|
} else {
|
@@ -1386,8 +1383,8 @@ class Config {
|
|
1386
1383
|
debugOperator(operator)
|
1387
1384
|
|
1388
1385
|
if (operator.allowDups) {
|
1389
|
-
if (operators.find(
|
1390
|
-
return
|
1386
|
+
if (operators.find((o) => o.pattern == operator.pattern)) {
|
1387
|
+
return
|
1391
1388
|
}
|
1392
1389
|
}
|
1393
1390
|
|
@@ -1446,19 +1443,19 @@ class Config {
|
|
1446
1443
|
}
|
1447
1444
|
}
|
1448
1445
|
|
1449
|
-
getServer() {
|
1446
|
+
getServer () {
|
1450
1447
|
return this._server
|
1451
1448
|
}
|
1452
1449
|
|
1453
|
-
getAPIKey() {
|
1450
|
+
getAPIKey () {
|
1454
1451
|
return this._key
|
1455
1452
|
}
|
1456
1453
|
|
1457
|
-
getQueryParams() {
|
1454
|
+
getQueryParams () {
|
1458
1455
|
return this._queryParams
|
1459
1456
|
}
|
1460
1457
|
|
1461
|
-
setQueryParams(queryParams) {
|
1458
|
+
setQueryParams (queryParams) {
|
1462
1459
|
this._queryParams = queryParams
|
1463
1460
|
}
|
1464
1461
|
|
@@ -1566,14 +1563,14 @@ class Config {
|
|
1566
1563
|
}
|
1567
1564
|
|
1568
1565
|
getConfigs () {
|
1569
|
-
const configs = {}
|
1566
|
+
const configs = {}
|
1570
1567
|
configs[this.name] = this
|
1571
1568
|
for (const config of this.configs) {
|
1572
1569
|
if (config.config instanceof Config) {
|
1573
1570
|
configs[config.config.name] = config.config
|
1574
1571
|
}
|
1575
1572
|
}
|
1576
|
-
return configs
|
1573
|
+
return configs
|
1577
1574
|
}
|
1578
1575
|
|
1579
1576
|
getConfigByUUID (uuid) {
|
@@ -1602,18 +1599,18 @@ class Config {
|
|
1602
1599
|
}
|
1603
1600
|
}
|
1604
1601
|
|
1605
|
-
removeDevelopmentElements(config) {
|
1602
|
+
removeDevelopmentElements (config) {
|
1606
1603
|
if (!config) {
|
1607
1604
|
return
|
1608
1605
|
}
|
1609
|
-
config.operators = config.operators.filter(
|
1610
|
-
config.bridges = config.bridges.filter(
|
1611
|
-
config.generators = config.generators.filter(
|
1612
|
-
config.semantics = config.semantics.filter(
|
1613
|
-
config.hierarchy = (config.hierarchy).filter(
|
1606
|
+
config.operators = config.operators.filter((element) => !element.development)
|
1607
|
+
config.bridges = config.bridges.filter((element) => !element.development)
|
1608
|
+
config.generators = config.generators.filter((element) => !element.development)
|
1609
|
+
config.semantics = config.semantics.filter((element) => !element.development)
|
1610
|
+
config.hierarchy = (config.hierarchy).filter((element) => !element.development)
|
1614
1611
|
for (const word in config.words) {
|
1615
1612
|
const defs = config.words[word] || []
|
1616
|
-
config.words[word] = defs.filter(
|
1613
|
+
config.words[word] = defs.filter((def) => !def.development)
|
1617
1614
|
if (config.words[word].length == 0) {
|
1618
1615
|
delete config.words[word]
|
1619
1616
|
}
|
@@ -1736,11 +1733,11 @@ class Config {
|
|
1736
1733
|
debugConfigProps(this.config)
|
1737
1734
|
}
|
1738
1735
|
|
1739
|
-
addArgs(moreArgs) {
|
1736
|
+
addArgs (moreArgs) {
|
1740
1737
|
this.addedArgss.push(moreArgs)
|
1741
1738
|
}
|
1742
1739
|
|
1743
|
-
getAddedArgs(args) {
|
1740
|
+
getAddedArgs (args) {
|
1744
1741
|
for (let addedArgs of this.addedArgss) {
|
1745
1742
|
addedArgs = addedArgs(args)
|
1746
1743
|
Object.assign(args, addedArgs)
|
@@ -1764,9 +1761,9 @@ class Config {
|
|
1764
1761
|
}
|
1765
1762
|
|
1766
1763
|
delta () {
|
1767
|
-
return {
|
1768
|
-
cacheKey: this._delta.cacheKey,
|
1769
|
-
json: this._delta.json
|
1764
|
+
return {
|
1765
|
+
cacheKey: this._delta.cacheKey,
|
1766
|
+
json: this._delta.json
|
1770
1767
|
}
|
1771
1768
|
}
|
1772
1769
|
|
@@ -1779,7 +1776,7 @@ class Config {
|
|
1779
1776
|
bridges: [],
|
1780
1777
|
associations: [],
|
1781
1778
|
priorities: [],
|
1782
|
-
hierarchy: []
|
1779
|
+
hierarchy: []
|
1783
1780
|
}
|
1784
1781
|
}
|
1785
1782
|
}
|
@@ -1796,11 +1793,11 @@ class Config {
|
|
1796
1793
|
}
|
1797
1794
|
}
|
1798
1795
|
|
1799
|
-
addAPI(api) {
|
1796
|
+
addAPI (api) {
|
1800
1797
|
if (this._api && this._api.multiApi) {
|
1801
1798
|
this._api.add(this, this._api, api)
|
1802
1799
|
} else {
|
1803
|
-
throw new Error(
|
1800
|
+
throw new Error('Can only add apis to a multi-api')
|
1804
1801
|
}
|
1805
1802
|
}
|
1806
1803
|
|
@@ -1863,15 +1860,15 @@ class Config {
|
|
1863
1860
|
}
|
1864
1861
|
|
1865
1862
|
// TODO add more details
|
1866
|
-
equal(config) {
|
1863
|
+
equal (config) {
|
1867
1864
|
if (JSON.stringify(this.config) != JSON.stringify(config.config)) {
|
1868
|
-
debugger
|
1869
|
-
return false
|
1865
|
+
debugger
|
1866
|
+
return false
|
1870
1867
|
}
|
1871
1868
|
return true
|
1872
1869
|
}
|
1873
1870
|
|
1874
|
-
dump(fn) {
|
1871
|
+
dump (fn) {
|
1875
1872
|
runtime.fs.writeFileSync(fn, JSON.stringify(this.config, 0, 2))
|
1876
1873
|
}
|
1877
1874
|
|
@@ -1883,7 +1880,7 @@ class Config {
|
|
1883
1880
|
const cp = new Config()
|
1884
1881
|
cp.logs = []
|
1885
1882
|
cp.maxDepth = this.maxDepth
|
1886
|
-
cp.debugLoops
|
1883
|
+
cp.debugLoops = this.debugLoops
|
1887
1884
|
cp.transitoryMode = this.transitoryMode
|
1888
1885
|
cp.configs = this.configs.map((km) => km.copy2(Object.assign({}, options, { getCounter: (name) => cp.getCounter(name), callInitializers: false })))
|
1889
1886
|
cp._uuid = cp.configs[0]._uuid
|
@@ -1920,7 +1917,7 @@ class Config {
|
|
1920
1917
|
cp.mapUUIDs(map)
|
1921
1918
|
|
1922
1919
|
if (cp._uuid == 'concept2') {
|
1923
|
-
|
1920
|
+
// debugger
|
1924
1921
|
}
|
1925
1922
|
if (options.callInitializers) {
|
1926
1923
|
cp.rebuild(options)
|
@@ -1943,7 +1940,7 @@ class Config {
|
|
1943
1940
|
// const namespace = km.namespace
|
1944
1941
|
cp.config.objects.namespaced[km._uuid] = {}
|
1945
1942
|
})
|
1946
|
-
/*
|
1943
|
+
/*
|
1947
1944
|
if (cp._uuid == 'concept2') {
|
1948
1945
|
if (!cp.api.objects.defaultTypesForHierarchy) {
|
1949
1946
|
debugger
|
@@ -2083,7 +2080,7 @@ class Config {
|
|
2083
2080
|
|
2084
2081
|
initializer (fn, options = {}) {
|
2085
2082
|
if (options) {
|
2086
|
-
for (
|
2083
|
+
for (const option of Object.keys(options)) {
|
2087
2084
|
const validOptions = []
|
2088
2085
|
if (!validOptions.includes(option)) {
|
2089
2086
|
throw new Error(`For Config.initializer, unrecognized option ${option}. The valid options are ${validOptions}`)
|
@@ -2249,7 +2246,7 @@ class Config {
|
|
2249
2246
|
// rebuild ({ isModule: mainIsModule = false } = {}) {
|
2250
2247
|
rebuild ({ isModule: mainIsModule } = {}) {
|
2251
2248
|
this.resetDelta()
|
2252
|
-
const debug = this.config.debug
|
2249
|
+
const debug = this.config.debug
|
2253
2250
|
this.config = _.cloneDeep(this.initConfig)
|
2254
2251
|
this.hierarchy = new DigraphInternal(this.config.hierarchy)
|
2255
2252
|
if (debug) {
|
@@ -2292,8 +2289,8 @@ class Config {
|
|
2292
2289
|
// const aw = (word, def) => this.addWord(word, def)
|
2293
2290
|
// const ag = (matchOrGenerator, applyOrNothing) => this.addGenerator(matchOrGenerator, applyOrNothing)
|
2294
2291
|
let config = km.config
|
2295
|
-
|
2296
|
-
if (config.addedArgss) {
|
2292
|
+
|
2293
|
+
if (config.addedArgss) {
|
2297
2294
|
this.addedArgss = this.addedArgss.concat(config.addedArgss)
|
2298
2295
|
}
|
2299
2296
|
|
@@ -2316,15 +2313,15 @@ class Config {
|
|
2316
2313
|
return config
|
2317
2314
|
}
|
2318
2315
|
// const hierarchy = new DigraphInternal((config.config || {}).hierarchy)
|
2319
|
-
const args = new Object(setupInitializerFNArgs(this, {
|
2320
|
-
isModule,
|
2321
|
-
hierarchy: this.hierarchy,
|
2316
|
+
const args = new Object(setupInitializerFNArgs(this, {
|
2317
|
+
isModule,
|
2318
|
+
hierarchy: this.hierarchy,
|
2322
2319
|
testConfig: config,
|
2323
|
-
currentConfig: config,
|
2324
|
-
uuid: config._uuid,
|
2325
|
-
objects: namespacedObjects,
|
2326
|
-
namespace,
|
2327
|
-
api: config.api
|
2320
|
+
currentConfig: config,
|
2321
|
+
uuid: config._uuid,
|
2322
|
+
objects: namespacedObjects,
|
2323
|
+
namespace,
|
2324
|
+
api: config.api
|
2328
2325
|
}))
|
2329
2326
|
|
2330
2327
|
const currentConfig = args.currentConfig
|
@@ -2341,12 +2338,12 @@ class Config {
|
|
2341
2338
|
// debugger
|
2342
2339
|
// greg55
|
2343
2340
|
config.initializerFn(args, { dontCallFn: true })
|
2344
|
-
|
2341
|
+
initAfterApis.unshift({ config, args })
|
2345
2342
|
if (config._api) {
|
2346
2343
|
if (config._api.initialize) {
|
2347
2344
|
// reverse the list
|
2348
2345
|
// TODO sync up the args with initialize of config
|
2349
|
-
inits.unshift(
|
2346
|
+
inits.unshift(() => config._api.initialize({ config: this, km: kmFn, ...args, api: config._api }))
|
2350
2347
|
// config._api.initialize({ config, api: config._api })
|
2351
2348
|
} else {
|
2352
2349
|
inits.unshift(null)
|
@@ -2388,13 +2385,13 @@ class Config {
|
|
2388
2385
|
this.config.priorities = []
|
2389
2386
|
this.config.associations = { positive: [], negative: [] }
|
2390
2387
|
this.config.words = {}
|
2391
|
-
|
2388
|
+
|
2392
2389
|
for (let i = 0; i < addInternals.length; ++i) {
|
2393
|
-
let name
|
2390
|
+
let name
|
2394
2391
|
if (addInternals[i]) {
|
2395
2392
|
this.addInternalR(addInternals[i], true, false, false, true)
|
2396
2393
|
name = addInternals[i].name
|
2397
|
-
} else{
|
2394
|
+
} else {
|
2398
2395
|
// the ones defined in config must come after the ones in the templates
|
2399
2396
|
this.config.generators = generators.concat(this.config.generators)
|
2400
2397
|
this.config.semantics = semantics.concat(this.config.semantics)
|
@@ -2408,7 +2405,7 @@ class Config {
|
|
2408
2405
|
}
|
2409
2406
|
if (initAfterApis[i]) {
|
2410
2407
|
const init = initAfterApis[i]
|
2411
|
-
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true})
|
2408
|
+
init.config.initializerFn({ ...init.args, kms: this.getConfigs(), isAfterApi: true })
|
2412
2409
|
}
|
2413
2410
|
const instance = this.instances.find((instance) => instance.name == name)
|
2414
2411
|
if (instance) {
|
@@ -2423,9 +2420,10 @@ class Config {
|
|
2423
2420
|
this.checkBridges()
|
2424
2421
|
}
|
2425
2422
|
|
2426
|
-
nameToUUID(name) {
|
2423
|
+
nameToUUID (name) {
|
2427
2424
|
return this.configs.find((km) => km._name == name)._uuid
|
2428
2425
|
}
|
2426
|
+
|
2429
2427
|
// name: namespace name
|
2430
2428
|
// others
|
2431
2429
|
// if undefined namespace applies to first loaded config
|
@@ -2602,7 +2600,7 @@ class Config {
|
|
2602
2600
|
context: context.map((id) => {
|
2603
2601
|
return [toNS(id[0]), id[1]]
|
2604
2602
|
}),
|
2605
|
-
choose
|
2603
|
+
choose
|
2606
2604
|
}
|
2607
2605
|
if (ordered) {
|
2608
2606
|
priority.ordered = ordered
|
@@ -2627,7 +2625,7 @@ class Config {
|
|
2627
2625
|
}
|
2628
2626
|
|
2629
2627
|
const seen = {}
|
2630
|
-
for (
|
2628
|
+
for (const operator of this.config.operators) {
|
2631
2629
|
if (seen[operator.pattern]) {
|
2632
2630
|
const key = `${operator.pattern} (namespace: ${operator.uuid})`
|
2633
2631
|
throw new Error(`Operator '${key}' is defined more than once in the operators`)
|
@@ -2700,10 +2698,10 @@ class Config {
|
|
2700
2698
|
throw new Error(`Setting invalid property ${property}`)
|
2701
2699
|
}
|
2702
2700
|
|
2703
|
-
if ('words'
|
2704
|
-
for (
|
2705
|
-
for (
|
2706
|
-
if (!def
|
2701
|
+
if (property == 'words') {
|
2702
|
+
for (const word in value) {
|
2703
|
+
for (const def of value[word]) {
|
2704
|
+
if (!def.uuid) {
|
2707
2705
|
throw new Error(`All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)} for the word '${word}'`)
|
2708
2706
|
}
|
2709
2707
|
}
|
@@ -2711,8 +2709,8 @@ class Config {
|
|
2711
2709
|
}
|
2712
2710
|
|
2713
2711
|
if (['operators', 'bridges'].includes(property)) {
|
2714
|
-
for (
|
2715
|
-
if (!def
|
2712
|
+
for (const def of value) {
|
2713
|
+
if (!def.uuid) {
|
2716
2714
|
throw new Error(`All definitions for '${property}' must have the uuid property set (config.uuid). uuid is missing from ${JSON.stringify(def)}`)
|
2717
2715
|
}
|
2718
2716
|
}
|
@@ -2792,9 +2790,9 @@ class Config {
|
|
2792
2790
|
this.configs.forEach((km) => {
|
2793
2791
|
this.instances = (km._config.instances || this.initInstances.slice()).concat(this.instances)
|
2794
2792
|
})
|
2795
|
-
|
2796
|
-
for (
|
2797
|
-
if (!noDups.find(
|
2793
|
+
const noDups = []
|
2794
|
+
for (const instance of this.instances) {
|
2795
|
+
if (!noDups.find((existing) => existing.name == instance.name)) {
|
2798
2796
|
noDups.push(instance)
|
2799
2797
|
}
|
2800
2798
|
}
|
@@ -2806,7 +2804,7 @@ class Config {
|
|
2806
2804
|
}
|
2807
2805
|
|
2808
2806
|
// TODO get rid of useOldVersion arg
|
2809
|
-
addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps
|
2807
|
+
addInternal (more, { uuid, addFirst = false, useOldVersion = true, skipObjects = false, includeNamespaces = true, allowNameToBeNull = false, handleCalculatedProps: hcps = false } = {}) {
|
2810
2808
|
validConfigProps(more)
|
2811
2809
|
if (more instanceof Config) {
|
2812
2810
|
more.initialize({ force: false })
|
@@ -2888,12 +2886,12 @@ class Config {
|
|
2888
2886
|
const isDup = (op1, op2) => op1.pattern == op2.pattern
|
2889
2887
|
for (const newOne of more[key]) {
|
2890
2888
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
2891
|
-
const oldOne = this.config[key][iOldOne]
|
2889
|
+
const oldOne = this.config[key][iOldOne]
|
2892
2890
|
if (isDup(newOne, oldOne)) {
|
2893
2891
|
if (oldOne.allowDups) {
|
2894
2892
|
// the old one takes precedence to match what would happen during the original load
|
2895
2893
|
this.config[key].splice(iOldOne, 1)
|
2896
|
-
break
|
2894
|
+
break
|
2897
2895
|
}
|
2898
2896
|
}
|
2899
2897
|
}
|
@@ -2904,14 +2902,14 @@ class Config {
|
|
2904
2902
|
const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
|
2905
2903
|
for (const newOne of more[key]) {
|
2906
2904
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
2907
|
-
const oldOne = this.config[key][iOldOne]
|
2905
|
+
const oldOne = this.config[key][iOldOne]
|
2908
2906
|
if (newOne.id == oldOne.id) {
|
2909
2907
|
if (oldOne.allowDups) {
|
2910
2908
|
// the old one takes precedence to match what would happen during the original load
|
2911
2909
|
this.config[key].splice(iOldOne, 1)
|
2912
|
-
break
|
2910
|
+
break
|
2913
2911
|
}
|
2914
|
-
}
|
2912
|
+
}
|
2915
2913
|
}
|
2916
2914
|
}
|
2917
2915
|
}
|
@@ -3009,12 +3007,12 @@ class Config {
|
|
3009
3007
|
const isDup = (op1, op2) => op1.pattern == op2.pattern
|
3010
3008
|
for (const newOne of more[key]) {
|
3011
3009
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
3012
|
-
const oldOne = this.config[key][iOldOne]
|
3010
|
+
const oldOne = this.config[key][iOldOne]
|
3013
3011
|
if (isDup(newOne, oldOne)) {
|
3014
3012
|
if (oldOne.allowDups) {
|
3015
3013
|
// the old one takes precedence to match what would happen during the original load
|
3016
3014
|
this.config[key].splice(iOldOne, 1)
|
3017
|
-
break
|
3015
|
+
break
|
3018
3016
|
}
|
3019
3017
|
}
|
3020
3018
|
}
|
@@ -3025,12 +3023,12 @@ class Config {
|
|
3025
3023
|
const idDup = (b1, b2) => b1.id == b2.id && b1.level == b2.level && b1.bridge == b2.bridge
|
3026
3024
|
for (const newOne of more[key]) {
|
3027
3025
|
for (let iOldOne = 0; iOldOne < this.config[key].length; ++iOldOne) {
|
3028
|
-
const oldOne = this.config[key][iOldOne]
|
3026
|
+
const oldOne = this.config[key][iOldOne]
|
3029
3027
|
if (newOne.id == oldOne.id) {
|
3030
3028
|
if (oldOne.allowDups) {
|
3031
3029
|
// the old one takes precedence to match what would happen during the original load
|
3032
3030
|
this.config[key].splice(iOldOne, 1)
|
3033
|
-
break
|
3031
|
+
break
|
3034
3032
|
}
|
3035
3033
|
}
|
3036
3034
|
}
|
@@ -3056,5 +3054,5 @@ module.exports = {
|
|
3056
3054
|
Config,
|
3057
3055
|
config_toServer,
|
3058
3056
|
operatorKey_valid,
|
3059
|
-
handleBridgeProps
|
3057
|
+
handleBridgeProps
|
3060
3058
|
}
|