@wxn0brp/db 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,194 +1,28 @@
1
- # DataBase Class
1
+ # @wxn0brp/db
2
2
 
3
- The `DataBase` class simplifies managing data with a file-based database, providing an easy way to perform CRUD operations, caching, and custom queries.
3
+ A lightweight file-based database management system that supports CRUD operations, custom queries, and graph structures.
4
4
 
5
5
  ## Installation
6
6
 
7
- Ensure you have Node.js installed. To install the `DataBase` package, run:
7
+ To install the package, run:
8
8
 
9
9
  ```bash
10
- npm install @wxn0brp/database
10
+ npm install @wxn0brp/db
11
11
  ```
12
12
 
13
- ## Usage Example
13
+ ## Usage
14
14
 
15
- ```javascript
16
- import DataBase from '@wxn0brp/database/database.js';
17
-
18
- async function main(){
19
- // Initialize the database with a folder path and optional cache settings
20
- const db = new DataBase('./data');
21
-
22
- // Create or check a collection
23
- await db.checkCollection('users');
24
-
25
- // Add a new user to the collection
26
- await db.add('users', { name: 'Alice', age: 30 });
27
-
28
- // Find users based on search criteria
29
- const users = await db.find('users', { age: 30 });
30
- console.log(users);
31
-
32
- // Update a user's data
33
- await db.update('users', { name: 'Alice' }, { age: 31 });
34
-
35
- // Remove a user
36
- await db.remove('users', { name: 'Alice' });
37
- }
38
-
39
- main().catch(console.error);
40
-
41
- ```
42
-
43
- ## Methods Overview
44
-
45
- | Method Name | Description | Parameters | Returns |
46
- | ----------- | ----------- | ---------- | ------- |
47
- | `getCollections` | Retrieves the names of all available collections. | None | `string[]` |
48
- | `checkCollection` | Ensures that a collection exists, creating it if necessary. | `collection` (string): Name of the collection | `Promise<void>` |
49
- | `issetCollection` | Checks if a collection exists. | `collection` (string): Name of the collection | `Promise<boolean>` |
50
- | `add` | Adds data to a collection, optionally generating an ID. | `collection` (string), `data` (Object), `id_gen` (boolean) | `Promise<Object>` |
51
- | `find` | Finds data entries matching a query. | `collection` (string), `search` (function/Object), `context` (Object), `options` (Object) - { max, reverse } | `Promise<Array<Object>>` |
52
- | `findOne` | Finds the first data entry matching a query. | `collection` (string), `search` (function/Object), `context` (Object) | `Promise<Object\|null>` |
53
- | `update` | Updates data entries matching a query. | `collection` (string), `search` (function/Object), `arg` (function/Object), `context` (Object) | `Promise<boolean>` |
54
- | `updateOne` | Updates the first data entry matching a query. | `collection` (string), `search` (function/Object), `arg` (function/Object), `context` (Object) | `Promise<boolean>` |
55
- | `remove` | Removes data entries matching a query. | `collection` (string), `search` (function/Object), `context` (Object) | `Promise<boolean>` |
56
- | `removeOne` | Removes the first data entry matching a query. | `collection` (string), `search` (function/Object), `context` (Object) | `Promise<boolean>` |
57
- | `updateOneOrAdd` | Updates one entry or adds a new one if no match is found. | `collection` (string), `search` (function/Object), `arg` (function/Object), `add_arg` (function/Object), `context` (Object), `id_gen` (boolean) | `Promise<boolean>` |
58
- | `removeDb` | Removes an entire database collection from the file system. | `collection` (string) | `void` |
59
-
60
- ---
61
-
62
- ### Querying Data
63
-
64
- The `DataBase` class offers flexibility for querying collections using either an object or a function as the `search` parameter in methods like `find`, `findOne`, `update`, and `remove`.
65
-
66
- #### Object-Based Queries
67
-
68
- You can use the following operators to build your queries:
69
-
70
- - **`$or`**: Matches if at least one condition is true.
71
-
72
- ```javascript
73
- const result = await db.find('users', {
74
- $or: [{ status: 'active' }, { role: 'admin' }]
75
- });
76
- ```
77
-
78
- - **`$not`**: Matches if the condition is false.
79
-
80
- ```javascript
81
- const result = await db.find('users', {
82
- $not: { status: 'inactive' }
83
- });
84
- ```
85
-
86
- - **`$and`**: Combines multiple conditions, all of which must be true. Useful for complex queries involving other operators.
87
-
88
- ```javascript
89
- const result = await db.find('users', {
90
- $and: [
91
- { age: 25 },
92
- { $or: [{ status: 'active' }, { status: 'away' }] }
93
- ]
94
- });
95
- ```
96
-
97
- - **`$set`**: Ensures that specified fields are present in the document.
98
-
99
- ```javascript
100
- const result = await db.find('users', {
101
- $set: { name: true }
102
- });
103
- ```
104
-
105
- #### Search as a Function
106
-
107
- Alternatively, you can use a function for more dynamic queries. The function receives each document as an argument and should return `true` for documents that match the criteria.
108
-
109
- ```javascript
110
- const results = await db.find('users', obj => obj.age > 30);
111
- ```
112
-
113
- This approach is powerful for cases where the query logic is too complex to be represented as an object.
114
-
115
- ### Update Argument
116
-
117
- When updating data, the `update` argument can also be either an object or a function.
118
-
119
- #### Update as an Object
120
-
121
- If you pass an object as the `update` argument, it will directly set the new values for the specified fields.
122
-
123
- ##### Example: Update with Object
15
+ You can import the necessary classes from the package as follows:
124
16
 
