Create a new reader instance for loading rules, functions, types, and constants into the provided workspace.
N.B. After creation you must either call withFS() or loadFileSystem() to provide access to the file system before attempting to read files in a Node environment.
The workspace into which the components will be loaded.
Determines whether to accept all valid components while logging errors for invalid ones ('partial') or to reject the entire file if any component is invalid ('all').
ProtectedremoveProtectedreadProtectedreadThis method is intended for use in the browser where File System access is not supported. In a node environment, use readFromFile() or readFromFiles().
The content of the file to parse.
The result of parsing, including the successfully parsed constants, functions, types, rules, and any errors encountered.
Attempt to read all files from a specified folder path and load their content into the workspace. N.B. If a folder contains subfolders, the reader will attempt to read files from those subfolders as well. If a file path is accidentally provided instead of a folder path, the reader will attempt to read that individual file.
If a folder path is included with the individual file paths, the reader will attempt to read files from that folder as well. The reader will determine the type of each file based on its name and extension, and use the appropriate parsing method. If any file fails to load and the accept option is set to 'partial', the reader will continue loading the remaining files while logging errors for the failed ones. If the accept option is set to 'all', the reader will stop loading further files upon encountering an error in any file.
the path of the folder containing the files to read.
true if components were registered successfully (according to 'all' or 'partial' option), otherwise false.
Attempt to read all given files and load their contents into the workspace. If a folder path is included with the individual file paths, the reader will attempt to read files from that folder as well.
The reader will determine the type of each file based on its name and extension, and use the appropriate parsing method. If any file fails to load and the accept option is set to 'partial', the reader will continue loading the remaining files while logging errors for the failed ones. If the accept option is set to 'all', the reader will stop loading further files upon encountering an error in any file.
an array of file paths to read.
true if components were registered successfully (according to 'all' or 'partial' option), otherwise false.
Attempt to read a file from a specified path and load its content into the workspace. If a folder path is included instead of a file path, the reader will fail silently and return false. The reader will determine the type of the file based on its name and extension, and use the appropriate parsing method.
the path of the file to read.
true if components were registered successfully (according to 'all' or 'partial' option), otherwise false.
Provide a node file system module to be used for reading files.
This method or the equivalent loadFileSystem() must be called before attempting to read files in a Node environment.
the node fs module to use.
the current instance for chaining.
Dynamically import the Node.js file system module in a Node environment.
This method or the equivalent withFS() must be called before attempting to read files in a Node environment.
In a browser environment, this method will log an error since file system access is not supported.
the imported fs module if successful, otherwise undefined.
ProtectedreadProtectedreadProtectedreadProtectedparseProtectedparseProtectedparseProtectedparseProtectedparseProtectedparseProtectedisProtectedisProtectedisProtectedrejectProtectedlogProtectedlog
Helper class to safely read rules, functions, types, and constants from files and load them into a workspace. It supports reading from strings, individual files, or entire folders, and can handle different file formats such as markdown, general, constants, rules, types, and functions files. The reader can be configured to either accept all valid components while logging errors for invalid ones, or to reject the entire file if any component is invalid.
N.B. Declarations do not need to be in order, although that is still recommended.
N.B. This is a transactional safe reader. If you provide a workspace and select the option accept: 'all', then that workplace will not be affected if any errors are encountered.
Files should be named according to their content, with the following conventions:
The reader will determine the type of each file based on these naming conventions and use the appropriate parsing method to load its content into the workspace.
NB: This class relies on Node's 'fs' module for file system access, so it is intended for use in Node.js environments. In browser environments, file reading should be handled differently; this class will report errors in a browser environment.