manyfest 1.0.18 → 1.0.20

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/debug/Harness.js CHANGED
@@ -1,15 +1,15 @@
1
1
  let libManyfest = require(`../source/Manyfest.js`);
2
2
 
3
- let animalManyfest = new libManyfest(
4
- {
5
- "Scope": "Animal",
6
- "Descriptors":
7
- {
8
- "IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
9
- "Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
10
- "Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." }
11
- }
12
- });
3
+ let animalManyfest = new libManyfest()
4
+ // {
5
+ // "Scope": "Animal",
6
+ // "Descriptors":
7
+ // {
8
+ // "IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
9
+ // "Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
10
+ // "Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." }
11
+ // }
12
+ // });
13
13
 
14
14
  // Make up a cute and furry test creature
15
15
  let testAnimal = {IDAnimal:8675309, Name:'BatBrains', Type:'Lab', Color:'Brown'};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "manyfest",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "JSON Object Manifest for Data Description and Parsing",
5
5
  "main": "source/Manyfest.js",
6
6
  "scripts": {
@@ -63,8 +63,7 @@
63
63
  "vinyl-source-stream": "^2.0.0"
64
64
  },
65
65
  "dependencies": {
66
- "elucidator": "^1.0.7",
67
- "precedent": "^1.0.9"
66
+ "precedent": "^1.0.11"
68
67
  },
69
68
  "author": "steven velozo <steven@velozo.com>",
70
69
  "license": "MIT",
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
 
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
 
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -38,48 +37,10 @@ class ManyfestObjectAddressResolverDeleteValue
38
37
  this.elucidatorSolverState = {};
39
38
 
40
39
  this.cleanWrapCharacters = fCleanWrapCharacters;
41
- }
42
-
43
- checkFilters(pAddress, pRecord)
44
- {
45
- let tmpPrecedent = new libPrecedent();
46
- // If we don't copy the string, precedent takes it out for good.
47
- // TODO: Consider adding a "don't replace" option for precedent
48
- let tmpAddress = pAddress;
49
-
50
- if (!this.elucidatorSolver)
51
- {
52
- // Again, manage against circular dependencies
53
- let libElucidator = require('elucidator');
54
- this.elucidatorSolver = new libElucidator({}, this.logInfo, this.logError);
55
- }
56
-
57
- if (this.elucidatorSolver)
58
- {
59
- // This allows the magic filtration with elucidator configuration
60
- // TODO: We could pass more state in (e.g. parent address, object, etc.)
61
- // TODO: Discuss this metaprogramming AT LENGTH
62
- let tmpFilterState = (
63
- {
64
- Record: pRecord,
65
- keepRecord: true
66
- });
40
+ this.precedent = new libPrecedent();
67
41
 
68
- // This is about as complex as it gets.
69
- // TODO: Optimize this so it is only initialized once.
70
- // TODO: That means figuring out a healthy pattern for passing in state to this
71
- tmpPrecedent.addPattern('<<~~', '~~>>',
72
- (pInstructionHash) =>
73
- {
74
- // This is for internal config on the solution steps. Right now config is not shared across steps.
75
- if (this.elucidatorSolverState.hasOwnProperty(pInstructionHash))
76
- {
77
- tmpFilterState.SolutionState = this.elucidatorSolverState[pInstructionHash];
78
- }
79
- this.elucidatorSolver.solveInternalOperation('Custom', pInstructionHash, tmpFilterState);
80
- });
81
- tmpPrecedent.addPattern('<<~?', '?~>>',
82
- (pMagicSearchExpression) =>
42
+ this.precedent.addPattern('<<~?', '?~>>',
43
+ (pMagicSearchExpression, pData) =>
83
44
  {
84
45
  if (typeof(pMagicSearchExpression) !== 'string')
85
46
  {
@@ -93,48 +54,56 @@ class ManyfestObjectAddressResolverDeleteValue
93
54
  let tmpSearchComparator = tmpMagicComparisonPatternSet[1];
94
55
  let tmpSearchValue = tmpMagicComparisonPatternSet[2];
95
56
 
96
- tmpFilterState.ComparisonState = (
97
- {
98
- SearchAddress: tmpSearchAddress,
99
- Comparator: tmpSearchComparator,
100
- SearchTerm: tmpSearchValue
101
- });
102
-
103
- this.elucidatorSolver.solveOperation(
104
- {
105
- "Description":
106
- {
107
- "Operation": "Simple_If",
108
- "Synopsis": "Test for "
109
- },
110
- "Steps":
111
- [
112
- {
113
- "Namespace": "Logic",
114
- "Instruction": "if",
115
-
116
- "InputHashAddressMap":
117
- {
118
- // This is ... dynamically assigning the address in the instruction
119
- // The complexity is astounding.
120
- "leftValue": `Record.${tmpSearchAddress}`,
121
- "rightValue": "ComparisonState.SearchTerm",
122
- "comparator": "ComparisonState.Comparator"
123
- },
124
- "OutputHashAddressMap": { "truthinessResult":"keepRecord" }
125
- }
126
- ]
127
- }, tmpFilterState);
57
+ switch(tmpSearchComparator)
58
+ {
59
+ case '!=':
60
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) != tmpSearchValue);
61
+ break;
62
+ case '<':
63
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) < tmpSearchValue);
64
+ break;
65
+ case '>':
66
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) > tmpSearchValue);
67
+ break;
68
+ case '<=':
69
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) <= tmpSearchValue);
70
+ break;
71
+ case '>=':
72
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) >= tmpSearchValue);
73
+ break;
74
+ case '===':
75
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) == tmpSearchValue);
76
+ break;
77
+ case '==':
78
+ default:
79
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) == tmpSearchValue);
80
+ break;
81
+ }
128
82
  });
