manyfest 1.0.43 → 1.0.44

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.
@@ -205,8 +205,6 @@ class ManyfestObjectAddressResolverGetValue
205
205
  {
206
206
  let tmpArgumentValues = [];
207
207
 
208
- let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
209
-
210
208
  // Now get the value for each argument
211
209
  for (let i = 0; i < tmpFunctionArguments.length; i++)
212
210
  {
@@ -358,13 +356,13 @@ class ManyfestObjectAddressResolverGetValue
358
356
  else
359
357
  {
360
358
  // Now is the point in recursion to return the value in the address
361
- if (typeof(pObject[pAddress]) != null)
359
+ if (typeof(pObject[pAddress]) != 'undefined')
362
360
  {
363
361
  return pObject[pAddress];
364
362
  }
365
363
  else
366
364
  {
367
- return null;
365
+ return undefined;
368
366
  }
369
367
  }
370
368
  }
@@ -439,8 +437,6 @@ class ManyfestObjectAddressResolverGetValue
439
437
  {
440
438
  let tmpArgumentValues = [];
441
439
 
442
- let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
443
-
444
440
  // Now get the value for each argument
445
441
  for (let i = 0; i < tmpFunctionArguments.length; i++)
446
442
  {
@@ -31,7 +31,7 @@ module.exports = {
31
31
  let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStartSymbolMap : DEFAULT_START_SYMBOL_MAP;
32
32
  let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEndSymbolMap : DEFAULT_END_SYMBOL_MAP;
33
33
 
34
- if (pString.length < 1)
34
+ if (tmpString.length < 1)
35
35
  {
36
36
  return 0;
37
37
  }
@@ -87,7 +87,7 @@ module.exports = {
87
87
  let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStartSymbolMap : DEFAULT_START_SYMBOL_MAP;
88
88
  let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEndSymbolMap : DEFAULT_END_SYMBOL_MAP;
89
89
 
90
- if (pString.length < 1)
90
+ if (tmpString.length < 1)
91
91
  {
92
92
  return '';
93
93
  }
@@ -145,7 +145,7 @@ module.exports = {
145
145
  let tmpCurrentSegmentStart = 0;
146
146
  let tmpSegmentList = [];
147
147
 
148
- if (pString.length < 1)
148
+ if (tmpString.length < 1)
149
149
  {
150
150
  return tmpSegmentList;
151
151
  }
@@ -4,6 +4,8 @@
4
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
5
5
  let fCleanWrapCharacters = require('./Manyfest-CleanWrapCharacters.js');
6
6
 
7
+ let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
8
+
7
9
  /**
8
10
  * Object Address Resolver - SetValue
9
11
  *
@@ -53,9 +55,10 @@ class ManyfestObjectAddressSetValue
53
55
  // Make sure pAddress is a string
54
56
  if (typeof(pAddress) != 'string') return false;
55
57
 
56
- let tmpSeparatorIndex = pAddress.indexOf('.');
58
+ // Use enclosure-aware parser to find the first segment separator
59
+ let tmpAddressPartBeginning = _MockFable.DataFormat.stringGetFirstSegment(pAddress);
57
60
 
58
- if (tmpSeparatorIndex == -1)
61
+ if (tmpAddressPartBeginning.length == pAddress.length)
59
62
  {
60
63
  // Check if it's a boxed property
61
64
  let tmpBracketStartIndex = pAddress.indexOf('[');
@@ -155,8 +158,8 @@ class ManyfestObjectAddressSetValue
155
158
  }
156
159
  else
157
160
  {
158
- let tmpSubObjectName = pAddress.substring(0, tmpSeparatorIndex);
159
- let tmpNewAddress = pAddress.substring(tmpSeparatorIndex+1);
161
+ let tmpSubObjectName = tmpAddressPartBeginning;
162
+ let tmpNewAddress = pAddress.substring(tmpAddressPartBeginning.length+1);
160
163
 
161
164
  // Test if the tmpNewAddress is an array or object
162
165
  // Check if it's a boxed property
@@ -27,20 +27,16 @@ const testCondition = (pManyfest, pRecord, pSearchAddress, pSearchComparator, pV
27
27
  {
28
28
  case 'TRUE':
29
29
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) === true);
30
- break;
31
30
  case 'FALSE':
32
31
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) === false);
33
- break;
34
32
  case 'LNGT':
35
33
  case 'LENGTH_GREATER_THAN':
36
34
  switch(typeof(pManyfest.getValueAtAddress(pRecord, pSearchAddress)))
37
35
  {
38
36
  case 'string':
39
37
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length > pValue);
40
- break;
41
38
  case 'object':
42
39
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length > pValue);
43
- break;
44
40
  default:
45
41
  return false;
46
42
  break;
@@ -52,10 +48,8 @@ const testCondition = (pManyfest, pRecord, pSearchAddress, pSearchComparator, pV
52
48
  {
53
49
  case 'string':
54
50
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length < pValue);
55
- break;
56
51
  case 'object':
57
52
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length < pValue);
58
- break;
59
53
  default:
60
54
  return false;
61
55
  break;
@@ -72,26 +66,19 @@ const testCondition = (pManyfest, pRecord, pSearchAddress, pSearchComparator, pV
72
66
  // break;
73
67
  case '!=':
74
68
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) != pValue);
75
- break;
76
69
  case '<':
77
70
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) < pValue);
78
- break;
79
71
  case '>':
80
72
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) > pValue);
81
- break;
82
73
  case '<=':
83
74
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) <= pValue);
84
- break;
85
75
  case '>=':
86
76
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) >= pValue);
87
- break;
88
77
  case '===':
89
78
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) === pValue);
90
- break;
91
79
  case '==':
92
80
  default:
93
81
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) == pValue);
94
- break;
95
82
  }
96
83
  };
97
84
 
@@ -229,11 +229,8 @@ class Manyfest extends libFableServiceProviderBase
229
229
  {
230
230
  if (typeof(tmpManifest.HashTranslations) === 'object')
231
231
  {
232
- for (let i = 0; i < tmpManifest.HashTranslations.length; i++)
233
- {
234
- // Each translation is
235
- //FIXME: ?????????
236
- }
232
+ // HashTranslations is serialized as a plain object of source:target pairs
233
+ this.hashTranslations.addTranslation(tmpManifest.HashTranslations);
237
234
  }
238
235
  }
239
236
  }
@@ -406,13 +403,15 @@ class Manyfest extends libFableServiceProviderBase
406
403
 
407
404
  lintAddress(pAddress)
408
405
  {
409
- let tmpLintedAddress = pAddress.trim();
410
- // Check for a single . (but not a ..) at the end of the address and remove it.
411
- if (tmpLintedAddress.endsWith('..'))
406
+ // Guard against non-string input
407
+ if (typeof(pAddress) != 'string')
412
408
  {
413
- tmpLintedAddress = tmpLintedAddress.slice(0, -1);
409
+ return '';
414
410
  }
415
- else if (tmpLintedAddress.endsWith('.'))
411
+ let tmpLintedAddress = pAddress.trim();
412
+ // Check for a single trailing . (but not a ..) at the end of the address and remove it.
413
+ // We must not strip '..' because that is back-navigation syntax.
414
+ if (tmpLintedAddress.endsWith('.') && !tmpLintedAddress.endsWith('..'))
416
415
  {
417
416
  tmpLintedAddress = tmpLintedAddress.slice(0, -1);
418
417
  }
@@ -454,16 +453,16 @@ class Manyfest extends libFableServiceProviderBase
454
453
  }
455
454
 
456
455
  // Delete the value of an element by its hash
457
- deleteValueByHash(pObject, pHash, pValue)
456
+ deleteValueByHash(pObject, pHash)
458
457
  {
459
- return this.deleteValueAtAddress(pObject, this.resolveHashAddress(pHash), pValue);
458
+ return this.deleteValueAtAddress(pObject, this.resolveHashAddress(pHash));
460
459
  }
461
460
 
462
461
  // Delete the value of an element at an address
463
- deleteValueAtAddress (pObject, pAddress, pValue)
462
+ deleteValueAtAddress (pObject, pAddress)
464
463
  {
465
464
  let tmpLintedAddress = this.lintAddress(pAddress);
466
- return this.objectAddressDeleteValue.deleteValueAtAddress(pObject, tmpLintedAddress, pValue);
465
+ return this.objectAddressDeleteValue.deleteValueAtAddress(pObject, tmpLintedAddress);
467
466
  }
468
467
 
469
468
  // Validate the consistency of an object against the schema
@@ -560,12 +559,20 @@ class Manyfest extends libFableServiceProviderBase
560
559
  }
561
560
  break;
562
561
 
562
+ case 'boolean':
563
+ if (tmpElementType != 'boolean')
564
+ {
565
+ addValidationError(tmpDescriptor.Address, `has a DataType ${tmpDescriptor.DataType} but is of the type ${tmpElementType}`);
566
+ }
567
+ break;
568
+
563
569
  case 'datetime':
564
570
  let tmpValueDate = new Date(tmpValue);
565
571
  if (tmpValueDate.toString() == 'Invalid Date')
566
572
  {
567
573
  addValidationError(tmpDescriptor.Address, `has a DataType ${tmpDescriptor.DataType} but is not parsable as a Date by Javascript`);
568
574
  }
575
+ break;
569
576
 
570
577
  default:
571
578
  // Check if this is a string, in the default case
@@ -605,7 +612,13 @@ class Manyfest extends libFableServiceProviderBase
605
612
  let tmpDataType = ('DataType' in pDescriptor) ? pDescriptor.DataType : 'String';
606
613
  if (tmpDataType in this.options.defaultValues)
607
614
  {
608
- return this.options.defaultValues[tmpDataType];
615
+ let tmpDefaultValue = this.options.defaultValues[tmpDataType];
616
+ // Return a copy of mutable defaults (Array and Object) to prevent shared state
617
+ if (typeof(tmpDefaultValue) == 'object' && tmpDefaultValue !== null)
618
+ {
619
+ return JSON.parse(JSON.stringify(tmpDefaultValue));
620
+ }
621
+ return tmpDefaultValue;
609
622
  }
610
623
  else
611
624
  {