@mdf.js/jsonl-archiver-provider is a tool designed for managing the storage of jsonl files in Node.js applications. It allows to append data to multiple files, maintaining the append and rotation processes independent for each file.
Abstract the management of jsonl files in Node.js applications, providing a simple and efficient way to store data in a jsonl format. This module is designed to be used in the @mdf.js environment, but it can be used in any Node.js application. Some examples of use cases are:
Using npm:
npm install @mdf.js/jsonl-archive-provider
Using yarn:
yarn add @mdf.js/jsonl-archive-provider
Check information about @mdf.js providers in the documentation of the core module @mdf.js/core.
This module is developed as a @mdf.js Provider
so that it can be used easily in any application, both in the @mdf.js environment and in any other Node.js application.
In order to use this module, your should use the Factory
exposed and create an instance using the create
method:
import { Factory } from '@mdf.js/jsonl-file-store-provider';
const default = Factory.create(); // Create a new instance with default options
const custom = Factory.create({
config: {...} // Custom options
name: 'custom' // Custom name
useEnvironment: true // Use environment variables
logger: myLoggerInstance // Custom logger
});
The configuration options (config
) are the following:
Defaults:
export interface ArchiveOptions {
separator?: string;
propertyData?: string;
propertyFileName?: string;
propertySkip?: string;
propertySkipValue?: string | number | boolean;
defaultBaseFilename?: string;
workingFolderPath: string;
archiveFolderPath: string;
createFolders: boolean;
inactiveTimeout?: number;
fileEncoding: BufferEncoding;
rotationInterval?: number;
rotationSize?: number;
rotationLines?: number;
retryOptions?: RetryOptions;
logger?: LoggerInstance;
}
Where each property has the next meaning:
\n
): Separator to use when writing the data to the file.undefined
): If set, this property will be used to store the data in the file, it could be a nested property in the data object expressed as a dot separated string.undefined
): If set, this property will be used as the filename, it could be a nested property in the data object expressed as a dot separated string.undefined
): If set, this property will be used to skip the data, it could be a nested property in the data object expressed as a dot separated string.undefined
): If set, this value will be used to skip the data, it could be a string, number or boolean. If value is not set, but propertySkip
is set, a not falsy value will be used to skip the data, this means that any value that is not false
, 0
or ''
will be used to skip the data.'file'
): Base filename for the files.'./data/working'
): Path to the folder where the working files are stored.'./data/archive'
): Path to the folder where the closed files are stored.true
): If true, it will create the folders if they don't exist.undefined
): Maximum inactivity time in milliseconds before a handler is cleaned up.'utf-8'
): Encoding to use when writing to files.600000
): Interval in milliseconds to rotate the file.10485760
): Max size of the file before rotating it.10000
): Max number of lines before rotating the file.{ attempts: 3, timeout: 1000, waitTime: 1000, maxWaitTime: 10000 }
): Retry options for the file handler operations. Check the @mdf.js/utils module for more information.undefined
): Logger instance to use. Check the @mdf.js/logger module for more information.Environment: remember to set the useEnvironment
flag to true
to use these environment variables.
{
workingFolderPath: process.env['CONFIG_JSONL_ARCHIVER_WORKING_FOLDER_PATH'],
archiveFolderPath: process.env['CONFIG_JSONL_ARCHIVER_ARCHIVE_FOLDER_PATH'],
fileEncoding: process.env['CONFIG_JSONL_ARCHIVER_FILE_ENCODING'],
createFolders: process.env['CONFIG_JSONL_ARCHIVER_CREATE_FOLDERS'], /* boolean */
rotationInterval: process.env['CONFIG_JSONL_ARCHIVER_ROTATION_INTERVAL'], /* number */
rotationSize: process.env['CONFIG_JSONL_ARCHIVER_ROTATION_SIZE'], /* number */
rotationLines: process.env['CONFIG_JSONL_ARCHIVER_ROTATION_LINES'], /* number */
}
'./data/working'
): Path to the folder where the open files are stored'./data/archive'
): Path to the folder where the closed files are stored'utf-8'
): File encodingtrue
): Create folders if they do not exist600000
): Interval in milliseconds to rotate the file10485760
): Max size of the file before rotating it10000
): Max number of lines before rotating the fileCopyright 2024 Mytra Control S.L. All rights reserved.
Use of this source code is governed by an MIT-style license that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.