125
17
  ```javascript
126
- // Updates the age of all users named 'Alice' to 31
127
- await db.update('users', { name: 'Alice' }, { age: 31 });
18
+ import { DataBase, Graph, DataBaseRemote, GraphRemote } from "@wxn0brp/db";
128
19
  ```
129
20
 
130
- #### Update as a Function
131
-
132
- If you pass a function, it receives the current object as an argument and should return the updated object. This allows for dynamic updates based on the current state of the object.
133
-
134
- ##### Example: Update with Function
135
-
136
- ```javascript
137
- // Increments the age of all users named 'Alice' by 1
138
- await db.update('users', { name: 'Alice' }, obj => {
139
- obj.age++;
140
- return obj;
141
- });
142
- ```
143
-
144
- This method is useful when you need to compute new values based on existing ones.
145
-
146
- ## Other Features
147
-
148
- ### Graph.js
149
-
150
- The `Graph` class extends the functionality of the `DataBase` class to handle graph-like structures, where relationships (edges) between nodes (vertices) are stored in collections.
151
-
152
- #### Methods
153
-
154
- - **`add(collection, a, b)`**: Adds an edge between `a` and `b` in the specified collection. The nodes are sorted to ensure consistency in the storage format.
155
-
156
- ```javascript
157
- // Adds a friendship between Alice and Bob
158
- await graph.add('friends', 'Alice', 'Bob');
159
- ```
160
-
161
- - **`remove(collection, a, b)`**: Removes the edge between `a` and `b`.
162
-
163
- ```javascript
164
- // Removes the friendship between Alice and Bob
165
- await graph.remove('friends', 'Alice', 'Bob');
166
- ```
167
-
168
- - **`find(collection, d)`**: Finds all edges where `d` is one of the nodes.
169
-
170
- ```javascript
171
- // Returns all friends of Alice
172
- const friends = await graph.find('friends', 'Alice');
173
- ```
174
-
175
- - **`findOne(collection, d, e)`**: Finds the edge between `d` and `e`.
176
-
177
- ```javascript
178
- // Returns the friendship between Alice and Bob, if it exists
179
- const relation = await graph.findOne('friends', 'Alice', 'Bob');
180
- ```
181
-
182
- ### Gen.js
183
-
184
- The `gen.js` file contains a utility function `genId`, which generates a unique identifier.
185
-
186
- #### Example: Generating an ID
187
-
188
- ```javascript
189
- const id = genId();
190
- ```
21
+ ## Documentation
191
22
 
192
- ## License
23
+ For detailed information, refer to the following resources:
193
24
 
