manyfest 1.0.1 → 1.0.3

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.
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "optOut": false,
3
- "lastUpdateCheck": 1664845901965
3
+ "lastUpdateCheck": 1665680610935
4
4
  }
package/README.md CHANGED
@@ -37,7 +37,7 @@ npm install --save Manyfest
37
37
 
38
38
  Then, you can include it in your source code as follows:
39
39
 
40
- ```
40
+ ```javascript
41
41
  const libManyfest = require('Manyfest');
42
42
 
43
43
  // Construct a Manyfest with a few defined columns
@@ -46,7 +46,7 @@ let animalManyfest = new libManyfest(
46
46
  "Scope": "Animal",
47
47
  "Descriptors":
48
48
  {
49
- "IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer" },
49
+ "IDAnimal": { "Name":"Database ID", "Description":"The unique integer-based database identifier for an Animal record.", "DataType":"Integer", "Default":0 },
50
50
  "Name": { "Description":"The animal's colloquial species name (e.g. Rabbit, Dog, Bear, Mongoose)." },
51
51
  "Type": { "Description":"Whether or not the animal is wild, domesticated, agricultural, in a research lab or a part of a zoo.." }
52
52
  }
@@ -70,16 +70,17 @@ Error does not mean the software throws an exception. It comes back as well-for
70
70
  Below is a lexicon of terms used throughout this documentation. If you see anything missing, want more elaboration or just dislike a particular term, please file an issue in github!
71
71
 
72
72
  | Term | Description |
73
- | Scope | The scope of this representation; generally the clustered or parent record name (e.g. Animal, User, Transaction, etc.) -- does not have functional purpose; only for information and logging. |
74
- | Schema | The stateful representation of an object's structural definition. |
75
- | Element | A defined element of data in an object. |
76
- | Address | The address where that data lies in the object. |
77
- | Descriptor | A description of an element including data such as Name, NameShort, Hash, Description, and other important properties. |
78
- | Name | The name of the element. Meant to be the most succinct human readable name possible. |
79
- | NameShort | A shorter name for the element. Meant to be useful enough to identify the property in log lines, tabular views, graphs and anywhere where we don't always want to see the full name. |
80
- | Description | A description for the element. Very useful when consuming other APIs with their own terse naming standards (or no naming standards)! |
81
- | Hash | A unique within this scope string-based key for this element. Used for easy access of data. |
82
- | Constraint | A validation constraint for an element such as MaxLength, MinLength, Required, Default and such. |
73
+ | ---- | ----------- |
74
+ Scope | The scope of this representation; generally the clustered or parent record name (e.g. Animal, User, Transaction, etc.) -- does not have functional purpose; only for information and logging.
75
+ Schema | The stateful representation of an object's structural definition.
76
+ Element | A defined element of data in an object.
77
+ Address | The address where that data lies in the object.
78
+ Descriptor | A description of an element including data such as Name, NameShort, Hash, Description, and other important properties.
79
+ Name | The name of the element. Meant to be the most succinct human readable name possible.
80
+ NameShort | A shorter name for the element. Meant to be useful enough to identify the property in log lines, tabular views, graphs and anywhere where we don't always want to see the full name.
81
+ Description | A description for the element. Very useful when consuming other APIs with their own terse naming standards (or no naming standards)!
82
+ Hash | A unique within this scope string-based key for this element. Used for easy access of data.
83
+ Required | Set to true if this element is required.
83
84
 
84
85
  ## A More Advanced Schema Example
85
86
 
@@ -88,7 +89,7 @@ Addresses are meant to be kinda magic. They describe locations in nested JSON j
88
89
 
89
90
  Let's use our Animal schema and extend it a little bit. In this case, a new JSON sub object needs to be included carrying important medical information about this animal.
90
91
 
