manyfest 1.0.9 → 1.0.11

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.9",
3
+ "version": "1.0.11",
4
4
  "description": "JSON Object Manifest for Data Description and Parsing",
5
5
  "main": "source/Manyfest.js",
6
6
  "scripts": {
@@ -249,6 +249,13 @@ class ManyfestObjectAddressResolver
249
249
  // TODO: Consider adding a "don't replace" option for precedent
250
250
  let tmpAddress = pAddress;
251
251
 
252
+ if (!this.elucidatorSolver)
253
+ {
254
+ // Again, manage against circular dependencies
255
+ let libElucidator = require('elucidator');
256
+ this.elucidatorSolver = new libElucidator({}, this.logInfo, this.logError);
257
+ }
258
+
252
259
  if (this.elucidatorSolver)
253
260
  {
254
261
  // This allows the magic filtration with elucidator configuration
@@ -263,7 +270,7 @@ class ManyfestObjectAddressResolver
263
270
  // This is about as complex as it gets.
264
271
  // TODO: Optimize this so it is only initialized once.
265
272
  // TODO: That means figuring out a healthy pattern for passing in state to this
266
- tmpPrecedent.addPattern('{<~~', '~~>}',
273
+ tmpPrecedent.addPattern('<<~~', '~~>>',
267
274
  (pInstructionHash) =>
268
275
  {
269
276
  // This is for internal config on the solution steps. Right now config is not shared across steps.
@@ -273,7 +280,54 @@ class ManyfestObjectAddressResolver
273
280
  }
274
281
  this.elucidatorSolver.solveInternalOperation('Custom', pInstructionHash, tmpFilterState);
275
282
  });
276
-
283
+ tmpPrecedent.addPattern('<<~?', '?~>>',
284
+ (pMagicSearchExpression) =>
285
+ {
286
+ if (typeof(pMagicSearchExpression) !== 'string')
287
+ {
288
+ return false;
289
+ }
290
+ // This expects a comma separated expression:
291
+ // Some.Address.In.The.Object,==,Search Term to Match
292
+ let tmpMagicComparisonPatternSet = pMagicSearchExpression.split(',');
293
+
294
+ let tmpSearchAddress = tmpMagicComparisonPatternSet[0];
295
+ let tmpSearchComparator = tmpMagicComparisonPatternSet[1];
296
+ let tmpSearchValue = tmpMagicComparisonPatternSet[2];
297
+
298
+ tmpFilterState.ComparisonState = (
299
+ {
300
+ SearchAddress: tmpSearchAddress,
301
+ Comparator: tmpSearchComparator,
302
+ SearchTerm: tmpSearchValue
303
+ });
304
+
305
+ this.elucidatorSolver.solveOperation(
306
+ {
307
+ "Description":
308
+ {
309
+ "Operation": "Simple_If",
310
+ "Synopsis": "Test for "
311
+ },
312
+ "Steps":
313
+ [
314
+ {
315
+ "Namespace": "Logic",
316
+ "Instruction": "if",
317
+
318
+ "InputHashAddressMap":
319
+ {
320
+ // This is ... dynamically assigning the address in the instruction
321
+ // The complexity is astounding.
322
+ "leftValue": `Record.${tmpSearchAddress}`,
323
+ "rightValue": "ComparisonState.SearchTerm",
324
+ "comparator": "ComparisonState.Comparator"
325
+ },
326
+ "OutputHashAddressMap": { "truthinessResult":"keepRecord" }
327
+ }
328
+ ]
329
+ }, tmpFilterState);
330
+ });
277
331
  tmpPrecedent.parseString(tmpAddress);
278
332
 
279
333
  // It is expected that the operation will mutate this to some truthy value
@@ -249,6 +249,17 @@ class Manyfest
249
249
  return this.elementDescriptors[pAddress];
250
250
  }
251
251
 
252
+ // execute an action function for each descriptor
253
+ eachDescriptor(fAction)
254
+ {
255
+ let tmpDescriptorAddresses = Object.keys(this.elementDescriptors);
256
+ for (let i = 0; i < tmpDescriptorAddresses.length; i++)
257
+ {
258
+ fAction(this.elementDescriptors[tmpDescriptorAddresses[i]]);
259
+ }
260
+
261
+ }
262
+
252
263
  /*************************************************************************
253
264
  * Beginning of Object Manipulation (read & write) Functions
254
265
  */
@@ -25,6 +25,43 @@ suite
25
25
  'Set Filtration',
26
26
  ()=>
27
27
  {
28
+ test
29
+ (
30
+ 'Magic filters should be magic.',
31
+ (fTestComplete)=>
32
+ {
33
+ let _Manyfest = new libManyfest(
34
+ {
35
+ Scope:'Archive.org',
36
+ Descriptors:
37
+ {
38
+ 'files[]': {Name:'Files', Hash:'FileSet'},
39
+ 'files[]<<~?format,==,Thumbnail?~>>': {Name:'Thumbnail Files', Hash:'ThumbnailFiles'},
40
+ 'files[]<<~?format,==,Metadata?~>>': {Name:'Metadata Files', Hash:'MetadataFiles'},
41
+ 'metadata.creator': {Name:'Creator', Hash:'Creator'}
42
+ }
43
+ });
44
+
45
+ // Grab magic filtered thumbnails
46
+ let tmpThumbnailFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'ThumbnailFiles');
47
+ Expect(tmpThumbnailFiles).to.be.an('array');
48
+ // There are 7 thumbnail files in the set.
49
+ Expect(tmpThumbnailFiles.length).to.equal(7);
50
+
51
+ // Grab magic filtered etadataFiles
52
+ let tmpMetadataFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'MetadataFiles');
53
+ Expect(tmpMetadataFiles).to.be.an('array');
54
+ // There are 3 metadata files in the set.
55
+ Expect(tmpMetadataFiles.length).to.equal(3);
56
+
57
+ let tmpFiles = _Manyfest.getValueByHash(_SampleDataArchiveOrgFrankenberry, 'FileSet');
58
+ Expect(tmpFiles).to.be.an('array');
59
+ // There are 17 total files in the set.
60
+ Expect(tmpFiles.length).to.equal(17);
61
+
62
+ fTestComplete();
63
+ }
64
+ );
28
65
  test
