@wxn0brp/db-core 0.1.1 → 0.1.3
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/dist/db/memory.js +1 -1
- package/dist/db/valthera.d.ts +5 -1
- package/dist/db/valthera.js +6 -5
- package/dist/helpers/CollectionManager.d.ts +8 -8
- package/dist/helpers/forge.d.ts +5 -0
- package/dist/{utils → helpers}/forge.js +4 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.js +3 -2
- package/dist/utils/sortId.d.ts +3 -0
- package/dist/utils/sortId.js +7 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/utils/forge.d.ts +0 -3
package/dist/db/memory.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomActionsBase } from "../base/custom.js";
|
|
2
2
|
import CustomFileCpu from "../customFileCpu.js";
|
|
3
|
-
import { forgeValthera } from "../
|
|
3
|
+
import { forgeValthera } from "../helpers/forge.js";
|
|
4
4
|
import ValtheraClass from "./valthera.js";
|
|
5
5
|
export class MemoryAction extends CustomActionsBase {
|
|
6
6
|
memory;
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ import Data from "../types/data.js";
|
|
|
7
7
|
import { DbOpts, DbFindOpts, FindOpts } from "../types/options.js";
|
|
8
8
|
import { VContext } from "../types/types.js";
|
|
9
9
|
import { ValtheraCompatible } from "../types/valthera.js";
|
|
10
|
+
import { VQuery } from "../types/query.js";
|
|
11
|
+
type DbActionsFns = keyof {
|
|
12
|
+
[K in keyof ActionsBase as ActionsBase[K] extends (...args: any[]) => any ? K : never]: any;
|
|
13
|
+
};
|
|
10
14
|
/**
|
|
11
15
|
* Represents a database management class for performing CRUD operations.
|
|
12
16
|
* @class
|
|
@@ -18,7 +22,7 @@ declare class ValtheraClass implements ValtheraCompatible {
|
|
|
18
22
|
version: string;
|
|
19
23
|
constructor(options?: DbOpts);
|
|
20
24
|
init(...args: any[]): Promise<unknown>;
|
|
21
|
-
|
|
25
|
+
execute<T>(name: DbActionsFns, query: VQuery): Promise<T>;
|
|
22
26
|
/**
|
|
23
27
|
* Create a new instance of a CollectionManager class.
|
|
24
28
|
*/
|
package/dist/db/valthera.js
CHANGED
|
@@ -28,11 +28,12 @@ class ValtheraClass {
|
|
|
28
28
|
self.dbAction._inited = true;
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
|
-
async execute(name,
|
|
31
|
+
async execute(name, query) {
|
|
32
32
|
await this.init();
|
|
33
|
-
const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction),
|
|
34
|
-
|
|
35
|
-
this.emiter.emit(
|
|
33
|
+
const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction), query);
|
|
34
|
+
const emitArgs = Array.from(arguments).slice(1);
|
|
35
|
+
this.emiter.emit(name, emitArgs, result);
|
|
36
|
+
this.emiter.emit("*", name, emitArgs, result);
|
|
36
37
|
return result;
|
|
37
38
|
}
|
|
38
39
|
/**
|
|
@@ -45,7 +46,7 @@ class ValtheraClass {
|
|
|
45
46
|
* Get the names of all available databases.
|
|
46
47
|
*/
|
|
47
48
|
async getCollections() {
|
|
48
|
-
return await this.execute("getCollections");
|
|
49
|
+
return await this.execute("getCollections", {});
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Check and create the specified collection if it doesn't exist.
|
|
@@ -10,34 +10,34 @@ declare class CollectionManager<D = Data> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Add data to a database.
|
|
12
12
|
*/
|
|
13
|
-
add<T =
|
|
13
|
+
add<T = Data>(data: Arg<T & D>, id_gen?: boolean): Promise<T>;
|
|
14
14
|
/**
|
|
15
15
|
* Find data in a database.
|
|
16
16
|
*/
|
|
17
|
-
find<T =
|
|
17
|
+
find<T = Data>(search?: Search<T & D>, context?: VContext, options?: DbFindOpts<T & Data>, findOpts?: FindOpts<T & Data>): Promise<T[]>;
|
|
18
18
|
/**
|
|
19
19
|
* Find one data entry in a database.
|
|
20
20
|
*/
|
|
21
|
-
findOne<T =
|
|
21
|
+
findOne<T = Data>(search?: Search<T & Data>, context?: VContext, findOpts?: FindOpts<T & Data>): Promise<T>;
|
|
22
22
|
/**
|
|
23
23
|
* Update data in a database.
|
|
24
24
|
*/
|
|
25
|
-
update<T =
|
|
25
|
+
update<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
|
|
26
26
|
/**
|
|
27
27
|
* Update one data entry in a database.
|
|
28
28
|
*/
|
|
29
|
-
updateOne<T =
|
|
29
|
+
updateOne<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, context?: VContext): Promise<boolean>;
|
|
30
30
|
/**
|
|
31
31
|
* Remove data from a database.
|
|
32
32
|
*/
|
|
33
|
-
remove<T =
|
|
33
|
+
remove<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
|
|
34
34
|
/**
|
|
35
35
|
* Remove one data entry from a database.
|
|
36
36
|
*/
|
|
37
|
-
removeOne<T =
|
|
37
|
+
removeOne<T = Data>(search: Search<T & Data>, context?: VContext): Promise<boolean>;
|
|
38
38
|
/**
|
|
39
39
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
40
40
|
*/
|
|
41
|
-
updateOneOrAdd<T =
|
|
41
|
+
updateOneOrAdd<T = Data>(search: Search<T & Data>, updater: Updater<T & Data>, add_arg?: Arg<T & Data>, context?: VContext, id_gen?: boolean): Promise<boolean>;
|
|
42
42
|
}
|
|
43
43
|
export default CollectionManager;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import CollectionManager from "./CollectionManager.js";
|
|
2
|
+
import Data from "../types/data.js";
|
|
3
|
+
import { ValtheraCompatible } from "../types/valthera.js";
|
|
4
|
+
export declare function forgeValthera<T extends string>(target: ValtheraCompatible): ValtheraCompatible & { [K in T]: CollectionManager; };
|
|
5
|
+
export declare function forgeTypedValthera<T extends Record<string, Data>>(target: ValtheraCompatible): ValtheraCompatible & { [K in keyof T]: CollectionManager<T[K]>; };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import CollectionManager from "
|
|
1
|
+
import CollectionManager from "./CollectionManager.js";
|
|
2
2
|
export function forgeValthera(target) {
|
|
3
3
|
return new Proxy(target, {
|
|
4
4
|
get(target, prop, receiver) {
|
|
@@ -14,4 +14,6 @@ export function forgeValthera(target) {
|
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
export function forgeTypedValthera(target) {
|
|
18
|
+
return forgeValthera(target);
|
|
19
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import Relation from "./helpers/relation.js";
|
|
|
6
6
|
import { ValtheraTypes } from "./types/export.js";
|
|
7
7
|
import { RelationTypes } from "./types/relation.js";
|
|
8
8
|
import { ValtheraCompatible } from "./types/valthera.js";
|
|
9
|
-
import { forgeValthera } from "./
|
|
10
|
-
|
|
11
|
-
export
|
|
9
|
+
import { forgeTypedValthera, forgeValthera } from "./helpers/forge.js";
|
|
10
|
+
import { sortByIds } from "./utils/sortId.js";
|
|
11
|
+
export { createMemoryValthera, CustomFileCpu, forgeTypedValthera, forgeValthera, genId, Relation, ValtheraClass, ValtheraMemory, sortByIds, };
|
|
12
|
+
export type { RelationTypes, ValtheraCompatible, ValtheraTypes, };
|
|
12
13
|
export type Id = import("./types/Id.js").Id;
|
package/dist/index.js
CHANGED
|
@@ -3,5 +3,6 @@ import ValtheraMemory, { createMemoryValthera } from "./db/memory.js";
|
|
|
3
3
|
import ValtheraClass from "./db/valthera.js";
|
|
4
4
|
import genId from "./helpers/gen.js";
|
|
5
5
|
import Relation from "./helpers/relation.js";
|
|
6
|
-
import { forgeValthera } from "./
|
|
7
|
-
|
|
6
|
+
import { forgeTypedValthera, forgeValthera } from "./helpers/forge.js";
|
|
7
|
+
import { sortByIds } from "./utils/sortId.js";
|
|
8
|
+
export { createMemoryValthera, CustomFileCpu, forgeTypedValthera, forgeValthera, genId, Relation, ValtheraClass, ValtheraMemory, sortByIds, };
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.1.
|
|
1
|
+
export const version = "0.1.3";
|
package/package.json
CHANGED
package/dist/utils/forge.d.ts
DELETED