91
- ```
92
+ ```javascript
92
93
  let animalManyfest = new libManyfest(
93
94
  {
94
95
  "Scope": "Animal",
@@ -108,7 +109,9 @@ let animalManyfest = new libManyfest(
108
109
  "Name":"Comfortable Environmental Temperature",
109
110
  "NameShort":"Comf Env Temp",
110
111
  "Hash":"ComfET",
111
- "Description":"The most comfortable temperature for this animal to survive in."}
112
+ "DataType":"Float",
113
+ "Description":"The most comfortable temperature for this animal to survive in."
114
+ }
112
115
  }
113
116
  });
114
117
  ```
@@ -117,6 +120,22 @@ Notice in this example, the addresses are more complex. They have a dot syntax.
117
120
 
118
121
  To aid in this discovery, reference and such, we've given it a NameShort (for use in things like tabular views and graphs/charts), a longer Name and a Hash (to enable easy reading and writing using the object element read/write functions described later in this documentation).
119
122
 
123
+ ### Data Types
124
+
125
+ | Type | Description |
126
+ | ---- | ----------- |
127
+ String | A pretty basic string
128
+ Integer | An integer number
129
+ Float | A floating point number; does not require a decimal point
130
+ Number | A number of any type
131
+ Boolean | A boolean value represented by the JSON true or false
132
+ Binary | A boolean value represented as 1 or 0
133
+ YesNo | A boolean value represented as Y or N
134
+ DateTime | A javascript date
135
+ Array | A plain old javascript array
136
+ Object | A plain old javascript object
137
+ Null | A null value
138
+
120
139
  ## Reading and Writing Element Properties
121
140
 
122
141
  Lastly, when working with objects, Manyfest provides a set of functions to read and write from/to these element addresses. This can be useful for consistently accessing objects across boundaries as well as filling out element defaults without requiring a crazy amount of boilerplate code.
@@ -134,7 +153,7 @@ In the example below, the read and write code throws an error. You could work a
134
153
  * write some kind of complex handler for it
135
154
  * something else clever?
136
155
 
137
- ```
156
+ ```javascript
138
157
  // Write Code
139
158
  let newAnimal = {};
140
159
 
@@ -142,7 +161,7 @@ let newAnimal = {};
142
161
  newAnimal.MedicalStats.HeartReat.RestingHeartRate.OverallAverage = 61;
143
162
  ```
144
163
 
145
- ```
164
+ ```javascript
146
165
  // Read Code
147
166
  let newAnimal = {};
148
167
 
@@ -157,7 +176,7 @@ console.log(newAnimal.MedicalStats.HeartReat.RestingHeartRate.OverallAverage);
157
176
 
