flysh
Version:
DOM Document Object Artifact Collector
247 lines • 11.4 kB
TypeScript
import { InputMessage } from "./io/InputMessage";
import { OutputMessage } from "./io/OutputMessage";
/**
* 'Flysh' Class definition
*
* This class called 'Flysh' is the main element of the library. It allows the extraction of data thanks to the interpretation of
* the DOM structure from HTML type documents. This is currently invoking specific libraries such as'JQuery' and 'JSDOM'.
*/
export declare class Flysh {
/**
* Constants
*/
private readonly CORE_PARSER_FILTER_SELECTOR_SPLITTER_CHILD_POSITION_VALUE;
private readonly CORE_PARSER_FILTER_SELECTOR_SPLITTER_PARENT_POSITION_VALUE;
private readonly CORE_PARSER_FILTER_SELECTOR_SPLITTER_SCOPE_POSITION_VALUE;
private readonly CORE_PARSER_FILTER_SELECTOR_SPLITTED_CHILD_TAG_POSITION_VALUE;
private readonly CORE_PARSER_FILTER_SELECTOR_SPLITTER_SIZE_VALUE;
private readonly CORE_PARSER_QUERY_SELECTOR_ALL_NO_MATCH_RESULT_VALUE;
private readonly DEFAULT_INSTANCE_JSDOM_OPTIONS_RESSOURCELOADER_PROXY_VALUE;
private readonly DEFAULT_INSTANCE_JSDOM_OPTIONS_RESSOURCELOADER_STRICT_SSL_VALUE;
private readonly DEFAULT_INSTANCE_JSDOM_OPTIONS_RESSOURCELOADER_USER_AGENT_VALUE;
private readonly DEFAULT_INSTANCE_JSDOM_OPTIONS_RUNSCRIPTS_VALUE;
private readonly HARVEST_NAVPANE_DOM_STACK_FIRST_OCCURENCE_VALUE;
private readonly MATRIX_MAPPER_LENGTH_INDEX_VALUE;
private readonly MFAM_DOM_SCP_MERGING_BUFF_REC_MIN_VALUE;
private readonly MFAM_DOM_SCP_MIN_OCCURENCE_VALUE;
private readonly OUTPUTMESSAGE_DEFAULT_ID_INSTANCE_VALUE;
private readonly OUTPUTMESSAGE_DEFAULT_URI_VALUE;
private readonly PAGERECORD_DEFAULT_ERROR_FLAG_VALUE;
private readonly PAGERECORD_ERROR_STATE_FLAG_VALUE;
private readonly PAGERECORD_MAPPER_UNDEFINED_FIELD_NUMBER_VALUE;
private readonly PAGERECORD_MAPPER_UNDEFINED_FIELD_SWAP_VALUE;
private readonly PAGERECORD_MERGER_FIRST_OCCURENCE_INDEX_VALUE;
private readonly PAGERECORD_MERGER_FOUND_ERROR_FLAG_VALUE;
private readonly PRCLEANER_REGEXP_EXEC_ARRAY_RESULT_INDEX_VALUE;
private readonly VALIDATION_MINIMUM_SPC_DOMELEMENT_VALUE;
private readonly VALIDATION_MINIMUM_TIMEOUT_VALUE;
/**
* Constants, exception codes
*/
private readonly EXCEPTION_ID_1500001200_MESSAGE_VALUE;
private readonly EXCEPTION_ID_1500001300_MESSAGE_VALUE;
private readonly EXCEPTION_ID_1500001400_MESSAGE_VALUE;
private readonly EXCEPTION_ID_1500003100_MESSAGE_VALUE;
private readonly EXCEPTION_ID_2000000000_MESSAGE_VALUE;
/**
* Class properties
*/
private domain;
private done;
private hasnavpane;
private filesystem;
private id;
private mfpagerecordsbuffer;
private navmap;
private navmapupdated;
private navpane;
private outputmessage;
private spc;
private timeout;
private URI;
/**
* JSDOM options (RessourceLoader)
*/
private resourceLoader;
/**
* JSDOM options
*
* NOTE: Behavior should be different either by using 'fromFile()' and 'fromURL()' methods
*/
private readonly JSDOMOptions;
/**
* Constructor
*
* @param config Contains the preseted input message 'InputMessage' class instance
*/
constructor(config: InputMessage);
/**
* Returns collected records from post-process
*
* @returns Returns the output message 'OutputMessage' class instance
*/
getOutputMessage(): OutputMessage;
/**
* Returns 'true' if the instance has finished his run
*
* @returns Returns the 'done' 'boolean' value if the instance has finished his run
*/
isDone(): Boolean;
/**
* Starts the whole process asynchronously and waits for the parsed data coming from local/distant document(s)
*
* @returns Returns a 'Promise' that contains the 'OutputMessage' class instance
*/
run(): Promise<OutputMessage>;
/**
* Class initialization
*/
private init;
/**
* Instance properties validation
*/
private validation;
/**
* Returns the 'JQuery' selector from prefetched 'DOM' object
*
* @param dom Object that contains the 'DOM' structure of the document
* @returns Returns the 'JQuery' selector
*/
private createWindowSelector;
/**
* Checks if the current parsed pages are elligible for 'MFaM' mode (Multiple Families) parsing
*
* @returns Returns a 'boolean' value set to true if the 'SCP' property is having more than 1 element
*/
private isMF;
/**
* Adds the 'PageRecords' class instance to the 'outputmessage' message property
*
* TODO : Create two models with records and 'FullListing' two methods 'setOutputMessage()' and 'addRecords(Object rec)'
*
* @param pageRecords Contains all the records parsed from a page
*/
private addHaverstedPages;
/**
* Updates the 'navmap' ('Paginator') property with the new URIs parsed from the page's navigation pane
*
* @param inputData Contains an array of URIs from the navigation ('Paginator') pane
*/
private updateNavMapURI;
/**
* Loops on each 'siblings' (fields) signature to overloads the 'filterselector'
*
* i.e : - '#scope-id div.product-description' + 'a' provides the full filter selector, '#scope-id div.product-description a'
* - '#scope-id div.product-description' + 'span.price' provides the full filter selector, '#scope-id div.product-description span.price'
*
* NOTE : The 'JQuery' selector is only able to catch up a precise tag through the page, the parsing method must be invoked multiple times
* NOTE : If the 'filterselector' is having maximum 3 distinct arguments, it means that it's 'full' and don't need to loop over again
* NOTE : Full filter means 'auto-mode'
*
* @param dom Document filter selector
* @param domelement Generic 'DomElement' type class
* @returns Returns an array of array of 'String' that contains each record collected from the page
*/
private pageParser;
/**
* Cleans each 'PageRecords' (records) with the corresponding sibling's regex (field). For each sibling, the function matches
* the right label name and lookups for the corresponding regular expression
*
* NOTE : If the regular expression matches (exec) the content an update will be applied, otherwise it does nothing
* TOTEST : Don't process in case of undefined/empty regex ('') (no matching sibling (PK? Label ?))
*
* @param pgRecords 'PageRecords' Class instance with original record(s)
* @param domE 'DomeElement' Generic type parameter used to retrieve the record field name
* @returns Returns a 'PageRecords' Class instance with cleaned field(s)
*/
private pageRecordsCleaner;
/**
* Maps the received matrix into a 'PageRecords' class instance and validates if the returned content from
* the selector is not empty
*
* @param matrix Array of array of string that contains the records
* @param domE 'DomeElement' generic type parameter used to retrieve the record field name
* @param uri String that contains document path from filesystem or network (lan/wan)
* @returns Returns a 'PageRecords' class instance
*/
private pageRecordsMapper;
/**
* Swaps arrays into array of array of 'string' (matrix)
*
* @param arrayRecords Array of string that contains record(s)
* @param fieldsNumber Number value that indicates the current field number
* @returns Returns an array of array of string
*/
private rowsMapper;
/**
* Swaps the initial matrix grid into array of array of 'string'
*
* NOTE :
* matrix[0][0] +':'+ matrix[1][0] +':'+ matrix[2][0]);
* matrix[0][1] +':'+ matrix[1][1] +':'+ matrix[2][1]);
* matrix[0][2] +':'+ matrix[1][2] +':'+ matrix[2][2]);
*
* @param matrix Array of array of 'string' that contains the records
* @param fieldsNumber Number of the current field
* @returns Returns an ordered (field) array of array of 'string'
*/
private matrixMapping;
/**
* Parses the current document with his corresponding selector, this function is the nearest core caller
* from the 'Jquery' library
*
* TODO : element.innerHTML less efficient than element.textContent ?
*
* DOC : JQuery core selector dev style 1 (https://learn.jquery.com/using-jquery-core/traversing/)
* DOC : JQuery core selector dev style 2 (http://net-informations.com/jq/iq/parent.htm)
*
* @param $ 'Jquery Document Selector' related to the current Document page (DOM)
* @param filterselector 'String' type that defines the 'Filter Selector' content
* @param attribute 'String' type that defines the attribute to read (optional : to optimize ?) (i.e : 'href')
* @returns Returns a generic object array either filled by a string, a null or an 'undefined' value
*/
private parser;
/**
* Fetches and returns the DOM document either from a distant URI or from the filesystem
*
* @param uri String that contains document path from filesystem or network (lan/wan)
* @returns Returns a 'Promise' which contains the DOM structure from document (filsesystem/network)
*/
private fetchDOM;
/**
* Merges the "scrapped" pages into one 'PageRecords' object instance. The mapping is the processing between the
* 'recordList' returned from the 'PageRecords' instance and the current "scraps" objects
*
* @param scraps Array of 'PageRecords' which contain all "scrapped" records from a page
* @returns Returns a unique 'PageRecords' containing all the "scrapped" records
*/
private pageRecordsMerger;
/**
* Checks if a page is either a "scrap" or not. This method evaluates when to set a new 'PageRecords' to the 'outputmessage'
* class property. It uses a 'PageRecords' type buffer (from scraps) with a size which equals the number of 'SCP' objects (fields).
* If the configuration is set to "MF/MultiFamily", the buffer will be filled till his maximum size. Once full,
* a new 'PageRecords' page will be created and being filled with the other 'PageRecords'. If the page is not considered
* as "MF/MultiFamily", the reference will simply be returned.
*
* @param pr 'PageRecords' class instance that contains the parsed records from a page
*/
private pageRecordsHandler;
/**
* Returns a 'Promise' that contains the parsed data from a window (dom.window). Each 'Promise' is either identified as a
* new 'PargeRecords' either a filepath/URIs to add
*
* NOTE : In case of multiple 'NavPane' ('Paginator') elements, the first occurrence will only be taken into account
*
* @param uri String that contains document path from filesystem or network (lan/wan)
* @returns Returns a 'Promise' that contains the parsed datas from the 'window' (dom.window)
*/
private harvesting;
/**
* Processing the page(s) preseted within the 'navmap'/'paginator' property
*
* NOTE : 'forEach()' method seems not handling a 'Promise' callback
* NOTE : Each back 'Promise' are stored from properties and available from getter functions
*/
private processing;
}
//# sourceMappingURL=Flysh.d.ts.map