als-store
Version:
Library for streamlined file management and advanced data caching, featuring intelligent file searching, dynamic cache control, and flexible file operations
32 lines (23 loc) • 1.9 kB
Markdown
### Store Class Constructor
The `Store` constructor creates a new instance of the `Store` class, which represents a file store with specific structure and functionality. It initializes the store with various configuration options provided through the `params` object.
#### Constructor Parameters and Validation:
- `params`: An object containing the following configuration parameters:
- `dirPath` (String, required, 3-255 characters): Specifies the path to the directory where files will be stored. This parameter is validated to ensure it is a string with a length between 3 and 255 characters.
- `schema` (Object, optional): A schema object used for validating files in the store. If provided, a new instance of `Schema` (als-schema package) is created with the provided schema. If not provided, no schema validation is used.
- `maxAge` (Number, optional, >= 1000): Specifies the maximum lifetime of a file in milliseconds. It is validated to be an optional numeric parameter with a minimum value of 1000.
- `maxActiveAge` (Number, optional, >= 1000): Specifies the maximum active time of a file in milliseconds. Similar to `maxAge`, it is validated as an optional numeric parameter with a minimum value of 1000.
#### Additional Actions in the Constructor:
- Calls `ensureDirSync(dirPath)` to ensure the existence of the directory at the specified path.
- Initializes internal variables and states of the store, such as `results`, `errors` arrays, and the `options` object.
This constructor allows flexible and scalable setup of a file store, catering to various use cases with customizable parameters.
#### Usage example
```js
const Store = require('als-store');
const params = {
dirPath = __dirname,
schema = {name:String,ext:String,ext1:String},
maxAge = 1000*60*60*30,
maxActiveAge = 1000*60*60*7
}
const store = new Store(params)
```