manyfest 1.0.28 → 1.0.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "manyfest",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "JSON Object Manifest for Data Description and Parsing",
5
5
  "main": "source/Manyfest.js",
6
6
  "scripts": {
@@ -44,10 +44,10 @@
44
44
  ]
45
45
  },
46
46
  "dependencies": {
47
- "fable-serviceproviderbase": "^3.0.12"
47
+ "fable-serviceproviderbase": "^3.0.13"
48
48
  },
49
49
  "devDependencies": {
50
- "quackage": "^1.0.25"
50
+ "quackage": "^1.0.29"
51
51
  },
52
52
  "author": "steven velozo <steven@velozo.com>",
53
53
  "license": "MIT",
@@ -23,11 +23,8 @@ let libSimpleLog = require('./Manyfest-LogToConsole.js');
23
23
  */
24
24
  class ManyfestObjectAddressResolverCheckAddressExists
25
25
  {
26
- constructor(pInfoLog, pErrorLog)
26
+ constructor()
27
27
  {
28
- // Wire in logging
29
- this.logInfo = (typeof(pInfoLog) == 'function') ? pInfoLog : libSimpleLog;
30
- this.logError = (typeof(pErrorLog) == 'function') ? pErrorLog : libSimpleLog;
31
28
  }
32
29
 
33
30
  // Check if an address exists.
@@ -37,7 +37,7 @@ class ManyfestObjectAddressResolverDeleteValue
37
37
  }
38
38
 
39
39
  // TODO: Dry me
40
- checkFilters(pAddress, pRecord)
40
+ checkRecordFilters(pAddress, pRecord)
41
41
  {
42
42
  return fParseConditionals(this, pAddress, pRecord);
43
43
  }
@@ -151,7 +151,7 @@ class ManyfestObjectAddressResolverDeleteValue
151
151
  for (let i = tmpInputArray.length - 1; i >= 0; i--)