129
- tmpPrecedent.parseString(tmpAddress);
83
+ }
130
84
 
131
- // It is expected that the operation will mutate this to some truthy value
132
- return tmpFilterState.keepRecord;
133
- }
134
- else
135
- {
136
- return true;
137
- }
85
+ // TODO: Dry me
86
+ checkFilters(pAddress, pRecord)
87
+ {
88
+ let tmpPrecedent = new libPrecedent();
89
+ // If we don't copy the string, precedent takes it out for good.
90
+ // TODO: Consider adding a "don't replace" option for precedent
91
+ let tmpAddress = pAddress;
92
+
93
+ // This allows the magic filtration with elucidator configuration
94
+ // TODO: We could pass more state in (e.g. parent address, object, etc.)
95
+ // TODO: Discuss this metaprogramming AT LENGTH
96
+ let tmpFilterState = (
97
+ {
98
+ Record: pRecord,
99
+ KeepRecord: true
100
+ });
101
+
102
+ // This is about as complex as it gets.
103
+
104
+ this.precedent.parseString(tmpAddress, tmpFilterState);
105
+
106
+ return tmpFilterState.KeepRecord;
138
107
  }
139
108
 
140
109
  // Delete the value of an element at an address
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -38,48 +37,11 @@ class ManyfestObjectAddressResolverGetValue
38
37
  this.elucidatorSolverState = {};
39
38
 
40
39
  this.cleanWrapCharacters = fCleanWrapCharacters;
