@wxn0brp/db-core 0.11.0 → 0.11.1-alpha.1
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/README.md +18 -5
- package/dist/db/valthera.d.ts +20 -1
- package/dist/db/valthera.js +4 -2
- package/dist/types/arg.d.ts +2 -2
- package/dist/types/fileCpu.d.ts +5 -5
- package/dist/types/query.d.ts +43 -11
- package/dist/utils/action.d.ts +1 -1
- package/dist/utils/action.js +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
1
|
# @wxn0brp/db-core
|
|
2
2
|
|
|
3
|
-
Core
|
|
3
|
+
Core runtime for [ValtheraDB](https://github.com/wxn0brP/ValtheraDB). This package contains the shared database logic that the higher-level Valthera packages build on.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
It is usually not something you install directly unless you are:
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- building a custom storage adapter
|
|
8
|
+
- extending the lower-level database runtime
|
|
9
|
+
- working on Valthera itself
|
|
8
10
|
|
|
9
|
-
##
|
|
11
|
+
## Install
|
|
10
12
|
|
|
11
13
|
```bash
|
|
12
14
|
npm install @wxn0brp/db-core
|
|
13
15
|
```
|
|
14
16
|
|
|
17
|
+
## What It Provides
|
|
18
|
+
|
|
19
|
+
- collection and document primitives
|
|
20
|
+
- query and update operators
|
|
21
|
+
- relation handling
|
|
22
|
+
- shared types used by the Valthera packages
|
|
23
|
+
|
|
24
|
+
## Package Note
|
|
25
|
+
|
|
26
|
+
If you are building an application, you probably want `@wxn0brp/db` instead of this package. `db-core` is the internal foundation.
|
|
27
|
+
|
|
15
28
|
## Documentation
|
|
16
29
|
|
|
17
30
|
See [typedoc](https://wxn0brp.github.io/ValtheraDB-core/).
|
|
@@ -22,4 +35,4 @@ Contributions are welcome! Please submit pull requests or open issues on GitHub.
|
|
|
22
35
|
|
|
23
36
|
## License
|
|
24
37
|
|
|
25
|
-
|
|
38
|
+
MIT. See [LICENSE](LICENSE).
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -13,11 +13,30 @@ import { ValtheraCompatible } from "../types/valthera.js";
|
|
|
13
13
|
export declare class ValtheraClass implements ValtheraCompatible {
|
|
14
14
|
dbAction: ActionsBase;
|
|
15
15
|
executor: ExecutorInterface;
|
|
16
|
-
|
|
16
|
+
emitter: VEE<{
|
|
17
17
|
[K in keyof ValtheraCompatible]: (query: VQuery, result: Awaited<ReturnType<ValtheraCompatible[K]>>) => void;
|
|
18
18
|
} & {
|
|
19
19
|
"*": (name: keyof ValtheraCompatible, query: VQuery, result: any) => void;
|
|
20
20
|
}>;
|
|
21
|
+
/** @deprecated typo */
|
|
22
|
+
emiter: VEE<{
|
|
23
|
+
c: (query: VQuery, result: Collection<unknown>) => void;
|
|
24
|
+
getCollections: (query: VQuery, result: string[]) => void;
|
|
25
|
+
ensureCollection: (query: VQuery, result: boolean) => void;
|
|
26
|
+
issetCollection: (query: VQuery, result: boolean) => void;
|
|
27
|
+
add: (query: VQuery, result: unknown) => void;
|
|
28
|
+
find: (query: VQuery, result: unknown[]) => void;
|
|
29
|
+
findOne: (query: VQuery, result: unknown) => void;
|
|
30
|
+
update: (query: VQuery, result: unknown[]) => void;
|
|
31
|
+
updateOne: (query: VQuery, result: unknown) => void;
|
|
32
|
+
remove: (query: VQuery, result: unknown[]) => void;
|
|
33
|
+
removeOne: (query: VQuery, result: unknown) => void;
|
|
34
|
+
removeCollection: (query: VQuery, result: boolean) => void;
|
|
35
|
+
updateOneOrAdd: (query: VQuery, result: VQueryT.UpdateOneOrAddResult<unknown>) => void;
|
|
36
|
+
toggleOne: (query: VQuery, result: VQueryT.ToggleOneResult<unknown>) => void;
|
|
37
|
+
} & {
|
|
38
|
+
"*": (name: keyof ValtheraCompatible, query: VQuery, result: any) => void;
|
|
39
|
+
}>;
|
|
21
40
|
version: string;
|
|
22
41
|
constructor(options: DbOpts);
|
|
23
42
|
init(...args: any[]): Promise<any>;
|
package/dist/db/valthera.js
CHANGED
|
@@ -9,7 +9,9 @@ import { version } from "../version.js";
|
|
|
9
9
|
export class ValtheraClass {
|
|
10
10
|
dbAction;
|
|
11
11
|
executor;
|
|
12
|
-
|
|
12
|
+
emitter = new VEE();
|
|
13
|
+
/** @deprecated typo */
|
|
14
|
+
emiter = this.emitter;
|
|
13
15
|
version = version;
|
|
14
16
|
constructor(options) {
|
|
15
17
|
this.dbAction = options.dbAction;
|
|
@@ -31,7 +33,7 @@ export class ValtheraClass {
|
|
|
31
33
|
async execute(name, query) {
|
|
32
34
|
await this.init();
|
|
33
35
|
const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction), query, typeof query === "string" ? query : query.collection);
|
|
34
|
-
this.
|
|
36
|
+
this.emitter.emit(name, query, result);
|
|
35
37
|
return result;
|
|
36
38
|
}
|
|
37
39
|
/**
|
package/dist/types/arg.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export type Arg<T = any> = {
|
|
|
7
7
|
} & Record<string, any>;
|
|
8
8
|
export type SearchFunc<T = any> = (data: T, context: VContext) => boolean;
|
|
9
9
|
export type UpdaterFunc<T = any> = (data: T, context: VContext) => Data | void;
|
|
10
|
-
export type Search<T = any> = SearchOptions<T> | SearchFunc<T>;
|
|
11
|
-
export type Updater<T = any> = UpdaterArg<T> | UpdaterFunc<T>;
|
|
10
|
+
export type Search<T = any, AllowFn extends boolean = true> = AllowFn extends true ? SearchOptions<T> | SearchFunc<T> : SearchOptions<T>;
|
|
11
|
+
export type Updater<T = any, AllowFn extends boolean = true> = AllowFn extends true ? UpdaterArg<T> | UpdaterFunc<T> : UpdaterArg<T>;
|
package/dist/types/fileCpu.d.ts
CHANGED
|
@@ -5,27 +5,27 @@ export interface FileCpu {
|
|
|
5
5
|
* Asynchronously adds an entry to a file.
|
|
6
6
|
* @returns A promise resolving to `void`.
|
|
7
7
|
*/
|
|
8
|
-
add(file: string, config: VQueryT.Add): Promise<void>;
|
|
8
|
+
add(file: string, config: VQueryT.Add, opts?: any): Promise<void>;
|
|
9
9
|
/**
|
|
10
10
|
* Asynchronously finds multiple entries in a file based on search criteria.
|
|
11
11
|
* @returns A promise resolving to an array of found entries, or `false` if the file does not exist.
|
|
12
12
|
*/
|
|
13
|
-
find(file: string, config: VQueryT.Find): Promise<DataInternal[]>;
|
|
13
|
+
find(file: string, config: VQueryT.Find, opts?: any): Promise<DataInternal[]>;
|
|
14
14
|
/**
|
|
15
15
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
16
16
|
* @returns A promise resolving to the found entry or `false` if not found.
|
|
17
17
|
*/
|
|
18
|
-
findOne(file: string, config: VQueryT.FindOne): Promise<DataInternal | false>;
|
|
18
|
+
findOne(file: string, config: VQueryT.FindOne, opts?: any): Promise<DataInternal | false>;
|
|
19
19
|
/**
|
|
20
20
|
* Asynchronously removes entries from a file based on search criteria.
|
|
21
21
|
* @param one If `true`, removes only the first matching entry.
|
|
22
22
|
* @returns A promise resolving to `true` if at least one entry was removed, otherwise `false`.
|
|
23
23
|
*/
|
|
24
|
-
remove(file: string, config: VQueryT.Remove, one: boolean): Promise<DataInternal[]>;
|
|
24
|
+
remove(file: string, config: VQueryT.Remove, one: boolean, opts?: any): Promise<DataInternal[]>;
|
|
25
25
|
/**
|
|
26
26
|
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
27
27
|
* @param one If `true`, updates only the first matching entry.
|
|
28
28
|
* @returns A promise resolving to `true` if at least one entry was updated, otherwise `false`.
|
|
29
29
|
*/
|
|
30
|
-
update(file: string, config: VQueryT.Update, one: boolean): Promise<DataInternal[]>;
|
|
30
|
+
update(file: string, config: VQueryT.Update, one: boolean, opts?: any): Promise<DataInternal[]>;
|
|
31
31
|
}
|
package/dist/types/query.d.ts
CHANGED
|
@@ -13,28 +13,60 @@ import { VContext } from "./types.js";
|
|
|
13
13
|
*/
|
|
14
14
|
export interface VQuery_Control {
|
|
15
15
|
}
|
|
16
|
-
export interface VQuery<T = Data> {
|
|
16
|
+
export interface VQuery<T = Data, AllowFn extends boolean = true> {
|
|
17
17
|
/** logic path, dir or file, depends on context */
|
|
18
18
|
collection?: string;
|
|
19
|
-
search?: Search<T>;
|
|
19
|
+
search?: Search<T, AllowFn>;
|
|
20
20
|
context?: VContext;
|
|
21
21
|
dbFindOpts?: DbFindOpts<T>;
|
|
22
22
|
findOpts?: FindOpts<T>;
|
|
23
23
|
data?: Arg<T>;
|
|
24
24
|
id_gen?: boolean;
|
|
25
25
|
add_arg?: Arg<T>;
|
|
26
|
-
updater?: Updater<T>;
|
|
26
|
+
updater?: Updater<T, AllowFn>;
|
|
27
27
|
control?: VQuery_Control;
|
|
28
28
|
}
|
|
29
29
|
export declare namespace VQueryT {
|
|
30
|
-
type QueryBase<T = Data> =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
type
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
type QueryBase<T = Data> = {
|
|
31
|
+
collection: string;
|
|
32
|
+
control?: VQuery_Control;
|
|
33
|
+
};
|
|
34
|
+
type Add<T = Data> = QueryBase<T> & {
|
|
35
|
+
data: Arg<T>;
|
|
36
|
+
id_gen?: boolean;
|
|
37
|
+
};
|
|
38
|
+
type Find<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
39
|
+
search?: Search<T, AllowFn>;
|
|
40
|
+
findOpts?: FindOpts<T>;
|
|
41
|
+
dbFindOpts?: DbFindOpts<T>;
|
|
42
|
+
context?: VContext;
|
|
43
|
+
};
|
|
44
|
+
type FindOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
45
|
+
search: Search<T, AllowFn>;
|
|
46
|
+
findOpts?: FindOpts<T>;
|
|
47
|
+
context?: VContext;
|
|
48
|
+
};
|
|
49
|
+
type Update<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
50
|
+
search: Search<T, AllowFn>;
|
|
51
|
+
updater: Updater<T, AllowFn>;
|
|
52
|
+
context?: VContext;
|
|
53
|
+
};
|
|
54
|
+
type Remove<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
55
|
+
search: Search<T, AllowFn>;
|
|
56
|
+
context?: VContext;
|
|
57
|
+
};
|
|
58
|
+
type UpdateOneOrAdd<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
59
|
+
search: Search<T, AllowFn>;
|
|
60
|
+
updater: Updater<T, AllowFn>;
|
|
61
|
+
add_arg?: Arg<T>;
|
|
62
|
+
id_gen?: boolean;
|
|
63
|
+
context?: VContext;
|
|
64
|
+
};
|
|
65
|
+
type ToggleOne<T = Data, AllowFn extends boolean = true> = QueryBase<T> & {
|
|
66
|
+
search: Search<T, AllowFn>;
|
|
67
|
+
data: Arg<T>;
|
|
68
|
+
context?: VContext;
|
|
69
|
+
};
|
|
38
70
|
interface UpdateOneOrAddResult<T> {
|
|
39
71
|
data: T;
|
|
40
72
|
type: "added" | "updated";
|
package/dist/utils/action.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { Data } from "../types/data.js";
|
|
2
2
|
import { FileCpu } from "../types/fileCpu.js";
|
|
3
3
|
import { VQueryT } from "../types/query.js";
|
|
4
|
-
export declare function findUtil(query: VQueryT.Find, fileCpuOrData: FileCpu | Object[], files: string[]): Promise<Data[]>;
|
|
4
|
+
export declare function findUtil(query: VQueryT.Find, fileCpuOrData: FileCpu | Object[], files: string[], fileCpuOpts?: any): Promise<Data[]>;
|
package/dist/utils/action.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compareSafe } from "./compare.js";
|
|
2
|
-
export async function findUtil(query, fileCpuOrData, files) {
|
|
2
|
+
export async function findUtil(query, fileCpuOrData, files, fileCpuOpts) {
|
|
3
3
|
const { dbFindOpts = {} } = query;
|
|
4
4
|
const { reverse = false, offset = 0, limit = -1, sortBy, sortAsc = true, min, max, avg, groupBy, count, } = dbFindOpts;
|
|
5
5
|
const needsAllData = min || max || avg || groupBy || count || sortBy;
|
|
@@ -18,7 +18,7 @@ export async function findUtil(query, fileCpuOrData, files) {
|
|
|
18
18
|
else {
|
|
19
19
|
const filesToProcess = reverse && !sortBy ? [...files].reverse() : files;
|
|
20
20
|
for (const f of filesToProcess) {
|
|
21
|
-
let entries = await fileCpuOrData.find(f, query);
|
|
21
|
+
let entries = await fileCpuOrData.find(f, query, fileCpuOpts);
|
|
22
22
|
if (reverse && !sortBy)
|
|
23
23
|
entries.reverse();
|
|
24
24
|
if (needsAllData) {
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.11.
|
|
1
|
+
export const version = "0.11.1-alpha.1";
|