@wxn0brp/db 0.5.6 → 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 +45 -5
- package/dist/CollectionManager.d.ts +4 -5
- package/dist/autoCreate.d.ts +12 -0
- package/dist/autoCreate.js +18 -0
- package/dist/client/{database.d.ts → valthera.d.ts} +4 -3
- package/dist/client/{database.js → valthera.js} +4 -3
- package/dist/graph.d.ts +2 -2
- package/dist/graph.js +2 -2
- package/dist/index.d.ts +8 -5
- package/dist/index.js +4 -3
- package/dist/memory.d.ts +2 -2
- package/dist/memory.js +2 -2
- package/dist/types/relation.d.ts +2 -3
- package/dist/types/valthera.d.ts +23 -0
- package/dist/types/valthera.js +1 -0
- package/dist/{database.d.ts → valthera.d.ts} +3 -2
- package/dist/{database.js → valthera.js} +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
# <img src="./logo.svg" alt="ValtheraDB Logo"
|
|
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
|
+
[](https://www.npmjs.com/package/@wxn0brp/db)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
[](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 {
|
|
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
|
-
- [
|
|
59
|
+
- [Valthera Documentation](./docs/valthera.md)
|
|
28
60
|
- [Graph Documentation](./docs/graph.md)
|
|
29
|
-
- [Remote
|
|
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
|
|
9
|
-
collection
|
|
10
|
-
constructor(db:
|
|
7
|
+
private db;
|
|
8
|
+
private collection;
|
|
9
|
+
constructor(db: ValtheraCompatible, collection: string);
|
|
11
10
|
/**
|
|
12
11
|
* Add data to a database.
|
|
13
12
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Remote } from "./client/remote.js";
|
|
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;
|
|
@@ -0,0 +1,18 @@
|
|
|
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) {
|
|
13
|
+
if (typeof cfg === "object")
|
|
14
|
+
return new ValtheraRemote(cfg);
|
|
15
|
+
if (cfg.startsWith("http"))
|
|
16
|
+
return new ValtheraRemote(cfg);
|
|
17
|
+
return new Valthera(cfg);
|
|
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
|
|
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,
|
|
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
|
|
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
|
|
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 = {},
|
|
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
|
|
146
|
+
export default ValtheraRemote;
|
package/dist/graph.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
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:
|
|
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
|
|
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
|
|
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,12 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Valthera from "./valthera.js";
|
|
2
2
|
import Graph from "./graph.js";
|
|
3
|
-
import
|
|
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
|
-
|
|
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, };
|
|
10
15
|
export type Id = import("./types/Id.js").Id;
|
|
11
16
|
export declare namespace ValtheraTypes {
|
|
12
17
|
type Arg = import("./types/arg.js").Arg;
|
|
@@ -18,5 +23,3 @@ export declare namespace ValtheraTypes {
|
|
|
18
23
|
type Data = import("./types/data.js").Data;
|
|
19
24
|
type SearchOptions = import("./types/searchOpts.js").SearchOptions;
|
|
20
25
|
}
|
|
21
|
-
import type { RelationTypes } from "./types/relation.js";
|
|
22
|
-
export type { RelationTypes };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Valthera from "./valthera.js";
|
|
2
2
|
import Graph from "./graph.js";
|
|
3
|
-
import
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
131
|
+
export default class ValtheraMemory extends Valthera {
|
|
132
132
|
constructor(...args) {
|
|
133
133
|
super("", { dbAction: new MemoryAction() });
|
|
134
134
|
}
|
package/dist/types/relation.d.ts
CHANGED
|
@@ -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]:
|
|
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
|
|
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
|
|
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
|
|
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
|
|
143
|
+
export default Valthera;
|
package/package.json
CHANGED