152
152
  {
153
153
  // The filtering is complex but allows config-based metaprogramming directly from schema
154
- let tmpKeepRecord = this.checkFilters(pAddress, tmpInputArray[i]);
154
+ let tmpKeepRecord = this.checkRecordFilters(pAddress, tmpInputArray[i]);
155
155
  if (tmpKeepRecord)
156
156
  {
157
157
  // Delete elements end to beginning
@@ -319,7 +319,7 @@ class ManyfestObjectAddressResolverDeleteValue
319
319
  let tmpValue = this.deleteValueAtAddress(pObject[tmpObjectPropertyName][tmpObjectPropertyKeys[i]], tmpNewAddress, tmpPropertyParentAddress);
320
320
 
321
321
  // The filtering is complex but allows config-based metaprogramming directly from schema
322
- let tmpKeepRecord = this.checkFilters(pAddress, tmpValue);
322
+ let tmpKeepRecord = this.checkRecordFilters(pAddress, tmpValue);
323
323
  if (tmpKeepRecord)
324
324
  {
325
325
  tmpContainerObject[`${tmpPropertyParentAddress}.${tmpNewAddress}`] = tmpValue;
@@ -36,7 +36,7 @@ class ManyfestObjectAddressResolverGetValue
36
36
  this.cleanWrapCharacters = fCleanWrapCharacters;
37
37
  }
38
38
 
39
- checkFilters(pAddress, pRecord)
39
+ checkRecordFilters(pAddress, pRecord)
40
40
  {
41
41
  return fParseConditionals(this, pAddress, pRecord);
42
42
  }
@@ -193,7 +193,7 @@ class ManyfestObjectAddressResolverGetValue
193
193
  for (let i = 0; i < tmpInputArray.length; i++)
194
194
  {
195
195
  // The filtering is complex but allows config-based metaprogramming directly from schema
196
- let tmpKeepRecord = this.checkFilters(pAddress, tmpInputArray[i]);
196
+ let tmpKeepRecord = this.checkRecordFilters(pAddress, tmpInputArray[i]);
197
197
  if (tmpKeepRecord)
198
198
  {
199
199
  tmpOutputArray.push(tmpInputArray[i]);
@@ -366,7 +366,7 @@ class ManyfestObjectAddressResolverGetValue
366
366
  let tmpValue = this.getValueAtAddress(pObject[tmpObjectPropertyName][tmpObjectPropertyKeys[i]], tmpNewAddress, tmpPropertyParentAddress, tmpRootObject);
367
367
 
368
368
  // The filtering is complex but allows config-based metaprogramming directly from schema
369
- let tmpKeepRecord = this.checkFilters(pAddress, tmpValue);
369
+ let tmpKeepRecord = this.checkRecordFilters(pAddress, tmpValue);
370
370
  if (tmpKeepRecord)
371
371
  {
372
372
  tmpContainerObject[`${tmpPropertyParentAddress}.${tmpNewAddress}`] = tmpValue;
@@ -17,11 +17,61 @@ const _ConditionalStanzaStartLength = _ConditionalStanzaStart.length;
17
17
  const _ConditionalStanzaEnd = '?~>>';
18
18
  const _ConditionalStanzaEndLength = _ConditionalStanzaEnd.length;
19
19
 
20
+ // Ugh dependency injection. Can't wait to make these all fable services.
21
+ let libObjectAddressCheckAddressExists = new (require('./Manyfest-ObjectAddress-CheckAddressExists.js'))();
22
+
20
23
  // Test the condition of a value in a record
21
24
  const testCondition = (pManyfest, pRecord, pSearchAddress, pSearchComparator, pValue) =>
22
25
  {
23
26
  switch(pSearchComparator)
24
27
  {
28
+ case 'TRUE':
29
+ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) === true);
30
+ break;
31
+ case 'FALSE':
32
+ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) === false);
33
+ break;
34
+ case 'LNGT':
35
+ case 'LENGTH_GREATER_THAN':
36
+ switch(typeof(typeof(pManyfest.getValueAtAddress(pRecord, pSearchAddress))))
37
+ {
38
+ case 'string':
39
+ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length > pValue);
40
+ break;
41
+ case 'object':
42
+ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length > pValue);
43
+ break;
44
+ default:
45
+ return false;
46
+ break;
47
+ }
48
+ break;
49
+ case 'LNLT':
50
+ case 'LENGTH_LESS_THAN':
51
+ switch(typeof(typeof(pManyfest.getValueAtAddress(pRecord, pSearchAddress))))
52
+ {
53
+ case 'string':
54
+ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length < pValue);
55
+ break;
56
+ case 'object':
57
+ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress).length < pValue);
58
+ break;
59
+ default:
60
+ return false;
61
+ break;
62
+ }
63
+ break;
64
+ case 'FALSE':
65
+ return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) === false);
66
+ break;
67
+ case 'EX':
68
+ case 'EXISTS':
69
+ return libObjectAddressCheckAddressExists.checkAddressExists(pRecord, pSearchAddress);
70
+ break;
71
+ case 'DNEX':
72
+ case 'DOES_NOT_EXIST':
73
+ return !libObjectAddressCheckAddressExists.checkAddressExists(pRecord, pSearchAddress);
74
+ break;
25
75
  case '!=':
26
76
  return (pManyfest.getValueAtAddress(pRecord, pSearchAddress) != pValue);
27
77
  break;
@@ -55,7 +105,6 @@ const parseConditionals = (pManyfest, pAddress, pRecord) =>
55
105
  Algorithm is simple:
56
106
 
57
107
  1. Enuerate start points
58
-
59
108
  2. Find stop points within each start point
60
109
  3. Check the conditional
61
110
  */
@@ -70,9 +119,22 @@ const parseConditionals = (pManyfest, pAddress, pRecord) =>
70
119
  {
71
120
  let tmpMagicComparisonPatternSet = pAddress.substring(tmpStartIndex+_ConditionalStanzaStartLength, tmpStopIndex).split(',');
72
121
 
122
+ // The address to search for
73
123
  let tmpSearchAddress = tmpMagicComparisonPatternSet[0];
74
- let tmpSearchComparator = tmpMagicComparisonPatternSet[1];
75
- let tmpSearchValue = tmpMagicComparisonPatternSet[2];
124
+
125
+ // The copmparison expression (EXISTS as default)
126
+ let tmpSearchComparator = 'EXISTS';
127
+ if (tmpMagicComparisonPatternSet.length > 1)
128
+ {
129
+ tmpSearchComparator = tmpMagicComparisonPatternSet[1];
130
+ }
131
+
132
+ // The value to search for
133
+ let tmpSearchValue = false;
134
+ if (tmpMagicComparisonPatternSet.length > 2)
135
+ {
136
+ tmpSearchValue = tmpMagicComparisonPatternSet[2];
137
+ }
76
138
 
77
139
  // Process the piece
78
140
  tmpKeepRecord = tmpKeepRecord && testCondition(pManyfest, pRecord, tmpSearchAddress, tmpSearchComparator, tmpSearchValue);
@@ -127,7 +127,8 @@
127
127
  "crc32": "d9e1b316",
128
128
  "sha1": "4dab42952fe0405a3b7f80146636b33d7b1bd01e",
129
129
  "format": "Item Tile",
130
- "rotation": "0"
130
+ "rotation": "0",
131
+ "thumbnail": true
131
132
  },
