Socket
Socket
Sign inDemoInstall

@alwatr/storage-engine

Package Overview
Dependencies
6
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.0 to 4.0.2

README.md

4

CHANGELOG.md

@@ -6,2 +6,6 @@ # Change Log

## [4.0.2](https://github.com/Alwatr/storage/compare/v4.0.1...v4.0.2) (2023-11-28)
**Note:** Version bump only for package @alwatr/storage-engine
# [4.0.0](https://github.com/Alwatr/storage/compare/v4.0.0-rc.0...v4.0.0) (2023-11-27)

@@ -8,0 +12,0 @@

4

package.json
{
"name": "@alwatr/storage-engine",
"version": "4.0.0",
"version": "4.0.2",
"description": "Extremely fast and compact JSON-based database that operates in memory, includes a JSON file backup, and serve over the highly accelerated Nginx.",

@@ -73,3 +73,3 @@ "keywords": [

},
"gitHead": "fba0c97808d1ac8c52dbca595631c469f089eb17"
"gitHead": "5cca9645a70e2f58381f1d30207a7a9f23890a44"
}

@@ -20,7 +20,24 @@ import { AlwatrStorageEngine } from './storage-engine.js';

protected _list: Record<string, AlwatrStorageEngine>;
/**
* Creates an instance of AlwatrStorageEngineProvider.
* @param _config The configuration for the storage engine provider.
*/
constructor(_config: AlwatrStorageEngineProviderConfig);
/**
* Retrieves a storage engine based on the provided configuration.
* If the storage engine does not exist, a new one is created.
* @param config The configuration for the storage engine.
* @returns The storage engine instance.
*/
get<T extends AlwatrDocumentObject = AlwatrDocumentObject>(config: AlwatrStorageEngineConfig): AlwatrStorageEngine<T>;
/**
* Unloads a storage engine with the specified name.
* @param name The name of the storage engine to unload.
*/
unload(name: string): void;
/**
* Unloads all storage engines.
*/
unloadAll(): void;
}
//# sourceMappingURL=provider.d.ts.map
import { createLogger } from "@alwatr/logger";
import { AlwatrStorageEngine } from "./storage-engine.js";
class AlwatrStorageEngineProvider {
/**
* Creates an instance of AlwatrStorageEngineProvider.
* @param _config The configuration for the storage engine provider.
*/
constructor(_config) {

@@ -10,3 +14,8 @@ this._config = _config;

}
// TODO: update all jsdoc and readme.
/**
* Retrieves a storage engine based on the provided configuration.
* If the storage engine does not exist, a new one is created.
* @param config The configuration for the storage engine.
* @returns The storage engine instance.
*/
get(config) {

@@ -24,2 +33,6 @@ this._logger.logMethodArgs?.("get", { name: config.name });

}
/**
* Unloads a storage engine with the specified name.
* @param name The name of the storage engine to unload.
*/
unload(name) {

@@ -34,2 +47,5 @@ this._logger.logMethodArgs?.("unload", { name });

}
/**
* Unloads all storage engines.
*/
unloadAll() {

@@ -36,0 +52,0 @@ for (const name in this._list) {

@@ -6,5 +6,6 @@ import { type AlwatrLogger } from '@alwatr/logger';

/**
* Elegant micro in-memory json-like storage with disk backed,
* Fastest NoSQL Database written in tiny TypeScript ES module.
* Extremely fast and compact JSON-based database that operates in memory, includes a JSON file backup.
*
* @template DocumentType - The type of the document object.
*
* Example:

@@ -65,3 +66,3 @@ *

/**
* Storage file full path.
* The path to the storage location.
*/

@@ -97,5 +98,12 @@ readonly storagePath: string;

protected get _newStorage(): AlwatrDocumentStorage<DocumentType>;
/**
* Creates a new instance of AlwatrStorageEngine.
*
* @param config - The configuration for the storage engine.
*/
constructor(config: AlwatrStorageEngineConfig);
/**
* load storage file.
* Loads the storage file.
*
* @returns The loaded storage data.
*/

@@ -105,4 +113,7 @@ protected load(): AlwatrDocumentStorage<DocumentType>;

/**
* Check documentId exist in the storage or not.
* Checks if a documentId exists in the storage.
*
* @param documentId - The id of the document.
* @returns `true` if the documentId exists, otherwise `false`.
*
* Example:

@@ -116,8 +127,8 @@ *

/**
* Get a document object by id.
* Gets a document object by id.
*
* @param documentId The id of the document object.
* @param fastInstance by default it will return a copy of the document.
* if you set fastInstance to true, it will return the original document.
* This is dangerous but much faster, you should use it only if you know what you are doing.
* @param documentId - The id of the document object.
* @param fastInstance - (Optional) If `true`, returns the original document object without making a copy.
* Default is `false`. This is dangerous but much faster, you should use it only if you know what you are doing.
* @returns The document object if found, otherwise `null`.
*

@@ -132,8 +143,8 @@ * Example:

/**
* Insert/update a document object in the storage.
* Inserts or updates a document object in the storage.
*
* @param documentObject The document object to insert/update contain `id`.
* @param fastInstance by default it will make a copy of the document before set.
* if you set fastInstance to true, it will set the original document.
* This is dangerous but much faster, you should use it only if you know what you are doing.
* @param documentObject - The document object to insert or update.
* @param fastInstance - (Optional) If `true`, sets the original document object without making a copy.
* Default is `false`.
* @returns The inserted or updated document object.
*

@@ -151,4 +162,7 @@ * Example:

/**
* Delete a document object from the storage.
* Deletes a document object from the storage.
*
* @param documentId - The id of the document object to delete.
* @returns `true` if the document object was deleted, otherwise `false`.
*
* Example:

@@ -162,4 +176,6 @@ *

/**
* Loop over all document objects.
* Iterates over all document objects in the storage.
*
* @returns A generator that yields each document object.
*
* Example:

@@ -177,13 +193,14 @@ *

/**
* Save the storage to disk (debounced and none blocking).
* Saves the storage to disk (debounced and non-blocking).
*/
save(): void;
/**
* Save the storage to disk without any debounce (none blocking) when `this.hasUnsavedChanges` is true.
* Saves the storage to disk without any debounce (non-blocking) when `this.hasUnsavedChanges` is true.
*
* @param [emergency=false] - Recommend to ignore it (default is false) for none blocking IO.
* @param emergency - (Optional) If `true`, performs an emergency save immediately. Default is `false`.
* @returns A promise that resolves when the save operation is complete.
*/
private _$save;
/**
* Unload storage data and free ram usage (auto saved before unload).
* Unloads the storage data and frees up memory usage (auto saved before unload).
*

@@ -190,0 +207,0 @@ * Example:

@@ -7,2 +7,7 @@ import { resolve } from "node:path";

const _AlwatrStorageEngine = class _AlwatrStorageEngine {
/**
* Creates a new instance of AlwatrStorageEngine.
*
* @param config - The configuration for the storage engine.
*/
constructor(config) {

@@ -68,3 +73,5 @@ /**

/**
* load storage file.
* Loads the storage file.
*
* @returns The loaded storage data.
*/

@@ -107,4 +114,7 @@ load() {

/**
* Check documentId exist in the storage or not.
* Checks if a documentId exists in the storage.
*
* @param documentId - The id of the document.
* @returns `true` if the documentId exists, otherwise `false`.
*
* Example:

@@ -120,8 +130,8 @@ *

/**
* Get a document object by id.
* Gets a document object by id.
*
* @param documentId The id of the document object.
* @param fastInstance by default it will return a copy of the document.
* if you set fastInstance to true, it will return the original document.
* This is dangerous but much faster, you should use it only if you know what you are doing.
* @param documentId - The id of the document object.
* @param fastInstance - (Optional) If `true`, returns the original document object without making a copy.
* Default is `false`. This is dangerous but much faster, you should use it only if you know what you are doing.
* @returns The document object if found, otherwise `null`.
*

@@ -148,8 +158,8 @@ * Example:

/**
* Insert/update a document object in the storage.
* Inserts or updates a document object in the storage.
*
* @param documentObject The document object to insert/update contain `id`.
* @param fastInstance by default it will make a copy of the document before set.
* if you set fastInstance to true, it will set the original document.
* This is dangerous but much faster, you should use it only if you know what you are doing.
* @param documentObject - The document object to insert or update.
* @param fastInstance - (Optional) If `true`, sets the original document object without making a copy.
* Default is `false`.
* @returns The inserted or updated document object.
*

@@ -191,4 +201,7 @@ * Example:

/**
* Delete a document object from the storage.
* Deletes a document object from the storage.
*
* @param documentId - The id of the document object to delete.
* @returns `true` if the document object was deleted, otherwise `false`.
*
* Example:

@@ -211,4 +224,6 @@ *

/**
* Loop over all document objects.
* Iterates over all document objects in the storage.
*
* @returns A generator that yields each document object.
*
* Example:

@@ -232,3 +247,3 @@ *

/**
* Save the storage to disk (debounced and none blocking).
* Saves the storage to disk (debounced and non-blocking).
*/

@@ -243,5 +258,6 @@ save() {

/**
* Save the storage to disk without any debounce (none blocking) when `this.hasUnsavedChanges` is true.
* Saves the storage to disk without any debounce (non-blocking) when `this.hasUnsavedChanges` is true.
*
* @param [emergency=false] - Recommend to ignore it (default is false) for none blocking IO.
* @param emergency - (Optional) If `true`, performs an emergency save immediately. Default is `false`.
* @returns A promise that resolves when the save operation is complete.
*/

@@ -264,3 +280,3 @@ _$save(emergency = false) {

/**
* Unload storage data and free ram usage (auto saved before unload).
* Unloads the storage data and frees up memory usage (auto saved before unload).
*

@@ -267,0 +283,0 @@ * Example:

@@ -31,5 +31,8 @@ export interface AlwatrStorageEngineConfig {

}
/**
* Configuration options for the AlwatrStorageEngineProvider.
*/
export interface AlwatrStorageEngineProviderConfig {
/**
* Default storage path. you can override it in get config params.
* Default storage path. You can override it in the getConfigParams method.
*

@@ -40,3 +43,3 @@ * @default './db'

/**
* Save debounce timeout for minimal disk iops usage.
* Save debounce timeout for minimal disk I/O operations usage.
*

@@ -55,3 +58,3 @@ * @default 100

*
* @default undefined Auto detect base in NODE_ENV
* @default undefined (Auto detect based on `NODE_ENV`)
*/

@@ -58,0 +61,0 @@ devMode?: boolean;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc