@wxn0brp/vql-client 0.2.6 → 0.2.8
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/vql.d.ts +60 -51
- package/package.json +1 -1
package/dist/vql.d.ts
CHANGED
|
@@ -1,72 +1,78 @@
|
|
|
1
|
-
export interface Data {
|
|
2
|
-
[key: string]: any;
|
|
3
|
-
}
|
|
4
|
-
export interface VContext {
|
|
5
|
-
[key: string]: any;
|
|
6
|
-
}
|
|
7
1
|
export type KeysMatching<T, V, C = V> = {
|
|
8
2
|
[K in keyof T]-?: T[K] extends C ? K : never;
|
|
9
3
|
}[keyof T];
|
|
10
|
-
export type
|
|
11
|
-
|
|
4
|
+
export type NestedValue<T, V, C = V> = {
|
|
5
|
+
[K in keyof T as T[K] extends C ? K : T[K] extends object ? K : never]?: T[K] extends C ? V : T[K] extends object ? NestedValue<T[K], V, C> : never;
|
|
6
|
+
};
|
|
7
|
+
export type DeepPartial<T> = {
|
|
8
|
+
[K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
|
|
9
|
+
};
|
|
10
|
+
export type JSPrimitiveType = "string" | "number" | "boolean" | "bigint" | "symbol" | "undefined" | "function" | "object";
|
|
12
11
|
export type LogicalOperators<T = any> = {
|
|
13
12
|
$and?: Array<SearchOptions<T>>;
|
|
14
13
|
$or?: Array<SearchOptions<T>>;
|
|
15
14
|
$not?: SearchOptions<T>;
|
|
16
15
|
};
|
|
17
16
|
export type ComparisonOperators<T = any> = {
|
|
18
|
-
$gt?:
|
|
19
|
-
$lt?:
|
|
20
|
-
$gte?:
|
|
21
|
-
$lte?:
|
|
22
|
-
$between?:
|
|
17
|
+
$gt?: NestedValue<T, number, number>;
|
|
18
|
+
$lt?: NestedValue<T, number, number>;
|
|
19
|
+
$gte?: NestedValue<T, number, number>;
|
|
20
|
+
$lte?: NestedValue<T, number, number>;
|
|
21
|
+
$between?: NestedValue<T, [
|
|
23
22
|
number,
|
|
24
23
|
number
|
|
25
24
|
], number>;
|
|
26
|
-
$in?:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
$
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
$in?: DeepPartial<T> & {
|
|
26
|
+
[K in keyof T]?: T[K] extends any[] ? T[K] : T[K][];
|
|
27
|
+
};
|
|
28
|
+
$nin?: DeepPartial<T> & {
|
|
29
|
+
[K in keyof T]?: T[K] extends any[] ? T[K] : T[K][];
|
|
30
|
+
};
|
|
31
|
+
$idGt?: NestedValue<T, string | number, string | number>;
|
|
32
|
+
$idLt?: NestedValue<T, string | number, string | number>;
|
|
33
|
+
$idGte?: NestedValue<T, string | number, string | number>;
|
|
34
|
+
$idLte?: NestedValue<T, string | number, string | number>;
|
|
32
35
|
};
|
|
33
36
|
export type TypeAndExistenceOperators<T = any> = {
|
|
34
|
-
$exists?:
|
|
35
|
-
$type?:
|
|
37
|
+
$exists?: NestedValue<T, boolean, any>;
|
|
38
|
+
$type?: NestedValue<T, JSPrimitiveType, any>;
|
|
36
39
|
};
|
|
37
40
|
export type ArrayOperators<T = any> = {
|
|
38
|
-
$arrinc?:
|
|
39
|
-
$arrincall?:
|
|
40
|
-
$size?:
|
|
41
|
+
$arrinc?: DeepPartial<T>;
|
|
42
|
+
$arrincall?: DeepPartial<T>;
|
|
43
|
+
$size?: NestedValue<T, number>;
|
|
41
44
|
};
|
|
42
45
|
export type StringOperators<T = any> = {
|
|
43
|
-
$regex?:
|
|
44
|
-
$startsWith?:
|
|
45
|
-
$endsWith?:
|
|
46
|
+
$regex?: NestedValue<T, RegExp | string, string>;
|
|
47
|
+
$startsWith?: NestedValue<T, string, string>;
|
|
48
|
+
$endsWith?: NestedValue<T, string, string>;
|
|
46
49
|
};
|
|
47
50
|
export type OtherOperators<T = any> = {
|
|
48
|
-
$subset?:
|
|
51
|
+
$subset?: DeepPartial<T>;
|
|
49
52
|
};
|
|
50
53
|
export type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
|
|
51
|
-
export type SearchOptions<T = any> = PredefinedSearchOperators<T> &
|
|
54
|
+
export type SearchOptions<T = any> = PredefinedSearchOperators<T> & DeepPartial<T> & Record<string, any>;
|
|
55
|
+
export interface VContext {
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}
|
|
52
58
|
export type ArrayUpdater<T = any> = {
|
|
53
|
-
$push?:
|
|
54
|
-
$pushset?:
|
|
55
|
-
$pull?:
|
|
56
|
-
$pullall?:
|
|
59
|
+
$push?: NestedValue<T, any>;
|
|
60
|
+
$pushset?: NestedValue<T, any>;
|
|
61
|
+
$pull?: NestedValue<T, any>;
|
|
62
|
+
$pullall?: NestedValue<T, any>;
|
|
57
63
|
};
|
|
58
64
|
export type ObjectUpdater<T = any> = {
|
|
59
|
-
$merge?:
|
|
60
|
-
$deepMerge?:
|
|
65
|
+
$merge?: NestedValue<T, any>;
|
|
66
|
+
$deepMerge?: NestedValue<T, any>;
|
|
61
67
|
};
|
|
62
68
|
export type ValueUpdater<T = any> = {
|
|
63
|
-
$inc?:
|
|
64
|
-
$dec?:
|
|
65
|
-
$unset?:
|
|
66
|
-
$rename?:
|
|
67
|
-
$set?:
|
|
69
|
+
$inc?: NestedValue<T, number>;
|
|
70
|
+
$dec?: NestedValue<T, number>;
|
|
71
|
+
$unset?: NestedValue<T, any>;
|
|
72
|
+
$rename?: NestedValue<T, any>;
|
|
73
|
+
$set?: NestedValue<T, any>;
|
|
68
74
|
};
|
|
69
|
-
export type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> &
|
|
75
|
+
export type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> & DeepPartial<T> & Record<string, any>;
|
|
70
76
|
export type Arg<T = any> = {
|
|
71
77
|
[K in keyof T]?: any;
|
|
72
78
|
} & Record<string, any>;
|
|
@@ -74,9 +80,12 @@ export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
|
74
80
|
export type UpdaterFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
75
81
|
export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
|
|
76
82
|
export type Updater<T = any> = UpdaterArg<T> | UpdaterArg<T>[] | UpdaterFunc<T>;
|
|
83
|
+
export interface Data {
|
|
84
|
+
[key: string]: any;
|
|
85
|
+
}
|
|
77
86
|
export interface DbFindOpts<T = any> {
|
|
78
87
|
reverse?: boolean;
|
|
79
|
-
|
|
88
|
+
limit?: number;
|
|
80
89
|
offset?: number;
|
|
81
90
|
sortBy?: KeysMatching<T, any>;
|
|
82
91
|
sortAsc?: boolean;
|
|
@@ -90,15 +99,15 @@ declare class CollectionManager<D = Data> {
|
|
|
90
99
|
private db;
|
|
91
100
|
private collection;
|
|
92
101
|
constructor(db: ValtheraCompatible, collection: string);
|
|
93
|
-
add
|
|
94
|
-
find
|
|
95
|
-
findOne
|
|
96
|
-
update
|
|
97
|
-
updateOne
|
|
98
|
-
remove
|
|
99
|
-
removeOne
|
|
100
|
-
updateOneOrAdd
|
|
101
|
-
toggleOne
|
|
102
|
+
add(data: Arg<D>, id_gen?: boolean): Promise<D>;
|
|
103
|
+
find(search?: Search<D>, options?: DbFindOpts<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D[]>;
|
|
104
|
+
findOne(search?: Search<D>, findOpts?: FindOpts<D>, context?: VContext): Promise<D>;
|
|
105
|
+
update(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<boolean>;
|
|
106
|
+
updateOne(search: Search<D>, updater: Updater<D>, context?: VContext): Promise<boolean>;
|
|
107
|
+
remove(search: Search<D>, context?: VContext): Promise<boolean>;
|
|
108
|
+
removeOne(search: Search<D>, context?: VContext): Promise<boolean>;
|
|
109
|
+
updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<boolean>;
|
|
110
|
+
toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<boolean>;
|
|
102
111
|
}
|
|
103
112
|
export interface ValtheraCompatible {
|
|
104
113
|
c(collection: string): CollectionManager;
|