41
- }
42
-
43
- checkFilters(pAddress, pRecord)
44
- {
45
- let tmpPrecedent = new libPrecedent();
46
- // If we don't copy the string, precedent takes it out for good.
47
- // TODO: Consider adding a "don't replace" option for precedent
48
- let tmpAddress = pAddress;
49
40
 
50
- if (!this.elucidatorSolver)
51
- {
52
- // Again, manage against circular dependencies
53
- let libElucidator = require('elucidator');
54
- this.elucidatorSolver = new libElucidator({}, this.logInfo, this.logError);
55
- }
41
+ this.precedent = new libPrecedent();
56
42
 
57
- if (this.elucidatorSolver)
58
- {
59
- // This allows the magic filtration with elucidator configuration
60
- // TODO: We could pass more state in (e.g. parent address, object, etc.)
61
- // TODO: Discuss this metaprogramming AT LENGTH
62
- let tmpFilterState = (
63
- {
64
- Record: pRecord,
65
- keepRecord: true
66
- });
67
-
68
- // This is about as complex as it gets.
69
- // TODO: Optimize this so it is only initialized once.
70
- // TODO: That means figuring out a healthy pattern for passing in state to this
71
- tmpPrecedent.addPattern('<<~~', '~~>>',
72
- (pInstructionHash) =>
73
- {
74
- // This is for internal config on the solution steps. Right now config is not shared across steps.
75
- if (this.elucidatorSolverState.hasOwnProperty(pInstructionHash))
76
- {
77
- tmpFilterState.SolutionState = this.elucidatorSolverState[pInstructionHash];
78
- }
79
- this.elucidatorSolver.solveInternalOperation('Custom', pInstructionHash, tmpFilterState);
80
- });
81
- tmpPrecedent.addPattern('<<~?', '?~>>',
82
- (pMagicSearchExpression) =>
43
+ this.precedent.addPattern('<<~?', '?~>>',
44
+ (pMagicSearchExpression, pData) =>
83
45
  {
84
46
  if (typeof(pMagicSearchExpression) !== 'string')
85
47
  {
@@ -93,48 +55,55 @@ class ManyfestObjectAddressResolverGetValue
93
55
  let tmpSearchComparator = tmpMagicComparisonPatternSet[1];
94
56
  let tmpSearchValue = tmpMagicComparisonPatternSet[2];
95
57
 
96
- tmpFilterState.ComparisonState = (
97
- {
98
- SearchAddress: tmpSearchAddress,
99
- Comparator: tmpSearchComparator,
100
- SearchTerm: tmpSearchValue
101
- });
102
-
103
- this.elucidatorSolver.solveOperation(
104
- {
105
- "Description":
106
- {
107
- "Operation": "Simple_If",
108
- "Synopsis": "Test for "
109
- },
110
- "Steps":
111
- [
112
- {
113
- "Namespace": "Logic",
114
- "Instruction": "if",
115
-
116
- "InputHashAddressMap":
117
- {
118
- // This is ... dynamically assigning the address in the instruction
119
- // The complexity is astounding.
120
- "leftValue": `Record.${tmpSearchAddress}`,
121
- "rightValue": "ComparisonState.SearchTerm",
122
- "comparator": "ComparisonState.Comparator"
123
- },
124
- "OutputHashAddressMap": { "truthinessResult":"keepRecord" }
125
- }
126
- ]
127
- }, tmpFilterState);
58
+ switch(tmpSearchComparator)
59
+ {
60
+ case '!=':
61
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) != tmpSearchValue);
62
+ break;
63
+ case '<':
64
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) < tmpSearchValue);
65
+ break;
66
+ case '>':
67
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) > tmpSearchValue);
68
+ break;
69
+ case '<=':
70
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) <= tmpSearchValue);
71
+ break;
72
+ case '>=':
73
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) >= tmpSearchValue);
74
+ break;
75
+ case '===':
76
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) == tmpSearchValue);
77
+ break;
78
+ case '==':
79
+ default:
80
+ pData.KeepRecord = (this.getValueAtAddress(pData.Record, tmpSearchAddress) == tmpSearchValue);
81
+ break;
82
+ }
128
83
  });
129
- tmpPrecedent.parseString(tmpAddress);
84
+ }
130
85
 
131
- // It is expected that the operation will mutate this to some truthy value
132
- return tmpFilterState.keepRecord;
133
- }
134
- else
135
- {
136
- return true;
137
- }
86
+ checkFilters(pAddress, pRecord)
87
+ {
88
+ let tmpPrecedent = new libPrecedent();
89
+ // If we don't copy the string, precedent takes it out for good.
90
+ // TODO: Consider adding a "don't replace" option for precedent
91
+ let tmpAddress = pAddress;
92
+
93
+ // This allows the magic filtration with elucidator configuration
94
+ // TODO: We could pass more state in (e.g. parent address, object, etc.)
95
+ // TODO: Discuss this metaprogramming AT LENGTH
96
+ let tmpFilterState = (
97
+ {
98
+ Record: pRecord,
99
+ KeepRecord: true
100
+ });
101
+
102
+ // This is about as complex as it gets.
103
+
104
+ this.precedent.parseString(tmpAddress, tmpFilterState);
105
+
106
+ return tmpFilterState.KeepRecord;
138
107
  }
