@wxn0brp/db 0.5.7 → 0.7.0

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,7 +1,11 @@
1
- # <img src="./logo.svg" alt="ValtheraDB Logo" style="width: 36px; height: 36px"> ValtheraDB (@wxn0brp/db)
1
+ # <img src="./logo.svg" alt="ValtheraDB Logo" width="36" height="36"> ValtheraDB (@wxn0brp/db)
2
2
 
3
3
  A lightweight file-based database management system that supports CRUD operations, custom queries, and graph structures.
4
4
 
5
+ [![npm version](https://img.shields.io/npm/v/@wxn0brp/db)](https://www.npmjs.com/package/@wxn0brp/db)
6
+ [![License](https://img.shields.io/npm/l/@wxn0brp/db)](./LICENSE)
7
+ [![Downloads](https://img.shields.io/npm/dm/@wxn0brp/db)](https://www.npmjs.com/package/@wxn0brp/db)
8
+
5
9
  ## Installation
6
10
 
7
11
  To install the package, run:
@@ -15,7 +19,35 @@ npm install @wxn0brp/db
15
19
  You can import the necessary classes from the package as follows:
16
20
 
17
21
  ```javascript
18
- import { DataBase, Graph, DataBaseRemote, GraphRemote, Relation, genId } from "@wxn0brp/db";
22
+ import { Valthera, Graph, ValtheraRemote, GraphRemote, Relation, genId, ValtheraMemory, ValtheraAutoCreate } from "@wxn0brp/db";
23
+ ```
24
+
25
+ ### Examples
26
+ ```javascript
27
+ import { Valthera } from '@wxn0brp/db';
28
+
29
+ // Create a new Valthera database instance
30
+ const db = new Valthera('./database');
31
+
32
+ // Add a new document to the database
33
+ const result = await db.add('users', { name: 'John Doe', age: 30 });
34
+ console.log(result); // { _id: 'xxx', name: 'John Doe', age: 30 }
35
+
36
+ // Find all documents in the collection
37
+ const results = await db.find('users', {});
38
+ console.log(results); // [{ _id: 'xxx', name: 'John Doe', age: 30 }]
39
+
40
+ // Find a single document in the collection.
41
+ const user = await db.findOne('users', { $gt: { age: 25 } });
42
+ console.log(user); // { _id: 'xxx', name: 'John Doe', age: 30 }
43
+
44
+ // Update a document in the collection
45
+ const updateResult = await db.updateOne('users', { name: 'John Doe' }, { age: 31 });
46
+ console.log(updateResult); // true
47
+
48
+ // Remove a document from the collection
49
+ const removeResult = await db.removeOne('users', { name: 'John Doe' });
50
+ console.log(removeResult); // true
19
51
  ```
20
52
 
21
53
  ## Documentation
@@ -24,10 +56,18 @@ Website: [https://wxn0brp.github.io/ValtheraDB/](https://wxn0brp.github.io/Valth
24
56
 
25
57
  For detailed information, refer to the following resources:
26
58
 
27
- - [DataBase Documentation](./docs/database.md)
59
+ - [Valthera Documentation](./docs/valthera.md)
28
60
  - [Graph Documentation](./docs/graph.md)
29
- - [Remote Database and Graph Client Documentation](./docs/remote.md)
61
+ - [Remote Valthera and Graph Client Documentation](./docs/remote.md)
30
62
  - [Search Options Documentation](./docs/search_opts.md)
31
63
  - [Find Options Documentation](./docs/find_opts.md)
32
64
  - [Updater Options Documentation](./docs/updater.md)
33
- - [Relation Documentation](./docs/relation.md)
65
+ - [Relation Documentation](./docs/relation.md)
66
+
67
+ ## License
68
+
69
+ This project is released under the [MIT License](./LICENSE).
70
+
71
+ ## Contributing
72
+
73
+ Contributions are welcome! Please submit a pull request or open an issue on our GitHub repository.
@@ -1,13 +1,12 @@
1
- import DataBase from "./database.js";
2
- import DataBaseRemote from "./client/database.js";
3
1
  import { Arg, Search, Updater } from "./types/arg.js";
4
2
  import { DbFindOpts, FindOpts } from "./types/options.js";
5
3
  import { Context } from "./types/types.js";
6
4
  import Data from "./types/data.js";
5
+ import { ValtheraCompatible } from "./types/valthera.js";
7
6
  declare class CollectionManager {
8
- db: DataBase | DataBaseRemote;
9
- collection: string;
10
- constructor(db: DataBase | DataBaseRemote, collection: string);
7
+ private db;
8
+ private collection;
9
+ constructor(db: ValtheraCompatible, collection: string);
11
10
  /**
12
11
  * Add data to a database.
13
12
  */
@@ -1,4 +1,12 @@
1
- import DataBaseRemote from "./client/database.js";
2
1
  import { Remote } from "./client/remote.js";
3
- import DataBase from "./database.js";
4
- export declare function autoCreate(cfg: string | Remote): DataBase | DataBaseRemote;
2
+ import { ValtheraCompatible } from "./types/valthera.js";
3
+ /**
4
+ * Creates a database instance based on the provided configuration.
5
+ * If the configuration is an object, it creates a DataBaseRemote instance.
6
+ * If the configuration is a string starting with "http", it also creates a DataBaseRemote instance.
7
+ * Otherwise, it creates a DataBase instance.
8
+ *
9
+ * @param cfg - The configuration object or string for the database.
10
+ * @returns A new instance of DataBaseRemote or DataBase.
11
+ */
12
+ export declare function ValtheraAutoCreate(cfg: string | Remote): ValtheraCompatible;
@@ -1,9 +1,18 @@
1
- import DataBaseRemote from "./client/database.js";
2
- import DataBase from "./database.js";
3
- export function autoCreate(cfg) {
1
+ import ValtheraRemote from "./client/valthera.js";
2
+ import Valthera from "./valthera.js";
3
+ /**
4
+ * Creates a database instance based on the provided configuration.
5
+ * If the configuration is an object, it creates a DataBaseRemote instance.
6
+ * If the configuration is a string starting with "http", it also creates a DataBaseRemote instance.
7
+ * Otherwise, it creates a DataBase instance.
8
+ *
9
+ * @param cfg - The configuration object or string for the database.
10
+ * @returns A new instance of DataBaseRemote or DataBase.
11
+ */
12
+ export function ValtheraAutoCreate(cfg) {
4
13
  if (typeof cfg === "object")
5
- return new DataBaseRemote(cfg);
14
+ return new ValtheraRemote(cfg);
6
15
  if (cfg.startsWith("http"))
7
- return new DataBaseRemote(cfg);
8
- return new DataBase(cfg);
16
+ return new ValtheraRemote(cfg);
17
+ return new Valthera(cfg);
9
18
  }
@@ -5,12 +5,13 @@ import { DbFindOpts, FindOpts } from "../types/options.js";
5
5
  import { Context } from "../types/types.js";
6
6
  import Data from "../types/data.js";
7
7
  import { Transaction } from "../types/transactions.js";
8
+ import { ValtheraCompatible } from "../types/valthera.js";
8
9
  /**
9
10
  * Represents a database management class for performing CRUD operations.
10
11
  * Uses a remote database.
11
12
  * @class
12
13
  */
13
- declare class DataBaseRemote {
14
+ declare class ValtheraRemote implements ValtheraCompatible {
14
15
  remote: Remote;
15
16
  constructor(remote: Remote | string);
16
17
  /**
@@ -48,7 +49,7 @@ declare class DataBaseRemote {
48
49
  /**
49
50
  * Find data in a database as a stream.
50
51
  */
51
- findStream<T = Data>(collection: string, search: Search, context?: Context, dbFindOpts?: DbFindOpts, findOpts?: FindOpts): Promise<void>;
52
+ findStream<T = Data>(collection: string, search: Search, context?: Context, findOpts?: FindOpts, limit?: number): Promise<AsyncGenerator<T, any, any>>;
52
53
  /**
53
54
  * Update data in a database.
54
55
  */
@@ -78,4 +79,4 @@ declare class DataBaseRemote {
78
79
  */
79
80
  transaction(collection: string, transaction: Transaction[]): Promise<boolean>;
80
81
  }
81
- export default DataBaseRemote;
82
+ export default ValtheraRemote;
@@ -6,7 +6,7 @@ import serializeFunctions from "./function.js";
6
6
  * Uses a remote database.
7
7
  * @class
8
8
  */
9
- class DataBaseRemote {
9
+ class ValtheraRemote {
10
10
  remote;
11
11
  constructor(remote) {
12
12
  if (typeof remote === "string") {
@@ -96,8 +96,9 @@ class DataBaseRemote {
96
96
  /**
97
97
  * Find data in a database as a stream.
98
98
  */
99
- async findStream(collection, search, context = {}, dbFindOpts = {}, findOpts = {}) {
99
+ async findStream(collection, search, context = {}, findOpts = {}, limit = -1) {
100
100
  throw new Error("Method not implemented.");
101
+ return await this._request("findStream", [collection, search, context, findOpts, limit]);
101
102
  }
102
103
  /**
103
104
  * Update data in a database.
@@ -142,4 +143,4 @@ class DataBaseRemote {
142
143
  return await this._request("transaction", [collection, transaction]);
143
144
  }
144
145
  }
145
- export default DataBaseRemote;
146
+ export default ValtheraRemote;
package/dist/graph.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import DataBase from "./database.js";
1
+ import Valthera from "./valthera.js";
2
2
  import Data from "./types/data.js";
3
3
  /**
4
4
  * A class representing a graph database.
5
5
  * @class
6
6
  */
7
7
  declare class Graph {
8
- db: DataBase;
8
+ db: Valthera;
9
9
  constructor(databaseFolder: string);
10
10
  /**
11
11
  * Adds an edge between two nodes.
package/dist/graph.js CHANGED
@@ -1,4 +1,4 @@
1
- import DataBase from "./database.js";
1
+ import Valthera from "./valthera.js";
2
2
  /**
3
3
  * A class representing a graph database.
4
4
  * @class
@@ -6,7 +6,7 @@ import DataBase from "./database.js";
6
6
  class Graph {
7
7
  db;
8
8
  constructor(databaseFolder) {
9
- this.db = new DataBase(databaseFolder);
9
+ this.db = new Valthera(databaseFolder);
10
10
  }
11
11
  /**
12
12
  * Adds an edge between two nodes.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,17 @@
1
- import DataBase from "./database.js";
1
+ import Valthera from "./valthera.js";
2
2
  import Graph from "./graph.js";
3
- import DataBaseRemote from "./client/database.js";
3
+ import ValtheraRemote from "./client/valthera.js";
4
4
  import GraphRemote from "./client/graph.js";
5
5
  import genId from "./gen.js";
6
6
  import Relation from "./relation.js";
7
7
  import CustomFileCpu from "./file/customFileCpu.js";
8
8
  import ValtheraMemory, { createMemoryValthera } from "./memory.js";
9
- import { autoCreate } from "./autoCreate.js";
10
- export { DataBase as Valthera, Graph, DataBaseRemote as ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, createMemoryValthera, autoCreate, };
9
+ import { ValtheraAutoCreate } from "./autoCreate.js";
10
+ import { RelationTypes } from "./types/relation.js";
11
+ import { ValtheraCompatible } from "./types/valthera.js";
12
+ export { Valthera, Graph, ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, createMemoryValthera, ValtheraAutoCreate, };
13
+ type GraphCompatible = Graph | GraphRemote;
14
+ export type { ValtheraCompatible, RelationTypes, GraphCompatible, };
11
15
  export type Id = import("./types/Id.js").Id;
12
16
  export declare namespace ValtheraTypes {
13
17
  type Arg = import("./types/arg.js").Arg;
@@ -19,5 +23,3 @@ export declare namespace ValtheraTypes {
19
23
  type Data = import("./types/data.js").Data;
20
24
  type SearchOptions = import("./types/searchOpts.js").SearchOptions;
21
25
  }
22
- import type { RelationTypes } from "./types/relation.js";
23
- export type { RelationTypes };
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import DataBase from "./database.js";
1
+ import Valthera from "./valthera.js";
2
2
  import Graph from "./graph.js";
3
- import DataBaseRemote from "./client/database.js";
3
+ import ValtheraRemote from "./client/valthera.js";
4
4
  import GraphRemote from "./client/graph.js";
5
5
  import genId from "./gen.js";
6
6
  import Relation from "./relation.js";
7
7
  import CustomFileCpu from "./file/customFileCpu.js";
8
8
  import ValtheraMemory, { createMemoryValthera } from "./memory.js";
9
- import { autoCreate } from "./autoCreate.js";
10
- export { DataBase as Valthera, Graph, DataBaseRemote as ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, createMemoryValthera, autoCreate, };
9
+ import { ValtheraAutoCreate } from "./autoCreate.js";
10
+ export { Valthera, Graph, ValtheraRemote, GraphRemote, Relation, genId, CustomFileCpu, ValtheraMemory, createMemoryValthera, ValtheraAutoCreate, };
package/dist/memory.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import dbActionC from "./action.js";
2
- import DataBase from "./database.js";
2
+ import Valthera from "./valthera.js";
3
3
  import { Arg, Search, Updater } from "./types/arg.js";
4
4
  import Data from "./types/data.js";
5
5
  import FileCpu from "./types/fileCpu.js";
@@ -76,7 +76,7 @@ export declare class MemoryAction implements dbActionC {
76
76
  */
77
77
  transaction(collection: string, transactions: Transaction[]): Promise<void>;
78
78
  }
79
- export default class ValtheraMemory extends DataBase {
79
+ export default class ValtheraMemory extends Valthera {
80
80
  constructor(...args: any[]);
81
81
  }
82
82
  export declare function createMemoryValthera<T = {
package/dist/memory.js CHANGED
@@ -1,4 +1,4 @@
1
- import DataBase from "./database.js";
1
+ import Valthera from "./valthera.js";
2
2
  import CustomFileCpu from "./file/customFileCpu.js";
3
3
  import genId from "./gen.js";
4
4
  export class MemoryAction {
@@ -128,7 +128,7 @@ export class MemoryAction {
128
128
  throw new Error("Method not supported in memory.");
129
129
  }
130
130
  }
131
- export default class ValtheraMemory extends DataBase {
131
+ export default class ValtheraMemory extends Valthera {
132
132
  constructor(...args) {
133
133
  super("", { dbAction: new MemoryAction() });
134
134
  }
@@ -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?: RelationTypes.FieldPath[]): Promise<any>;
8
- find(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select?: RelationTypes.FieldPath[], findOpts?: DbFindOpts): Promise<any[]>;
7
+ findOne(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select?: string[][] | Record<string, any>): Promise<any>;
8
+ find(path: RelationTypes.Path, search: Search, relations: RelationTypes.Relation, select?: string[][] | Record<string, any>, findOpts?: DbFindOpts): Promise<any[]>;
9
9
  }
10
10
  export default Relation;
package/dist/relation.js CHANGED
@@ -1,85 +1,118 @@
1
- async function processRelations(dbs, cfg, data) {
2
- if (!data)
1
+ function pickByPath(obj, paths) {
2
+ const result = {};
3
+ for (const path of paths) {
4
+ let src = obj;
5
+ let dst = result;
6
+ for (let i = 0; i < path.length; i++) {
7
+ const k = path[i];
8
+ if (src == null)
9
+ break;
10
+ if (i === path.length - 1) {
11
+ dst[k] = src[k];
12
+ }
13
+ else {
14
+ dst[k] ||= {};
15
+ dst = dst[k];
16
+ src = src[k];
17
+ }
18
+ }
19
+ }
20
+ return result;
21
+ }
22
+ function convertSearchObjToSearchArray(obj, parentKeys = []) {
23
+ return Object.entries(obj).reduce((acc, [key, value]) => {
24
+ const currentPath = [...parentKeys, key];
25
+ if (!value) {
26
+ return acc;
27
+ }
28
+ else if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
29
+ return [...acc, ...convertSearchObjToSearchArray(value, currentPath)];
30
+ }
31
+ else {
32
+ return [...acc, currentPath];
33
+ }
34
+ }, []);
35
+ }
36
+ async function processRelations(dbs, cfg, data, parentList = null) {
37
+ if (!data && !parentList)
3
38
  return;
4
- for (const [key, relation] of Object.entries(cfg)) {
5
- const { pk = "_id", fk = "_id", type = "1" } = relation;
39
+ const batchMode = Array.isArray(parentList);
40
+ const targets = batchMode ? parentList : [data];
41
+ for (const [key, rel] of Object.entries(cfg)) {
42
+ const { pk = "_id", fk = "_id", type = "1", path, as = key, select, findOpts, through } = rel;
43
+ const [dbKey, coll] = path;
44
+ const db = dbs[dbKey];
6
45
  if (type === "1") {
7
- const db = dbs[relation.path[0]];
8
- const collection = relation.path[1];
9
- const item = await db.findOne(collection, { [fk]: data[pk] }, {}, { select: relation.select || null });
10
- const field = relation.as || key;
11
- if (!item) {
12
- data[field] = null;
13
- continue;
14
- }
15
- if (relation.relations) {
16
- await processRelations(dbs, relation.relations, item);
46
+ for (const item of targets) {
47
+ const result = await db.findOne(coll, { [fk]: item[pk] }, { projection: select });
48
+ if (result && rel.relations) {
49
+ await processRelations(dbs, rel.relations, result);
50
+ }
51
+ item[as] = result || null;
17
52
  }
18
- data[field] = item;
19
53
  }
20
54
  else if (type === "1n") {
21
- const db = dbs[relation.path[0]];
22
- const collection = relation.path[1];
23
- const items = await db.find(collection, { [fk]: data[pk] }, {}, relation.findOpts || {}, { select: relation.select || null });
24
- const field = relation.as || key;
25
- if (relation.relations) {
26
- await Promise.all(items.map(item => processRelations(dbs, relation.relations, item)));
55
+ const ids = targets.map(i => i[pk]);
56
+ const results = await db.find(coll, { [fk]: { $in: ids } }, { ...findOpts, projection: select });
57
+ const grouped = results.reduce((acc, row) => {
58
+ const id = row[fk];
59
+ (acc[id] ||= []).push(row);
60
+ return acc;
61
+ }, {});
62
+ for (const item of targets) {
63
+ item[as] = grouped[item[pk]] || [];
64
+ }
65
+ if (rel.relations) {
66
+ await Promise.all(results.map(row => processRelations(dbs, rel.relations, row)));
27
67
  }
28
- data[field] = items;
29
68
  }
30
69
  else if (type === "nm") {
31
- const db = dbs[relation.path[0]];
32
- const collection = relation.path[1];
33
- const items = await db.find(collection, {}, {}, {}, { select: relation.select || null });
34
- const field = relation.as || key;
35
- if (relation.relations) {
36
- await Promise.all(items.map(item => processRelations(dbs, relation.relations, item)));
70
+ if (!through || !through.table || !through.pk || !through.fk) {
71
+ throw new Error(`Relation type "nm" requires a defined 'through' in '${key}'`);
72
+ }
73
+ for (const item of targets) {
74
+ const pivotDb = dbs[through.db || dbKey];
75
+ const pivots = await pivotDb.find(through.table, { [through.pk]: item[pk] });
76
+ const ids = pivots.map(p => p[through.fk]);
77
+ const related = await db.find(coll, { [fk]: { $in: ids } }, { projection: select });
78
+ item[as] = related;
79
+ if (rel.relations) {
80
+ await Promise.all(related.map(row => processRelations(dbs, rel.relations, row)));
81
+ }
37
82
  }
38
- data[field] = items;
39
83
  }
40
84
  else {
41
- throw new Error(`Unknown relation type: ${relation.type}`);
85
+ throw new Error(`Unknown relation type: ${type}`);
42
86
  }
43
87
  }
44
88
  }
45
- function selectDataSelf(data, select) {
46
- if (!data)
47
- return null;
48
- if (!select || select.length === 0)
49
- return data;
50
- if (Array.isArray(data))
51
- return data.map(item => selectDataSelf(item, select));
52
- return selectDataSelf(data[select[0]], select.slice(1));
53
- }
54
- function selectData(data, select) {
55
- if (!select)
56
- return data;
57
- if (!data && select.length === 0)
58
- return null;
59
- const newData = {};
60
- for (const field of select) {
61
- const key = field.map(f => f.replaceAll(".", "\\.")).join(".");
62
- newData[key] = selectDataSelf(data, field);
63
- }
64
- return newData;
65
- }
66
89
  class Relation {
67
90
  dbs;
68
91
  constructor(dbs) {
69
92
  this.dbs = dbs;
70
93
  }
71
94
  async findOne(path, search, relations, select) {
72
- const db = this.dbs[path[0]];
73
- const data = await db.findOne(path[1], search);
95
+ const [dbKey, coll] = path;
96
+ const db = this.dbs[dbKey];
97
+ const data = await db.findOne(coll, search);
98
+ if (!data)
99
+ return null;
100
+ if (typeof select === "object") {
101
+ select = convertSearchObjToSearchArray(select);
102
+ }
74
103
  await processRelations(this.dbs, relations, data);
75
- const result = selectData(data, select);
76
- return Object.keys(result).length === 0 ? null : result;
104
+ return select ? pickByPath(data, select) : data;
77
105
  }
78
106
  async find(path, search, relations, select, findOpts = {}) {
79
- const db = this.dbs[path[0]];
80
- const data = await db.find(path[1], search, {}, findOpts);
81
- await Promise.all(data.map(item => processRelations(this.dbs, relations, item)));
82
- return data.map(item => selectData(item, select));
107
+ const [dbKey, coll] = path;
108
+ const db = this.dbs[dbKey];
109
+ const data = await db.find(coll, search, findOpts);
110
+ if (relations)
111
+ await processRelations(this.dbs, relations, null, data);
112
+ if (typeof select === "object") {
113
+ select = convertSearchObjToSearchArray(select);
114
+ }
115
+ return select ? data.map(d => pickByPath(d, select)) : data;
83
116
  }
84
117
  }
85
118
  export default Relation;
@@ -1,11 +1,10 @@
1
- import DataBaseRemote from "../client/database.js";
2
- import DataBase from "../database.js";
3
1
  import { DbFindOpts } from "./options.js";
2
+ import { ValtheraCompatible } from "./valthera.js";
4
3
  export declare namespace RelationTypes {
5
4
  type Path = [string, string];
6
5
  type FieldPath = string[];
7
6
  interface DBS {
8
- [key: string]: DataBase | DataBaseRemote;
7
+ [key: string]: ValtheraCompatible;
9
8
  }
10
9
  interface Relation {
11
10
  [key: string]: RelationConfig;
@@ -19,5 +18,11 @@ export declare namespace RelationTypes {
19
18
  findOpts?: DbFindOpts;
20
19
  type?: "1" | "1n" | "nm";
21
20
  relations?: Relation;
21
+ through?: {
22
+ table: string;
23
+ db?: string;
24
+ pk: string;
25
+ fk: string;
26
+ };
22
27
  }
23
28
  }
@@ -0,0 +1,23 @@
1
+ import CollectionManager from "../CollectionManager.js";
2
+ import { Arg, Search, Updater } from "./arg.js";
3
+ import Data from "./data.js";
4
+ import { DbFindOpts, FindOpts } from "./options.js";
5
+ import { Transaction } from "./transactions.js";
6
+ import { Context } from "./types.js";
7
+ export interface ValtheraCompatible {
8
+ c(collection: string): CollectionManager;
9
+ getCollections(): Promise<string[]>;
10
+ checkCollection(collection: string): Promise<boolean>;
11
+ issetCollection(collection: string): Promise<boolean>;
12
+ add<T = Data>(collection: string, data: Arg, id_gen?: boolean): Promise<T>;
13
+ find<T = Data>(collection: string, search: Search, context?: Context, options?: DbFindOpts, findOpts?: FindOpts): Promise<T[]>;
14
+ findOne<T = Data>(collection: string, search: Search, context?: Context, findOpts?: FindOpts): Promise<T | null>;
15
+ findStream<T = Data>(collection: string, search: Search, context?: Context, findOpts?: FindOpts, limit?: number): Promise<AsyncGenerator<T>>;
16
+ update(collection: string, search: Search, updater: Updater, context?: Context): Promise<boolean>;
17
+ updateOne(collection: string, search: Search, updater: Updater, context?: Context): Promise<boolean>;
18
+ remove(collection: string, search: Search, context?: Context): Promise<boolean>;
19
+ removeOne(collection: string, search: Search, context?: Context): Promise<boolean>;
20
+ removeCollection(collection: string): Promise<boolean>;
21
+ transaction(collection: string, transaction: Transaction[]): Promise<boolean>;
22
+ updateOneOrAdd(collection: string, search: Search, updater: Updater, add_arg?: Arg, context?: Context, id_gen?: boolean): Promise<boolean>;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -8,11 +8,12 @@ import { Context } from "./types/types.js";
8
8
  import FileCpu from "./types/fileCpu.js";
9
9
  import { Transaction } from "./types/transactions.js";
10
10
  import { EventEmitter } from "events";
11
+ import { ValtheraCompatible } from "./types/valthera.js";
11
12
  /**
12
13
  * Represents a database management class for performing CRUD operations.
13
14
  * @class
14
15
  */
15
- declare class DataBase {
16
+ declare class Valthera implements ValtheraCompatible {
16
17
  dbAction: dbActionC;
17
18
  executor: executorC;
18
19
  emiter: EventEmitter;
@@ -79,4 +80,4 @@ declare class DataBase {
79
80
  */
80
81
  transaction(collection: string, transaction: Transaction[]): Promise<boolean>;
81
82
  }
82
- export default DataBase;
83
+ export default Valthera;
@@ -7,7 +7,7 @@ import { EventEmitter } from "events";
7
7
  * Represents a database management class for performing CRUD operations.
8
8
  * @class
9
9
  */
10
- class DataBase {
10
+ class Valthera {
11
11
  dbAction;
12
12
  executor;
13
13
  emiter;
@@ -140,4 +140,4 @@ class DataBase {
140
140
  return await this.execute("transaction", collection, transaction);
141
141
  }
142
142
  }
143
- export default DataBase;
143
+ export default Valthera;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db",
3
- "version": "0.5.7",
3
+ "version": "0.7.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "A simple file-based database management system with support for CRUD operations, custom queries, and graph structures.",