@wxn0brp/db 0.5.3 → 0.5.5
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 +1 -1
- package/dist/memory.d.ts +78 -2
- package/dist/memory.js +1 -1
- package/dist/relation.d.ts +2 -2
- package/dist/relation.js +5 -2
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/memory.d.ts
CHANGED
|
@@ -1,8 +1,84 @@
|
|
|
1
|
+
import dbActionC from "./action.js";
|
|
1
2
|
import DataBase from "./database.js";
|
|
3
|
+
import { Arg, Search, Updater } from "./types/arg.js";
|
|
2
4
|
import Data from "./types/data.js";
|
|
5
|
+
import FileCpu from "./types/fileCpu.js";
|
|
6
|
+
import { DbFindOpts, DbOpts, FindOpts } from "./types/options.js";
|
|
7
|
+
import { SearchOptions } from "./types/searchOpts.js";
|
|
8
|
+
import { Transaction } from "./types/transactions.js";
|
|
9
|
+
import { Context } from "./types/types.js";
|
|
10
|
+
export declare class MemoryAction implements dbActionC {
|
|
11
|
+
folder: string;
|
|
12
|
+
options: DbOpts;
|
|
13
|
+
fileCpu: FileCpu;
|
|
14
|
+
memory: Map<string, any[]>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new instance of dbActionC.
|
|
17
|
+
* @constructor
|
|
18
|
+
* @param folder - The folder where database files are stored.
|
|
19
|
+
* @param options - The options object.
|
|
20
|
+
*/
|
|
21
|
+
constructor();
|
|
22
|
+
_readMemory(key: string): any[];
|
|
23
|
+
_writeMemory(key: string, data: any[]): void;
|
|
24
|
+
_getCollectionPath(collection: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get a list of available databases in the specified folder.
|
|
27
|
+
*/
|
|
28
|
+
getCollections(): Promise<string[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Check and create the specified collection if it doesn't exist.
|
|
31
|
+
*/
|
|
32
|
+
checkCollection(collection: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Check if a collection exists.
|
|
35
|
+
*/
|
|
36
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Add a new entry to the specified database.
|
|
39
|
+
*/
|
|
40
|
+
add(collection: string, arg: Arg, id_gen?: boolean): Promise<Arg>;
|
|
41
|
+
/**
|
|
42
|
+
* Find entries in the specified database based on search criteria.
|
|
43
|
+
*/
|
|
44
|
+
find(collection: string, arg: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<Data[]>;
|
|
45
|
+
/**
|
|
46
|
+
* Find the first matching entry in the specified database based on search criteria.
|
|
47
|
+
*/
|
|
48
|
+
findOne(collection: string, arg: SearchOptions, context?: Context, findOpts?: FindOpts): Promise<Data>;
|
|
49
|
+
/**
|
|
50
|
+
* Find entries in the specified database based on search criteria and return a stream of results.
|
|
51
|
+
*/
|
|
52
|
+
findStream(collection: string, arg: Search, context?: Context, findOpts?: FindOpts, limit?: number): AsyncGenerator<any>;
|
|
53
|
+
/**
|
|
54
|
+
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
55
|
+
*/
|
|
56
|
+
update(collection: string, arg: Search, updater: Updater, context?: {}): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
59
|
+
*/
|
|
60
|
+
updateOne(collection: string, arg: Search, updater: Updater, context?: Context): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Remove entries from the specified database based on search criteria.
|
|
63
|
+
*/
|
|
64
|
+
remove(collection: string, arg: Search, context?: Context): Promise<boolean>;
|
|
65
|
+
/**
|
|
66
|
+
* Remove the first matching entry from the specified database based on search criteria.
|
|
67
|
+
*/
|
|
68
|
+
removeOne(collection: string, arg: Search, context?: Context): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Removes a database collection from the file system.
|
|
71
|
+
*/
|
|
72
|
+
removeCollection(collection: string): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Executes a list of transactions on the specified database collection.
|
|
75
|
+
* @throws Error - Method not supported in memory.
|
|
76
|
+
*/
|
|
77
|
+
transaction(collection: string, transactions: Transaction[]): Promise<void>;
|
|
78
|
+
}
|
|
3
79
|
export default class ValtheraMemory extends DataBase {
|
|
4
80
|
constructor(...args: any[]);
|
|
5
81
|
}
|
|
6
|
-
export declare function createMemoryValthera
|
|
82
|
+
export declare function createMemoryValthera<T = {
|
|
7
83
|
[key: string]: Data[];
|
|
8
|
-
}): ValtheraMemory;
|
|
84
|
+
}>(data?: T): ValtheraMemory;
|
package/dist/memory.js
CHANGED
package/dist/relation.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { RelationTypes } from "./types/relation.js";
|
|
|
4
4
|
declare class Relation {
|
|
5
5
|
dbs: RelationTypes.DBS;
|
|
6
6
|
constructor(dbs: RelationTypes.DBS);
|
|
7
|
-
findOne(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select
|
|
8
|
-
find(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select
|
|
7
|
+
findOne(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select?: RelationTypes.FieldPath[]): Promise<any>;
|
|
8
|
+
find(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select?: RelationTypes.FieldPath[], findOpts?: DbFindOpts): Promise<any[]>;
|
|
9
9
|
}
|
|
10
10
|
export default Relation;
|
package/dist/relation.js
CHANGED
|
@@ -52,8 +52,10 @@ function selectDataSelf(data, select) {
|
|
|
52
52
|
return selectDataSelf(data[select[0]], select.slice(1));
|
|
53
53
|
}
|
|
54
54
|
function selectData(data, select) {
|
|
55
|
-
if (!select
|
|
55
|
+
if (!select)
|
|
56
56
|
return data;
|
|
57
|
+
if (!data && select.length === 0)
|
|
58
|
+
return null;
|
|
57
59
|
const newData = {};
|
|
58
60
|
for (const field of select) {
|
|
59
61
|
const key = field.map(f => f.replaceAll(".", "\\.")).join(".");
|
|
@@ -70,7 +72,8 @@ class Relation {
|
|
|
70
72
|
const db = this.dbs[path[0]];
|
|
71
73
|
const data = await db.findOne(path[1], search);
|
|
72
74
|
await processRelations(this.dbs, relations, data);
|
|
73
|
-
|
|
75
|
+
const result = selectData(data, select);
|
|
76
|
+
return Object.keys(result).length === 0 ? null : result;
|
|
74
77
|
}
|
|
75
78
|
async find(path, search, relations, select, findOpts = {}) {
|
|
76
79
|
const db = this.dbs[path[0]];
|
package/package.json
CHANGED