Contains all system defined business rules for parsing strings related to constants.
- Copyright:
- Copyright © 2022-… by Seth Hollingsead. All rights reserved
- Source:
Requires
- module:ruleParsing
- module:configurator
- module:loggers
- module:data
- @haystacks/constants
- chalk
- https://nodejs.dev/
- path
Methods
(inner) constantsFulfillmentSystem(inputData, inputMetaData) → {string}
Determines what is the most optimized way to define a new constant using existing constant strings.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The constant to be defined/fulfilled. |
inputMetaData |
string | The original user-defined constant to be fulfilled, so the recursive algorithm can continue processing the rest of the string, after a first match is found. |
Returns:
The fully optimized definition for the new constant.
- Type
- string
(inner) constantsOptimizedFulfillmentSystem(inputData, inputMetaData) → {string}
Determines what is the most optimized way to define a string using existing constant strings.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | the string that should be determined or find a constant to fulfill part of the string. |
inputMetaData |
string | Not used for this business rule. |
Returns:
A constant that represents part of the input string.
- Type
- string
(inner) convertConstantTypeToConstantPrefix(inputData, inputMetaData) → {string}
Converts the constant type to a constant prefix so it can be used to assist with defining an optimized constant definition.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The constant type that should be used when converting to a constant prefix. |
inputMetaData |
string | Not used for this business rule. |
Returns:
The appropriate constant prefix.
- Type
- string
(inner) determineConstantsContextQualifiedPrefix(inputData, inputMetaData) → {string}
Takes the filename to a constants file and determines The standard prefix that should be used in the code to reference that constants file.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The filename of the constants file or the full path and file name of the constants file. (Should work just the same with either one) |
inputMetaData |
string | The name of the data hive that contains the appropriate matching constants validation data. |
Returns:
A string code that represents the method to reference a constants file in the code.
- Type
- string
(inner) determineSuggestedConstantsValidationLineOfCode(inputData, inputMetaData) → {string}
Takes the name of the missing constant and determines a suggested lin of code to ad to the appropriate constants validation file. This will make it really easy for developers to maintain the constants validation system.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The name of the constant file that is missing and should have a line of code generated for it. |
inputMetaData |
string | The prefix used to reference the constants file in the code. |
Returns:
The suggested line of code that should be added to the appropriate constants validation code file.
- Type
- string
(inner) doesConstantExist(inputData, inputMetaData) → {boolean}
Walks through all of the constants validation files and checks to see if any of the expected values match the string that is passed in.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value that should be looked for in all the constants files. |
inputMetaData |
string | Not used for this business rule. |
Returns:
True or False to indicate if a matching constant definition was found or not.
- Type
- boolean
(inner) doesConstantExistInConstantLibraryObject(inputData, inputMetaData) → {boolean}
This is a middle management of the search, walks through all of the constants validation parent collection objects, filters out all the meta-data entries and ensures that searches are only performed on actual constants validation data values. This function provides a re-usability function so we don't need to have repeated code in the doesConstantExist function.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value that should be looked for in the constants validation data library, that is also provided as input. |
inputMetaData |
object | A JSON data object that contains all of the constants validation data namespace objects that should be searched. |
Returns:
True or False to indicate if a matching constant definition was found or not.
- Type
- boolean
(inner) doesConstantExistInConstantNamespaceObject(inputData, inputMetaData) → {boolean}
Walks through all of the constants validation data inside the specified input data structure. Checks to see if any of the expected values match the string that is passed in.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value that should be looked for in all the constants data that is provided also as input. |
inputMetaData |
object | The constants validation data structure that should be searched. |
Returns:
True or False to indicate if a matching constant definition was found or not.
- Type
- boolean
(inner) doesConstantNamespaceExist(inputData, inputMetaData) → {boolean}
Searches through the input data structure to determine if it contains the specified constant namespace or not.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The name of the data element that should be searched for. |
inputMetaData |
object | The data that should be searched for the specified named data parameter. |
Returns:
True or False to indicate if a matching namespace was found in the specified data structure or not.
- Type
- boolean
(inner) findConstantName(inputData, inputMetaData) → {string}
Looks through a string and tries to weed out a constant name.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The string that should be searched for a constant name. |
inputMetaData |
string | Not used for this business rule. |
Returns:
The name of the constant that was found.
- Type
- string
(inner) getConstantActualValue(inputData, inputMetaData) → {string}
Determines the actual value of the named constant given the constant type.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The name of the constant we are looking for to get the actual value of the constant. |
inputMetaData |
string | (OPTIONAL) The type or library where the constant should be found. |
Returns:
The actual value of the string.
- Type
- string
(inner) getConstantActualValueInConstantLibraryObject(inputData, inputMetaData) → {string|boolean}
This is a middle management function to get the actual value of the constant that is found. Walks through all of the constants validation parent collection objects, filters out all of the meta-data entries and ensures that searches are only performed on actual constants validation data values. This function provides a re-usability function so we don't need to have repeated code in the getConstantName function.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value that should be looked for in the constants validation data library that is also provided as input. |
inputMetaData |
object | A JSON data object that contains all of the constants validation data namespace objects that should be searched. |
Returns:
The actual value of the constant if a match is found, False if no match is found.
- Type
- string | boolean
(inner) getConstantActualValueInConstantNamespaceObject(inputData, inputMetaData) → {string|boolean}
Walks through all of the constants validation data inside the specified input data structure. Checks to see if any of the expected values match the string that is passed in and returns the actual value of a match if/when it's found.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value that should be looked for in all the constants data that is provided also as input. |
inputMetaData |
object | The constants validation data structure that should be searched. |
Returns:
The actual value of the constant or False if it is not found.
- Type
- string | boolean
(inner) getConstantName(inputData, inputMetaData) → {string}
Gets the constant name given the constant value, or what the constant should resolve as. Can only return the first instance.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The constant string value that should be used when getting the constant name. |
inputMetaData |
string | Not used for this business rule. |
Returns:
The name of the constant: eg: cSystem
- Type
- string
(inner) getConstantNameInConstantLibraryObject(inputData, inputMetaData) → {string|boolean}
This is a middle management function to get the name of the constant that is found. Walks through all of the constants validation parent collection objects, filters out all of the meta-data entries and ensures that searches are only performed on actual constants validation data values. This function provides a re-usability function so we don't need to have repeated code in the getConstantName function.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value that should be looked for in the constants validation data library, that is also provided as input. |
inputMetaData |
object | A JSON data object that contains all of the constants validation data namespace objects that should be searched. |
Returns:
The name of the constant if a match is found, False if no match is found.
- Type
- string | boolean
(inner) getConstantNameInConstantNamespaceObject(inputData, inputMetaData) → {string|boolean}
Walks through all of the constants validation data inside the specified input data structure. Checks to see if any of the expected values match the string that is passed in and returns the name of a match if/when it's found.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value that should be looked for in all the constants data that is provided also as input. |
inputMetaData |
object | The constants validation data structure that should be searched. |
Returns:
The name of the constant or False if it is not found.
- Type
- string | boolean
(inner) getConstantsValidationNamespaceObject(inputData, inputMetaData) → {object}
Searches the constants validation top-level data structure, framework, applications, plugins for the specified namespace and returns the JSON object.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The name of the constants data hive that we should search for and find as a namespace object. |
inputMetaData |
string | Not used for this business rule. |
Returns:
A JSON object that contains the constants validation data for the specified constants validation data-set, False if nothing is found.
- Type
- object
(inner) getConstantsValidationNamespaceParentObject(inputData, inputMetaData) → {object}
Searches the constants validation top-level data structure, framework, applications, plugins for the specified namespace and returns the parent JSON object, which contains all the meta-data necessary to generate failure messages and suggested line of code information.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The name of the constants data hive that we should search for and find as a namespace object. |
inputMetaData |
string | Not used for this business rule. |
Returns:
A JSON object that contains the constants short names, file names, prefixes and file paths, validation messages and related constants validation data. In short the constants validation parent context object.
- Type
- object
(inner) getConstantType(inputData, inputMetaData) → {string}
Determines what constant library a particular constant is defined in. (This will aid developers who are trying to understand & develop under this complicated constants system.)
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The string value that should be searched in all of the constants libraries. |
inputMetaData |
boolean | True or False to indicate if the function should exit on first discovery or continue to discover all possible matches. |
Returns:
A list of constants libraries where the constant was found to be defined in.
- Type
- string
(inner) getConstantTypeInConstantLibraryObject(inputData, inputMetaData) → {boolean|string}
This is a middle management function to get the type of constant that is found. Walks through all of the constants validation parent collection objects, filters out all of the meta-data entries and ensures that searches are only performed on actual constants validation data values. This function provides a re-usability function so we don't need to have repeated code in the getConstantType function.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
array.<string, boolean> | An array that contains The value that should have it's matching type returned, and a boolean to indicate if the function should or should not continue searching for additional matches after the first match is found. inputData[0] = The value of the constant that should be searched for to find a match and return the type. inputData[1] = True or False value to indicate if the search should continue after finding the first match or not. |
inputMetaData |
object | A JSON data object that contains all of the constants validation data namespace objects that should be search. |
Returns:
A string that contains the name of the matching constant type or False if its matching constant definition is not found.
- Type
- boolean | string
(inner) isConstantTypeValid(inputData, inputMetaData) → {boolean}
Determines if a string is a valid constant type/library or not.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The string that should be validated if it is a valid constant type or not. |
inputMetaData |
string | Not used for this business rule. |
Returns:
True or False to indicate if the string is a valid constant type/library that exists within the system or not.
- Type
- boolean
(inner) isConstantValid(inputData, inputMetaData) → {boolean}
Determines if the user entered some valid input constant string or not. User must have entered more than 4 characters.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The value of the constant as a string. |
inputMetaData |
string | Not used for this business rule. |
Returns:
True or False to indicate if the user entered a valid constant or not.
- Type
- boolean
(inner) validateConstantsDataValidation(inputData, inputMetaData) → {boolean}
Validates that validation data to ensure that all the contents of the constants validation data matches with the actual constants definitions.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | the path of the constants file that should be validated. |
inputMetaData |
string | The name of the data hive that contains the appropriate matching constants validation data. |
Returns:
True or False to indicate if all of the contents of the constants are fully validated or not.
- Type
- boolean
(inner) validateConstantsDataValidationLineItemName(inputData, inputMetaData) → {boolean}
Loops through all of the constants validation data and verifies if a matching constant definition can be found, or not found.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | the constant definition that should be searched for. |
inputMetaData |
string | The name of the data hive that contains the appropriate matching constants validation data. |
Returns:
True or False to indicate if a match was found or not found.
- Type
- boolean
(inner) validateConstantsDataValues(inputData, inputMetaData) → {boolean}
Iterates over all the constants values in the constants validation data specified by the input parameter and validates the content.
Parameters:
| Name | Type | Description |
|---|---|---|
inputData |
string | The name of the data-hive that should contain all of the validation data that should be used to execute the validation procedures. |
inputMetaData |
string | Not used for this business rule. |
Returns:
True or False to indicate if the validation passed for the entire data hive or if it did not pass.
- Type
- boolean