158
177
  However with the Manyfest reading and writing methods you can do this (all in one example since it doesn't blow up):
159
178
 
160
- ```
179
+ ```javascript
161
180
  let newAnimal = {};
162
181
 
163
182
  // You can now try to access the value on a "clean" object...
@@ -178,7 +197,7 @@ console.log(animalManyfest.getValueAtAddress(newAnimal, "MedicalStats.HeartRate.
178
197
 
179
198
  Because we have mappings to and from more human readable names to the addresses, we can happily use either the Name or Hash for these lookups. For instance, from the example above, if we have our Comfortable Environmental Temperature for an animal which was in the address `someAnimal.MedicalStats.Temps.CET` and had a hash of `ComfET`, a developer could easily access it by hash (assuming the `favoriteAnimalAPI` function returns a JSON representation of my favorite animal):
180
199
 
181
- ```
200
+ ```javascript
182
201
  let favAnimal = favoriteAnimalAPI();
183
202
 
184
203
  console.log(animalManyfest.getValueByHash(favAnimal,'ComfET'));
@@ -190,7 +209,7 @@ For any elements that haven't defined a Hash, the Address is used. This allows
190
209
 
191
210
  Sometimes we don't have schemas, and want to define object element structure on the fly. This can be done programmatically. As a refresher, here is how we loaded our simplest schema manifest above:
192
211
 
193
- ```
212
+ ```javascript
194
213
  const libManyfest = require('Manyfest');
195
214
 
196
215
  // Construct a Manyfest with a few defined columns
@@ -208,7 +227,7 @@ let animalManyfest = new libManyfest(
208
227
 
209
228
  The programmatic equivalent is the following code:
210
229
 
211
- ```
230
+ ```javascript
212
231
  const libManyfest = require('Manyfest');
213
232
 
214
233
  // Construct a Manyfest with a few defined columns
@@ -231,4 +250,329 @@ Programmatic definition is interesting because you can start with a pre-defined
231
250
 
232
251
  Have you ever tried to code against a weather API? They use *so many* different structures of data. And once you've used their structure, you are kindof stuck with it.
233
252
 
234
- With manyfest, you can easily create a description for each API and code against getting values by hash. This abstracts the complexity of multiple API services without requiring you to marshal it into your own persistence format.
253
+ With manyfest, you can easily create a description for each API and code against getting values by hash. This abstracts the complexity of multiple API services without requiring you to marshal it into your own persistence format.
254
+
255
+ ## Archive dot Org
256
+
257
+ Modern APIs are super complicated. And worse, they change. Let's take a real example. [Archive.org](https://archive.org/) is a wonderful resource for downloading awesome content gathered from the web and such.
258
+
259
+ There is an API to access their data. It's ... really messy, the data you get back. below is the JSON for a single video (a rad Count Chocula commercial from 1971) -- it takes quite a bit of scroll to get down to the bottom.
260
+
261
+ ![Count Chocula will Rise Again](http://ia800202.us.archive.org/7/items/FrankenberryCountChoculaTevevisionCommercial1971/frankerberry_countchockula_1971.0001.gif)
262
+
263
+ ```JSON
264
+ {
265
+ "created": 1664830085,
266
+ "d1": "ia600202.us.archive.org",
267
+ "d2": "ia800202.us.archive.org",
268
+ "dir": "/7/items/FrankenberryCountChoculaTevevisionCommercial1971",
269
+ "files": [
270
+ {
271
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000001.jpg",
272
+ "source": "derivative",
273
+ "format": "Thumbnail",
274
+ "original": "frankerberry_countchockula_1971.0001.mpg",
275
+ "mtime": "1296336956",
276
+ "size": "838",
277
+ "md5": "e47269cd5a82db9594f265a65785ec12",
278
+ "crc32": "165c668b",
279
+ "sha1": "383303d9546c381267569ad4e33aff691f0bb8c7"
280
+ },
281
+ {
282
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000004.jpg",
283
+ "source": "derivative",
284
+ "format": "Thumbnail",
285
+ "original": "frankerberry_countchockula_1971.0001.mpg",
286
+ "mtime": "1296336957",
287
+ "size": "6843",
288
+ "md5": "c93fa52000ab4665e69b25c403e11aff",
289
+ "crc32": "9444e6f6",
290
+ "sha1": "716b4f9950b8147f51d3265f9c62ff86451308d5"
291
+ },
292
+ {
293
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000009.jpg",
294
+ "source": "derivative",
295
+ "format": "Thumbnail",
296
+ "original": "frankerberry_countchockula_1971.0001.mpg",
297
+ "mtime": "1296336957",
298
+ "size": "8388",
299
+ "md5": "30eb3eb4cbbdfa08d531a0a74da7c000",
300
+ "crc32": "be874a9e",
301
+ "sha1": "0c392d777609e967b6022be27edad678c5ae74e2"
302
+ },
303
+ {
304
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000014.jpg",
305
+ "source": "derivative",
306
+ "format": "Thumbnail",
307
+ "original": "frankerberry_countchockula_1971.0001.mpg",
308
+ "mtime": "1296336958",
309
+ "size": "5993",
310
+ "md5": "4e9ebc3d076bec8cf7dfe76795f8c769",
311
+ "crc32": "912ec98c",
312
+ "sha1": "01dc49c852e1bbb421199450dd902935c62b06de"
313
+ },
314
+ {
315
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000019.jpg",
316
+ "source": "derivative",
317
+ "format": "Thumbnail",
318
+ "original": "frankerberry_countchockula_1971.0001.mpg",
319
+ "mtime": "1296336958",
320
+ "size": "4951",
321
+ "md5": "59f190f0c5b0a048415b26412860b6dd",
322
+ "crc32": "a70a30b1",
323
+ "sha1": "a284af9757cb24d28f96ec88ec1b1c23a8cea9fe"
324
+ },
325
+ {
326
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000024.jpg",
327
+ "source": "derivative",
328
+ "format": "Thumbnail",
329
+ "original": "frankerberry_countchockula_1971.0001.mpg",
330
+ "mtime": "1296336959",
331
+ "size": "3383",
332
+ "md5": "be2a908acd563b896e7758b598295148",
333
+ "crc32": "ed467831",
334
+ "sha1": "94c001e72ebc86d837a78c61a004db9ab9d597bd"
335
+ },
336
+ {
337
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971.thumbs/frankerberry_countchockula_1971.0001_000029.jpg",
338
+ "source": "derivative",
339
+ "format": "Thumbnail",
340
+ "original": "frankerberry_countchockula_1971.0001.mpg",
341
+ "mtime": "1296336960",
342
+ "size": "3503",
343
+ "md5": "c82199d09be07633000fd07b363dd8a3",
344
+ "crc32": "a1fd79cb",
345
+ "sha1": "2bc8e761edb24a441fa5906dda1c424e1f98a47a"
346
+ },
347
+ {
348
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971_archive.torrent",
349
+ "source": "metadata",
350
+ "btih": "de6b371e7cc3c83db1cc08150500753eae533409",
351
+ "mtime": "1542761794",
352
+ "size": "4093",
353
+ "md5": "a275d3b4028cccb5bea8b47a88c838af",
354
+ "crc32": "5ffa7334",
355
+ "sha1": "af8222637b574cba1360d0ea77e231640ffd43c4",
356
+ "format": "Archive BitTorrent"
357
+ },
358
+ {
359
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971_files.xml",
360
+ "source": "metadata",
361
+ "format": "Metadata",
362
+ "md5": "3a7e87b08bed1e203a5858b31352c110"
363
+ },
364
+ {
365
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971_meta.xml",
366
+ "source": "metadata",
367
+ "format": "Metadata",
368
+ "mtime": "1542761793",
369
+ "size": "1371",
370
+ "md5": "0b9c9bf21b9a26aea43a2f735b404624",
371
+ "crc32": "41077288",
372
+ "sha1": "22e6f2c73bf63072f671d846355da2785db51dbd"
373
+ },
374
+ {
375
+ "name": "FrankenberryCountChoculaTevevisionCommercial1971_reviews.xml",
376
+ "source": "original",
377
+ "mtime": "1466898697",
378
+ "size": "620",
379
+ "md5": "260bfba5d696772445dcc7ff6e6d5bdb",
380
+ "crc32": "25ea3229",
381
+ "sha1": "7d541f18fcd5ad9c6e593afe5a80f18771f23b32",
382
+ "format": "Metadata"
383
+ },
384
+ {
385
+ "name": "__ia_thumb.jpg",
386
+ "source": "original",
387
+ "mtime": "1539115881",
388
+ "size": "7481",
389
+ "md5": "8cec324fa0016fd77cc04e6a4b2ebb00",
390
+ "crc32": "d9e1b316",
391
+ "sha1": "4dab42952fe0405a3b7f80146636b33d7b1bd01e",
392
+ "format": "Item Tile",
393
+ "rotation": "0"
394
+ },
395
+ {
396
+ "name": "frankerberry_countchockula_1971.0001.gif",
397
+ "source": "derivative",
398
+ "format": "Animated GIF",
399
+ "original": "frankerberry_countchockula_1971.0001.mpg",
400
+ "mtime": "1296336965",
401
+ "size": "101114",
402
+ "md5": "b78a13094030f104900eb996bafe2b7d",
403
+ "crc32": "6650cd8",
404
+ "sha1": "669798c037205cac14f70592deef6f7831b3d4a1"
405
+ },
406
+ {
407
+ "name": "frankerberry_countchockula_1971.0001.mpg",
408
+ "source": "original",
409
+ "format": "MPEG2",
410
+ "mtime": "1296335803",
411
+ "size": "31625216",
412
+ "md5": "762ba18b026b85b3f074523e7fcb4db0",
413
+ "crc32": "42347f78",
414
+ "sha1": "41162dc2d1a91b618124c84628d0c231544a02be",
415
+ "length": "31.14",
416
+ "height": "480",
417
+ "width": "640"
418
+ },
419
+ {
420
+ "name": "frankerberry_countchockula_1971.0001.mpg.idx",
421
+ "source": "derivative",
422
+ "format": "Video Index",
423
+ "original": "frankerberry_countchockula_1971.0001.mpg",
424
+ "mtime": "1296336956",
425
+ "size": "31141",
426
+ "md5": "49423e072726e4ea3cdd8ebdd26c7dfc",
427
+ "crc32": "ae969a68",
428
+ "sha1": "805782cd2d0f9002555816daadf3b8607e621f79"
429
+ },
430
+ {
431
+ "name": "frankerberry_countchockula_1971.0001.ogv",
432
+ "source": "derivative",
433
+ "format": "Ogg Video",
434
+ "original": "frankerberry_countchockula_1971.0001.mpg",
435
+ "mtime": "1296336994",
436
+ "size": "2248166",
437
+ "md5": "f1b933e97ce63594fb28a0a019ff3436",
438
+ "crc32": "a2a0e5e9",
439
+ "sha1": "a6bf0aec9f006baeca37c03f586686ebe685d59b",
440
+ "length": "31.15",
441
+ "height": "300",
442
+ "width": "400"
443
+ },
444
+ {
445
+ "name": "frankerberry_countchockula_1971.0001_512kb.mp4",
446
+ "source": "derivative",
447
+ "format": "512Kb MPEG4",
448
+ "original": "frankerberry_countchockula_1971.0001.mpg",
449
+ "mtime": "1296336977",
450
+ "size": "2378677",
451
+ "md5": "a7750839519c61ba3bb99fc66b32011d",
452
+ "crc32": "4dbd37c8",
453
+ "sha1": "3929314c192dec006fac2739bcb4730788e8c068",
454
+ "length": "31.13",
455
+ "height": "240",
456
+ "width": "320"
457
+ }
458
+ ],
459
+ "files_count": 17,
460
+ "item_last_updated": 1542761794,
461
+ "item_size": 36431778,
462
+ "metadata": {
463
+ "identifier": "FrankenberryCountChoculaTevevisionCommercial1971",
464
+ "title": "Franken Berry / Count Chocula : Tevevision Commercial 1971",
465
+ "creator": "General Mills",
466
+ "mediatype": "movies",
467
+ "collection": [
468
+ "classic_tv_commercials",
469
+ "television"
470
+ ],
471
+ "description": "Count Chocula and Franken Berry were both introduced in 1971. Boo Berry Cereal appeared in 1973 followed by Fruit Brute in 1974. Yummy Mummy appeared more than a decade later in 1988 - completing the the group known as the General Mills Monster Cereals.",
472
+ "subject": "Third Eye Cinema; Classic Television Commercials; animation; cartoons;General Mills",
473
+ "licenseurl": "http://creativecommons.org/publicdomain/mark/1.0/",
474
+ "publicdate": "2011-01-29 21:36:42",
475
+ "addeddate": "2011-01-29 21:35:38",
476
+ "uploader": "bolexman@msn.com",
477
+ "updater": [
478
+ "Bolexman",
479
+ "Bolexman",
480
+ "Jeff Kaplan"
481
+ ],
482
+ "updatedate": [
483
+ "2011-01-29 21:45:38",
484
+ "2011-01-29 21:55:46",
485
+ "2011-01-29 23:04:55"
486
+ ],
487
+ "sound": "sound",
488
+ "color": "color",
489
+ "runtime": "0:31",
490
+ "backup_location": "ia903608_22",
491
+ "ia_orig__runtime": "31 seconds"
492
+ },
493
+ "reviews": [
494
+ {
495
+ "reviewbody": "Sugar cereal cartoon Karloff and Lugosi argue self-importance pre Lorre ghost. Interesting how kids still know the voices without any idea of the origins.",
496
+ "reviewtitle": "pre booberry",
497
+ "reviewer": "outofthebox",
498
+ "reviewdate": "2016-06-25 23:51:36",
499
+ "createdate": "2016-06-25 23:51:36",
500
+ "stars": "4"
501
+ }
502
+ ],
503
+ "server": "ia800202.us.archive.org",
504
+ "uniq": 1957612749,
505
+ "workable_servers": [
506
+ "ia800202.us.archive.org",
507
+ "ia600202.us.archive.org"
508
+ ]
509
+ }
510
+ ```
511
+
512
+ ### A Manyfest Schema for Count Chocula to Thrive In
513
+
514
+ With just a small number of element descriptors, we can make this huge blob of JSON very usable for a developer.
515
+
516
+ ```JSON
517
+ {
518
+ "Scope": "Archive.org",
519
+ "Descriptors": {
520
+ "d1": {
521
+ "Hash": "Server",
522
+ "Name": "Server",
523
+ "Description": "The primary server to download these files from.",
524
+ "DataType": "String"
525
+ },
526
+ "d2": {
527
+ "Hash": "ServerAlternate",
528
+ "Name": "Alternate Server",
529
+ "Description": "The alternate server to download these files from.",
530
+ "DataType": "String"
531
+ },
532
+ "dir": {
533
+ "Hash": "Path",
534
+ "Name": "Server URL Path",
535
+ "NameShort": "Path",
536
+ "Description": "The path on the server where these files are located."
537
+ },
538
+ "metadata.identifier": {
539
+ "Hash": "GUID",
540
+ "Name": "Globally Unique Identifier",
541
+ "NameShort": "GUID",
542
+ "Description": "Archive.org unique identifier string."
543
+ },
544
+ "metadata.title": {
545
+ "Hash": "Title",
546
+ "Name": "Title",
547
+ "NameShort": "Title",
548
+ "Description": "The title of the media item."
549
+ },
550
+ "metadata.creator": {
551
+ "Hash": "Creator",
552
+ "Name": "Creator",
553
+ "NameShort": "Creator",
554
+ "Description": "The creator of the media item."
555
+ },
556
+ "metadata.mediatype": {
557
+ "Hash": "Type",
558
+ "Name": "Media Type",
559
+ "NameShort": "Type",
560
+ "Description": "The type of media item."
561
+ }
562
+ }
563
+ }
564
+ ```
565
+
566
+ These two JSON files are in the [examples/chocula](https://github.com/stevenvelozo/manyfest/tree/main/examples/chocula) folder along with a javascript file `Chocula.js` you can try out yourself and hack on.
567
+
568
+ ```
569
+ let libManyfest = require('../../source/Manyfest.js');
570
+
571
+ let dataArchiveOrg = require(`./Data-Archive-org-Frankenberry.json`);
572
+ let schemaArchiveOrg = require(`./Schema-Archive-org-Item.json`);
573
+
574
+ let _Schema = new libManyfest(schemaArchiveOrg);
575
+
576
+ console.log(`The URL for "${_Schema.getValueByHash(dataArchiveOrg,'Title')}" is: ${_Schema.getValueByHash(dataArchiveOrg,'Server')}${_Schema.getValueByHash(dataArchiveOrg,'Path')}`);
577
+ ```
578
+
@@ -0,0 +1,8 @@
1
+ let libManyfest = require('../../source/Manyfest.js');
2
+
3
+ let dataArchiveOrg = require(`./Data-Archive-org-Frankenberry.json`);
4
+ let schemaArchiveOrg = require(`./Schema-Archive-org-Item.json`);
5
+
6
+ let _Schema = new libManyfest(schemaArchiveOrg);
7
+
8
+ console.log(`The URL for "${_Schema.getValueByHash(dataArchiveOrg,'Title')}" is: ${_Schema.getValueByHash(dataArchiveOrg,'Server')}${_Schema.getValueByHash(dataArchiveOrg,'Path')}`);