manyfest 1.0.42 → 1.0.44
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/README.md +91 -260
- package/dist/manyfest.compatible.js +279 -112
- package/dist/manyfest.compatible.js.map +1 -1
- package/dist/manyfest.compatible.min.js +1 -1
- package/dist/manyfest.compatible.min.js.map +1 -1
- package/dist/manyfest.js +280 -112
- package/dist/manyfest.js.map +1 -1
- package/dist/manyfest.min.js +1 -1
- package/dist/manyfest.min.js.map +1 -1
- package/docs/.nojekyll +0 -0
- package/docs/README.md +108 -0
- package/docs/_sidebar.md +17 -0
- package/docs/address-notation.md +244 -0
- package/docs/cover.md +11 -0
- package/docs/hash-translation.md +202 -0
- package/docs/index.html +51 -0
- package/docs/quickstart.md +203 -0
- package/docs/reading.md +339 -0
- package/docs/schema-manipulation.md +186 -0
- package/docs/schema.md +319 -0
- package/docs/validating.md +344 -0
- package/docs/writing.md +300 -0
- package/package.json +3 -3
- package/source/Manyfest-CleanWrapCharacters.js +7 -1
- package/source/Manyfest-HashTranslation.js +29 -8
- package/source/Manyfest-ObjectAddress-CheckAddressExists.js +31 -17
- package/source/Manyfest-ObjectAddress-DeleteValue.js +27 -7
- package/source/Manyfest-ObjectAddress-GetValue.js +25 -10
- package/source/Manyfest-ObjectAddress-Parser.js +42 -35
- package/source/Manyfest-ObjectAddress-SetValue.js +21 -6
- package/source/Manyfest-ObjectAddressGeneration.js +23 -12
- package/source/Manyfest-ParseConditionals.js +3 -16
- package/source/Manyfest-SchemaManipulation.js +44 -21
- package/source/Manyfest.js +72 -17
- package/test/Manyfest_Performance_tests.js +48 -0
- package/types/Manyfest-CleanWrapCharacters.d.ts +7 -1
- package/types/Manyfest-CleanWrapCharacters.d.ts.map +1 -1
- package/types/Manyfest-HashTranslation.d.ts +34 -7
- package/types/Manyfest-HashTranslation.d.ts.map +1 -1
- package/types/Manyfest-ObjectAddress-CheckAddressExists.d.ts +23 -4
- package/types/Manyfest-ObjectAddress-CheckAddressExists.d.ts.map +1 -1
- package/types/Manyfest-ObjectAddress-DeleteValue.d.ts +25 -6
- package/types/Manyfest-ObjectAddress-DeleteValue.d.ts.map +1 -1
- package/types/Manyfest-ObjectAddress-GetValue.d.ts +26 -6
- package/types/Manyfest-ObjectAddress-GetValue.d.ts.map +1 -1
- package/types/Manyfest-ObjectAddress-Parser.d.ts +5 -5
- package/types/Manyfest-ObjectAddress-Parser.d.ts.map +1 -1
- package/types/Manyfest-ObjectAddress-SetValue.d.ts +18 -5
- package/types/Manyfest-ObjectAddress-SetValue.d.ts.map +1 -1
- package/types/Manyfest-ObjectAddressGeneration.d.ts +25 -4
- package/types/Manyfest-ObjectAddressGeneration.d.ts.map +1 -1
- package/types/Manyfest-SchemaManipulation.d.ts +47 -6
- package/types/Manyfest-SchemaManipulation.d.ts.map +1 -1
- package/types/Manyfest.d.ts +35 -12
- package/types/Manyfest.d.ts.map +1 -1
|
@@ -20,6 +20,10 @@ let libSimpleLog = require('./Manyfest-LogToConsole.js');
|
|
|
20
20
|
*/
|
|
21
21
|
class ManyfestHashTranslation
|
|
22
22
|
{
|
|
23
|
+
/**
|
|
24
|
+
* @param {function} [pInfoLog] - (optional) A logging function for info messages
|
|
25
|
+
* @param {function} [pErrorLog] - (optional) A logging function for error messages
|
|
26
|
+
*/
|
|
23
27
|
constructor(pInfoLog, pErrorLog)
|
|
24
28
|
{
|
|
25
29
|
// Wire in logging
|
|
@@ -29,11 +33,17 @@ class ManyfestHashTranslation
|
|
|
29
33
|
this.translationTable = {};
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @return {number} The number of translations in the table
|
|
38
|
+
*/
|
|
32
39
|
translationCount()
|
|
33
40
|
{
|
|
34
41
|
return Object.keys(this.translationTable).length;
|
|
35
42
|
}
|
|
36
43
|
|
|
44
|
+
/**
|
|
45
|
+
* @param {object} pTranslation - An object containing source:destination hash pairs to add to the translation table
|
|
46
|
+
*/
|
|
37
47
|
addTranslation(pTranslation)
|
|
38
48
|
{
|
|
39
49
|
// This adds a translation in the form of:
|
|
@@ -60,17 +70,23 @@ class ManyfestHashTranslation
|
|
|
60
70
|
});
|
|
61
71
|
}
|
|
62
72
|
|
|
73
|
+
/**
|
|
74
|
+
* @param {string} pTranslationHash - The source hash to remove from the translation table
|
|
75
|
+
*/
|
|
63
76
|
removeTranslationHash(pTranslationHash)
|
|
64
77
|
{
|
|
65
|
-
|
|
66
|
-
{
|
|
67
|
-
delete this.translationTable[pTranslationHash];
|
|
68
|
-
}
|
|
78
|
+
delete this.translationTable[pTranslationHash];
|
|
69
79
|
}
|
|
70
80
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
/**
|
|
82
|
+
* This removes translations.
|
|
83
|
+
* If passed a string, just removes the single one.
|
|
84
|
+
* If passed an object, it does all the source keys.
|
|
85
|
+
*
|
|
86
|
+
* @param {string|object} pTranslation - Either a source hash string to remove, or an object containing source:destination hash pairs to remove
|
|
87
|
+
*
|
|
88
|
+
* @return {boolean} True if the removal was successful, false otherwise
|
|
89
|
+
*/
|
|
74
90
|
removeTranslation(pTranslation)
|
|
75
91
|
{
|
|
76
92
|
if (typeof(pTranslation) == 'string')
|
|
@@ -101,6 +117,11 @@ class ManyfestHashTranslation
|
|
|
101
117
|
this.translationTable = {};
|
|
102
118
|
}
|
|
103
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @param {string} pTranslation - The source hash to translate
|
|
122
|
+
*
|
|
123
|
+
* @return {string} The translated hash, or the original if no translation exists
|
|
124
|
+
*/
|
|
104
125
|
translate(pTranslation)
|
|
105
126
|
{
|
|
106
127
|
if (pTranslation in this.translationTable)
|
|
@@ -114,4 +135,4 @@ class ManyfestHashTranslation
|
|
|
114
135
|
}
|
|
115
136
|
}
|
|
116
137
|
|
|
117
|
-
module.exports = ManyfestHashTranslation;
|
|
138
|
+
module.exports = ManyfestHashTranslation;
|
|
@@ -5,6 +5,8 @@ const libSimpleLog = require('./Manyfest-LogToConsole.js');
|
|
|
5
5
|
// This is for resolving functions mid-address
|
|
6
6
|
const libGetObjectValue = require('./Manyfest-ObjectAddress-GetValue.js');
|
|
7
7
|
|
|
8
|
+
const fCleanWrapCharacters = require('./Manyfest-CleanWrapCharacters.js');
|
|
9
|
+
|
|
8
10
|
// TODO: Just until this is a fable service.
|
|
9
11
|
let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
|
|
10
12
|
|
|
@@ -28,6 +30,10 @@ let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
|
|
|
28
30
|
*/
|
|
29
31
|
class ManyfestObjectAddressResolverCheckAddressExists
|
|
30
32
|
{
|
|
33
|
+
/**
|
|
34
|
+
* @param {function} [pInfoLog] - (optional) Function to use for info logging
|
|
35
|
+
* @param {function} [pErrorLog] - (optional) Function to use for error logging
|
|
36
|
+
*/
|
|
31
37
|
constructor(pInfoLog, pErrorLog)
|
|
32
38
|
{
|
|
33
39
|
// Wire in logging
|
|
@@ -35,15 +41,24 @@ class ManyfestObjectAddressResolverCheckAddressExists
|
|
|
35
41
|
this.logError = (typeof(pErrorLog) == 'function') ? pErrorLog : libSimpleLog;
|
|
36
42
|
|
|
37
43
|
this.getObjectValueClass = new libGetObjectValue(this.logInfo, this.logError);
|
|
44
|
+
this.cleanWrapCharacters = fCleanWrapCharacters;
|
|
38
45
|
}
|
|
39
46
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Check if an address exists.
|
|
49
|
+
*
|
|
50
|
+
* This is necessary because the getValueAtAddress function is ambiguous on
|
|
51
|
+
* whether the element/property is actually there or not (it returns
|
|
52
|
+
* undefined whether the property exists or not). This function checks for
|
|
53
|
+
* existance and returns true or false dependent.
|
|
54
|
+
*
|
|
55
|
+
* @param {object} pObject - The object to check within
|
|
56
|
+
* @param {string} pAddress - The address to check for
|
|
57
|
+
* @param {object} [pRootObject] - (optional) The root object for function resolution context
|
|
58
|
+
*
|
|
59
|
+
* @return {boolean} - True if the address exists, false if it does not
|
|
60
|
+
*/
|
|
61
|
+
checkAddressExists(pObject, pAddress, pRootObject)
|
|
47
62
|
{
|
|
48
63
|
// TODO: Should these throw an error?
|
|
49
64
|
// Make sure pObject is an object
|
|
@@ -193,7 +208,7 @@ class ManyfestObjectAddressResolverCheckAddressExists
|
|
|
193
208
|
let tmpFunctionAddress = tmpSubObjectName.substring(0, tmpFunctionStartIndex).trim();
|
|
194
209
|
//tmpParentAddress = `${tmpParentAddress}${(tmpParentAddress.length > 0) ? '.' : ''}${tmpSubObjectName}`;
|
|
195
210
|
|
|
196
|
-
if (
|
|
211
|
+
if (typeof pObject[tmpFunctionAddress] !== 'function')
|
|
197
212
|
{
|
|
198
213
|
// The address suggests it is a function, but it is not.
|
|
199
214
|
return false;
|
|
@@ -214,14 +229,14 @@ class ManyfestObjectAddressResolverCheckAddressExists
|
|
|
214
229
|
catch(pError)
|
|
215
230
|
{
|
|
216
231
|
// The function call failed, so the address doesn't exist
|
|
217
|
-
libSimpleLog
|
|
232
|
+
libSimpleLog(`Error calling function ${tmpFunctionAddress} (address [${pAddress}]): ${pError.message}`);
|
|
218
233
|
return false;
|
|
219
234
|
}
|
|
220
235
|
}
|
|
221
236
|
else
|
|
222
237
|
{
|
|
223
238
|
// The function doesn't exist, so the address doesn't exist
|
|
224
|
-
libSimpleLog
|
|
239
|
+
libSimpleLog(`Function ${tmpFunctionAddress} does not exist (address [${pAddress}])`);
|
|
225
240
|
return false;
|
|
226
241
|
}
|
|
227
242
|
}
|
|
@@ -229,7 +244,7 @@ class ManyfestObjectAddressResolverCheckAddressExists
|
|
|
229
244
|
{
|
|
230
245
|
let tmpArgumentValues = [];
|
|
231
246
|
|
|
232
|
-
|
|
247
|
+
|
|
233
248
|
|
|
234
249
|
// Now get the value for each argument
|
|
235
250
|
for (let i = 0; i < tmpFunctionArguments.length; i++)
|
|
@@ -249,14 +264,14 @@ class ManyfestObjectAddressResolverCheckAddressExists
|
|
|
249
264
|
catch(pError)
|
|
250
265
|
{
|
|
251
266
|
// The function call failed, so the address doesn't exist
|
|
252
|
-
libSimpleLog
|
|
267
|
+
libSimpleLog(`Error calling function ${tmpFunctionAddress} (address [${pAddress}]): ${pError.message}`);
|
|
253
268
|
return false;
|
|
254
269
|
}
|
|
255
270
|
}
|
|
256
271
|
else
|
|
257
272
|
{
|
|
258
273
|
// The function doesn't exist, so the address doesn't exist
|
|
259
|
-
libSimpleLog
|
|
274
|
+
libSimpleLog(`Function ${tmpFunctionAddress} does not exist (address [${pAddress}])`);
|
|
260
275
|
return false;
|
|
261
276
|
}
|
|
262
277
|
}
|
|
@@ -336,12 +351,11 @@ class ManyfestObjectAddressResolverCheckAddressExists
|
|
|
336
351
|
}
|
|
337
352
|
else
|
|
338
353
|
{
|
|
339
|
-
//
|
|
340
|
-
|
|
341
|
-
return this.checkAddressExists(pObject[tmpSubObjectName], tmpNewAddress, tmpRootObject);
|
|
354
|
+
// The sub-object doesn't exist, so the address doesn't exist
|
|
355
|
+
return false;
|
|
342
356
|
}
|
|
343
357
|
}
|
|
344
358
|
}
|
|
345
|
-
}
|
|
359
|
+
}
|
|
346
360
|
|
|
347
361
|
module.exports = ManyfestObjectAddressResolverCheckAddressExists;
|
|
@@ -5,6 +5,8 @@ let libSimpleLog = require('./Manyfest-LogToConsole.js');
|
|
|
5
5
|
let fCleanWrapCharacters = require('./Manyfest-CleanWrapCharacters.js');
|
|
6
6
|
let fParseConditionals = require(`../source/Manyfest-ParseConditionals.js`)
|
|
7
7
|
|
|
8
|
+
let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* Object Address Resolver - DeleteValue
|
|
10
12
|
*
|
|
@@ -27,6 +29,10 @@ let fParseConditionals = require(`../source/Manyfest-ParseConditionals.js`)
|
|
|
27
29
|
*/
|
|
28
30
|
class ManyfestObjectAddressResolverDeleteValue
|
|
29
31
|
{
|
|
32
|
+
/**
|
|
33
|
+
* @param {function} [pInfoLog] - (optional) A logging function for info messages
|
|
34
|
+
* @param {function} [pErrorLog] - (optional) A logging function for error messages
|
|
35
|
+
*/
|
|
30
36
|
constructor(pInfoLog, pErrorLog)
|
|
31
37
|
{
|
|
32
38
|
// Wire in logging
|
|
@@ -37,12 +43,26 @@ class ManyfestObjectAddressResolverDeleteValue
|
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
// TODO: Dry me
|
|
46
|
+
/**
|
|
47
|
+
* @param {string} pAddress - The address being evaluated
|
|
48
|
+
* @param {object} pRecord - The record being evaluated
|
|
49
|
+
*
|
|
50
|
+
* @return {boolean} True if the record passes the filters, false if it does not
|
|
51
|
+
*/
|
|
40
52
|
checkRecordFilters(pAddress, pRecord)
|
|
41
53
|
{
|
|
42
54
|
return fParseConditionals(this, pAddress, pRecord);
|
|
43
55
|
}
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Delete the value of an element at an address
|
|
59
|
+
*
|
|
60
|
+
* @param {object} pObject - The object to delete the value from
|
|
61
|
+
* @param {string} pAddress - The address to delete the value at
|
|
62
|
+
* @param {string} [pParentAddress] - (optional) The parent address for recursion
|
|
63
|
+
*
|
|
64
|
+
* @return {boolean|object|undefined} - True if the value was deleted, false if it could not be deleted, undefined on error
|
|
65
|
+
*/
|
|
46
66
|
deleteValueAtAddress (pObject, pAddress, pParentAddress)
|
|
47
67
|
{
|
|
48
68
|
// Make sure pObject (the object we are meant to be recursing) is an object (which could be an array or object)
|
|
@@ -56,11 +76,11 @@ class ManyfestObjectAddressResolverDeleteValue
|
|
|
56
76
|
tmpParentAddress = pParentAddress;
|
|
57
77
|
}
|
|
58
78
|
|
|
59
|
-
//
|
|
60
|
-
let
|
|
79
|
+
// Use enclosure-aware parser to find the first segment separator
|
|
80
|
+
let tmpAddressPartBeginning = _MockFable.DataFormat.stringGetFirstSegment(pAddress);
|
|
61
81
|
|
|
62
82
|
// This is the terminal address string (no more dots so the RECUSION ENDS IN HERE somehow)
|
|
63
|
-
if (
|
|
83
|
+
if (tmpAddressPartBeginning.length == pAddress.length)
|
|
64
84
|
{
|
|
65
85
|
// Check if the address refers to a boxed property
|
|
66
86
|
let tmpBracketStartIndex = pAddress.indexOf('[');
|
|
@@ -183,8 +203,8 @@ class ManyfestObjectAddressResolverDeleteValue
|
|
|
183
203
|
}
|
|
184
204
|
else
|
|
185
205
|
{
|
|
186
|
-
let tmpSubObjectName =
|
|
187
|
-
let tmpNewAddress = pAddress.substring(
|
|
206
|
+
let tmpSubObjectName = tmpAddressPartBeginning;
|
|
207
|
+
let tmpNewAddress = pAddress.substring(tmpAddressPartBeginning.length+1);
|
|
188
208
|
|
|
189
209
|
// BOXED ELEMENTS
|
|
190
210
|
// Test if the tmpNewAddress is an array or object
|
|
@@ -352,4 +372,4 @@ class ManyfestObjectAddressResolverDeleteValue
|
|
|
352
372
|
}
|
|
353
373
|
};
|
|
354
374
|
|
|
355
|
-
module.exports = ManyfestObjectAddressResolverDeleteValue;
|
|
375
|
+
module.exports = ManyfestObjectAddressResolverDeleteValue;
|
|
@@ -29,6 +29,10 @@ let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
|
|
|
29
29
|
*/
|
|
30
30
|
class ManyfestObjectAddressResolverGetValue
|
|
31
31
|
{
|
|
32
|
+
/**
|
|
33
|
+
* @param {function} [pInfoLog] - (optional) A logging function for info messages
|
|
34
|
+
* @param {function} [pErrorLog] - (optional) A logging function for error messages
|
|
35
|
+
*/
|
|
32
36
|
constructor(pInfoLog, pErrorLog)
|
|
33
37
|
{
|
|
34
38
|
// Wire in logging
|
|
@@ -38,12 +42,27 @@ class ManyfestObjectAddressResolverGetValue
|
|
|
38
42
|
this.cleanWrapCharacters = fCleanWrapCharacters;
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @param {string} pAddress - The address of the record to check
|
|
47
|
+
* @param {object} pRecord - The record to check against the filters
|
|
48
|
+
*
|
|
49
|
+
* @return {boolean} - True if the record passes the filters, false otherwise
|
|
50
|
+
*/
|
|
41
51
|
checkRecordFilters(pAddress, pRecord)
|
|
42
52
|
{
|
|
43
53
|
return fParseConditionals(this, pAddress, pRecord);
|
|
44
54
|
}
|
|
45
55
|
|
|
46
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Get the value of an element at an address
|
|
58
|
+
*
|
|
59
|
+
* @param {object} pObject - The object to resolve the address against
|
|
60
|
+
* @param {string} pAddress - The address to resolve
|
|
61
|
+
* @param {string} [pParentAddress] - (optional) The parent address for back-navigation
|
|
62
|
+
* @param {object} [pRootObject] - (optional) The root object for function argument resolution
|
|
63
|
+
*
|
|
64
|
+
* @return {any} The value at the address, or undefined if not found
|
|
65
|
+
*/
|
|
47
66
|
getValueAtAddress (pObject, pAddress, pParentAddress, pRootObject)
|
|
48
67
|
{
|
|
49
68
|
// Make sure pObject (the object we are meant to be recursing) is an object (which could be an array or object)
|
|
@@ -150,7 +169,7 @@ class ManyfestObjectAddressResolverGetValue
|
|
|
150
169
|
{
|
|
151
170
|
let tmpFunctionAddress = pAddress.substring(0, tmpFunctionStartIndex).trim();
|
|
152
171
|
|
|
153
|
-
if (
|
|
172
|
+
if (typeof pObject[tmpFunctionAddress] !== 'function')
|
|
154
173
|
{
|
|
155
174
|
// The address suggests it is a function, but it is not.
|
|
156
175
|
return false;
|
|
@@ -186,8 +205,6 @@ class ManyfestObjectAddressResolverGetValue
|
|
|
186
205
|
{
|
|
187
206
|
let tmpArgumentValues = [];
|
|
188
207
|
|
|
189
|
-
let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
|
|
190
|
-
|
|
191
208
|
// Now get the value for each argument
|
|
192
209
|
for (let i = 0; i < tmpFunctionArguments.length; i++)
|
|
193
210
|
{
|
|
@@ -339,13 +356,13 @@ class ManyfestObjectAddressResolverGetValue
|
|
|
339
356
|
else
|
|
340
357
|
{
|
|
341
358
|
// Now is the point in recursion to return the value in the address
|
|
342
|
-
if (typeof(pObject[pAddress]) !=
|
|
359
|
+
if (typeof(pObject[pAddress]) != 'undefined')
|
|
343
360
|
{
|
|
344
361
|
return pObject[pAddress];
|
|
345
362
|
}
|
|
346
363
|
else
|
|
347
364
|
{
|
|
348
|
-
return
|
|
365
|
+
return undefined;
|
|
349
366
|
}
|
|
350
367
|
}
|
|
351
368
|
}
|
|
@@ -384,7 +401,7 @@ class ManyfestObjectAddressResolverGetValue
|
|
|
384
401
|
let tmpFunctionAddress = tmpSubObjectName.substring(0, tmpFunctionStartIndex).trim();
|
|
385
402
|
tmpParentAddress = `${tmpParentAddress}${(tmpParentAddress.length > 0) ? '.' : ''}${tmpSubObjectName}`;
|
|
386
403
|
|
|
387
|
-
if (
|
|
404
|
+
if (typeof pObject[tmpFunctionAddress] !== 'function')
|
|
388
405
|
{
|
|
389
406
|
// The address suggests it is a function, but it is not.
|
|
390
407
|
return false;
|
|
@@ -420,8 +437,6 @@ class ManyfestObjectAddressResolverGetValue
|
|
|
420
437
|
{
|
|
421
438
|
let tmpArgumentValues = [];
|
|
422
439
|
|
|
423
|
-
let tmpRootObject = (typeof(pRootObject) == 'undefined') ? pObject : pRootObject;
|
|
424
|
-
|
|
425
440
|
// Now get the value for each argument
|
|
426
441
|
for (let i = 0; i < tmpFunctionArguments.length; i++)
|
|
427
442
|
{
|
|
@@ -631,4 +646,4 @@ class ManyfestObjectAddressResolverGetValue
|
|
|
631
646
|
}
|
|
632
647
|
};
|
|
633
648
|
|
|
634
|
-
module.exports = ManyfestObjectAddressResolverGetValue;
|
|
649
|
+
module.exports = ManyfestObjectAddressResolverGetValue;
|
|
@@ -8,15 +8,19 @@
|
|
|
8
8
|
// Until we shift Manyfest to be a fable service, these three functions were pulled out of
|
|
9
9
|
// fable to aid in parsing functions with nested enclosures.
|
|
10
10
|
|
|
11
|
+
const DEFAULT_START_SYMBOL_MAP = { '{': 0, '[': 1, '(': 2 };
|
|
12
|
+
const DEFAULT_END_SYMBOL_MAP = { '}': 0, ']': 1, ')': 2 };
|
|
13
|
+
|
|
11
14
|
module.exports = {
|
|
12
15
|
/**
|
|
13
16
|
* Count the number of segments in a string, respecting enclosures
|
|
14
|
-
*
|
|
15
|
-
* @param {string} pString
|
|
16
|
-
* @param {string} pSeparator
|
|
17
|
-
* @param {
|
|
18
|
-
* @param {
|
|
19
|
-
*
|
|
17
|
+
*
|
|
18
|
+
* @param {string} pString
|
|
19
|
+
* @param {string} [pSeparator]
|
|
20
|
+
* @param {Record<string, number>} [pEnclosureStartSymbolMap]
|
|
21
|
+
* @param {Record<string, number>} [pEnclosureEndSymbolMap]
|
|
22
|
+
*
|
|
23
|
+
* @return {number} - The number of segments in the string
|
|
20
24
|
*/
|
|
21
25
|
stringCountSegments: (pString, pSeparator, pEnclosureStartSymbolMap, pEnclosureEndSymbolMap) =>
|
|
22
26
|
{
|
|
@@ -24,10 +28,10 @@ module.exports = {
|
|
|
24
28
|
|
|
25
29
|
let tmpSeparator = (typeof(pSeparator) == 'string') ? pSeparator : '.';
|
|
26
30
|
|
|
27
|
-
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ?
|
|
28
|
-
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ?
|
|
31
|
+
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStartSymbolMap : DEFAULT_START_SYMBOL_MAP;
|
|
32
|
+
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEndSymbolMap : DEFAULT_END_SYMBOL_MAP;
|
|
29
33
|
|
|
30
|
-
if (
|
|
34
|
+
if (tmpString.length < 1)
|
|
31
35
|
{
|
|
32
36
|
return 0;
|
|
33
37
|
}
|
|
@@ -66,12 +70,13 @@ module.exports = {
|
|
|
66
70
|
|
|
67
71
|
/**
|
|
68
72
|
* Get the first segment in a string, respecting enclosures
|
|
69
|
-
*
|
|
70
|
-
* @param {string} pString
|
|
71
|
-
* @param {string} pSeparator
|
|
72
|
-
* @param {
|
|
73
|
-
* @param {
|
|
74
|
-
*
|
|
73
|
+
*
|
|
74
|
+
* @param {string} pString
|
|
75
|
+
* @param {string} [pSeparator]
|
|
76
|
+
* @param {Record<string, number>} [pEnclosureStartSymbolMap]
|
|
77
|
+
* @param {Record<string, number>} [pEnclosureEndSymbolMap]
|
|
78
|
+
*
|
|
79
|
+
* @return {string} - the first segment in the string as a string
|
|
75
80
|
*/
|
|
76
81
|
stringGetFirstSegment: (pString, pSeparator, pEnclosureStartSymbolMap, pEnclosureEndSymbolMap) =>
|
|
77
82
|
{
|
|
@@ -79,12 +84,12 @@ module.exports = {
|
|
|
79
84
|
|
|
80
85
|
let tmpSeparator = (typeof(pSeparator) == 'string') ? pSeparator : '.';
|
|
81
86
|
|
|
82
|
-
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ?
|
|
83
|
-
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ?
|
|
87
|
+
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStartSymbolMap : DEFAULT_START_SYMBOL_MAP;
|
|
88
|
+
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEndSymbolMap : DEFAULT_END_SYMBOL_MAP;
|
|
84
89
|
|
|
85
|
-
if (
|
|
90
|
+
if (tmpString.length < 1)
|
|
86
91
|
{
|
|
87
|
-
return
|
|
92
|
+
return '';
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
let tmpEnclosureStack = [];
|
|
@@ -120,26 +125,27 @@ module.exports = {
|
|
|
120
125
|
|
|
121
126
|
/**
|
|
122
127
|
* Get all segments in a string, respecting enclosures
|
|
123
|
-
*
|
|
124
|
-
* @param {string} pString
|
|
125
|
-
* @param {string} pSeparator
|
|
126
|
-
* @param {
|
|
127
|
-
* @param {
|
|
128
|
-
*
|
|
128
|
+
*
|
|
129
|
+
* @param {string} pString
|
|
130
|
+
* @param {string} [pSeparator]
|
|
131
|
+
* @param {Record<string, number>} [pEnclosureStartSymbolMap]
|
|
132
|
+
* @param {Record<string, number>} [pEnclosureEndSymbolMap]
|
|
133
|
+
*
|
|
134
|
+
* @return {Array<string>} - the segments in the string as an array of strings
|
|
129
135
|
*/
|
|
130
|
-
stringGetSegments: (pString, pSeparator, pEnclosureStartSymbolMap, pEnclosureEndSymbolMap)=>
|
|
136
|
+
stringGetSegments: (pString, pSeparator, pEnclosureStartSymbolMap, pEnclosureEndSymbolMap) =>
|
|
131
137
|
{
|
|
132
138
|
let tmpString = (typeof(pString) == 'string') ? pString : '';
|
|
133
139
|
|
|
134
140
|
let tmpSeparator = (typeof(pSeparator) == 'string') ? pSeparator : '.';
|
|
135
141
|
|
|
136
|
-
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ?
|
|
137
|
-
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ?
|
|
142
|
+
let tmpEnclosureStartSymbolMap = (typeof(pEnclosureStartSymbolMap) == 'object') ? pEnclosureStartSymbolMap : DEFAULT_START_SYMBOL_MAP;
|
|
143
|
+
let tmpEnclosureEndSymbolMap = (typeof(pEnclosureEndSymbolMap) == 'object') ? pEnclosureEndSymbolMap : DEFAULT_END_SYMBOL_MAP;
|
|
138
144
|
|
|
139
145
|
let tmpCurrentSegmentStart = 0;
|
|
140
146
|
let tmpSegmentList = [];
|
|
141
147
|
|
|
142
|
-
if (
|
|
148
|
+
if (tmpString.length < 1)
|
|
143
149
|
{
|
|
144
150
|
return tmpSegmentList;
|
|
145
151
|
}
|
|
@@ -187,8 +193,8 @@ module.exports = {
|
|
|
187
193
|
* If no start or end characters are specified, it will default to parentheses. If the string is not a string, it will return 0.
|
|
188
194
|
*
|
|
189
195
|
* @param {string} pString
|
|
190
|
-
* @param {string} pEnclosureStart
|
|
191
|
-
* @param {string} pEnclosureEnd
|
|
196
|
+
* @param {string} [pEnclosureStart]
|
|
197
|
+
* @param {string} [pEnclosureEnd]
|
|
192
198
|
* @returns the count of full in the string
|
|
193
199
|
*/
|
|
194
200
|
stringCountEnclosures: (pString, pEnclosureStart, pEnclosureEnd) =>
|
|
@@ -227,9 +233,10 @@ module.exports = {
|
|
|
227
233
|
*
|
|
228
234
|
* @param {string} pString
|
|
229
235
|
* @param {number} pEnclosureIndexToGet
|
|
230
|
-
* @param {string} pEnclosureStart
|
|
231
|
-
* @param {string}
|
|
232
|
-
*
|
|
236
|
+
* @param {string} [pEnclosureStart]
|
|
237
|
+
* @param {string} [pEnclosureEnd]
|
|
238
|
+
*
|
|
239
|
+
* @return {string} - The value of the enclosure at the specified index
|
|
233
240
|
*/
|
|
234
241
|
stringGetEnclosureValueByIndex: (pString, pEnclosureIndexToGet, pEnclosureStart, pEnclosureEnd) =>
|
|
235
242
|
{
|
|
@@ -295,4 +302,4 @@ module.exports = {
|
|
|
295
302
|
return tmpString.substring(tmpEnclosedValueStartIndex+1);
|
|
296
303
|
}
|
|
297
304
|
}
|
|
298
|
-
}
|
|
305
|
+
}
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
let libSimpleLog = require('./Manyfest-LogToConsole.js');
|
|
5
5
|
let fCleanWrapCharacters = require('./Manyfest-CleanWrapCharacters.js');
|
|
6
6
|
|
|
7
|
+
let _MockFable = { DataFormat: require('./Manyfest-ObjectAddress-Parser.js') };
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Object Address Resolver - SetValue
|
|
9
11
|
*
|
|
@@ -24,6 +26,10 @@ let fCleanWrapCharacters = require('./Manyfest-CleanWrapCharacters.js');
|
|
|
24
26
|
*/
|
|
25
27
|
class ManyfestObjectAddressSetValue
|
|
26
28
|
{
|
|
29
|
+
/**
|
|
30
|
+
* @param {function} [pInfoLog] - (optional) A logging function for info messages
|
|
31
|
+
* @param {function} [pErrorLog] - (optional) A logging function for error messages
|
|
32
|
+
*/
|
|
27
33
|
constructor(pInfoLog, pErrorLog)
|
|
28
34
|
{
|
|
29
35
|
// Wire in logging
|
|
@@ -33,7 +39,15 @@ class ManyfestObjectAddressSetValue
|
|
|
33
39
|
this.cleanWrapCharacters = fCleanWrapCharacters;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Set the value of an element at an address
|
|
44
|
+
*
|
|
45
|
+
* @param {object} pObject - The object to set the value in
|
|
46
|
+
* @param {string} pAddress - The address to set the value at
|
|
47
|
+
* @param {any} pValue - The value to set at the address
|
|
48
|
+
*
|
|
49
|
+
* @return {boolean} True if the value was set, false otherwise
|
|
50
|
+
*/
|
|
37
51
|
setValueAtAddress (pObject, pAddress, pValue)
|
|
38
52
|
{
|
|
39
53
|
// Make sure pObject is an object
|
|
@@ -41,9 +55,10 @@ class ManyfestObjectAddressSetValue
|
|
|
41
55
|
// Make sure pAddress is a string
|
|
42
56
|
if (typeof(pAddress) != 'string') return false;
|
|
43
57
|
|
|
44
|
-
|
|
58
|
+
// Use enclosure-aware parser to find the first segment separator
|
|
59
|
+
let tmpAddressPartBeginning = _MockFable.DataFormat.stringGetFirstSegment(pAddress);
|
|
45
60
|
|
|
46
|
-
if (
|
|
61
|
+
if (tmpAddressPartBeginning.length == pAddress.length)
|
|
47
62
|
{
|
|
48
63
|
// Check if it's a boxed property
|
|
49
64
|
let tmpBracketStartIndex = pAddress.indexOf('[');
|
|
@@ -143,8 +158,8 @@ class ManyfestObjectAddressSetValue
|
|
|
143
158
|
}
|
|
144
159
|
else
|
|
145
160
|
{
|
|
146
|
-
let tmpSubObjectName =
|
|
147
|
-
let tmpNewAddress = pAddress.substring(
|
|
161
|
+
let tmpSubObjectName = tmpAddressPartBeginning;
|
|
162
|
+
let tmpNewAddress = pAddress.substring(tmpAddressPartBeginning.length+1);
|
|
148
163
|
|
|
149
164
|
// Test if the tmpNewAddress is an array or object
|
|
150
165
|
// Check if it's a boxed property
|
|
@@ -261,4 +276,4 @@ class ManyfestObjectAddressSetValue
|
|
|
261
276
|
}
|
|
262
277
|
};
|
|
263
278
|
|
|
264
|
-
module.exports = ManyfestObjectAddressSetValue;
|
|
279
|
+
module.exports = ManyfestObjectAddressSetValue;
|
|
@@ -27,6 +27,10 @@ let libSimpleLog = require('./Manyfest-LogToConsole.js');
|
|
|
27
27
|
*/
|
|
28
28
|
class ManyfestObjectAddressGeneration
|
|
29
29
|
{
|
|
30
|
+
/**
|
|
31
|
+
* @param {function} [pInfoLog] - (optional) A logging function for info messages
|
|
32
|
+
* @param {function} [pErrorLog] - (optional) A logging function for error messages
|
|
33
|
+
*/
|
|
30
34
|
constructor(pInfoLog, pErrorLog)
|
|
31
35
|
{
|
|
32
36
|
// Wire in logging
|
|
@@ -34,15 +38,23 @@ class ManyfestObjectAddressGeneration
|
|
|
34
38
|
this.logError = (typeof(pErrorLog) == 'function') ? pErrorLog : libSimpleLog;
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
/**
|
|
42
|
+
* generateAddressses
|
|
43
|
+
*
|
|
44
|
+
* This flattens an object into a set of key:value pairs for *EVERY SINGLE
|
|
45
|
+
* POSSIBLE ADDRESS* in the object. It can get ... really insane really
|
|
46
|
+
* quickly. This is not meant to be used directly to generate schemas, but
|
|
47
|
+
* instead as a starting point for scripts or UIs.
|
|
48
|
+
*
|
|
49
|
+
* This will return a mega set of key:value pairs with all possible schema
|
|
50
|
+
* permutations and default values (when not an object) and everything else.
|
|
51
|
+
*
|
|
52
|
+
* @param {any} pObject - The object to generate addresses for
|
|
53
|
+
* @param {string} [pBaseAddress] - (optional) The base address to start from
|
|
54
|
+
* @param {object} [pSchema] - (optional) The schema object to append to
|
|
55
|
+
*
|
|
56
|
+
* @return {object} The generated schema object
|
|
57
|
+
*/
|
|
46
58
|
generateAddressses (pObject, pBaseAddress, pSchema)
|
|
47
59
|
{
|
|
48
60
|
let tmpBaseAddress = (typeof(pBaseAddress) == 'string') ? pBaseAddress : '';
|
|
@@ -62,7 +74,7 @@ class ManyfestObjectAddressGeneration
|
|
|
62
74
|
|
|
63
75
|
if ((tmpObjectType == 'object') && (pObject == null))
|
|
64
76
|
{
|
|
65
|
-
tmpObjectType = '
|
|
77
|
+
tmpObjectType = 'undefined';
|
|
66
78
|
}
|
|
67
79
|
|
|
68
80
|
switch(tmpObjectType)
|
|
@@ -79,7 +91,6 @@ class ManyfestObjectAddressGeneration
|
|
|
79
91
|
tmpSchema[tmpBaseAddress] = tmpSchemaObjectEntry;
|
|
80
92
|
break;
|
|
81
93
|
case 'undefined':
|
|
82
|
-
case 'null':
|
|
83
94
|
tmpSchemaObjectEntry.DataType = 'Any';
|
|
84
95
|
tmpSchemaObjectEntry.Default = pObject;
|
|
85
96
|
tmpSchema[tmpBaseAddress] = tmpSchemaObjectEntry;
|
|
@@ -125,4 +136,4 @@ class ManyfestObjectAddressGeneration
|
|
|
125
136
|
}
|
|
126
137
|
};
|
|
127
138
|
|
|
128
|
-
module.exports = ManyfestObjectAddressGeneration;
|
|
139
|
+
module.exports = ManyfestObjectAddressGeneration;
|