@wxn0brp/db-core 0.7.0 → 0.8.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/LICENSE +1 -1
- package/dist/base/actions.d.ts +3 -3
- package/dist/base/actions.js +16 -12
- package/dist/db/valthera.d.ts +2 -2
- package/dist/helpers/collection.d.ts +5 -3
- package/dist/types/action.d.ts +3 -3
- package/dist/types/collection.d.ts +7 -0
- package/dist/types/collection.js +1 -0
- package/dist/types/query.d.ts +16 -7
- package/dist/types/query.js +2 -0
- package/dist/types/valthera.d.ts +3 -18
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/LICENSE
CHANGED
package/dist/base/actions.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionsBaseInterface } from "../types/action.js";
|
|
2
2
|
import { DataInternal } from "../types/data.js";
|
|
3
|
-
import { VQuery } from "../types/query.js";
|
|
3
|
+
import { ToggleOneResult, UpdateOneOrAddResult, VQuery } from "../types/query.js";
|
|
4
4
|
export declare abstract class ActionsBase implements ActionsBaseInterface {
|
|
5
5
|
_inited: boolean;
|
|
6
6
|
numberId: boolean;
|
|
@@ -16,6 +16,6 @@ export declare abstract class ActionsBase implements ActionsBaseInterface {
|
|
|
16
16
|
abstract remove(config: VQuery): Promise<DataInternal[] | null>;
|
|
17
17
|
abstract removeOne(config: VQuery): Promise<DataInternal | null>;
|
|
18
18
|
abstract removeCollection(config: VQuery): Promise<boolean>;
|
|
19
|
-
updateOneOrAdd(config: VQuery): Promise<DataInternal
|
|
20
|
-
toggleOne(config: VQuery): Promise<
|
|
19
|
+
updateOneOrAdd(config: VQuery): Promise<UpdateOneOrAddResult<DataInternal>>;
|
|
20
|
+
toggleOne(config: VQuery): Promise<ToggleOneResult<DataInternal>>;
|
|
21
21
|
}
|
package/dist/base/actions.js
CHANGED
|
@@ -5,24 +5,28 @@ export class ActionsBase {
|
|
|
5
5
|
async init(...args) { }
|
|
6
6
|
async updateOneOrAdd(config) {
|
|
7
7
|
const res = await this.updateOne(config);
|
|
8
|
-
const controlData = { updated: true };
|
|
9
|
-
config.control ||= {};
|
|
10
|
-
config.control.updateOneOrAdd = controlData;
|
|
11
8
|
if (res)
|
|
12
|
-
return
|
|
9
|
+
return {
|
|
10
|
+
data: res,
|
|
11
|
+
type: "updated"
|
|
12
|
+
};
|
|
13
13
|
setDataForUpdateOneOrAdd(config);
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
return {
|
|
15
|
+
data: await this.add(config),
|
|
16
|
+
type: "added"
|
|
17
|
+
};
|
|
16
18
|
}
|
|
17
19
|
async toggleOne(config) {
|
|
18
20
|
const res = await this.removeOne(config);
|
|
19
|
-
const controlData = { data: res };
|
|
20
|
-
config.control ||= {};
|
|
21
|
-
config.control.toggleOne = controlData;
|
|
22
21
|
if (res)
|
|
23
|
-
return
|
|
22
|
+
return {
|
|
23
|
+
data: res,
|
|
24
|
+
type: "removed"
|
|
25
|
+
};
|
|
24
26
|
setDataForToggleOne(config);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
return {
|
|
28
|
+
data: await this.add(config),
|
|
29
|
+
type: "added"
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
}
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -4,8 +4,8 @@ import { Collection } from "../helpers/collection.js";
|
|
|
4
4
|
import { Executor } from "../helpers/executor.js";
|
|
5
5
|
import { Data } from "../types/data.js";
|
|
6
6
|
import { DbOpts } from "../types/options.js";
|
|
7
|
-
import { VQuery } from "../types/query.js";
|
|
8
|
-
import {
|
|
7
|
+
import { AddQuery, FindOneQuery, FindQuery, RemoveQuery, ToggleOneQuery, UpdateOneOrAddQuery, UpdateQuery, VQuery } from "../types/query.js";
|
|
8
|
+
import { ValtheraCompatible } from "../types/valthera.js";
|
|
9
9
|
/**
|
|
10
10
|
* Represents a database management class for performing CRUD operations.
|
|
11
11
|
* @class
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Arg, Search, Updater } from "../types/arg.js";
|
|
2
|
+
import { UpdateOneOrAdd } from "../types/collection.js";
|
|
2
3
|
import { Data } from "../types/data.js";
|
|
3
4
|
import { DbFindOpts, FindOpts } from "../types/options.js";
|
|
5
|
+
import { ToggleOneResult, UpdateOneOrAddResult } from "../types/query.js";
|
|
4
6
|
import { VContext } from "../types/types.js";
|
|
5
|
-
import {
|
|
7
|
+
import { ValtheraCompatible } from "../types/valthera.js";
|
|
6
8
|
export declare class Collection<D = Data> {
|
|
7
9
|
db: ValtheraCompatible;
|
|
8
10
|
collection: string;
|
|
@@ -41,12 +43,12 @@ export declare class Collection<D = Data> {
|
|
|
41
43
|
/**
|
|
42
44
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
43
45
|
*/
|
|
44
|
-
updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<D
|
|
46
|
+
updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<UpdateOneOrAddResult<D>>;
|
|
45
47
|
/**
|
|
46
48
|
* 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
49
|
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
48
50
|
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
49
51
|
* after the operation.
|
|
50
52
|
*/
|
|
51
|
-
toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<
|
|
53
|
+
toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<ToggleOneResult<D>>;
|
|
52
54
|
}
|
package/dist/types/action.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataInternal } from "./data.js";
|
|
2
|
-
import { VQuery } from "./query.js";
|
|
2
|
+
import { ToggleOneResult, UpdateOneOrAddResult, VQuery } from "./query.js";
|
|
3
3
|
export interface ActionsBaseInterface {
|
|
4
4
|
_inited: boolean;
|
|
5
5
|
numberId: boolean;
|
|
@@ -15,6 +15,6 @@ export interface ActionsBaseInterface {
|
|
|
15
15
|
remove(config: VQuery): Promise<DataInternal[] | null>;
|
|
16
16
|
removeOne(config: VQuery): Promise<DataInternal | null>;
|
|
17
17
|
removeCollection(config: VQuery): Promise<boolean>;
|
|
18
|
-
updateOneOrAdd(config: VQuery): Promise<DataInternal
|
|
19
|
-
toggleOne(config: VQuery): Promise<
|
|
18
|
+
updateOneOrAdd(config: VQuery): Promise<UpdateOneOrAddResult<DataInternal>>;
|
|
19
|
+
toggleOne(config: VQuery): Promise<ToggleOneResult<DataInternal>>;
|
|
20
20
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/query.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Arg, Search, Updater } from "./arg.js";
|
|
2
|
-
import { Data } from "./data.js";
|
|
3
2
|
import { DbFindOpts, FindOpts } from "./options.js";
|
|
4
3
|
import { VContext } from "./types.js";
|
|
5
4
|
/**
|
|
@@ -12,12 +11,6 @@ import { VContext } from "./types.js";
|
|
|
12
11
|
* }
|
|
13
12
|
*/
|
|
14
13
|
export interface VQuery_Control {
|
|
15
|
-
updateOneOrAdd?: {
|
|
16
|
-
updated?: boolean;
|
|
17
|
-
};
|
|
18
|
-
toggleOne?: {
|
|
19
|
-
data?: Data;
|
|
20
|
-
};
|
|
21
14
|
}
|
|
22
15
|
export interface VQuery {
|
|
23
16
|
collection?: string;
|
|
@@ -31,3 +24,19 @@ export interface VQuery {
|
|
|
31
24
|
updater?: Updater;
|
|
32
25
|
control?: VQuery_Control;
|
|
33
26
|
}
|
|
27
|
+
export type QueryBase = Required<Pick<VQuery, "collection" | "search">> & Pick<VQuery, "control">;
|
|
28
|
+
export type AddQuery = Required<Pick<VQuery, "data" | "collection">> & Pick<VQuery, "id_gen" | "control">;
|
|
29
|
+
export type FindQuery = Omit<QueryBase, "search"> & Pick<VQuery, "search"> & Pick<VQuery, "findOpts" | "dbFindOpts" | "context">;
|
|
30
|
+
export type FindOneQuery = QueryBase & Pick<VQuery, "findOpts" | "context">;
|
|
31
|
+
export type UpdateQuery = QueryBase & Required<Pick<VQuery, "updater">> & Pick<VQuery, "context">;
|
|
32
|
+
export type RemoveQuery = QueryBase & Pick<VQuery, "context">;
|
|
33
|
+
export type UpdateOneOrAddQuery = QueryBase & UpdateQuery & Pick<VQuery, "add_arg" | "id_gen">;
|
|
34
|
+
export type ToggleOneQuery = QueryBase & Pick<VQuery, "data" | "context">;
|
|
35
|
+
export interface UpdateOneOrAddResult<T> {
|
|
36
|
+
data: T;
|
|
37
|
+
type: "added" | "updated";
|
|
38
|
+
}
|
|
39
|
+
export interface ToggleOneResult<T> {
|
|
40
|
+
data: T;
|
|
41
|
+
type: "added" | "removed";
|
|
42
|
+
}
|
package/dist/types/query.js
CHANGED
package/dist/types/valthera.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import { Collection } from "../helpers/collection.js";
|
|
2
|
-
import { Arg } from "./arg.js";
|
|
3
2
|
import { Data } from "./data.js";
|
|
4
|
-
import {
|
|
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 = Omit<QueryBase, "search"> & Pick<VQuery, "search"> & 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">;
|
|
3
|
+
import { AddQuery, FindOneQuery, FindQuery, RemoveQuery, ToggleOneQuery, ToggleOneResult, UpdateOneOrAddQuery, UpdateOneOrAddResult, UpdateQuery } from "./query.js";
|
|
14
4
|
export interface ValtheraCompatible {
|
|
15
5
|
c(collection: string): Collection;
|
|
16
6
|
getCollections(): Promise<string[]>;
|
|
@@ -24,11 +14,6 @@ export interface ValtheraCompatible {
|
|
|
24
14
|
remove<T = Data>(query: RemoveQuery): Promise<T[] | null>;
|
|
25
15
|
removeOne<T = Data>(query: RemoveQuery): Promise<T | null>;
|
|
26
16
|
removeCollection(collection: string): Promise<boolean>;
|
|
27
|
-
updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery): Promise<T
|
|
28
|
-
toggleOne(query: ToggleOneQuery): Promise<
|
|
29
|
-
}
|
|
30
|
-
export interface UpdateOneOrAdd<T> {
|
|
31
|
-
add_arg?: Arg<T>;
|
|
32
|
-
id_gen?: boolean;
|
|
33
|
-
context?: VContext;
|
|
17
|
+
updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery): Promise<UpdateOneOrAddResult<T>>;
|
|
18
|
+
toggleOne<T = Data>(query: ToggleOneQuery): Promise<ToggleOneResult<T>>;
|
|
34
19
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.8.0";
|