194
- This project is licensed under the [MIT License](https://opensource.org/licenses/MIT). See the [LICENSE](./LICENSE) file for details.
25
+ - [DataBase Documentation](./docs/database.md)
26
+ - [Graph Documentation](./docs/graph.md)
27
+ - [Remote Database and Graph Client Documentation](./docs/remote.md)
28
+ - [Remote Server Documentation](./docs/remote_server.md)
@@ -0,0 +1,140 @@
1
+ # DataBase Class Documentation
2
+
3
+ This documentation provides a detailed overview of the `DataBase` class, designed for performing CRUD operations on database collections. The class uses the `dbActionC` module for file-based operations and `executorC` for managing execution tasks.
4
+
5
+ ## Class: `DataBase`
6
+
7
+ ### Constructor: `DataBase(folder, options={})`
8
+ Creates a new instance of the `DataBase` class.
9
+
10
+ - **Parameters:**
11
+ - `folder` (`string`): The folder path where the database files are stored.
12
+ - `options` (`object`): Optional configuration options.
13
+ - `cacheThreshold` (`number`, default: 3): The threshold for caching entries.
14
+ - `cacheTTL` (`number`, default: 300000): Time-to-live for cache entries in milliseconds (default: 5 minutes).
15
+
16
+ ### Method: `c(collection)`
17
+ Creates a new instance of the `CollectionManager` class for the specified collection.
18
+
19
+ - **Parameters:**
20
+ - `collection` (`string`): The name of the collection.
21
+ - **Returns:**
22
+ - `CollectionManager`: A new instance of `CollectionManager`.
23
+
24
+ ### Method: `async getCollections()`
25
+ Gets the names of all available collections in the database.
26
+
27
+ - **Returns:**
28
+ - `Promise<string[]>`: A promise that resolves with an array of collection names.
29
+
30
+ ### Method: `async checkCollection(collection)`
31
+ Checks and creates the specified collection if it doesn't exist.
32
+
33
+ - **Parameters:**
34
+ - `collection` (`string`): The name of the collection to check.
35
+
36
+ ### Method: `async issetCollection(collection)`
37
+ Checks if a collection exists.
38
+
39
+ - **Parameters:**
40
+ - `collection` (`string`): The name of the collection.
41
+ - **Returns:**
42
+ - `Promise<boolean>`: A promise that resolves to `true` if the collection exists, otherwise `false`.
43
+
44
+ ### Method: `async add(collection, data, id_gen=true)`
45
+ Adds data to a specified collection.
46
+
47
+ - **Parameters:**
48
+ - `collection` (`string`): The name of the collection.
49
+ - `data` (`Object`): The data to add.
50
+ - `id_gen` (`boolean`, default: true): Whether to generate an ID for the entry.
51
+ - **Returns:**
52
+ - `Promise<Object>`: A promise that resolves with the added data.
53
+
54
+ ### Method: `async find(collection, search, context={}, options={}, findOpts={})`
55
+ Finds data in a collection based on a query.
56
+
57
+ - **Parameters:**
58
+ - `collection` (`string`): The name of the collection.
59
+ - `search` (`function|Object`): The search query.
60
+ - `context` (`Object`): The context object (for functions).
61
+ - `options` (`Object`): Search options.
62
+ - `max` (`number`, default: -1): Maximum number of entries to return.
63
+ - `reverse` (`boolean`, default: false): Whether to reverse the search results.
64
+ - `findOpts` (`Object`): Options for updating the search result.
65
+ - **Returns:**
66
+ - `Promise<Array<Object>>`: A promise that resolves with the matching data.
67
+
68
+ ### Method: `async findOne(collection, search, context={}, findOpts={})`
69
+ Finds one matching entry in a collection.
70
+
71
+ - **Parameters:**
72
+ - `collection` (`string`): The name of the collection.
73
+ - `search` (`function|Object`): The search query.
74
+ - `context` (`Object`): The context object (for functions).
75
+ - `findOpts` (`Object`): Options for updating the search result.
76
+ - **Returns:**
77
+ - `Promise<Object|null>`: A promise that resolves with the found entry, or `null` if no match is found.
78
+
79
+ ### Method: `async update(collection, search, arg, context={})`
80
+ Updates data in a collection.
81
+
82
+ - **Parameters:**
83
+ - `collection` (`string`): The name of the collection.
84
+ - `search` (`function|Object`): The search query.
85
+ - `arg` (`function|Object`): Update arguments.
86
+ - `context` (`Object`): The context object (for functions).
87
+ - **Returns:**
88
+ - `Promise<boolean>`: A promise that resolves when the data is updated.
89
+
90
+ ### Method: `async updateOne(collection, search, arg, context={})`
91
+ Updates one entry in a collection.
92
+
93
+ - **Parameters:**
94
+ - `collection` (`string`): The name of the collection.
95
+ - `search` (`function|Object`): The search query.
96
+ - `arg` (`function|Object`): Update arguments.
97
+ - `context` (`Object`): The context object (for functions).
98
+ - **Returns:**
99
+ - `Promise<boolean>`: A promise that resolves when the data is updated.
100
+
101
+ ### Method: `async updateOneOrAdd(collection, search, arg, add_arg={}, context={}, id_gen=true)`
102
+ Updates one entry or adds a new one if it doesn't exist.
103
+
104
+ - **Parameters:**
105
+ - `collection` (`string`): The name of the collection.
106
+ - `search` (`function|Object`): The search query.
107
+ - `arg` (`function|Object`): Update arguments.
108
+ - `add_arg` (`function|Object`): Data to add if no match is found.
109
+ - `context` (`Object`): The context object (for functions).
110
+ - `id_gen` (`boolean`, default: true): Whether to generate an ID for the new entry.
111
+ - **Returns:**
112
+ - `Promise<boolean>`: A promise that resolves to `true` if the entry was updated, otherwise `false`.
113
+
114
+ ### Method: `async remove(collection, search, context={})`
115
+ Removes data from a collection.
116
+
117
+ - **Parameters:**
118
+ - `collection` (`string`): The name of the collection.
119
+ - `search` (`function|Object`): The search query.
120
+ - `context` (`Object`): The context object (for functions).
121
+ - **Returns:**
122
+ - `Promise<boolean>`: A promise that resolves when the data is removed.
123
+
124
+ ### Method: `async removeOne(collection, search, context={})`
125
+ Removes one entry from a collection.
126
+
127
+ - **Parameters:**
128
+ - `collection` (`string`): The name of the collection.
129
+ - `search` (`function|Object`): The search query.
130
+ - `context` (`Object`): The context object (for functions).
131
+ - **Returns:**
132
+ - `Promise<boolean>`: A promise that resolves when the entry is removed.
133
+
134
+ ### Method: `removeDb(collection)`
135
+ Removes the specified collection from the database file system.
136
+
137
+ - **Parameters:**
138
+ - `collection` (`string`): The name of the collection to remove.
139
+ - **Returns:**
140
+ - `void`
package/docs/graph.md ADDED
@@ -0,0 +1,78 @@
1
+ # Graph Database Documentation
2
+
3
+ This documentation provides an overview of the `Graph` class, which represents a graph database built on top of a custom `DataBase` module. The `Graph` class allows for managing graph structures by adding, removing, and querying edges between nodes in the database.
4
+
5
+ ## Class: `Graph`
6
+
7
+ ### Constructor: `Graph(databaseFolder)`
8
+ Initializes the graph database.
9
+
10
+ - **Parameters:**
11
+ - `databaseFolder` (`string`): The folder where the database is stored.
12
+
13
+ ### Method: `async add(collection, nodeA, nodeB)`
14
+ Adds an edge between two nodes in the specified collection.
15
+
16
+ - **Parameters:**
17
+ - `collection` (`string`): The name of the collection.
18
+ - `nodeA` (`string`): The first node.
19
+ - `nodeB` (`string`): The second node.
20
+ - **Returns:**
21
+ - `Promise<Object>`: A promise that resolves with the added edge.
22
+
23
+ ### Method: `async remove(collection, nodeA, nodeB)`
24
+ Removes an edge between two nodes in the specified collection.
25
+
26
+ - **Parameters:**
27
+ - `collection` (`string`): The name of the collection.
28
+ - `nodeA` (`string`): The first node.
29
+ - `nodeB` (`string`): The second node.
30
+ - **Returns:**
31
+ - `Promise<boolean>`: A promise that resolves to `true` if the edge is removed, otherwise `false`.
32
+
33
+ ### Method: `async find(collection, node)`
34
+ Finds all edges with either node equal to the specified `node`.
35
+
36
+ - **Parameters:**
37
+ - `collection` (`string`): The name of the collection.
38
+ - `node` (`string`): The node to search for.
39
+ - **Returns:**
40
+ - `Promise<Object[]>`: A promise that resolves with an array of edges.
41
+
42
+ ### Method: `async findOne(collection, nodeA, nodeB)`
43
+ Finds one edge with either `nodeA` or `nodeB` as nodes.
44
+
45
+ - **Parameters:**
46
+ - `collection` (`string`): The name of the collection.
47
+ - `nodeA` (`string`): The first node.
48
+ - `nodeB` (`string`): The second node.
49
+ - **Returns:**
50
+ - `Promise<Object|null>`: A promise that resolves with the found edge or `null` if no edge is found.
51
+
52
+ ### Method: `async getAll(collection)`
53
+ Gets all edges in the specified collection.
54
+
55
+ - **Parameters:**
56
+ - `collection` (`string`): The name of the collection.
57
+ - **Returns:**
58
+ - `Promise<Object[]>`: A promise that resolves with all edges in the collection.
59
+
60
+ ### Method: `async getCollections()`
61
+ Returns the names of all available collections in the database.
62
+
63
+ - **Returns:**
64
+ - `Promise<string[]>`: A promise that resolves with an array of collection names.
65
+
66
+ ### Method: `async checkCollection(collection)`
67
+ Checks and creates the specified collection if it doesn't exist.
68
+
69
+ - **Parameters:**
70
+ - `collection` (`string`): The name of the collection.
71
+
72
+ ### Method: `async issetCollection(collection)`
73
+ Checks if the specified collection exists.
74
+
75
+ - **Parameters:**
76
+ - `collection` (`string`): The name of the collection.
77
+ - **Returns:**
78
+ - `Promise<boolean>`: A promise that resolves to `true` if the collection exists, otherwise `false`.
package/docs/remote.md ADDED
@@ -0,0 +1,30 @@
1
+ # Remote Database and Graph Database Client Documentation
2
+
3
+ ## `remote` object structure.
4
+ - `name` (`string`): The name of the database.
5
+ - `url` (`string`): The URL of the remote database.
6
+ - `auth` (`string`): The authentication token for accessing the database.
7
+
8
+ ## Class: `DataBaseRemote(remote)`
9
+ `DataBaseRemote` is an extended version of the `DataBase` class, designed to handle API requests. It provides the same functionalities as `DataBase`, but enables remote communication, allowing you to interact with databases through HTTP requests.
10
+
11
+ ## Example Usage
12
+ ```javascript
13
+ const remoteDB = new DataBaseRemote({
14
+ name: 'myRemoteDB',
15
+ url: 'https://example.com/db',
16
+ auth: 'your-auth-token'
17
+ });
18
+ ```
19
+
20
+ ## Class: `GraphRemote(remote)`
21
+ `GraphRemote` is an extension of the `Graph` class, specifically designed for working with graph databases over HTTP. It supports querying and modifying graph data, providing methods tailored for graph operations such as adding nodes, edges, and executing graph queries.
22
+
23
+ ## Example Usage
24
+ ```javascript
25
+ const remoteGraph = new GraphRemote({
26
+ name: 'myRemoteGraph',
27
+ url: 'https://example.com/db',
28
+ auth: 'your-auth-token'
29
+ });
30
+ ```
@@ -0,0 +1,35 @@
1
+ # Installation
2
+
3
+ Clone the repository and install the necessary development dependencies:
4
+
5
+ ```bash
6
+ git clone https://github.com/wxn0brP/db.git
7
+ cd db
8
+ npm install
9
+ ```
10
+
11
+ # Usage
12
+
13
+ To start the server, run:
14
+
15
+ ```bash
16
+ node remote/server/index.js
17
+ ```
18
+
19
+ # Server Management
20
+
21
+ Manage the server using the following command:
22
+
23
+ ```bash
24
+ node remote/serverMgmt/index.js
25
+ ```
26
+
27
+ ## Available Parameters:
28
+
29
+ - `help`: Display this help message
30
+ - `add-db <type> <name> <folder> <opts>`: Add a new database
31
+ - `rm-db <name>`: Remove an existing database
32
+ - `list-dbs`: List all databases
33
+ - `add-user <login> <password>`: Create a new user
34
+ - `rm-user <login>`: Delete a user
35
+ - `list-users`: Display all users
package/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import DataBase from "./database.js";
2
+ import Graph from "./graph.js";
3
+ import DataBaseRemote from "./remote/client/database.js";
4
+ import GraphRemote from "./remote/client/graph.js";
5
+
6
+ export { DataBase, Graph, DataBaseRemote, GraphRemote };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "main": "index.js",
5
5
  "description": "A simple file-based database management system with support for CRUD operations, custom queries, and graph structures.",
6
6
  "homepage": "https://github.com/wxn0brP/database",
@@ -19,14 +19,16 @@
19
19
  "license": "MIT",
20
20
  "type": "module",
21
21
  "dependencies": {
22
+ "json5": "^2.2.3",
23
+ "got": "^14.4.2",
24
+ "readline": "^1.3.0"
25
+ },
26
+ "devDependencies": {
22
27
  "body-parser": "^1.20.3",
23
28
  "cors": "^2.8.5",
24
29
  "dotenv": "^16.4.5",
25
30
  "express": "^4.21.1",
26
- "got": "^14.4.2",
27
- "json5": "^2.2.3",
28
31
  "jwt-simple": "^0.5.6",
29
- "node-cache": "^5.1.2",
30
- "readline": "^1.3.0"
32
+ "node-cache": "^5.1.2"
31
33
  }
32
34
  }
