@wxn0brp/db-core 0.5.0 → 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/dist/base/actions.d.ts +16 -15
- package/dist/base/actions.js +12 -50
- package/dist/base/custom.d.ts +1 -1
- package/dist/customFileCpu.js +6 -2
- package/dist/db/multiStorage.d.ts +7 -7
- package/dist/db/routedStorage.d.ts +7 -7
- package/dist/db/valthera.d.ts +1 -1
- package/dist/db/valthera.js +2 -3
- package/dist/helpers/addId.js +1 -1
- package/dist/types/action.d.ts +20 -0
- package/dist/types/action.js +1 -0
- package/dist/types/data.d.ts +1 -0
- package/dist/types/fileCpu.d.ts +5 -5
- package/dist/types/options.d.ts +1 -2
- package/dist/types/query.d.ts +6 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/base/actions.d.ts
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ActionsBaseInterface } from "../types/action.js";
|
|
2
|
+
import { DataInternal } from "../types/data.js";
|
|
2
3
|
import { VQuery } from "../types/query.js";
|
|
3
|
-
export declare class ActionsBase {
|
|
4
|
+
export declare abstract class ActionsBase implements ActionsBaseInterface {
|
|
4
5
|
_inited: boolean;
|
|
5
6
|
numberId: boolean;
|
|
6
7
|
init(...args: any[]): Promise<void>;
|
|
7
|
-
getCollections(): Promise<string[]>;
|
|
8
|
-
ensureCollection(config: VQuery): Promise<boolean>;
|
|
9
|
-
issetCollection(config: VQuery): Promise<boolean>;
|
|
10
|
-
add(config: VQuery): Promise<
|
|
11
|
-
find(config: VQuery): Promise<
|
|
12
|
-
findOne(config: VQuery): Promise<
|
|
13
|
-
update(config: VQuery): Promise<
|
|
14
|
-
updateOne(config: VQuery): Promise<
|
|
15
|
-
remove(config: VQuery): Promise<
|
|
16
|
-
removeOne(config: VQuery): Promise<
|
|
17
|
-
removeCollection(config: VQuery): Promise<boolean>;
|
|
18
|
-
updateOneOrAdd(config: VQuery): Promise<
|
|
19
|
-
toggleOne(config: VQuery): Promise<
|
|
8
|
+
abstract getCollections(): Promise<string[]>;
|
|
9
|
+
abstract ensureCollection(config: VQuery): Promise<boolean>;
|
|
10
|
+
abstract issetCollection(config: VQuery): Promise<boolean>;
|
|
11
|
+
abstract add(config: VQuery): Promise<DataInternal>;
|
|
12
|
+
abstract find(config: VQuery): Promise<DataInternal[]>;
|
|
13
|
+
abstract findOne(config: VQuery): Promise<DataInternal | null>;
|
|
14
|
+
abstract update(config: VQuery): Promise<DataInternal[] | null>;
|
|
15
|
+
abstract updateOne(config: VQuery): Promise<DataInternal | null>;
|
|
16
|
+
abstract remove(config: VQuery): Promise<DataInternal[] | null>;
|
|
17
|
+
abstract removeOne(config: VQuery): Promise<DataInternal | null>;
|
|
18
|
+
abstract removeCollection(config: VQuery): Promise<boolean>;
|
|
19
|
+
updateOneOrAdd(config: VQuery): Promise<DataInternal>;
|
|
20
|
+
toggleOne(config: VQuery): Promise<DataInternal | null>;
|
|
20
21
|
}
|
package/dist/base/actions.js
CHANGED
|
@@ -3,64 +3,26 @@ export class ActionsBase {
|
|
|
3
3
|
_inited = true;
|
|
4
4
|
numberId = false;
|
|
5
5
|
async init(...args) { }
|
|
6
|
-
async getCollections() {
|
|
7
|
-
throw new Error("Not implemented");
|
|
8
|
-
return [];
|
|
9
|
-
}
|
|
10
|
-
async ensureCollection(config) {
|
|
11
|
-
throw new Error("Not implemented");
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
async issetCollection(config) {
|
|
15
|
-
throw new Error("Not implemented");
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
async add(config) {
|
|
19
|
-
throw new Error("Not implemented");
|
|
20
|
-
return {};
|
|
21
|
-
}
|
|
22
|
-
async find(config) {
|
|
23
|
-
throw new Error("Not implemented");
|
|
24
|
-
return [];
|
|
25
|
-
}
|
|
26
|
-
async findOne(config) {
|
|
27
|
-
throw new Error("Not implemented");
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
async update(config) {
|
|
31
|
-
throw new Error("Not implemented");
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
async updateOne(config) {
|
|
35
|
-
throw new Error("Not implemented");
|
|
36
|
-
return {};
|
|
37
|
-
}
|
|
38
|
-
async remove(config) {
|
|
39
|
-
throw new Error("Not implemented");
|
|
40
|
-
return [];
|
|
41
|
-
}
|
|
42
|
-
async removeOne(config) {
|
|
43
|
-
throw new Error("Not implemented");
|
|
44
|
-
return {};
|
|
45
|
-
}
|
|
46
|
-
async removeCollection(config) {
|
|
47
|
-
throw new Error("Not implemented");
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
6
|
async updateOneOrAdd(config) {
|
|
51
7
|
const res = await this.updateOne(config);
|
|
8
|
+
const controlData = { updated: true };
|
|
9
|
+
config.control ||= {};
|
|
10
|
+
config.control.updateOneOrAdd = controlData;
|
|
52
11
|
if (res)
|
|
53
|
-
return
|
|
12
|
+
return res;
|
|
54
13
|
setDataForUpdateOneOrAdd(config);
|
|
55
|
-
|
|
56
|
-
return
|
|
14
|
+
config.control.updateOneOrAdd.updated = false;
|
|
15
|
+
return await this.add(config);
|
|
57
16
|
}
|
|
58
17
|
async toggleOne(config) {
|
|
59
18
|
const res = await this.removeOne(config);
|
|
19
|
+
const controlData = { created: false };
|
|
20
|
+
config.control ||= {};
|
|
21
|
+
config.control.toggleOne = controlData;
|
|
60
22
|
if (res)
|
|
61
|
-
return
|
|
23
|
+
return res;
|
|
62
24
|
setDataForToggleOne(config);
|
|
63
|
-
|
|
64
|
-
return
|
|
25
|
+
config.control.toggleOne.created = true;
|
|
26
|
+
return await this.add(config);
|
|
65
27
|
}
|
|
66
28
|
}
|
package/dist/base/custom.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { CustomFileCpu } from "../customFileCpu.js";
|
|
|
2
2
|
import { Data } from "../types/data.js";
|
|
3
3
|
import { VQuery } from "../types/query.js";
|
|
4
4
|
import { ActionsBase } from "./actions.js";
|
|
5
|
-
export declare class CustomActionsBase extends ActionsBase {
|
|
5
|
+
export declare abstract class CustomActionsBase extends ActionsBase {
|
|
6
6
|
fileCpu: CustomFileCpu;
|
|
7
7
|
constructor();
|
|
8
8
|
/**
|
package/dist/customFileCpu.js
CHANGED
|
@@ -21,13 +21,17 @@ export class CustomFileCpu {
|
|
|
21
21
|
file = pathRepair(file);
|
|
22
22
|
const entries = await this._readFile(file);
|
|
23
23
|
const results = entries.filter(entry => typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search));
|
|
24
|
-
return results.length ?
|
|
24
|
+
return results.length ?
|
|
25
|
+
results.map(res => updateFindObject(res, findOpts)) :
|
|
26
|
+
[];
|
|
25
27
|
}
|
|
26
28
|
async findOne(file, search, context = {}, findOpts = {}) {
|
|
27
29
|
file = pathRepair(file);
|
|
28
30
|
const entries = await this._readFile(file);
|
|
29
31
|
const result = entries.find(entry => typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search));
|
|
30
|
-
return result ?
|
|
32
|
+
return result ?
|
|
33
|
+
updateFindObject(result, findOpts) :
|
|
34
|
+
false;
|
|
31
35
|
}
|
|
32
36
|
async remove(file, one, search, context = {}) {
|
|
33
37
|
file = pathRepair(file);
|
|
@@ -5,13 +5,13 @@ export declare class MultiBackend extends ActionsBase {
|
|
|
5
5
|
primaryBackend: ActionsBase;
|
|
6
6
|
constructor(backends: ActionsBase[], primaryIndex?: number);
|
|
7
7
|
init(...args: any[]): Promise<void>;
|
|
8
|
-
add(config: VQuery): Promise<import("../types/data.js").
|
|
9
|
-
find(config: VQuery): Promise<import("../types/data.js").
|
|
10
|
-
findOne(config: VQuery): Promise<import("../types/data.js").
|
|
11
|
-
update(config: VQuery): Promise<import("../types/data.js").
|
|
12
|
-
updateOne(config: VQuery): Promise<import("../types/data.js").
|
|
13
|
-
remove(config: VQuery): Promise<import("../types/data.js").
|
|
14
|
-
removeOne(config: VQuery): Promise<import("../types/data.js").
|
|
8
|
+
add(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
9
|
+
find(config: VQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
10
|
+
findOne(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
11
|
+
update(config: VQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
12
|
+
updateOne(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
13
|
+
remove(config: VQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
14
|
+
removeOne(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
15
15
|
ensureCollection(config: VQuery): Promise<boolean>;
|
|
16
16
|
issetCollection(config: VQuery): Promise<boolean>;
|
|
17
17
|
removeCollection(config: VQuery): Promise<boolean>;
|
|
@@ -13,13 +13,13 @@ export declare class RoutedStorage extends ActionsBase {
|
|
|
13
13
|
_withAll<T>(config: VQuery, fn: (b: ActionsBase) => Promise<T>, gather?: boolean): Promise<T>;
|
|
14
14
|
_withFirst<T>(config: VQuery, fn: (b: ActionsBase) => Promise<T>): Promise<T>;
|
|
15
15
|
init(...args: any[]): Promise<void>;
|
|
16
|
-
add(config: VQuery): Promise<import("../types/data.js").
|
|
17
|
-
find(config: VQuery): Promise<import("../types/data.js").
|
|
18
|
-
findOne(config: VQuery): Promise<import("../types/data.js").
|
|
19
|
-
update(config: VQuery): Promise<import("../types/data.js").
|
|
20
|
-
updateOne(config: VQuery): Promise<import("../types/data.js").
|
|
21
|
-
remove(config: VQuery): Promise<import("../types/data.js").
|
|
22
|
-
removeOne(config: VQuery): Promise<import("../types/data.js").
|
|
16
|
+
add(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
17
|
+
find(config: VQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
18
|
+
findOne(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
19
|
+
update(config: VQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
20
|
+
updateOne(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
21
|
+
remove(config: VQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
22
|
+
removeOne(config: VQuery): Promise<import("../types/data.js").DataInternal>;
|
|
23
23
|
ensureCollection(config: VQuery): Promise<boolean>;
|
|
24
24
|
issetCollection(config: VQuery): Promise<boolean>;
|
|
25
25
|
removeCollection(config: VQuery): Promise<boolean>;
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class ValtheraClass implements ValtheraCompatible {
|
|
|
19
19
|
"*": (name: keyof ValtheraCompatible, query: VQuery, result: any) => void;
|
|
20
20
|
}>;
|
|
21
21
|
version: string;
|
|
22
|
-
constructor(options
|
|
22
|
+
constructor(options: DbOpts);
|
|
23
23
|
init(...args: any[]): Promise<unknown>;
|
|
24
24
|
execute<T>(name: keyof ValtheraCompatible, query: VQuery): Promise<T>;
|
|
25
25
|
/**
|
package/dist/db/valthera.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { VEE } from "@wxn0brp/event-emitter";
|
|
2
|
-
import { ActionsBase } from "../base/actions.js";
|
|
3
2
|
import { Collection } from "../helpers/collection.js";
|
|
4
3
|
import { Executor } from "../helpers/executor.js";
|
|
5
4
|
import { version } from "../version.js";
|
|
@@ -12,8 +11,8 @@ export class ValtheraClass {
|
|
|
12
11
|
executor;
|
|
13
12
|
emiter = new VEE();
|
|
14
13
|
version = version;
|
|
15
|
-
constructor(options
|
|
16
|
-
this.dbAction = options.dbAction
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.dbAction = options.dbAction;
|
|
17
16
|
this.executor = options.executor || new Executor();
|
|
18
17
|
if (options.numberId)
|
|
19
18
|
this.dbAction.numberId = true;
|
package/dist/helpers/addId.js
CHANGED
|
@@ -12,7 +12,7 @@ export async function addId(query, actions, defaultGen = true) {
|
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
14
|
const find = await actions.findOne({ collection: "__vdb_id", search: { c: collection } });
|
|
15
|
-
data._id = find ? find.i + 1 : 1;
|
|
15
|
+
data._id = find?.i ? find.i + 1 : 1;
|
|
16
16
|
await actions.updateOneOrAdd({
|
|
17
17
|
collection: "__vdb_id",
|
|
18
18
|
search: { c: collection },
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DataInternal } from "./data.js";
|
|
2
|
+
import { VQuery } from "./query.js";
|
|
3
|
+
export interface ActionsBaseInterface {
|
|
4
|
+
_inited: boolean;
|
|
5
|
+
numberId: boolean;
|
|
6
|
+
init(...args: any[]): Promise<void>;
|
|
7
|
+
getCollections(): Promise<string[]>;
|
|
8
|
+
ensureCollection(config: VQuery): Promise<boolean>;
|
|
9
|
+
issetCollection(config: VQuery): Promise<boolean>;
|
|
10
|
+
add(config: VQuery): Promise<DataInternal>;
|
|
11
|
+
find(config: VQuery): Promise<DataInternal[]>;
|
|
12
|
+
findOne(config: VQuery): Promise<DataInternal | null>;
|
|
13
|
+
update(config: VQuery): Promise<DataInternal[] | null>;
|
|
14
|
+
updateOne(config: VQuery): Promise<DataInternal | null>;
|
|
15
|
+
remove(config: VQuery): Promise<DataInternal[] | null>;
|
|
16
|
+
removeOne(config: VQuery): Promise<DataInternal | null>;
|
|
17
|
+
removeCollection(config: VQuery): Promise<boolean>;
|
|
18
|
+
updateOneOrAdd(config: VQuery): Promise<DataInternal>;
|
|
19
|
+
toggleOne(config: VQuery): Promise<DataInternal | null>;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/data.d.ts
CHANGED
package/dist/types/fileCpu.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Search, Updater } from "./arg.js";
|
|
2
|
-
import { Data } from "./data.js";
|
|
2
|
+
import { Data, DataInternal } from "./data.js";
|
|
3
3
|
import { FindOpts } from "./options.js";
|
|
4
4
|
import { VContext } from "./types.js";
|
|
5
5
|
export interface FileCpu {
|
|
@@ -18,7 +18,7 @@ export interface FileCpu {
|
|
|
18
18
|
* @param findOpts Additional options for searching.
|
|
19
19
|
* @returns A promise resolving to an array of found entries, or `false` if the file does not exist.
|
|
20
20
|
*/
|
|
21
|
-
find(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<
|
|
21
|
+
find(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<DataInternal[]>;
|
|
22
22
|
/**
|
|
23
23
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
24
24
|
* @param file The path to the file.
|
|
@@ -27,7 +27,7 @@ export interface FileCpu {
|
|
|
27
27
|
* @param findOpts Additional options for searching.
|
|
28
28
|
* @returns A promise resolving to the found entry or `false` if not found.
|
|
29
29
|
*/
|
|
30
|
-
findOne(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<
|
|
30
|
+
findOne(file: string, search: Search, context?: VContext, findOpts?: FindOpts): Promise<DataInternal | false>;
|
|
31
31
|
/**
|
|
32
32
|
* Asynchronously removes entries from a file based on search criteria.
|
|
33
33
|
* @param file The path to the file.
|
|
@@ -36,7 +36,7 @@ export interface FileCpu {
|
|
|
36
36
|
* @param one If `true`, removes only the first matching entry.
|
|
37
37
|
* @returns A promise resolving to `true` if at least one entry was removed, otherwise `false`.
|
|
38
38
|
*/
|
|
39
|
-
remove(file: string, one: boolean, search: Search, context?: VContext): Promise<
|
|
39
|
+
remove(file: string, one: boolean, search: Search, context?: VContext): Promise<DataInternal[]>;
|
|
40
40
|
/**
|
|
41
41
|
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
42
42
|
* @param file The path to the file.
|
|
@@ -46,5 +46,5 @@ export interface FileCpu {
|
|
|
46
46
|
* @param one If `true`, updates only the first matching entry.
|
|
47
47
|
* @returns A promise resolving to `true` if at least one entry was updated, otherwise `false`.
|
|
48
48
|
*/
|
|
49
|
-
update(file: string, one: boolean, search: Search, updater: Updater, context?: VContext): Promise<
|
|
49
|
+
update(file: string, one: boolean, search: Search, updater: Updater, context?: VContext): Promise<DataInternal[]>;
|
|
50
50
|
}
|
package/dist/types/options.d.ts
CHANGED
|
@@ -2,8 +2,7 @@ import { ActionsBase } from "../base/actions.js";
|
|
|
2
2
|
import { Executor } from "../helpers/executor.js";
|
|
3
3
|
import { KeysMatching } from "./utils.js";
|
|
4
4
|
export interface DbOpts {
|
|
5
|
-
|
|
6
|
-
dbAction?: ActionsBase;
|
|
5
|
+
dbAction: ActionsBase;
|
|
7
6
|
executor?: Executor;
|
|
8
7
|
numberId?: boolean;
|
|
9
8
|
}
|
package/dist/types/query.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ import { DbFindOpts, FindOpts } from "./options.js";
|
|
|
11
11
|
* }
|
|
12
12
|
*/
|
|
13
13
|
export interface VQuery_Control {
|
|
14
|
+
updateOneOrAdd?: {
|
|
15
|
+
updated?: boolean;
|
|
16
|
+
};
|
|
17
|
+
toggleOne?: {
|
|
18
|
+
created?: boolean;
|
|
19
|
+
};
|
|
14
20
|
}
|
|
15
21
|
export interface VQuery {
|
|
16
22
|
collection?: string;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.6.0";
|