theprogrammablemind_4wp 9.3.0 → 9.4.1
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 +79 -69
- package/demo.js +2 -2
- package/package.json +2 -1
- package/src/config.js +135 -91
- package/src/configHelpers.js +14 -9
- package/src/debug.js +2 -2
- package/src/digraph.js +2 -2
- package/src/digraph_internal.js +2 -2
- package/src/flatten.js +1 -1
- package/src/generators.js +6 -6
- package/src/helpers.js +16 -15
- package/src/project.js +25 -2
- package/src/project2.js +54 -0
- package/src/semantics.js +4 -4
- package/src/unflatten.js +1 -1
package/src/digraph.js
CHANGED
@@ -22,7 +22,7 @@ class Digraph {
|
|
22
22
|
while (Object.keys(frontier).length > 0) {
|
23
23
|
const n = Object.keys(frontier)[0]
|
24
24
|
const ps = frontier[n]
|
25
|
-
if (to
|
25
|
+
if (to === n) {
|
26
26
|
return ps[0]
|
27
27
|
}
|
28
28
|
if (done.has(n)) {
|
@@ -184,7 +184,7 @@ class Digraph {
|
|
184
184
|
}
|
185
185
|
|
186
186
|
exists (child, parent) {
|
187
|
-
return this._edges.find((edge) => edge[0]
|
187
|
+
return this._edges.find((edge) => edge[0] === child && edge[1] === parent)
|
188
188
|
}
|
189
189
|
|
190
190
|
addList (l) {
|
package/src/digraph_internal.js
CHANGED
@@ -24,7 +24,7 @@ class DigraphInternal {
|
|
24
24
|
addEdge (edge) {
|
25
25
|
edge = toA(edge)
|
26
26
|
// if (this._edges.find((existing) => _.isEqual(edge, existing))) {
|
27
|
-
if (this._edges.find((existing) => edge[0]
|
27
|
+
if (this._edges.find((existing) => edge[0] === existing[0] && edge[1] === existing[1])) {
|
28
28
|
return false
|
29
29
|
}
|
30
30
|
this._edges.push(edge)
|
@@ -154,7 +154,7 @@ class DigraphInternal {
|
|
154
154
|
}
|
155
155
|
|
156
156
|
exists (child, parent) {
|
157
|
-
return this._edges.findIndex((edge) => edge[0]
|
157
|
+
return this._edges.findIndex((edge) => edge[0] === child && edge[1] === parent) != -1
|
158
158
|
}
|
159
159
|
|
160
160
|
addList (l) {
|
package/src/flatten.js
CHANGED
@@ -92,7 +92,7 @@ const flatten = (markers, value) => {
|
|
92
92
|
const split = markers.includes(marker)
|
93
93
|
if (split) {
|
94
94
|
if ('value' in properties) {
|
95
|
-
flattenedValues = []
|
95
|
+
let flattenedValues = []
|
96
96
|
for (const v of properties.value) {
|
97
97
|
if (v.flatten) {
|
98
98
|
flattenedValues = flattenedValues.concat(flatten(markers, v)[0])
|
package/src/generators.js
CHANGED
@@ -65,7 +65,7 @@ class Generator {
|
|
65
65
|
// return this.match(args)
|
66
66
|
const matches = await this.match(args)
|
67
67
|
if ((matches && (options.debug || {}).match) ||
|
68
|
-
callId
|
68
|
+
callId === this.callId) {
|
69
69
|
// next line is the matcher
|
70
70
|
debugger // eslint-disable-line no-debugger
|
71
71
|
await this.match(args)
|
@@ -78,7 +78,7 @@ class Generator {
|
|
78
78
|
if (!log) {
|
79
79
|
throw new Error('generators.apply argument log is required')
|
80
80
|
}
|
81
|
-
if (baseArgs.call && config &&
|
81
|
+
if (baseArgs.call && config && baseArgs.calls.stack.length > config.maxDepth) {
|
82
82
|
throw new Error(`Max depth of ${config.maxDepth} for calls has been exceeded. maxDepth can be set on the config object. To see the calls run with the --dl or set the debugLoops property on the config`)
|
83
83
|
}
|
84
84
|
|
@@ -116,11 +116,11 @@ class Generator {
|
|
116
116
|
apis: this.getAPIs(config)
|
117
117
|
}
|
118
118
|
const args = Object.assign({}, baseArgs, moreArgs, (baseArgs.getUUIDScoped || (() => { return {} }))(this.uuid))
|
119
|
-
if (this.property
|
119
|
+
if (this.property === 'generatorp') {
|
120
120
|
args.g = args.gp
|
121
121
|
}
|
122
122
|
if ((options.debug || {}).apply ||
|
123
|
-
callId
|
123
|
+
callId === this.callId) {
|
124
124
|
debugger // eslint-disable-line no-debugger
|
125
125
|
}
|
126
126
|
return await this._apply(args)
|
@@ -218,7 +218,7 @@ class Generators {
|
|
218
218
|
lines.setElement(0, 2, stack)
|
219
219
|
lines.newRow()
|
220
220
|
lines.setElement(0, 1, 'DEBUG')
|
221
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
221
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
222
222
|
lines.newRow()
|
223
223
|
lines.setElement(0, 1, 'ERROR')
|
224
224
|
lines.setElement(0, 2, errorMessage)
|
@@ -250,7 +250,7 @@ class Generators {
|
|
250
250
|
lines.setElement(0, 2, stack)
|
251
251
|
lines.newRow()
|
252
252
|
lines.setElement(0, 1, 'DEBUG')
|
253
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
253
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
254
254
|
lines.newRow()
|
255
255
|
lines.setElement(0, 1, 'TO')
|
256
256
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
package/src/helpers.js
CHANGED
@@ -97,7 +97,7 @@ const appendNoDups = (l1, l2) => {
|
|
97
97
|
}
|
98
98
|
|
99
99
|
const safeNoDups = (list) => {
|
100
|
-
noDups = []
|
100
|
+
const noDups = []
|
101
101
|
for (const element of list) {
|
102
102
|
if (!noDups.find((e) => safeEquals(e, element))) {
|
103
103
|
noDups.push(element)
|
@@ -112,14 +112,14 @@ const safeEquals = (v1, v2) => {
|
|
112
112
|
}
|
113
113
|
|
114
114
|
const type = typeof v1
|
115
|
-
if (type
|
116
|
-
return v1
|
117
|
-
} else if (type
|
118
|
-
return v1.toString()
|
115
|
+
if (type === 'number' || type === 'string') {
|
116
|
+
return v1 === v2
|
117
|
+
} else if (type === 'function') {
|
118
|
+
return v1.toString() === v2.toString()
|
119
119
|
} else if (v1 == undefined || v2 == undefined) {
|
120
|
-
return v1
|
120
|
+
return v1 === v2
|
121
121
|
} else {
|
122
|
-
if (v1.length
|
122
|
+
if (v1.length !== v2.length) {
|
123
123
|
return false
|
124
124
|
}
|
125
125
|
for (const key in v1) {
|
@@ -148,7 +148,7 @@ const semanticsGenerate = (from, known) => {
|
|
148
148
|
}
|
149
149
|
|
150
150
|
return {
|
151
|
-
match: ({context}) => marker
|
151
|
+
match: ({context}) => marker === marker,
|
152
152
|
apply: ({context}) => {
|
153
153
|
},
|
154
154
|
}
|
@@ -299,9 +299,9 @@ const sortJson = (json) => {
|
|
299
299
|
const validProps = (valids, object, type) => {
|
300
300
|
for (const prop of Object.keys(object)) {
|
301
301
|
let okay = false
|
302
|
-
for (valid of valids) {
|
302
|
+
for (const valid of valids) {
|
303
303
|
if (typeof valid === 'string') {
|
304
|
-
okay = prop
|
304
|
+
okay = prop === valid
|
305
305
|
} else {
|
306
306
|
okay = prop.match(valid)
|
307
307
|
}
|
@@ -310,6 +310,7 @@ const validProps = (valids, object, type) => {
|
|
310
310
|
}
|
311
311
|
}
|
312
312
|
if (!okay) {
|
313
|
+
valids.sort()
|
313
314
|
throw new Error(`Unknown property "${prop}" in the ${type}. Valid properties are ${valids.join(', ')}. The ${type} is ${JSON.stringify(object)}`)
|
314
315
|
}
|
315
316
|
}
|
@@ -334,7 +335,7 @@ const updateQueries = (queryOrConfig) => {
|
|
334
335
|
|
335
336
|
const functionsToStrings = (config) => {
|
336
337
|
config = { ...config }
|
337
|
-
defToStrings = (def) => {
|
338
|
+
const defToStrings = (def) => {
|
338
339
|
if (def.apply) {
|
339
340
|
// return { ...def, match: def.match.toString(), apply: def.apply.toString() }
|
340
341
|
return { match: def.match.toString(), apply: def.apply.toString() }
|
@@ -390,7 +391,7 @@ const ecatch = (where, call) => {
|
|
390
391
|
}
|
391
392
|
|
392
393
|
const equalKey = (key1, key2) => {
|
393
|
-
return key1[0]
|
394
|
+
return key1[0] === key2[0] && key1[1] === key2[1]
|
394
395
|
}
|
395
396
|
|
396
397
|
// matches for { context: ..., [ordered], choose: ... } exactely OR
|
@@ -399,8 +400,8 @@ const subPriority = (sub, sup) => {
|
|
399
400
|
if (Array.isArray(sub)) {
|
400
401
|
const subChoosen = sub[0]
|
401
402
|
const subOther = sub[1]
|
402
|
-
const hasChoosen = sup.choose.find((index) => equalKey(sup.context[index], subChoosen))
|
403
|
-
const hasOtherChosen = sup.choose.find((index) => equalKey(sup.context[index], subOther))
|
403
|
+
const hasChoosen = sup.choose.find((index) => equalKey(sup.context[index], subChoosen)) !== undefined
|
404
|
+
const hasOtherChosen = sup.choose.find((index) => equalKey(sup.context[index], subOther)) !== undefined
|
404
405
|
const hasOther = sup.context.find((other) => equalKey(other, subOther)) !== undefined
|
405
406
|
return !!(hasChoosen && hasOther) && !hasOtherChosen
|
406
407
|
}
|
@@ -418,7 +419,7 @@ const subPriority = (sub, sup) => {
|
|
418
419
|
}
|
419
420
|
const chosen1 = choose(sub)
|
420
421
|
const chosen2 = choose(sup)
|
421
|
-
const sameId = (id1, id2) => id1[0]
|
422
|
+
const sameId = (id1, id2) => id1[0] === id2[0] && id1[1] === id2[1]
|
422
423
|
// same length so only need one way
|
423
424
|
const missing1 = chosen1.find((id1) => !chosen2.find((id2) => sameId(id1, id2)))
|
424
425
|
if (missing1) {
|
package/src/project.js
CHANGED
@@ -1,15 +1,38 @@
|
|
1
|
+
function isObject(value) {
|
2
|
+
return typeof value === "object" && value !== null;
|
3
|
+
}
|
4
|
+
|
5
|
+
const merge = (value1, value2) => {
|
6
|
+
if (Array.isArray(value1) && Array.isArray(value2)) {
|
7
|
+
const merged = []
|
8
|
+
for (let i = 0; i < value1.length; ++i) {
|
9
|
+
merged.push(merge(value1[i], value2[i]))
|
10
|
+
}
|
11
|
+
return merged
|
12
|
+
}
|
13
|
+
if (isObject(value1) && isObject(value2)) {
|
14
|
+
return Object.assign({}, value1, value2)
|
15
|
+
}
|
16
|
+
}
|
1
17
|
|
2
18
|
const project = (object, filter) => {
|
3
19
|
if (!object) {
|
4
20
|
return
|
5
21
|
}
|
22
|
+
if (typeof object === 'string' || typeof object === 'number') {
|
23
|
+
return object
|
24
|
+
}
|
6
25
|
|
7
26
|
const projection = {}
|
8
27
|
const set = (property, value) => {
|
9
28
|
if (value === null || value === undefined) {
|
10
29
|
return
|
11
30
|
}
|
12
|
-
projection[property]
|
31
|
+
if (projection[property]) {
|
32
|
+
projection[property] = merge(value, projection[property])
|
33
|
+
} else {
|
34
|
+
projection[property] = value
|
35
|
+
}
|
13
36
|
}
|
14
37
|
if (Array.isArray(filter)) {
|
15
38
|
if (Array.isArray(object)) {
|
@@ -78,4 +101,4 @@ const project = (object, filter) => {
|
|
78
101
|
return projection
|
79
102
|
}
|
80
103
|
|
81
|
-
module.exports = { project }
|
104
|
+
module.exports = { project, merge }
|
package/src/project2.js
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
function project(source, filters) {
|
2
|
+
if (['string', 'number'].includes(typeof source)) {
|
3
|
+
return source
|
4
|
+
}
|
5
|
+
|
6
|
+
if (Object.keys(source).length === 0 && filters.length === 0) {
|
7
|
+
return {};
|
8
|
+
}
|
9
|
+
|
10
|
+
// Find the applicable filter for the current context
|
11
|
+
const filter = filters.find(f => f.match({ context: source }));
|
12
|
+
if (!filter) {
|
13
|
+
if (Array.isArray(source)) {
|
14
|
+
return source.map((element) => project(element, filters))
|
15
|
+
}
|
16
|
+
return {};
|
17
|
+
}
|
18
|
+
|
19
|
+
// Get the properties to include from the apply function
|
20
|
+
let properties = filter.apply(source);
|
21
|
+
|
22
|
+
// update
|
23
|
+
const updatedProperties = []
|
24
|
+
for (const property of properties) {
|
25
|
+
if (property.properties) {
|
26
|
+
for (const moreProperty of source[property.properties] || []) {
|
27
|
+
updatedProperties.push(moreProperty)
|
28
|
+
}
|
29
|
+
} else {
|
30
|
+
updatedProperties.push(property)
|
31
|
+
}
|
32
|
+
}
|
33
|
+
properties = updatedProperties
|
34
|
+
|
35
|
+
// Build the result object
|
36
|
+
const result = {};
|
37
|
+
properties.forEach(prop => {
|
38
|
+
if (source.hasOwnProperty(prop)) {
|
39
|
+
// If the property is an object and not null, recursively project it
|
40
|
+
if (typeof source[prop] === 'object' && source[prop] !== null) {
|
41
|
+
result[prop] = project(source[prop], filters);
|
42
|
+
} else {
|
43
|
+
// Copy primitive or null properties directly
|
44
|
+
result[prop] = source[prop];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
});
|
48
|
+
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
|
52
|
+
module.exports = {
|
53
|
+
project
|
54
|
+
}
|
package/src/semantics.js
CHANGED
@@ -72,7 +72,7 @@ class Semantic {
|
|
72
72
|
async matches (args, context, options = {}) {
|
73
73
|
this.fixUpArgs(args, context)
|
74
74
|
const matches = await this.matcher(args)
|
75
|
-
if (matches && (options.debug || {}).match || args.callId
|
75
|
+
if (matches && (options.debug || {}).match || args.callId === this.callId) {
|
76
76
|
// next line is the matcher
|
77
77
|
debugger // eslint-disable-line no-debugger
|
78
78
|
await this.matcher(args)
|
@@ -92,7 +92,7 @@ class Semantic {
|
|
92
92
|
const contextPrime = Object.assign({}, context)
|
93
93
|
this.fixUpArgs(args, contextPrime)
|
94
94
|
|
95
|
-
if ((options.debug || {}).apply || args.callId
|
95
|
+
if ((options.debug || {}).apply || args.callId === this.callId) {
|
96
96
|
debugger // eslint-disable-line no-debugger
|
97
97
|
}
|
98
98
|
if (args.breakOnSemantics) {
|
@@ -234,7 +234,7 @@ class Semantics {
|
|
234
234
|
lines.setElement(0, 2, stack)
|
235
235
|
lines.newRow()
|
236
236
|
lines.setElement(0, 1, 'DEBUG')
|
237
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
237
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
238
238
|
lines.newRow()
|
239
239
|
lines.setElement(0, 1, 'ERROR')
|
240
240
|
lines.setElement(0, 2, errorMessage)
|
@@ -269,7 +269,7 @@ class Semantics {
|
|
269
269
|
lines.setElement(0, 2, stack)
|
270
270
|
lines.newRow()
|
271
271
|
lines.setElement(0, 1, 'DEBUG')
|
272
|
-
lines.setElement(0, 2, `To debug this use args.callId
|
272
|
+
lines.setElement(0, 2, `To debug this use args.callId === '${args.calls.current()}'`)
|
273
273
|
lines.newRow()
|
274
274
|
lines.setElement(0, 1, 'RESULT')
|
275
275
|
lines.setElement(0, 2, `context_id: ${context.context_id}`)
|
package/src/unflatten.js
CHANGED
@@ -36,7 +36,7 @@ const concatLists = (l1, l2) => {
|
|
36
36
|
|
37
37
|
const findPropertyWithManyValues = (contexts, properties) => {
|
38
38
|
for (const property of properties) {
|
39
|
-
if (new Set(contexts.map((context) => context[property])).size
|
39
|
+
if (new Set(contexts.map((context) => context[property])).size === 1) {
|
40
40
|
return property
|
41
41
|
}
|
42
42
|
}
|