tpmkms_4wp 9.5.1 → 9.6.0

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.
Files changed (122) hide show
  1. package/common/animals.instance.json +21 -61
  2. package/common/asking.js +116 -106
  3. package/common/avatar.test.json +1001 -860
  4. package/common/can.instance.json +2174 -0
  5. package/common/can.js +254 -0
  6. package/common/can.test.json +51307 -0
  7. package/common/characters.js +5 -5
  8. package/common/colors.instance.json +12 -12
  9. package/common/comparable.instance.json +3 -3
  10. package/common/concept.js +25 -27
  11. package/common/concept.test.json +180 -144
  12. package/common/conjunction.js +13 -5
  13. package/common/conjunction.test.json +32 -42
  14. package/common/crew.instance.json +196 -160
  15. package/common/crew.js +1 -1
  16. package/common/crew.test.json +4148 -3324
  17. package/common/currency.js +1 -1
  18. package/common/dateTimeSelectors.instance.json +2 -2
  19. package/common/dateTimeSelectors.js +3 -3
  20. package/common/dateTimeSelectors.test.json +76935 -35739
  21. package/common/dates.instance.json +3 -3
  22. package/common/dates.test.json +284 -287
  23. package/common/dialogues.js +41 -119
  24. package/common/dialogues.test.json +1171 -996
  25. package/common/dimension.instance.json +21369 -557
  26. package/common/dimension.js +148 -54
  27. package/common/dimension.test.json +8753 -3495
  28. package/common/drone.instance.json +23712 -0
  29. package/common/drone.js +448 -0
  30. package/common/drone.test.json +66665 -0
  31. package/common/edible.instance.json +32 -32
  32. package/common/emotions.instance.json +75 -76
  33. package/common/emotions.js +1 -1
  34. package/common/emotions.test.json +242 -174
  35. package/common/english_helpers.js +336 -0
  36. package/common/errors.js +6 -6
  37. package/common/evaluate.js +2 -2
  38. package/common/events.js +8 -8
  39. package/common/fastfood.instance.json +389 -245
  40. package/common/fastfood.js +11 -11
  41. package/common/fastfood.test.json +6970 -6829
  42. package/common/formulas.instance.json +1 -1
  43. package/common/formulas.js +1 -1
  44. package/common/gdefaults.js +111 -17
  45. package/common/help.js +12 -12
  46. package/common/help.test.json +65 -11
  47. package/common/helpers/concept.js +1 -1
  48. package/common/helpers/conjunction.js +54 -44
  49. package/common/helpers/dateTimeSelectors.js +2 -2
  50. package/common/helpers/dialogues.js +7 -2
  51. package/common/helpers/formulas.js +13 -11
  52. package/common/helpers/menus.js +12 -12
  53. package/common/helpers/meta.js +9 -9
  54. package/common/helpers/properties.js +185 -62
  55. package/common/helpers.js +167 -48
  56. package/common/hierarchy.js +6 -4
  57. package/common/kirk.instance.json +1 -1
  58. package/common/kirk.test.json +600 -424
  59. package/common/latin.instance.json +12 -12
  60. package/common/latin.js +9 -9
  61. package/common/length.instance.json +27612 -2890
  62. package/common/length.js +6 -1
  63. package/common/length.test.json +45315 -3925
  64. package/common/math.instance.json +29 -29
  65. package/common/math.js +47 -46
  66. package/common/menus.instance.json +7 -10
  67. package/common/menus.js +2 -9
  68. package/common/meta.js +77 -60
  69. package/common/nameable.js +20 -13
  70. package/common/nameable.test.json +436 -0
  71. package/common/numbers.js +1 -1
  72. package/common/ordering.instance.json +87 -19
  73. package/common/ordering.js +1 -1
  74. package/common/ordering.test.json +835 -417
  75. package/common/people.instance.json +96 -348
  76. package/common/people.js +6 -4
  77. package/common/people.test.json +4135 -3606
  78. package/common/pipboy.instance.json +17 -17
  79. package/common/pipboy.js +2 -3
  80. package/common/pokemon.instance.json +13 -13
  81. package/common/pokemon.js +1 -1
  82. package/common/pressure.instance.json +3579 -1610
  83. package/common/pressure.test.json +433 -477
  84. package/common/properties.instance.json +6 -17
  85. package/common/properties.js +25 -7
  86. package/common/properties.test.json +9565 -6951
  87. package/common/rates.instance.json +59 -0
  88. package/common/rates.js +97 -0
  89. package/common/rates.test.json +27702 -0
  90. package/common/reminders.instance.json +4 -4
  91. package/common/reminders.js +5 -5
  92. package/common/reminders.test.json +64635 -25787
  93. package/common/reports.instance.json +3 -3
  94. package/common/reports.js +18 -16
  95. package/common/scorekeeper.js +6 -6
  96. package/common/sdefaults.js +22 -2
  97. package/common/spock.instance.json +1 -1
  98. package/common/spock.test.json +606 -430
  99. package/common/stgame.js +1 -1
  100. package/common/stm.js +17 -6
  101. package/common/tell.js +1 -1
  102. package/common/temperature.instance.json +3659 -1690
  103. package/common/temperature.test.json +433 -477
  104. package/common/tester.js +3 -3
  105. package/common/time.instance.json +24762 -0
  106. package/common/time.js +137 -141
  107. package/common/time.test.json +31876 -3757
  108. package/common/tokenize.js +5 -2
  109. package/common/ui.instance.json +2 -5
  110. package/common/ui.js +1 -8
  111. package/common/weight.instance.json +10360 -4078
  112. package/common/weight.test.json +2601 -2263
  113. package/common/words.instance.json +9 -0
  114. package/common/words.js +53 -0
  115. package/common/words.test.json +2 -0
  116. package/common/wp.instance.json +408 -8
  117. package/common/wp.js +8 -4
  118. package/common/wp.test.json +7385 -6906
  119. package/main.js +4 -2
  120. package/package.json +20 -5
  121. package/common/listener.js +0 -50
  122. package/common/listener.test.json +0 -142
