@wxn0brp/db-core 0.2.9 → 0.2.10

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.
@@ -1,4 +1,4 @@
1
- import { setDataUsingUpdateOneOrAdd } from "../helpers/updateOneOrAdd.js";
1
+ import { setDataUsingToggleOne, setDataUsingUpdateOneOrAdd } from "../helpers/updateOneOrAdd.js";
2
2
  class ActionsBase {
3
3
  _inited = true;
4
4
  numberId = false;
@@ -57,8 +57,10 @@ class ActionsBase {
57
57
  }
58
58
  async toggleOne(config) {
59
59
  const res = await this.removeOne(config);
60
- if (!res)
60
+ if (!res) {
61
+ setDataUsingToggleOne(config);
61
62
  await this.add(config);
63
+ }
62
64
  return res;
63
65
  }
64
66
  }
@@ -77,7 +77,7 @@ declare class ValtheraClass implements ValtheraCompatible {
77
77
  /**
78
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
79
  */
80
- toggleOne<T = Data>(collection: string, search: Search<T>, data: Arg<T>, context?: VContext): Promise<boolean>;
80
+ toggleOne<T = Data>(collection: string, search: Search<T>, data?: Arg<T>, context?: VContext): Promise<boolean>;
81
81
  /**
82
82
  * Removes a database collection from the file system.
83
83
  */
@@ -110,7 +110,7 @@ class ValtheraClass {
110
110
  /**
111
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
112
  */
113
- async toggleOne(collection, search, data, context = {}) {
113
+ async toggleOne(collection, search, data = {}, context = {}) {
114
114
  return await this.execute("toggleOne", { collection, search, data, context, id_gen: false });
115
115
  }
116
116
  /**
@@ -1,2 +1,4 @@
1
1
  import { VQuery } from "../types/query.js";
2
+ export declare function assignDataPush(data: any): {};
2
3
  export declare function setDataUsingUpdateOneOrAdd(query: VQuery): void;
4
+ export declare function setDataUsingToggleOne(query: VQuery): void;
@@ -1,4 +1,4 @@
1
- function assignDataPush(data) {
1
+ export function assignDataPush(data) {
2
2
  if (typeof data !== "object" || Array.isArray(data))
3
3
  return;
4
4
  const obj = {};
@@ -16,3 +16,6 @@ function assignDataPush(data) {
16
16
  export function setDataUsingUpdateOneOrAdd(query) {
17
17
  query.data = Object.assign({}, assignDataPush(query.search), assignDataPush(query.updater), assignDataPush(query.add_arg));
18
18
  }
19
+ export function setDataUsingToggleOne(query) {
20
+ query.data = Object.assign({}, assignDataPush(query.search), assignDataPush(query.data));
21
+ }
@@ -18,7 +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
+ toggleOne<T = Data>(collection: string, search: Search<T>, data?: Arg<T>, context?: VContext): Promise<boolean>;
22
22
  }
23
23
  export interface UpdateOneOrAdd<T> {
24
24
  add_arg?: Arg<T>;
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const version = "0.2.9";
1
+ export const version = "0.2.10";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wxn0brp/db-core",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.js",
6
6
  "author": "wxn0brP",