139
108
 
140
109
  // Get the value of an element at an address
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -1,5 +1,4 @@
1
1
  /**
2
- * @license MIT
3
2
  * @author <steven@velozo.com>
4
3
  */
5
4
  let libSimpleLog = require('./Manyfest-LogToConsole.js');
@@ -14,6 +13,8 @@ let libObjectAddressDeleteValue = require('./Manyfest-ObjectAddress-DeleteValue.
14
13
  let libObjectAddressGeneration = require('./Manyfest-ObjectAddressGeneration.js');
15
14
  let libSchemaManipulation = require('./Manyfest-SchemaManipulation.js');
16
15
 
16
+ const _DefaultConfiguration = { Scope:'Default', Descriptors: {} }
17
+
17
18
 
18
19
  /**
19
20
  * Manyfest object address-based descriptions and manipulations.
@@ -130,72 +131,44 @@ class Manyfest
130
131
  if (typeof(pManifest) !== 'object')
131
132
  {
132
133
  this.logError(`(${this.scope}) Error loading manifest; expecting an object but parameter was type ${typeof(pManifest)}.`);
133
- return false;
134
134
  }
135
135
 
136
- if (pManifest.hasOwnProperty('Scope'))
136
+ let tmpManifest = (typeof(pManifest) == 'object') ? pManifest : {};
137
+
138
+ if (tmpManifest.hasOwnProperty('Scope'))
137
139
  {
138
- if (typeof(pManifest.Scope) === 'string')
140
+ if (typeof(tmpManifest.Scope) === 'string')
139
141
  {
140
- this.scope = pManifest.Scope;
142
+ this.scope = tmpManifest.Scope;
141
143
  }
142
144
  else
143
145
  {
144
- this.logError(`(${this.scope}) Error loading scope from manifest; expecting a string but property was type ${typeof(pManifest.Scope)}.`, pManifest);
146
+ this.logError(`(${this.scope}) Error loading scope from manifest; expecting a string but property was type ${typeof(tmpManifest.Scope)}.`, tmpManifest);
145
147
  }
146
148
  }
147
149
  else
148
150
  {
149
- this.logError(`(${this.scope}) Error loading scope from manifest object. Property "Scope" does not exist in the root of the object.`, pManifest);
151
+ this.logError(`(${this.scope}) Error loading scope from manifest object. Property "Scope" does not exist in the root of the object.`, tmpManifest);
150
152
  }
151
153
 
152
- if (pManifest.hasOwnProperty('Descriptors'))
154
+ if (tmpManifest.hasOwnProperty('Descriptors'))
153
155
  {
154
- if (typeof(pManifest.Descriptors) === 'object')
156
+ if (typeof(tmpManifest.Descriptors) === 'object')
155
157
  {
156
- let tmpDescriptionAddresses = Object.keys(pManifest.Descriptors);
158
+ let tmpDescriptionAddresses = Object.keys(tmpManifest.Descriptors);
157
159
  for (let i = 0; i < tmpDescriptionAddresses.length; i++)
158
160
  {
159
- this.addDescriptor(tmpDescriptionAddresses[i], pManifest.Descriptors[tmpDescriptionAddresses[i]]);
161
+ this.addDescriptor(tmpDescriptionAddresses[i], tmpManifest.Descriptors[tmpDescriptionAddresses[i]]);
160
162
  }
161
163
  }
162
164
  else
163
165
  {
164
- this.logError(`(${this.scope}) Error loading description object from manifest object. Expecting an object in 'Manifest.Descriptors' but the property was type ${typeof(pManifest.Descriptors)}.`, pManifest);
166
+ this.logError(`(${this.scope}) Error loading description object from manifest object. Expecting an object in 'Manifest.Descriptors' but the property was type ${typeof(tmpManifest.Descriptors)}.`, tmpManifest);
165
167
  }
166
168
  }
167
169
  else
168
170
  {
169
- this.logError(`(${this.scope}) Error loading object description from manifest object. Property "Descriptors" does not exist in the root of the Manifest object.`, pManifest);
170
- }
171
-
172
- // This seems like it would create a circular dependency issue but it only goes as deep as the schema defines Solvers
173
- if ((pManifest.hasOwnProperty('Solvers')) && (typeof(pManifest.Solvers) == 'object'))
174
- {
175
- // There are elucidator solvers passed-in, so we will create one to filter data.
176
- let libElucidator = require('elucidator');
177
- // WARNING THESE CAN MUTATE THE DATA
178
- // The pattern for the solver is: {<~~SolverName~~>} anywhere in a property.
179
- // Yes, this means your Javascript elements can't have my self-styled jellyfish brackets in them.
180
- // This does, though, mean we can filter at multiple layers safely.
181
- // Because these can be put at any address
182
- // The solver themselves:
183
- // They are passed-in an object, and the current record is in the Record subobject.
184
- // Basic operations can just write to the root object but...
185
- // IF YOU PERMUTE THE Record SUBOBJECT YOU CAN AFFECT RECURSION
186
- // This is mostly meant for if statements to filter.
187
- // Basically on aggregation, if a filter is set it will set "keep record" to true and let the solver decide differently.
188
- this.dataSolvers = new libElucidator(pManifest.Solvers, this.logInfo, this.logError);
189
-
190
- // Load the solver state in so each instruction can have internal config
191
- // TODO: Should this just be a part of the lower layer pattern?
192
- let tmpSolverKeys = Object.keys(pManifest.Solvers)
193
- for (let i = 0; i < tmpSolverKeys.length; i++)
194
- {
195
- this.dataSolverState[tmpSolverKeys] = pManifest.Solvers[tmpSolverKeys[i]];
196
- }
197
-
198
- this.setElucidatorSolvers(this.dataSolvers, this.dataSolverState);
171
+ this.logError(`(${this.scope}) Error loading object description from manifest object. Property "Descriptors" does not exist in the root of the Manifest object.`, tmpManifest);
199
172
  }
200
173
  }
201
174
 
@@ -62,61 +62,6 @@ suite
62
62
  fTestComplete();
63
63
  }
64
64
  );
65
- test
66
- (
67
- 'We should be able to access sets of properties from objects with schema.',
68
- (fTestComplete)=>
69
- {
70
- let _Manyfest = new libManyfest(
71
- {
72
- Scope:'Archive.org',
73
- Descriptors:
74
- {
75
- 'files[]': {Name:'Files', Hash:'FileSet'},
76
- 'files[].size': {Name:'FileSizes', Hash:'FileSizes'},
77
- 'files[]<<~~ThumbnailFilesOnly~~>>': {Name:'Thumbnail Files', Hash:'ThumbnailFiles'},
78
- 'metadata.creator': {Name:'Creator', Hash:'Creator'},
79
- 'metadata{}': {Name:'Metadata', Hash:'Metadata'}
80
- },
81
- Solvers:
82
- {
83
- 'ThumbnailFilesOnly':
84
- {
85
- "Description":
86
- {
87
- "Operation": "ThumbnailFilesOnly",
88
- "Synopsis": "Filter files down to just thumbnails"
89
- },
90
- "Config": { "SearchTerm": "Thumbnail" },
91
- "Steps":
92
- [
93
- {
94
- "Namespace": "Logic",
95
- "Instruction": "if",
96
-
97
- "InputHashAddressMap":
98
- {
99
- "leftValue": "Record.format",
100
- "rightValue": "SolutionState.Config.SearchTerm",
101
- "comparator": "=="
102
- },
103
- "OutputHashAddressMap": { "truthinessResult":"keepRecord" }
104
- }
105
- ]
106
- }
107
- }
108
- });
109
- let tmpThumbnailFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'ThumbnailFiles');
110
- Expect(tmpThumbnailFiles).to.be.an('array');
111
- // There are 7 thumbnail files in the set.
112
- Expect(tmpThumbnailFiles.length).to.equal(7);
113
- let tmpFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FileSet');
114
- Expect(tmpFiles).to.be.an('array');
115
- // There are 7 thumbnail files in the set.
116
- Expect(tmpFiles.length).to.equal(17);
117
- fTestComplete();
118
- }
119
- );
120
65
  }
121
66
  );
122
67
  }