manyfest 1.0.46 → 1.0.48
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 +2 -2
- package/source/Manyfest.js +26 -0
- package/test/Manyfest_CheckStringRole_tests.js +191 -0
- package/.babelrc +0 -3
- package/.browserslistrc +0 -1
- /package/docs/{cover.md → _cover.md} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "manyfest",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.48",
|
|
4
4
|
"description": "JSON Object Manifest for Data Description and Parsing",
|
|
5
5
|
"main": "source/Manyfest.js",
|
|
6
6
|
"scripts": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
]
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"fable-serviceproviderbase": "^3.0.
|
|
49
|
+
"fable-serviceproviderbase": "^3.0.19"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"quackage": "^1.0.51",
|
package/source/Manyfest.js
CHANGED
|
@@ -354,6 +354,32 @@ class Manyfest extends libFableServiceProviderBase
|
|
|
354
354
|
return this.objectAddressCheckAddressExists.checkAddressExists(pObject, pAddress);
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
+
/**
|
|
358
|
+
* Check what role a string plays in this manifest -- whether it is a Hash, an Address, both or neither.
|
|
359
|
+
*
|
|
360
|
+
* @param {string} pString - The string to check.
|
|
361
|
+
*
|
|
362
|
+
* @return {{ IsHash: boolean, IsAddress: boolean, ResolvedAddress: string|undefined }} The role of the string.
|
|
363
|
+
*/
|
|
364
|
+
checkStringRole(pString)
|
|
365
|
+
{
|
|
366
|
+
if (typeof(pString) !== 'string' || pString.length === 0)
|
|
367
|
+
{
|
|
368
|
+
return { IsHash: false, IsAddress: false, ResolvedAddress: undefined };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
let tmpIsAddress = (pString in this.elementDescriptors);
|
|
372
|
+
let tmpIsHash = (pString in this.elementHashes);
|
|
373
|
+
let tmpResolvedAddress = tmpIsHash ? this.elementHashes[pString] : undefined;
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
{
|
|
377
|
+
IsHash: tmpIsHash,
|
|
378
|
+
IsAddress: tmpIsAddress,
|
|
379
|
+
ResolvedAddress: tmpResolvedAddress
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
|
|
357
383
|
// Turn a hash into an address, factoring in the translation table.
|
|
358
384
|
resolveHashAddress(pHash)
|
|
359
385
|
{
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for Manyfest checkStringRole
|
|
3
|
+
*
|
|
4
|
+
* @license MIT
|
|
5
|
+
*
|
|
6
|
+
* @author Steven Velozo <steven@velozo.com>
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var Chai = require("chai");
|
|
10
|
+
var Expect = Chai.expect;
|
|
11
|
+
|
|
12
|
+
let libManyfest = require('../source/Manyfest.js');
|
|
13
|
+
|
|
14
|
+
suite
|
|
15
|
+
(
|
|
16
|
+
'Manyfest checkStringRole',
|
|
17
|
+
function()
|
|
18
|
+
{
|
|
19
|
+
setup (() => {} );
|
|
20
|
+
|
|
21
|
+
suite
|
|
22
|
+
(
|
|
23
|
+
'checkStringRole',
|
|
24
|
+
() =>
|
|
25
|
+
{
|
|
26
|
+
test
|
|
27
|
+
(
|
|
28
|
+
'Should return IsHash:false, IsAddress:false for an empty string.',
|
|
29
|
+
(fTestComplete) =>
|
|
30
|
+
{
|
|
31
|
+
let _Manyfest = new libManyfest(
|
|
32
|
+
{
|
|
33
|
+
Scope: 'Test',
|
|
34
|
+
Descriptors:
|
|
35
|
+
{
|
|
36
|
+
'Name': { Hash: 'PersonName', DataType: 'String' }
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
let tmpResult = _Manyfest.checkStringRole('');
|
|
40
|
+
Expect(tmpResult.IsHash).to.equal(false);
|
|
41
|
+
Expect(tmpResult.IsAddress).to.equal(false);
|
|
42
|
+
Expect(tmpResult.ResolvedAddress).to.equal(undefined);
|
|
43
|
+
fTestComplete();
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
test
|
|
47
|
+
(
|
|
48
|
+
'Should return IsHash:false, IsAddress:false for a non-string.',
|
|
49
|
+
(fTestComplete) =>
|
|
50
|
+
{
|
|
51
|
+
let _Manyfest = new libManyfest(
|
|
52
|
+
{
|
|
53
|
+
Scope: 'Test',
|
|
54
|
+
Descriptors:
|
|
55
|
+
{
|
|
56
|
+
'Name': { Hash: 'PersonName', DataType: 'String' }
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
let tmpResult = _Manyfest.checkStringRole(42);
|
|
60
|
+
Expect(tmpResult.IsHash).to.equal(false);
|
|
61
|
+
Expect(tmpResult.IsAddress).to.equal(false);
|
|
62
|
+
fTestComplete();
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
test
|
|
66
|
+
(
|
|
67
|
+
'Should return IsHash:false, IsAddress:false for an unknown string.',
|
|
68
|
+
(fTestComplete) =>
|
|
69
|
+
{
|
|
70
|
+
let _Manyfest = new libManyfest(
|
|
71
|
+
{
|
|
72
|
+
Scope: 'Test',
|
|
73
|
+
Descriptors:
|
|
74
|
+
{
|
|
75
|
+
'Name': { Hash: 'PersonName', DataType: 'String' }
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
let tmpResult = _Manyfest.checkStringRole('SomethingUnknown');
|
|
79
|
+
Expect(tmpResult.IsHash).to.equal(false);
|
|
80
|
+
Expect(tmpResult.IsAddress).to.equal(false);
|
|
81
|
+
Expect(tmpResult.ResolvedAddress).to.equal(undefined);
|
|
82
|
+
fTestComplete();
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
test
|
|
86
|
+
(
|
|
87
|
+
'Should identify a string that is only a Hash (not an Address).',
|
|
88
|
+
(fTestComplete) =>
|
|
89
|
+
{
|
|
90
|
+
let _Manyfest = new libManyfest(
|
|
91
|
+
{
|
|
92
|
+
Scope: 'Test',
|
|
93
|
+
Descriptors:
|
|
94
|
+
{
|
|
95
|
+
'Full.Name.Path': { Hash: 'PersonName', DataType: 'String' }
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
let tmpResult = _Manyfest.checkStringRole('PersonName');
|
|
99
|
+
Expect(tmpResult.IsHash).to.equal(true);
|
|
100
|
+
Expect(tmpResult.IsAddress).to.equal(false);
|
|
101
|
+
Expect(tmpResult.ResolvedAddress).to.equal('Full.Name.Path');
|
|
102
|
+
fTestComplete();
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
test
|
|
106
|
+
(
|
|
107
|
+
'Should identify a string that is only an Address (not a custom Hash).',
|
|
108
|
+
(fTestComplete) =>
|
|
109
|
+
{
|
|
110
|
+
let _Manyfest = new libManyfest(
|
|
111
|
+
{
|
|
112
|
+
Scope: 'Test',
|
|
113
|
+
Descriptors:
|
|
114
|
+
{
|
|
115
|
+
'Full.Name.Path': { Hash: 'PersonName', DataType: 'String' }
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
// The address is always added as a hash too (mapping to itself), so it's both
|
|
119
|
+
let tmpResult = _Manyfest.checkStringRole('Full.Name.Path');
|
|
120
|
+
Expect(tmpResult.IsHash).to.equal(true);
|
|
121
|
+
Expect(tmpResult.IsAddress).to.equal(true);
|
|
122
|
+
Expect(tmpResult.ResolvedAddress).to.equal('Full.Name.Path');
|
|
123
|
+
fTestComplete();
|
|
124
|
+
}
|
|
125
|
+
);
|
|
126
|
+
test
|
|
127
|
+
(
|
|
128
|
+
'Should identify a string that is both Hash and Address (same string).',
|
|
129
|
+
(fTestComplete) =>
|
|
130
|
+
{
|
|
131
|
+
// When Hash is not specified, it defaults to the address
|
|
132
|
+
let _Manyfest = new libManyfest(
|
|
133
|
+
{
|
|
134
|
+
Scope: 'Test',
|
|
135
|
+
Descriptors:
|
|
136
|
+
{
|
|
137
|
+
'ValueArray': { DataType: 'Array' }
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
let tmpResult = _Manyfest.checkStringRole('ValueArray');
|
|
141
|
+
Expect(tmpResult.IsHash).to.equal(true);
|
|
142
|
+
Expect(tmpResult.IsAddress).to.equal(true);
|
|
143
|
+
Expect(tmpResult.ResolvedAddress).to.equal('ValueArray');
|
|
144
|
+
fTestComplete();
|
|
145
|
+
}
|
|
146
|
+
);
|
|
147
|
+
test
|
|
148
|
+
(
|
|
149
|
+
'Should handle multiple descriptors with distinct hashes and addresses.',
|
|
150
|
+
(fTestComplete) =>
|
|
151
|
+
{
|
|
152
|
+
let _Manyfest = new libManyfest(
|
|
153
|
+
{
|
|
154
|
+
Scope: 'Test',
|
|
155
|
+
Descriptors:
|
|
156
|
+
{
|
|
157
|
+
'DataTableAddress': { Hash: 'DataTable', DataType: 'Array' },
|
|
158
|
+
'DataTableAddress[].ValueAddress': { Hash: 'ValueArray', DataType: 'Array' },
|
|
159
|
+
'AggregateValueAddress': { Hash: 'AggregateValue', DataType: 'PreciseNumber' }
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
// DataTable is a hash only
|
|
163
|
+
let tmpDataTable = _Manyfest.checkStringRole('DataTable');
|
|
164
|
+
Expect(tmpDataTable.IsHash).to.equal(true);
|
|
165
|
+
Expect(tmpDataTable.IsAddress).to.equal(false);
|
|
166
|
+
Expect(tmpDataTable.ResolvedAddress).to.equal('DataTableAddress');
|
|
167
|
+
|
|
168
|
+
// DataTableAddress is both (always added as hash mapping to itself)
|
|
169
|
+
let tmpAddr = _Manyfest.checkStringRole('DataTableAddress');
|
|
170
|
+
Expect(tmpAddr.IsHash).to.equal(true);
|
|
171
|
+
Expect(tmpAddr.IsAddress).to.equal(true);
|
|
172
|
+
Expect(tmpAddr.ResolvedAddress).to.equal('DataTableAddress');
|
|
173
|
+
|
|
174
|
+
// ValueArray is a hash only
|
|
175
|
+
let tmpValueArray = _Manyfest.checkStringRole('ValueArray');
|
|
176
|
+
Expect(tmpValueArray.IsHash).to.equal(true);
|
|
177
|
+
Expect(tmpValueArray.IsAddress).to.equal(false);
|
|
178
|
+
Expect(tmpValueArray.ResolvedAddress).to.equal('DataTableAddress[].ValueAddress');
|
|
179
|
+
|
|
180
|
+
// Unknown string
|
|
181
|
+
let tmpUnknown = _Manyfest.checkStringRole('NotInManifest');
|
|
182
|
+
Expect(tmpUnknown.IsHash).to.equal(false);
|
|
183
|
+
Expect(tmpUnknown.IsAddress).to.equal(false);
|
|
184
|
+
|
|
185
|
+
fTestComplete();
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
);
|
package/.babelrc
DELETED
package/.browserslistrc
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
> 0.01%
|
|
File without changes
|