package/common/helpers.js CHANGED
@@ -1,13 +1,14 @@
1
1
  const pluralize = require('pluralize')
2
+ const { flatten } = require('./runtime').theprogrammablemind
2
3
 
3
- const unshiftL = (list, element, max) => {
4
+ function unshiftL(list, element, max) {
4
5
  if (list.length >= max) {
5
6
  list.pop()
6
7
  }
7
8
  list.unshift(element)
8
9
  }
9
10
 
10
- const pushL = (list, element, max) => {
11
+ function pushL(list, element, max) {
11
12
  if (list.length >= max) {
12
13
  list.shift()
13
14
  }
@@ -15,11 +16,11 @@ const pushL = (list, element, max) => {
15
16
  }
16
17
 
17
18
  // X pm today or tomorrow
18
- const millisecondsUntilHourOfDay = (newDate, hour) => {
19
+ function millisecondsUntilHourOfDay(newDate, hour) {
19
20
  const now = newDate()
20
21
  const target = newDate(now)
21
22
 
22
- const addHours = (date, h) => {
23
+ function addHours(date, h) {
23
24
  date.setTime(date.getTime() + (h*60*60*1000));
24
25
  }
25
26
  const hours = target.getHours()
@@ -34,11 +35,11 @@ const millisecondsUntilHourOfDay = (newDate, hour) => {
34
35
  return diff;
35
36
  }
36
37
 
37
- const indent = (string, indent) => {
38
+ function indent(string, indent) {
38
39
  return string.replace(/^/gm, ' '.repeat(indent));
39
40
  }
40
41
 
41
- const getCount = (context) => {
42
+ function getCount(context) {
42
43
  if (context.quantity) {
43
44
  return context.quantity.value
44
45
  }
@@ -47,13 +48,23 @@ const getCount = (context) => {
47
48
  }
48
49
  }
49
50
 
50
- const words = (word, additional = {}) => {
51
+ function words(word, additional = {}) {
51
52
  return [{ word: pluralize.singular(word), number: 'one', ...additional }, { word: pluralize.plural(word), number: 'many', ...additional }]
52
53
  }
53
54
 
54
- const isMany = (context) => {
55
- if (((context || {}).value || {}).marker == 'list' && (((context || {}).value || {}).value || []).length > 1) {
56
- return true
55
+ function isMany(context) {
56
+ if (!context) {
57
+ return
58
+ }
59
+ // if (((context || {}).value || {}).marker == 'list' && (((context || {}).value || {}).value || []).length > 1) {
60
+ const isList = context.marker == 'list' || context.value?.marker == 'list'
61
+ if (isList) {
62
+ if (context.value?.length > 1) {
63
+ return true
64
+ }
65
+ if (context.value?.value?.length > 1) {
66
+ return true
67
+ }
57
68
  }
58
69
 
59
70
  let number = context.number
@@ -77,13 +88,13 @@ const isMany = (context) => {
77
88
  return false
78
89
  }
79
90
 
80
- const requiredArgument = (value, name) => {
91
+ function requiredArgument(value, name) {
81
92
  if (!value) {
82
93
  throw new Error(`${name} is a required argument`)
83
94
  }
84
95
  }
85
96
 
86
- const chooseNumber = (context, one, many) => {
97
+ function chooseNumber(context, one, many) {
87
98
  if (isMany(context)) {
88
99
  return many;
89
100
  } else {
@@ -91,7 +102,7 @@ const chooseNumber = (context, one, many) => {
91
102
  }
92
103
  }
93
104
 
94
- const zip = (...arrays) => {
105
+ function zip(...arrays) {
95
106
  if (arrays == []) {
96
107
  return []
97
108
  }
@@ -107,15 +118,21 @@ const zip = (...arrays) => {
107
118
  }
108
119
 
109
120
 
110
- const focus = (context) => {
111
- const helper = (context) => {
121
+ function focus(context) {
122
+ function helper(context) {
112
123
  if (!context || !context.focusable) {
113
124
  return null
114
125
  }
115
126
  for (const property of context.focusable) {
116
127
  let focus = helper(context[property])
117
- if (!focus && (context[property] || {}).focus) {
118
- focus = context[property]
128
+ if (!focus) {
129
+ const flat = flatten(['list'], context[property])[0]
130
+ for (const element of flat) {
131
+ if (element.focus) {
132
+ focus = context[property]
133
+ break
134
+ }
135
+ }
119
136
  }
120
137
  return focus
121
138
  }
@@ -126,7 +143,7 @@ const focus = (context) => {
126
143
 
127
144
  // if property is a list make array of elements of the list, if not return an array with the property value
128
145
  // fromList
129
- const propertyToArray = (value) => {
146
+ function propertyToArray(value) {
130
147
  if (Array.isArray(value)) {
131
148
  return value
132
149
  } else if (value.marker == 'list') {
@@ -136,7 +153,23 @@ const propertyToArray = (value) => {
136
153
  }
137
154
  }
138
155
 
139
- wordNumber = (word, toPlural) => {
156
+ // values is marker: 'list' or some context
157
+ function concats(values) {
158
+ combined = []
159
+ for (const value of values) {
160
+ if (value.marker == 'list') {
161
+ combined = combined.concat(value.value)
162
+ } else {
163
+ combined.push(value)
164
+ }
165
+ }
166
+ return {
167
+ marker: 'list',
168
+ value: combined
169
+ }
170
+ }
171
+
172
+ function wordNumber(word, toPlural) {
140
173
  if (toPlural) {
141
174
  return pluralize.plural(word)
142
175
  } else {
@@ -144,17 +177,18 @@ wordNumber = (word, toPlural) => {
144
177
  }
145
178
  }
146
179
 
147
- const toEValue = (context) => {
180
+ function toEValue(context) {
148
181
  while( context.evalue ) {
149
182
  context = context.evalue
150
183
  }
151
184
  return context;
152
185
  }
153
186
 
154
- const defaultObjectCheck = (extra = []) => {
187
+ function defaultObjectCheck(extra = []) {
155
188
  return {
156
189
  objects: [
157
190
  {
191
+ extra,
158
192
  match: ({objects}) => true,
159
193
  apply: () => extra
160
194
  },
@@ -162,57 +196,62 @@ const defaultObjectCheck = (extra = []) => {
162
196
  }
163
197
  }
164
198
 
165
- const defaultContextCheckProperties = (extra) => {
199
+ function defaultContextCheckProperties(extra) {
166
200
  return ['marker', 'text', 'verbatim', 'value', 'evalue', 'isResponse', { properties: 'modifiers' }, { properties: 'postModifiers' }, ...extra]
167
201
  }
168
202
 
169
- const defaultContextCheck = ({marker, extra = [], exported = false} = {}) => {
203
+ function defaultContextCheck({marker, extra = [], exported = false} = {}) {
170
204
  let match
171
205
  if (marker) {
172
206
  match = ({context}) => context.marker == marker
173
207
  } else {
174
- match = ({context}) => !Array.isArray(context)
175
208
  }
176
209
  return {
210
+ marker,
177
211
  match,
178
212
  exported,
179
213
  apply: () => ['marker', 'text', 'verbatim', 'value', 'evalue', 'isResponse', { properties: 'modifiers' }, { properties: 'postModifiers' }, ...extra],
180
214
  }
181
215
  }
182
216
 
183
- const isA = (hierarchy) => (child, parent, { strict=false } = {}) => {
184
- if (!child || !parent) {
185
- return false
186
- }
187
-
188
- if (strict) {
189
- if (child.marker) {
190
- child = child.marker
191
- }
192
- if (parent.marker) {
193
- parent = parent.marker
194
- }
195
- return hierarchy.isA(child, parent)
196
- } else {
197
- if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
198
- return true
217
+ function isA(hierarchy) {
218
+ return (child, parent, { strict=false } = {}) => {
219
+ if (!child || !parent) {
220
+ return false
199
221
  }
200
- for (const childT of child.types || [child]) {
201
- for (const parentT of parent.types || [parent]) {
202
- if (hierarchy.isA(childT, parentT)) {
203
- return true
222
+
223
+ if (strict) {
224
+ if (child.marker) {
225
+ child = child.marker
226
+ }
227
+ if (parent.marker) {
228
+ parent = parent.marker
229
+ }
230
+ return hierarchy.isA(child, parent)
231
+ } else {
232
+ if (hierarchy.isA(child.marker || child, parent.marker || parent)) {
233
+ return true
234
+ }
235
+ for (const childT of child.types || [child]) {
236
+ for (const parentT of parent.types || [parent]) {
237
+ if (hierarchy.isA(childT, parentT)) {
238
+ return true
239
+ }
204
240
  }
205
241
  }
242
+ return false
206
243
  }
207
- return false
208
244
  }
209
245
  }
210
246
 
211
- const getValue = (propertyPath, object) => {
247
+ function getValue(propertyPath, object) {
212
248
  if (!propertyPath) {
213
249
  return
214
250
  }
215
- const path = propertyPath.split('.')
251
+ let path = propertyPath
252
+ if (typeof path == 'string') {
253
+ path = propertyPath.split('.')
254
+ }
216
255
  let value = object
217
256
  for (const name of path) {
218
257
  if (!value) {
@@ -223,7 +262,30 @@ const getValue = (propertyPath, object) => {
223
262
  return value
224
263
  }
225
264
 
226
- const processTemplateString = async (template, evaluate) => {
265
+ function setValue(propertyPath, object, newValue) {
266
+ if (!propertyPath) {
267
+ return;
268
+ }
269
+ let path = propertyPath;
270
+ if (typeof path === 'string') {
271
+ path = propertyPath.split('.');
272
+ }
273
+ let current = object;
274
+ for (let i = 0; i < path.length; i++) {
275
+ const name = path[i];
276
+ if (i === path.length - 1) {
277
+ // Set the value at the final step
278
+ current[name] = newValue;
279
+ break;
280
+ }
281
+ if (current[name] === undefined || current[name] === null) {
282
+ current[name] = {}; // Create a plain object for nesting
283
+ }
284
+ current = current[name];
285
+ }
286
+ }
287
+
288
+ async function processTemplateString(template, evaluate) {
227
289
  async function resolveWithCallback(strings, ...keys) {
228
290
  // const resolvedValues = await Promise.all(keys.map(key => lookupVariable(key)));
229
291
  const resolvedValues = await Promise.all(keys.map(async (key) => {
@@ -263,11 +325,66 @@ const processTemplateString = async (template, evaluate) => {
263
325
  return await processTemplateString(template)
264
326
  }
265
327
 
328
+ // removeProp.js
329
+ function removeProp(obj, testFn, { maxDepth = Infinity, seen = new WeakSet() } = {}) {
330
+ if (!obj || typeof obj !== 'object' || maxDepth <= 0) return obj;
331
+ if (seen.has(obj)) return obj;
332
+ seen.add(obj);
333
+
334
+ if (Array.isArray(obj)) {
335
+ // ---- ARRAY: process each element (but don't remove elements unless testFn says so)
336
+ let writeIdx = 0;
337
+ for (let i = 0; i < obj.length; i++) {
338
+ const element = obj[i];
339
+ const shouldRemoveElement = testFn(element, i, obj);
340
+
341
+ if (shouldRemoveElement) {
342
+ // Remove the whole array element
343
+ if (element && typeof element === 'object') {
344
+ // Still walk inside it in case testFn wants side effects
345
+ removeProp(element, testFn, { maxDepth: maxDepth - 1, seen });
346
+ }
347
+ // Skip writing it back
348
+ } else {
349
+ // Keep element, but walk into it to remove inner props
350
+ removeProp(element, testFn, { maxDepth: maxDepth - 1, seen });
351
+ if (writeIdx !== i) {
352
+ obj[writeIdx] = element;
353
+ }
354
+ writeIdx++;
355
+ }
356
+ }
357
+ obj.length = writeIdx;
358
+ return obj;
359
+ }
360
+
361
+ // ---- OBJECT: iterate over own keys
362
+ const keys = Reflect.ownKeys(obj);
363
+ for (const key of keys) {
364
+ const val = obj[key];
365
+ const shouldRemove = testFn(val, key, obj);
366
+
367
+ if (shouldRemove) {
368
+ delete obj[key];
369
+ if (val && typeof val === 'object') {
370
+ removeProp(val, testFn, { maxDepth: maxDepth - 1, seen });
371
+ }
372
+ } else {
373
+ removeProp(val, testFn, { maxDepth: maxDepth - 1, seen });
374
+ }
375
+ }
376
+
377
+ return obj;
378
+ }
379
+
266
380
  module.exports = {
267
381
  processTemplateString,
268
382
  unshiftL,
269
383
  pushL,
384
+
270
385
  getValue,
386
+ setValue,
387
+
271
388
  defaultContextCheck,
272
389
  defaultContextCheckProperties,
273
390
  defaultObjectCheck,
@@ -284,4 +401,6 @@ module.exports = {
284
401
  wordNumber,
285
402
  requiredArgument,
286
403
  isA,
404
+ removeProp,
405
+ concats
287
406
  }
@@ -1,4 +1,4 @@
1
- const { knowledgeModule, where } = require('./runtime').theprogrammablemind
1
+ const { debug, knowledgeModule, where } = require('./runtime').theprogrammablemind
2
2
  const { defaultContextCheck } = require('./helpers')
3
3
  const properties = require('./properties')
4
4
  const hierarchy_tests = require('./hierarchy.test.json')
@@ -6,11 +6,11 @@ const pluralize = require('pluralize')
6
6
  const _ = require('lodash')
7
7
  const { isMany } = require('./helpers')
8
8
 
9
- const getTypes = ( km, concept, instance ) => {
9
+ function getTypes( km, concept, instance ) {
10
10
  const propertiesAPI = km('properties').api;
11
11
  const conceptAPI = km('concept').api;
12
12
  const digraph = propertiesAPI.digraph;
13
- const intersect = (set1, set2) => {
13
+ function intersect(set1, set2) {
14
14
  return new Set([...set1].filter(x => set2.has(x)))
15
15
  }
16
16
  const descendants = digraph.descendants(concept.value)
@@ -253,9 +253,11 @@ const config = {
253
253
  const twoConcepts = asList(context.same);
254
254
  for (const oneConcept of oneConcepts.value) {
255
255
  for (const twoConcept of twoConcepts.value) {
256
+ // debug.counter('greg23', { breakAt: 39 })
256
257
  oneConceptId = await api.makeObject({...args, context: oneConcept})
257
258
  twoConceptId = await api.makeObject({...args, context: twoConcept})
258
259
  api.rememberIsA(oneConceptId, twoConceptId)
260
+ api.seenHierarchyWatcher({ childId: oneConceptId, child: oneConcept, parentId: twoConceptId, parent: twoConcept })
259
261
  context.sameWasProcessed = true
260
262
  }
261
263
  }
@@ -286,7 +288,7 @@ const config = {
286
288
  ]
287
289
  };
288
290
 
289
- const initializer = ({apis, hierarchy}) => {
291
+ function initializer({apis, hierarchy}) {
290
292
  apis('stm').addIsA( (child, parent) => {
291
293
  return hierarchy.isA(child, parent)
292
294
  })
@@ -1666,7 +1666,7 @@
1666
1666
  "dead": true,
1667
1667
  "range": {
1668
1668
  "start": 0,
1669
- "end": 11
1669
+ "end": 2
1670
1670
  },
1671
1671
  "types": [
1672
1672
  "self"