29
66
  (
30
67
  'We should be able to access sets of properties from objects with schema.',
@@ -37,7 +74,7 @@ suite
37
74
  {
38
75
  'files[]': {Name:'Files', Hash:'FileSet'},
39
76
  'files[].size': {Name:'FileSizes', Hash:'FileSizes'},
40
- 'files[]{<~~ThumbnailFilesOnly~~>}': {Name:'Thumbnail Files', Hash:'ThumbnailFiles'},
77
+ 'files[]<<~~ThumbnailFilesOnly~~>>': {Name:'Thumbnail Files', Hash:'ThumbnailFiles'},
41
78
  'metadata.creator': {Name:'Creator', Hash:'Creator'},
42
79
  'metadata{}': {Name:'Metadata', Hash:'Metadata'}
43
80
  },
@@ -243,6 +243,48 @@ suite
243
243
  fTestComplete();
244
244
  }
245
245
  );
246
+ test
247
+ (
248
+ 'Iterate through elements of a schema.',
249
+ (fTestComplete)=>
250
+ {
251
+ let _Manyfest = new libManyfest(
252
+ {
253
+ "Scope": "Animal",
254
+ "Descriptors":
255
+ {
256
+ "IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
257
+ "Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
258
+ "Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." },
259
+ "MedicalStats":
260
+ {
261
+ "Name":"Medical Statistics", "Description":"Basic medical statistics for this animal"
262
+ },
263
+ "MedicalStats.Temps.MinET": { "Name":"Minimum Environmental Temperature", "NameShort":"MinET", "Description":"Safest minimum temperature for this animal to survive in."},
264
+ "MedicalStats.Temps.MaxET": { "Name":"Maximum Environmental Temperature", "NameShort":"MaxET", "Description":"Safest maximum temperature for this animal to survive in."},
265
+ "MedicalStats.Temps.CET":
266
+ {
267
+ "Name":"Comfortable Environmental Temperature",
268
+ "NameShort":"Comf Env Temp",
269
+ "Hash":"ComfET",
270
+ "Description":"The most comfortable temperature for this animal to survive in.",
271
+ "Default": "96.8"
272
+ }
273
+ }
274
+ });
275
+
276
+ let tmpSchemaAddresses = [];
277
+
278
+ _Manyfest.eachDescriptor(
279
+ (pDescriptor)=>
280
+ {
281
+ tmpSchemaAddresses.push(pDescriptor.Hash);
282
+ })
283
+ Expect(tmpSchemaAddresses.length).to.equal(7);
284
+ Expect(tmpSchemaAddresses[6]).to.equal('ComfET');
285
+ fTestComplete();
286
+ }
287
+ );
246
288
  }
247
289
  );
248
290
  }