132
133
  {
133
134
  "name": "frankerberry_countchockula_1971.0001.gif",
@@ -151,7 +152,8 @@
151
152
  "sha1": "41162dc2d1a91b618124c84628d0c231544a02be",
152
153
  "length": "31.14",
153
154
  "height": "480",
154
- "width": "640"
155
+ "width": "640",
156
+ "thumbnail": false
155
157
  },
156
158
  {
157
159
  "name": "frankerberry_countchockula_1971.0001.mpg.idx",
@@ -51,7 +51,55 @@ suite
51
51
  )
52
52
  test
53
53
  (
54
- 'Magic filters should be magic.',
54
+ 'Magic filters should be able to process non equality filters.',
55
+ (fTestComplete)=>
56
+ {
57
+ let _Manyfest = new libManyfest(
58
+ {
59
+ Scope:'Archive.org',
60
+ Descriptors:
61
+ {
62
+ 'files[]<<~?length,EXISTS?~>>': {Name:'Files With a length Property', Hash:'FilesWithLength'},
63
+ 'files[]<<~?length,DNEX?~>>': {Name:'Files Without a length Property', Hash:'FilesWithoutLength'},
64
+ 'files[]<<~?length,DNEX?~>><<~?source,==,original?~>>': {Name:'Original Files With a length Property', Hash:'OriginalFilesWithLength'},
65
+ 'files[]<<~?thumbnail,EXISTS?~>>': {Name:'Thumbnail Bit is Explicitly Set', Hash:'ThumbnailExplicitlySet'},
66
+ 'files[]<<~?thumbnail,TRUE?~>>': {Name:'Thumbnail Files', Hash:'ThumbnailFiles'},
67
+ 'files[]<<~?thumbnail,FALSE?~>>': {Name:'Not Thumbnail Files', Hash:'NotThumbnailFiles'}
68
+ }
69
+ });
70
+
71
+ // Grab magic filtered thumbnails
72
+ // Also, the "thumbnail" property was added to the data later ... it's not actually from archive.org but I wanted to test this feature.
73
+ let tmpThumbnailFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'ThumbnailFiles');
74
+ Expect(tmpThumbnailFiles).to.be.an('array');
75
+ Expect(tmpThumbnailFiles.length).to.equal(1);
76
+
77
+ let tmpNotThumbnailFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'NotThumbnailFiles');
78
+ Expect(tmpNotThumbnailFiles).to.be.an('array');
79
+ Expect(tmpNotThumbnailFiles.length).to.equal(1);
80
+
81
+ let tmpFilesWithLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FilesWithLength');
82
+ Expect(tmpFilesWithLength).to.be.an('array');
83
+ Expect(tmpFilesWithLength.length).to.equal(3);
84
+
85
+ let tmpOGFilesWithLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'OriginalFilesWithLength');
86
+ Expect(tmpOGFilesWithLength).to.be.an('array');
87
+ Expect(tmpOGFilesWithLength.length).to.equal(2);
88
+
89
+ let tmpFilesWithoutLength = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FilesWithoutLength');
90
+ Expect(tmpFilesWithoutLength).to.be.an('array');
91
+ Expect(tmpFilesWithoutLength.length).to.equal(14);
92
+
93
+ let tmpExplicitlyExists = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'ThumbnailExplicitlySet');
94
+ Expect(tmpExplicitlyExists).to.be.an('array');
95
+ Expect(tmpExplicitlyExists.length).to.equal(2);
96
+
97
+ fTestComplete();
98
+ }
99
+ );
100
+ test
101
+ (
102
+ 'Magic filters should be magic and process equality filters.',
55
103
  (fTestComplete)=>
56
104
  {
57
105
  let _Manyfest = new libManyfest(