@wxn0brp/db-core 0.4.0 → 0.5.0-alpha.1
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/base/actions.d.ts +6 -7
- package/dist/base/actions.js +5 -6
- package/dist/base/custom.d.ts +7 -7
- package/dist/base/custom.js +5 -3
- package/dist/customFileCpu.d.ts +7 -8
- package/dist/customFileCpu.js +18 -20
- package/dist/db/memory.d.ts +5 -5
- package/dist/db/memory.js +3 -3
- package/dist/db/multiStorage.d.ts +5 -5
- package/dist/db/multiStorage.js +9 -11
- package/dist/db/routedStorage.d.ts +5 -5
- package/dist/db/routedStorage.js +1 -1
- package/dist/db/valthera.d.ts +19 -24
- package/dist/db/valthera.js +52 -27
- package/dist/helpers/addId.d.ts +1 -1
- package/dist/helpers/addId.js +1 -1
- package/dist/helpers/{collectionManager.d.ts → collection.d.ts} +14 -11
- package/dist/helpers/collection.js +59 -0
- package/dist/helpers/executor.d.ts +2 -4
- package/dist/helpers/executor.js +1 -3
- package/dist/helpers/forge.d.ts +15 -4
- package/dist/helpers/forge.js +2 -2
- package/dist/helpers/gen.d.ts +17 -1
- package/dist/helpers/gen.js +36 -30
- package/dist/helpers/relation.d.ts +5 -2
- package/dist/helpers/relation.js +44 -33
- package/dist/index.d.ts +11 -13
- package/dist/index.js +7 -8
- package/dist/types/data.d.ts +0 -1
- package/dist/types/fileCpu.d.ts +6 -7
- package/dist/types/options.d.ts +3 -3
- package/dist/types/query.d.ts +12 -0
- package/dist/types/relation.d.ts +1 -1
- package/dist/types/valthera.d.ts +22 -14
- package/dist/utils/action.d.ts +2 -2
- package/dist/utils/hasFields.d.ts +1 -1
- package/dist/utils/hasFields.js +1 -1
- package/dist/utils/hasFieldsAdvanced.d.ts +1 -1
- package/dist/utils/hasFieldsAdvanced.js +2 -2
- package/dist/utils/updateFindObject.d.ts +1 -1
- package/dist/utils/updateFindObject.js +1 -1
- package/dist/utils/updateObject.d.ts +1 -1
- package/dist/utils/updateObject.js +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/dist/helpers/collectionManager.js +0 -62
package/dist/types/query.d.ts
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { VContext } from "./types.js";
|
|
2
2
|
import { Arg, Search, Updater } from "./arg.js";
|
|
3
3
|
import { DbFindOpts, FindOpts } from "./options.js";
|
|
4
|
+
/**
|
|
5
|
+
* To extend via adapters
|
|
6
|
+
* @example
|
|
7
|
+
* declare module "@wxn0brp/db-core" {
|
|
8
|
+
* export interface VQuery_Control {
|
|
9
|
+
* key?: "value";
|
|
10
|
+
* }
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
export interface VQuery_Control {
|
|
14
|
+
}
|
|
4
15
|
export interface VQuery {
|
|
5
16
|
collection?: string;
|
|
6
17
|
search?: Search;
|
|
@@ -11,4 +22,5 @@ export interface VQuery {
|
|
|
11
22
|
id_gen?: boolean;
|
|
12
23
|
add_arg?: Arg;
|
|
13
24
|
updater?: Updater;
|
|
25
|
+
control?: VQuery_Control;
|
|
14
26
|
}
|
package/dist/types/relation.d.ts
CHANGED
package/dist/types/valthera.d.ts
CHANGED
|
@@ -1,23 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Arg
|
|
3
|
-
import Data from "./data.js";
|
|
4
|
-
import {
|
|
1
|
+
import { Collection } from "../helpers/collection.js";
|
|
2
|
+
import { Arg } from "./arg.js";
|
|
3
|
+
import { Data } from "./data.js";
|
|
4
|
+
import { VQuery } from "./query.js";
|
|
5
5
|
import { VContext } from "./types.js";
|
|
6
|
+
export type QueryBase = Required<Pick<VQuery, "collection" | "search">> & Pick<VQuery, "control">;
|
|
7
|
+
export type AddQuery = Required<Pick<VQuery, "data" | "collection">> & Pick<VQuery, "id_gen" | "control">;
|
|
8
|
+
export type FindQuery = QueryBase & Pick<VQuery, "findOpts" | "dbFindOpts" | "context">;
|
|
9
|
+
export type FindOneQuery = QueryBase & Pick<VQuery, "findOpts" | "context">;
|
|
10
|
+
export type UpdateQuery = QueryBase & Required<Pick<VQuery, "updater">> & Pick<VQuery, "context">;
|
|
11
|
+
export type RemoveQuery = QueryBase & Pick<VQuery, "context">;
|
|
12
|
+
export type UpdateOneOrAddQuery = QueryBase & UpdateQuery & Pick<VQuery, "add_arg" | "id_gen">;
|
|
13
|
+
export type ToggleOneQuery = QueryBase & Pick<VQuery, "data" | "context">;
|
|
6
14
|
export interface ValtheraCompatible {
|
|
7
|
-
c(collection: string):
|
|
15
|
+
c(collection: string): Collection;
|
|
8
16
|
getCollections(): Promise<string[]>;
|
|
9
17
|
ensureCollection(collection: string): Promise<boolean>;
|
|
10
18
|
issetCollection(collection: string): Promise<boolean>;
|
|
11
|
-
add<T = Data>(
|
|
12
|
-
find<T = Data>(
|
|
13
|
-
findOne<T = Data>(
|
|
14
|
-
update<T = Data>(
|
|
15
|
-
updateOne<T = Data>(
|
|
16
|
-
remove<T = Data>(
|
|
17
|
-
removeOne<T = Data>(
|
|
19
|
+
add<T = Data>(query: AddQuery): Promise<T>;
|
|
20
|
+
find<T = Data>(query: FindQuery): Promise<T[]>;
|
|
21
|
+
findOne<T = Data>(query: FindOneQuery): Promise<T | null>;
|
|
22
|
+
update<T = Data>(query: UpdateQuery): Promise<T[] | null>;
|
|
23
|
+
updateOne<T = Data>(query: UpdateQuery): Promise<T | null>;
|
|
24
|
+
remove<T = Data>(query: RemoveQuery): Promise<T[] | null>;
|
|
25
|
+
removeOne<T = Data>(query: RemoveQuery): Promise<T | null>;
|
|
18
26
|
removeCollection(collection: string): Promise<boolean>;
|
|
19
|
-
updateOneOrAdd<T = Data>(
|
|
20
|
-
toggleOne<T = Data>(
|
|
27
|
+
updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery): Promise<T>;
|
|
28
|
+
toggleOne<T = Data>(query: ToggleOneQuery): Promise<T | null>;
|
|
21
29
|
}
|
|
22
30
|
export interface UpdateOneOrAdd<T> {
|
|
23
31
|
add_arg?: Arg<T>;
|
package/dist/utils/action.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Data from "../types/data.js";
|
|
2
|
-
import FileCpu from "../types/fileCpu.js";
|
|
1
|
+
import { Data } from "../types/data.js";
|
|
2
|
+
import { FileCpu } from "../types/fileCpu.js";
|
|
3
3
|
import { VQuery } from "../types/query.js";
|
|
4
4
|
export declare function findUtil(query: VQuery, fileCpu: FileCpu, files: string[]): Promise<Data[]>;
|
package/dist/utils/hasFields.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @param fields - Criteria to compare.
|
|
5
5
|
* @returns Whether the object matches the criteria.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function hasFields(obj, fields) {
|
|
8
8
|
const keys = Object.keys(fields);
|
|
9
9
|
return keys.every(key => {
|
|
10
10
|
if (obj[key] !== undefined) {
|
|
@@ -2,4 +2,4 @@ import { Arg } from "../types/arg.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Checks if an object meets the criteria specified in the fields with operators.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export declare function hasFieldsAdvanced(obj: Object, fields: Arg): any;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import hasFields from "./hasFields.js";
|
|
1
|
+
import { hasFields } from "./hasFields.js";
|
|
2
2
|
import { compareIds } from "./id.js";
|
|
3
3
|
/**
|
|
4
4
|
* Checks if an object meets the criteria specified in the fields with operators.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export function hasFieldsAdvanced(obj, fields) {
|
|
7
7
|
if (typeof fields !== "object" || fields === null) {
|
|
8
8
|
throw new Error("Fields must be an object");
|
|
9
9
|
}
|
|
@@ -8,4 +8,4 @@ import { FindOpts } from "../types/options.js";
|
|
|
8
8
|
* @param [findOpts.exclude] - An array of fields to exclude from the target object.
|
|
9
9
|
* @returns The updated object.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export declare function updateFindObject(obj: Object, findOpts: FindOpts): Object;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @param [findOpts.exclude] - An array of fields to exclude from the target object.
|
|
8
8
|
* @returns The updated object.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export function updateFindObject(obj, findOpts) {
|
|
11
11
|
const { transform, select, exclude, } = findOpts;
|
|
12
12
|
if (typeof transform === "function")
|
|
13
13
|
obj = transform(obj);
|
|
@@ -4,4 +4,4 @@ import { UpdaterArg } from "../types/updater.js";
|
|
|
4
4
|
* @param obj - The object to update.
|
|
5
5
|
* @param field - An object containing new values to update in the target object.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export declare function updateObjectAdvanced(obj: Record<string, any>, field: UpdaterArg): Record<string, any>;
|
|
@@ -4,7 +4,7 @@ import { _deepMerge } from "./merge.js";
|
|
|
4
4
|
* @param obj - The object to update.
|
|
5
5
|
* @param field - An object containing new values to update in the target object.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export function updateObjectAdvanced(obj, field) {
|
|
8
8
|
if (typeof field !== "object" || field === null) {
|
|
9
9
|
throw new Error("Fields must be an object or object array");
|
|
10
10
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.5.0-alpha.1";
|
package/package.json
CHANGED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export class CollectionManager {
|
|
2
|
-
db;
|
|
3
|
-
collection;
|
|
4
|
-
constructor(db, collection) {
|
|
5
|
-
this.db = db;
|
|
6
|
-
this.collection = collection;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Add data to a database.
|
|
10
|
-
*/
|
|
11
|
-
async add(data, id_gen = true) {
|
|
12
|
-
return await this.db.add(this.collection, data, id_gen);
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Find data in a database.
|
|
16
|
-
*/
|
|
17
|
-
async find(search = {}, options = {}, findOpts = {}, context = {}) {
|
|
18
|
-
return await this.db.find(this.collection, search, options, findOpts, context);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Find one data entry in a database.
|
|
22
|
-
*/
|
|
23
|
-
async findOne(search = {}, findOpts = {}, context = {}) {
|
|
24
|
-
return await this.db.findOne(this.collection, search, findOpts, context);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Update data in a database.
|
|
28
|
-
*/
|
|
29
|
-
async update(search, updater, context = {}) {
|
|
30
|
-
return await this.db.update(this.collection, search, updater, context);
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Update one data entry in a database.
|
|
34
|
-
*/
|
|
35
|
-
async updateOne(search, updater, context = {}) {
|
|
36
|
-
return await this.db.updateOne(this.collection, search, updater, context);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Remove data from a database.
|
|
40
|
-
*/
|
|
41
|
-
async remove(search, context = {}) {
|
|
42
|
-
return await this.db.remove(this.collection, search, context);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Remove one data entry from a database.
|
|
46
|
-
*/
|
|
47
|
-
async removeOne(search, context = {}) {
|
|
48
|
-
return await this.db.removeOne(this.collection, search, context);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
52
|
-
*/
|
|
53
|
-
async updateOneOrAdd(search, updater, { add_arg = {}, context = {}, id_gen = true } = {}) {
|
|
54
|
-
return await this.db.updateOneOrAdd(this.collection, search, updater, { add_arg, context, id_gen });
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
58
|
-
*/
|
|
59
|
-
async toggleOne(search, data = {}, context = {}) {
|
|
60
|
-
return await this.db.toggleOne(this.collection, search, data, context);
|
|
61
|
-
}
|
|
62
|
-
}
|