@wxn0brp/db-core 0.2.7 → 0.2.9

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.
@@ -16,5 +16,6 @@ declare class ActionsBase {
16
16
  removeOne(config: VQuery): Promise<boolean>;
17
17
  removeCollection(config: VQuery): Promise<boolean>;
18
18
  updateOneOrAdd(config: VQuery): Promise<boolean>;
19
+ toggleOne(config: VQuery): Promise<boolean>;
19
20
  }
20
21
  export default ActionsBase;
@@ -55,5 +55,11 @@ class ActionsBase {
55
55
  }
56
56
  return res;
57
57
  }
58
+ async toggleOne(config) {
59
+ const res = await this.removeOne(config);
60
+ if (!res)
61
+ await this.add(config);
62
+ return res;
63
+ }
58
64
  }
59
65
  export default ActionsBase;
@@ -2,7 +2,7 @@ import { VEE } from "@wxn0brp/event-emitter";
2
2
  import ActionsBase from "../base/actions.js";
3
3
  import CollectionManager from "../helpers/CollectionManager.js";
4
4
  import executorC from "../helpers/executor.js";
5
- import { Search, Updater } from "../types/arg.js";
5
+ import { Arg, Search, Updater } from "../types/arg.js";
6
6
  import Data from "../types/data.js";
7
7
  import { DbFindOpts, DbOpts, FindOpts } from "../types/options.js";
8
8
  import { VQuery } from "../types/query.js";
@@ -74,6 +74,10 @@ declare class ValtheraClass implements ValtheraCompatible {
74
74
  * Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
75
75
  */
76
76
  updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, { add_arg, context, id_gen }?: UpdateOneOrAdd<T>): Promise<boolean>;
77
+ /**
78
+ * Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
79
+ */
80
+ toggleOne<T = Data>(collection: string, search: Search<T>, data: Arg<T>, context?: VContext): Promise<boolean>;
77
81
  /**
78
82
  * Removes a database collection from the file system.
79
83
  */
@@ -107,6 +107,12 @@ class ValtheraClass {
107
107
  async updateOneOrAdd(collection, search, updater, { add_arg = {}, context = {}, id_gen = true } = {}) {
108
108
  return await this.execute("updateOneOrAdd", { collection, search, updater, add_arg, context, id_gen });
109
109
  }
110
+ /**
111
+ * Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
112
+ */
113
+ async toggleOne(collection, search, data, context = {}) {
114
+ return await this.execute("toggleOne", { collection, search, data, context, id_gen: false });
115
+ }
110
116
  /**
111
117
  * Removes a database collection from the file system.
112
118
  */
@@ -18,6 +18,7 @@ export interface ValtheraCompatible {
18
18
  removeOne<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
19
19
  removeCollection(collection: string): Promise<boolean>;
20
20
  updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, opts?: UpdateOneOrAdd<T>): Promise<boolean>;
21
+ toggleOne<T = Data>(collection: string, search: Search<T>, data: Arg<T>, context: VContext): Promise<boolean>;
21
22
  }
22
23
  export interface UpdateOneOrAdd<T> {
23
24
  add_arg?: Arg<T>;
@@ -38,4 +39,5 @@ export interface ValtheraCompatibleInternal {
38
39
  removeOne(config: VQuery): Promise<boolean>;
39
40
  removeCollection(config: VQuery): Promise<boolean>;
40
41
  updateOneOrAdd(config: VQuery): Promise<boolean>;
42
+ toggleOne(config: VQuery): Promise<boolean>;
41
43
  }
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.2.7";
1
+ export const version = "0.2.9";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",