@wxn0brp/db-core 0.0.3 → 0.0.6
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/db/valthera.d.ts +8 -8
- package/dist/types/arg.d.ts +5 -7
- package/dist/types/options.d.ts +6 -5
- package/dist/types/searchOpts.d.ts +28 -27
- package/dist/types/updater.d.ts +15 -16
- package/dist/types/utils.d.ts +5 -0
- package/dist/types/utils.js +1 -0
- package/dist/types/valthera.d.ts +8 -8
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/db/valthera.d.ts
CHANGED
|
@@ -37,35 +37,35 @@ declare class ValtheraClass implements ValtheraCompatible {
|
|
|
37
37
|
/**
|
|
38
38
|
* Add data to a database.
|
|
39
39
|
*/
|
|
40
|
-
add<T = Data>(collection: string, data: Arg
|
|
40
|
+
add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
|
|
41
41
|
/**
|
|
42
42
|
* Find data in a database.
|
|
43
43
|
*/
|
|
44
|
-
find<T = Data>(collection: string, search: Search
|
|
44
|
+
find<T = Data>(collection: string, search: Search<T>, context?: VContext, dbFindOpts?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
|
|
45
45
|
/**
|
|
46
46
|
* Find one data entry in a database.
|
|
47
47
|
*/
|
|
48
|
-
findOne<T = Data>(collection: string, search: Search
|
|
48
|
+
findOne<T = Data>(collection: string, search: Search<T>, context?: VContext, findOpts?: FindOpts<T>): Promise<T>;
|
|
49
49
|
/**
|
|
50
50
|
* Update data in a database.
|
|
51
51
|
*/
|
|
52
|
-
update(collection: string, search: Search
|
|
52
|
+
update<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: {}): Promise<boolean>;
|
|
53
53
|
/**
|
|
54
54
|
* Update one data entry in a database.
|
|
55
55
|
*/
|
|
56
|
-
updateOne(collection: string, search: Search
|
|
56
|
+
updateOne<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
57
57
|
/**
|
|
58
58
|
* Remove data from a database.
|
|
59
59
|
*/
|
|
60
|
-
remove(collection: string, search: Search
|
|
60
|
+
remove<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
61
61
|
/**
|
|
62
62
|
* Remove one data entry from a database.
|
|
63
63
|
*/
|
|
64
|
-
removeOne(collection: string, search: Search
|
|
64
|
+
removeOne<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
65
65
|
/**
|
|
66
66
|
* Asynchronously updates one entry in a database or adds a new one if it doesn't exist.
|
|
67
67
|
*/
|
|
68
|
-
updateOneOrAdd(collection: string, search: Search
|
|
68
|
+
updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, add_arg?: Arg, context?: VContext, id_gen?: boolean): Promise<boolean>;
|
|
69
69
|
/**
|
|
70
70
|
* Removes a database collection from the file system.
|
|
71
71
|
*/
|
package/dist/types/arg.d.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import Id from "./Id.js";
|
|
2
1
|
import { SearchOptions } from "./searchOpts.js";
|
|
3
2
|
import { VContext } from "./types.js";
|
|
4
3
|
import { UpdaterArg } from "./updater.js";
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
4
|
+
export type Arg<T = any> = {
|
|
5
|
+
[K in keyof T]?: any;
|
|
6
|
+
} & Record<string, any>;
|
|
9
7
|
export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
10
8
|
export type UpdaterFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
11
|
-
export type Search<T = any> = SearchOptions | SearchFunc<T>;
|
|
12
|
-
export type Updater<T = any> = UpdaterArg | UpdaterArg[] | UpdaterFunc<T>;
|
|
9
|
+
export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
|
|
10
|
+
export type Updater<T = any> = UpdaterArg<T> | UpdaterArg<T>[] | UpdaterFunc<T>;
|
package/dist/types/options.d.ts
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import dbActionBase from "../base/actions.js";
|
|
2
2
|
import executorC from "../helpers/executor.js";
|
|
3
|
+
import { KeysMatching } from "./utils.js";
|
|
3
4
|
export interface DbOpts {
|
|
4
5
|
maxFileSize?: number;
|
|
5
6
|
dbAction?: dbActionBase;
|
|
6
7
|
executor?: executorC;
|
|
7
8
|
}
|
|
8
|
-
export interface DbFindOpts {
|
|
9
|
+
export interface DbFindOpts<T = any> {
|
|
9
10
|
reverse?: boolean;
|
|
10
11
|
max?: number;
|
|
11
12
|
offset?: number;
|
|
12
|
-
sortBy?:
|
|
13
|
+
sortBy?: KeysMatching<T, any>;
|
|
13
14
|
sortAsc?: boolean;
|
|
14
15
|
}
|
|
15
|
-
export interface FindOpts {
|
|
16
|
-
select?:
|
|
17
|
-
exclude?:
|
|
16
|
+
export interface FindOpts<T = any> {
|
|
17
|
+
select?: KeysMatching<T, any>[];
|
|
18
|
+
exclude?: KeysMatching<T, any>[];
|
|
18
19
|
transform?: Function;
|
|
19
20
|
}
|
|
@@ -5,58 +5,59 @@
|
|
|
5
5
|
* to validate and query data objects.
|
|
6
6
|
*/
|
|
7
7
|
import { Arg } from "./arg.js";
|
|
8
|
+
import { PartialOfType, PartialPickMatching } from "./utils.js";
|
|
8
9
|
/** Logical Operators */
|
|
9
|
-
export type LogicalOperators = {
|
|
10
|
+
export type LogicalOperators<T = any> = {
|
|
10
11
|
/**
|
|
11
12
|
* Recursively applies multiple conditions, all of which must evaluate to true.
|
|
12
13
|
* Can include other operators such as $gt, $exists, or nested $and/$or conditions.
|
|
13
14
|
*/
|
|
14
|
-
$and?: Array<SearchOptions
|
|
15
|
+
$and?: Array<SearchOptions<T>>;
|
|
15
16
|
/**
|
|
16
17
|
* Recursively applies multiple conditions, at least one of which must evaluate to true.
|
|
17
18
|
* Can include other operators such as $lt, $type, or nested $and/$or conditions.
|
|
18
19
|
*/
|
|
19
|
-
$or?: Array<SearchOptions
|
|
20
|
+
$or?: Array<SearchOptions<T>>;
|
|
20
21
|
/**
|
|
21
22
|
* Negates a single condition.
|
|
22
23
|
* Can include any other operator as its value.
|
|
23
24
|
*/
|
|
24
|
-
$not?: SearchOptions
|
|
25
|
+
$not?: SearchOptions<T>;
|
|
25
26
|
};
|
|
26
27
|
/** Comparison Operators */
|
|
27
|
-
export type ComparisonOperators = {
|
|
28
|
-
$gt?:
|
|
29
|
-
$lt?:
|
|
30
|
-
$gte?:
|
|
31
|
-
$lte?:
|
|
32
|
-
$
|
|
33
|
-
$
|
|
34
|
-
$
|
|
28
|
+
export type ComparisonOperators<T = any> = {
|
|
29
|
+
$gt?: PartialOfType<T, number>;
|
|
30
|
+
$lt?: PartialOfType<T, number>;
|
|
31
|
+
$gte?: PartialOfType<T, number>;
|
|
32
|
+
$lte?: PartialOfType<T, number>;
|
|
33
|
+
$between?: PartialOfType<T, [number, number], number>;
|
|
34
|
+
$in?: Partial<Record<keyof T, T[keyof T][]>>;
|
|
35
|
+
$nin?: Partial<Record<keyof T, T[keyof T][]>>;
|
|
35
36
|
};
|
|
36
37
|
/** Type and Existence Operators */
|
|
37
|
-
export type TypeAndExistenceOperators = {
|
|
38
|
-
$exists?:
|
|
39
|
-
$type?:
|
|
38
|
+
export type TypeAndExistenceOperators<T = any> = {
|
|
39
|
+
$exists?: PartialOfType<T, boolean, any>;
|
|
40
|
+
$type?: PartialOfType<T, string>;
|
|
40
41
|
};
|
|
41
42
|
/** Array Operators */
|
|
42
|
-
export type ArrayOperators = {
|
|
43
|
-
$arrinc?:
|
|
44
|
-
$arrincall?:
|
|
45
|
-
$size?:
|
|
43
|
+
export type ArrayOperators<T = any> = {
|
|
44
|
+
$arrinc?: PartialPickMatching<T, any[]>;
|
|
45
|
+
$arrincall?: PartialPickMatching<T, any[]>;
|
|
46
|
+
$size?: PartialOfType<T, number>;
|
|
46
47
|
};
|
|
47
48
|
/** String Operators */
|
|
48
|
-
export type StringOperators = {
|
|
49
|
-
$regex?:
|
|
50
|
-
$startsWith?:
|
|
51
|
-
$endsWith?:
|
|
49
|
+
export type StringOperators<T = any> = {
|
|
50
|
+
$regex?: PartialOfType<T, RegExp, string>;
|
|
51
|
+
$startsWith?: PartialOfType<T, string>;
|
|
52
|
+
$endsWith?: PartialOfType<T, string>;
|
|
52
53
|
};
|
|
53
54
|
/** Other Operators */
|
|
54
|
-
export type OtherOperators = {
|
|
55
|
-
$subset?: Record<
|
|
55
|
+
export type OtherOperators<T = any> = {
|
|
56
|
+
$subset?: Partial<Record<keyof T, T[keyof T]>>;
|
|
56
57
|
};
|
|
57
58
|
/** Predefined Search Operators */
|
|
58
|
-
export type PredefinedSearchOperators = LogicalOperators & ComparisonOperators & TypeAndExistenceOperators & ArrayOperators & StringOperators & OtherOperators
|
|
59
|
+
export type PredefinedSearchOperators<T = any> = LogicalOperators<T> & ComparisonOperators<T> & TypeAndExistenceOperators<T> & ArrayOperators<T> & StringOperators<T> & OtherOperators<T>;
|
|
59
60
|
/**
|
|
60
61
|
* SearchOptions can be either a function or an object with predefined operators.
|
|
61
62
|
*/
|
|
62
|
-
export type SearchOptions = PredefinedSearchOperators & Arg
|
|
63
|
+
export type SearchOptions<T = any> = PredefinedSearchOperators<T> & Arg<T>;
|
package/dist/types/updater.d.ts
CHANGED
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Predefined type for updating data.
|
|
3
3
|
*/
|
|
4
|
+
import { Arg } from "./arg.js";
|
|
5
|
+
import { PartialOfType } from "./utils.js";
|
|
4
6
|
/** Arrays */
|
|
5
|
-
export type ArrayUpdater = {
|
|
6
|
-
$push?: any
|
|
7
|
+
export type ArrayUpdater<T = any> = {
|
|
8
|
+
$push?: PartialOfType<T, any>;
|
|
7
9
|
/** Pushes items into an array and removes duplicates */
|
|
8
|
-
$pushset?: any
|
|
9
|
-
$pull?: any
|
|
10
|
-
$pullall?: any
|
|
10
|
+
$pushset?: PartialOfType<T, any>;
|
|
11
|
+
$pull?: PartialOfType<T, any>;
|
|
12
|
+
$pullall?: PartialOfType<T, any>;
|
|
11
13
|
};
|
|
12
14
|
/** Objects */
|
|
13
|
-
export type ObjectUpdater = {
|
|
14
|
-
$merge?: any
|
|
15
|
+
export type ObjectUpdater<T = any> = {
|
|
16
|
+
$merge?: PartialOfType<T, any[]>;
|
|
15
17
|
};
|
|
16
18
|
/** Values */
|
|
17
|
-
export type ValueUpdater = {
|
|
18
|
-
$
|
|
19
|
-
$
|
|
20
|
-
$
|
|
21
|
-
$
|
|
22
|
-
$rename?: any;
|
|
23
|
-
};
|
|
24
|
-
export type UpdaterArg = ArrayUpdater & ObjectUpdater & ValueUpdater & {
|
|
25
|
-
[key: string]: any;
|
|
19
|
+
export type ValueUpdater<T = any> = {
|
|
20
|
+
$inc?: PartialOfType<T, number>;
|
|
21
|
+
$dec?: PartialOfType<T, number>;
|
|
22
|
+
$unset?: PartialOfType<T, any>;
|
|
23
|
+
$rename?: PartialOfType<T, any>;
|
|
26
24
|
};
|
|
25
|
+
export type UpdaterArg<T = any> = ArrayUpdater<T> & ObjectUpdater<T> & ValueUpdater<T> & Arg<T>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type KeysMatching<T, V, C = V> = {
|
|
2
|
+
[K in keyof T]-?: T[K] extends C ? K : never;
|
|
3
|
+
}[keyof T];
|
|
4
|
+
export type PartialOfType<T, V, C = V> = Partial<Record<KeysMatching<T, V, C>, V>>;
|
|
5
|
+
export type PartialPickMatching<T, V, C = V> = Partial<Pick<T, KeysMatching<T, V, C>>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/valthera.d.ts
CHANGED
|
@@ -9,15 +9,15 @@ export interface ValtheraCompatible {
|
|
|
9
9
|
getCollections(): Promise<string[]>;
|
|
10
10
|
checkCollection(collection: string): Promise<boolean>;
|
|
11
11
|
issetCollection(collection: string): Promise<boolean>;
|
|
12
|
-
add<T = Data>(collection: string, data: Arg
|
|
13
|
-
find<T = Data>(collection: string, search: Search
|
|
14
|
-
findOne<T = Data>(collection: string, search: Search
|
|
15
|
-
update(collection: string, search: Search
|
|
16
|
-
updateOne(collection: string, search: Search
|
|
17
|
-
remove(collection: string, search: Search
|
|
18
|
-
removeOne(collection: string, search: Search
|
|
12
|
+
add<T = Data>(collection: string, data: Arg<T>, id_gen?: boolean): Promise<T>;
|
|
13
|
+
find<T = Data>(collection: string, search: Search<T>, context?: VContext, options?: DbFindOpts<T>, findOpts?: FindOpts<T>): Promise<T[]>;
|
|
14
|
+
findOne<T = Data>(collection: string, search: Search<T>, context?: VContext, findOpts?: FindOpts<T>): Promise<T | null>;
|
|
15
|
+
update<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
16
|
+
updateOne<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, context?: VContext): Promise<boolean>;
|
|
17
|
+
remove<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
18
|
+
removeOne<T = Data>(collection: string, search: Search<T>, context?: VContext): Promise<boolean>;
|
|
19
19
|
removeCollection(collection: string): Promise<boolean>;
|
|
20
|
-
updateOneOrAdd(collection: string, search: Search
|
|
20
|
+
updateOneOrAdd<T = Data>(collection: string, search: Search<T>, updater: Updater<T>, add_arg?: Arg<T>, context?: VContext, id_gen?: boolean): Promise<boolean>;
|
|
21
21
|
}
|
|
22
22
|
export interface ValtheraCompatibleInternal {
|
|
23
23
|
c(config: VQuery): CollectionManager;
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.0.
|
|
1
|
+
export const version = "0.0.6";
|