@@ -12,7 +12,6 @@ class DataBaseRemote{
12
12
  * @constructor
13
13
  * @param {object} remote - The remote database object.
14
14
  * @param {string} remote.name - The name of the database.
15
- * @param {string} remote.folder - The folder path where the database files are stored.
16
15
  * @param {string} remote.auth - The authentication token.
17
16
  * @param {string} remote.url - The URL of the remote database.
18
17
  */
@@ -11,7 +11,6 @@ class GraphRemote{
11
11
  * @constructor
12
12
  * @param {object} remote - The remote database object.
13
13
  * @param {string} remote.name - The name of the database.
14
- * @param {string} remote.folder - The folder path where the database files are stored.
15
14
  * @param {string} remote.auth - The authentication token.
16
15
  * @param {string} remote.url - The URL of the remote database.
17
16
  */
package/cacheManager.js DELETED
@@ -1,83 +0,0 @@
1
- /**
2
- * A cache manager for storing and managing cached data.
3
- * @class
4
- */
5
- class CacheManager{
6
- /**
7
- * Create a new cache manager instance.
8
- * @constructor
9
- * @param {number} cacheThreshold - The threshold for caching query results.
10
- * @param {number} ttl - The time-to-live (TTL) for cached data in milliseconds.
11
- */
12
- constructor(cacheThreshold, ttl){
13
- this.queryCounterCache = {};
14
- this.dataCache = {};
15
- this.cacheThreshold = cacheThreshold;
16
- this.ttl = ttl;
17
- }
18
-
19
- /**
20
- * Increment the query counter for a specific cache key.
21
- * @private
22
- * @param {string} key - The cache key.
23
- * @returns {number} The updated query count for the cache key.
24
- */
25
- _incrementQueryCounter(key){
26
- if(!this.queryCounterCache[key]){
27
- this.queryCounterCache[key] = 1;
28
- }else{
29
- this.queryCounterCache[key]++;
30
- }
31
- return this.queryCounterCache[key];
32
- }
33
-
34
- /**
35
- * Set data in the cache for a specific cache key.
36
- * @private
37
- * @param {string} key - The cache key.
38
- * @param {*} data - The data to be cached.
39
- */
40
- _setCache(key, data){
41
- this.dataCache[key] = { data, expires: Date.now() + this.ttl };
42
- }
43
-
44
- /**
45
- * Get data from the cache for a specific cache key if it is not expired.
46
- * @param {string} key - The cache key.
47
- * @returns {*} The cached data if not expired, otherwise null.
48
- */
49
- getFromCache(key){
50
- const item = this.dataCache[key];
51
- if(item && Date.now() < item.expires){
52
- return item.data;
53
- }
54
- delete this.dataCache[key];
55
- return null;
56
- }
57
-
58
- /**
59
- * Add data to the cache if the query count exceeds the cache threshold.
60
- * @param {string} key - The cache key.
61
- * @param {*} data - The data to be cached.
62
- */
63
- addToCacheIfNeeded(key, data){
64
- const queryCount = this._incrementQueryCounter(key);
65
- if(queryCount > this.cacheThreshold){
66
- this._setCache(key, data);
67
- }
68
- }
69
-
70
- /**
71
- * Invalidate cache entries matching a specific key pattern.
72
- * @param {string} keyPattern - The key pattern to match and invalidate cache entries.
73
- */
74
- invalidateCache(keyPattern){
75
- Object.keys(this.dataCache).forEach(key => {
76
- if(key.startsWith(keyPattern)){
77
- delete this.dataCache[key];
78
- }
79
- });
80
- }
81
- }
82
-
83
- export default CacheManager;
@@ -1,10 +0,0 @@
1
- import databaseC from "./database.js";
2
- import graphC from "./graph.js";
3
-
4
- export async function DataBase(remote){
5
- return new databaseC(remote);
6
- }
7
-
8
- export async function Graph(remote){
9
- return new graphC(remote);
10
- }