UNPKG

als-store

Version:

Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations

36 lines (26 loc) 1.81 kB
### Method: `get()` #### Overview: The `get(value=false)` method is an asynchronous function responsible for retrieving files from the store based on the current options set in the `Store` instance. It filters, sorts, and limits the results according to the specified criteria. **if value parameter set to true (false by default), return files with values.** #### Functionality: - **Retrieval and Filtering**: Retrieves files from the specified directory (and subdirectories, if needed) based on the depth level, filtering criteria, and sorting options. - **Validation and Sorting**: After retrieving the files, it performs additional operations like validating file stats, applying filters, and sorting the results if required. - **Handling Values and Removing Outdated Files**: Optionally retrieves the values of the files and removes outdated files based on `maxAge` and `maxActiveAge` settings. #### Implementation Details: - Resets the internal state before starting the retrieval process. - Combines multiple conditions like filters, sorting, and pagination (limit and skip) to process the file list. - Uses promises to handle asynchronous operations efficiently. - Filters and sorts the results based on the provided options. - Optionally loads the content of the files if the `values` option is set. - Performs cleanup of outdated files. #### API `get` method return Store instance which initialize `store.results` and `store.errors` as empty arrays before `get` runs. All results added to `store.results` and errors to `store.errors` and can be available after promise is resolved. Each result is instance of `File` class. #### Example ```js const {results=[],errors=[]} = await store.get() // or await store.get() const {results=[],errors=[]} = store ```