@wxn0brp/db 0.5.7 → 0.6.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
  }
@@ -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;
@@ -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.6.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.",