@wxn0brp/db-core 0.6.0 → 0.7.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 +1 -1
- package/dist/base/actions.js +4 -4
- package/dist/db/valthera.d.ts +3 -0
- package/dist/db/valthera.js +4 -0
- package/dist/helpers/collection.d.ts +5 -2
- package/dist/helpers/collection.js +3 -0
- package/dist/helpers/forge.js +3 -3
- package/dist/types/action.d.ts +1 -1
- package/dist/types/query.d.ts +3 -2
- package/dist/types/valthera.d.ts +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/base/actions.d.ts
CHANGED
|
@@ -17,5 +17,5 @@ export declare abstract class ActionsBase implements ActionsBaseInterface {
|
|
|
17
17
|
abstract removeOne(config: VQuery): Promise<DataInternal | null>;
|
|
18
18
|
abstract removeCollection(config: VQuery): Promise<boolean>;
|
|
19
19
|
updateOneOrAdd(config: VQuery): Promise<DataInternal>;
|
|
20
|
-
toggleOne(config: VQuery): Promise<
|
|
20
|
+
toggleOne(config: VQuery): Promise<boolean>;
|
|
21
21
|
}
|
package/dist/base/actions.js
CHANGED
|
@@ -16,13 +16,13 @@ export class ActionsBase {
|
|
|
16
16
|
}
|
|
17
17
|
async toggleOne(config) {
|
|
18
18
|
const res = await this.removeOne(config);
|
|
19
|
-
const controlData = {
|
|
19
|
+
const controlData = { data: res };
|
|
20
20
|
config.control ||= {};
|
|
21
21
|
config.control.toggleOne = controlData;
|
|
22
22
|
if (res)
|
|
23
|
-
return
|
|
23
|
+
return false;
|
|
24
24
|
setDataForToggleOne(config);
|
|
25
|
-
config.control.toggleOne.
|
|
26
|
-
return
|
|
25
|
+
config.control.toggleOne.data = await this.add(config);
|
|
26
|
+
return true;
|
|
27
27
|
}
|
|
28
28
|
}
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -72,6 +72,9 @@ export declare class ValtheraClass implements ValtheraCompatible {
|
|
|
72
72
|
updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery): Promise<T>;
|
|
73
73
|
/**
|
|
74
74
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
75
|
+
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
76
|
+
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
77
|
+
* after the operation.
|
|
75
78
|
*/
|
|
76
79
|
toggleOne<T = Data>(query: ToggleOneQuery): Promise<T>;
|
|
77
80
|
/**
|
package/dist/db/valthera.js
CHANGED
|
@@ -69,6 +69,7 @@ export class ValtheraClass {
|
|
|
69
69
|
* Find data in a database.
|
|
70
70
|
*/
|
|
71
71
|
find(query) {
|
|
72
|
+
query.search ||= {};
|
|
72
73
|
query.dbFindOpts ||= {};
|
|
73
74
|
query.findOpts ||= {};
|
|
74
75
|
query.context ||= {};
|
|
@@ -128,6 +129,9 @@ export class ValtheraClass {
|
|
|
128
129
|
}
|
|
129
130
|
/**
|
|
130
131
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
132
|
+
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
133
|
+
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
134
|
+
* after the operation.
|
|
131
135
|
*/
|
|
132
136
|
toggleOne(query) {
|
|
133
137
|
query.data ||= {};
|
|
@@ -10,7 +10,7 @@ export declare class Collection<D = Data> {
|
|
|
10
10
|
/**
|
|
11
11
|
* Add data to a database.
|
|
12
12
|
*/
|
|
13
|
-
add(data: Arg<D>, id_gen:
|
|
13
|
+
add(data: Arg<D>, id_gen: false): Promise<D>;
|
|
14
14
|
add(data: Arg<D>, id_gen?: true): Promise<D & {
|
|
15
15
|
_id: string;
|
|
16
16
|
}>;
|
|
@@ -44,6 +44,9 @@ export declare class Collection<D = Data> {
|
|
|
44
44
|
updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<D>;
|
|
45
45
|
/**
|
|
46
46
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
47
|
+
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
48
|
+
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
49
|
+
* after the operation.
|
|
47
50
|
*/
|
|
48
|
-
toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<
|
|
51
|
+
toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<boolean>;
|
|
49
52
|
}
|
|
@@ -52,6 +52,9 @@ export class Collection {
|
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
54
54
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
55
|
+
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
56
|
+
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
57
|
+
* after the operation.
|
|
55
58
|
*/
|
|
56
59
|
toggleOne(search, data = {}, context = {}) {
|
|
57
60
|
return this.db.toggleOne({ collection: this.collection, search, data, context });
|
package/dist/helpers/forge.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Collection } from "./collection.js";
|
|
2
2
|
export function forgeValthera(target) {
|
|
3
|
+
return forgeTypedValthera(target);
|
|
4
|
+
}
|
|
5
|
+
export function forgeTypedValthera(target) {
|
|
3
6
|
return new Proxy(target, {
|
|
4
7
|
get(target, prop, receiver) {
|
|
5
8
|
if (prop in target) {
|
|
@@ -14,6 +17,3 @@ export function forgeValthera(target) {
|
|
|
14
17
|
}
|
|
15
18
|
});
|
|
16
19
|
}
|
|
17
|
-
export function forgeTypedValthera(target) {
|
|
18
|
-
return forgeValthera(target);
|
|
19
|
-
}
|
package/dist/types/action.d.ts
CHANGED
|
@@ -16,5 +16,5 @@ export interface ActionsBaseInterface {
|
|
|
16
16
|
removeOne(config: VQuery): Promise<DataInternal | null>;
|
|
17
17
|
removeCollection(config: VQuery): Promise<boolean>;
|
|
18
18
|
updateOneOrAdd(config: VQuery): Promise<DataInternal>;
|
|
19
|
-
toggleOne(config: VQuery): Promise<
|
|
19
|
+
toggleOne(config: VQuery): Promise<boolean>;
|
|
20
20
|
}
|
package/dist/types/query.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { VContext } from "./types.js";
|
|
2
1
|
import { Arg, Search, Updater } from "./arg.js";
|
|
2
|
+
import { Data } from "./data.js";
|
|
3
3
|
import { DbFindOpts, FindOpts } from "./options.js";
|
|
4
|
+
import { VContext } from "./types.js";
|
|
4
5
|
/**
|
|
5
6
|
* To extend via adapters
|
|
6
7
|
* @example
|
|
@@ -15,7 +16,7 @@ export interface VQuery_Control {
|
|
|
15
16
|
updated?: boolean;
|
|
16
17
|
};
|
|
17
18
|
toggleOne?: {
|
|
18
|
-
|
|
19
|
+
data?: Data;
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
export interface VQuery {
|
package/dist/types/valthera.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { VQuery } from "./query.js";
|
|
|
5
5
|
import { VContext } from "./types.js";
|
|
6
6
|
export type QueryBase = Required<Pick<VQuery, "collection" | "search">> & Pick<VQuery, "control">;
|
|
7
7
|
export type AddQuery = Required<Pick<VQuery, "data" | "collection">> & Pick<VQuery, "id_gen" | "control">;
|
|
8
|
-
export type FindQuery = QueryBase & Pick<VQuery, "findOpts" | "dbFindOpts" | "context">;
|
|
8
|
+
export type FindQuery = Omit<QueryBase, "search"> & Pick<VQuery, "search"> & Pick<VQuery, "findOpts" | "dbFindOpts" | "context">;
|
|
9
9
|
export type FindOneQuery = QueryBase & Pick<VQuery, "findOpts" | "context">;
|
|
10
10
|
export type UpdateQuery = QueryBase & Required<Pick<VQuery, "updater">> & Pick<VQuery, "context">;
|
|
11
11
|
export type RemoveQuery = QueryBase & Pick<VQuery, "context">;
|
|
@@ -25,7 +25,7 @@ export interface ValtheraCompatible {
|
|
|
25
25
|
removeOne<T = Data>(query: RemoveQuery): Promise<T | null>;
|
|
26
26
|
removeCollection(collection: string): Promise<boolean>;
|
|
27
27
|
updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery): Promise<T>;
|
|
28
|
-
toggleOne
|
|
28
|
+
toggleOne(query: ToggleOneQuery): Promise<boolean>;
|
|
29
29
|
}
|
|
30
30
|
export interface UpdateOneOrAdd<T> {
|
|
31
31
|
add_arg?: Arg<T>;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.7.0";
|