@wxn0brp/db-core 0.11.1-alpha.0 → 0.11.1-alpha.2
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/base/actions.d.ts +1 -0
- package/dist/base/actions.js +1 -0
- package/dist/db/multiStorage.d.ts +1 -0
- package/dist/db/multiStorage.js +3 -0
- package/dist/db/routedStorage.d.ts +1 -0
- package/dist/db/routedStorage.js +7 -0
- package/dist/db/valthera.d.ts +1 -0
- package/dist/db/valthera.js +11 -0
- package/dist/types/action.d.ts +1 -0
- package/dist/types/fileCpu.d.ts +5 -5
- 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/base/actions.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare abstract class ActionsBase implements ActionsBaseInterface {
|
|
|
6
6
|
numberId: boolean;
|
|
7
7
|
smartExecutor: boolean;
|
|
8
8
|
init(...args: any[]): Promise<void>;
|
|
9
|
+
close(...args: any[]): Promise<void>;
|
|
9
10
|
abstract getCollections(): Promise<string[]>;
|
|
10
11
|
abstract ensureCollection(collection: string): Promise<boolean>;
|
|
11
12
|
abstract issetCollection(collection: string): Promise<boolean>;
|
package/dist/base/actions.js
CHANGED
|
@@ -5,6 +5,7 @@ export declare class MultiBackend extends ActionsBase {
|
|
|
5
5
|
primaryBackend: ActionsBase;
|
|
6
6
|
constructor(backends: ActionsBase[], primaryIndex?: number);
|
|
7
7
|
init(...args: any[]): Promise<void>;
|
|
8
|
+
close(...args: any[]): Promise<void>;
|
|
8
9
|
add(config: VQueryT.Add): Promise<import("../types/data.js").DataInternal>;
|
|
9
10
|
find(config: VQueryT.Find): Promise<import("../types/data.js").DataInternal[]>;
|
|
10
11
|
findOne(config: VQueryT.FindOne): Promise<import("../types/data.js").DataInternal>;
|
package/dist/db/multiStorage.js
CHANGED
|
@@ -10,6 +10,9 @@ export class MultiBackend extends ActionsBase {
|
|
|
10
10
|
async init(...args) {
|
|
11
11
|
await Promise.all(this.backends.map(b => b.init?.(...args)));
|
|
12
12
|
}
|
|
13
|
+
async close(...args) {
|
|
14
|
+
await Promise.all(this.backends.map(b => b.close(...args)));
|
|
15
|
+
}
|
|
13
16
|
async add(config) {
|
|
14
17
|
return await this.primaryBackend.add({ ...config });
|
|
15
18
|
}
|
|
@@ -13,6 +13,7 @@ export declare class RoutedStorage extends ActionsBase {
|
|
|
13
13
|
_withAll<T>(config: VQuery | string, fn: (b: ActionsBase) => Promise<T>, gather?: boolean): Promise<T>;
|
|
14
14
|
_withFirst<T>(config: VQuery | string, fn: (b: ActionsBase) => Promise<T>): Promise<T>;
|
|
15
15
|
init(...args: any[]): Promise<void>;
|
|
16
|
+
close(...args: any[]): Promise<void>;
|
|
16
17
|
add(config: VQueryT.Add): Promise<import("../types/data.js").DataInternal>;
|
|
17
18
|
find(config: VQueryT.Find): Promise<import("../types/data.js").DataInternal[]>;
|
|
18
19
|
findOne(config: VQueryT.FindOne): Promise<import("../types/data.js").DataInternal>;
|
package/dist/db/routedStorage.js
CHANGED
|
@@ -41,6 +41,13 @@ export class RoutedStorage extends ActionsBase {
|
|
|
41
41
|
const all = new Set(this.rules.flatMap(r => r.backends));
|
|
42
42
|
await Promise.all(Array.from(all).map(b => b.init?.(...args)));
|
|
43
43
|
}
|
|
44
|
+
async close(...args) {
|
|
45
|
+
const all = new Set([
|
|
46
|
+
...this.rules.flatMap(r => r.backends),
|
|
47
|
+
...this.defaultBackend
|
|
48
|
+
]);
|
|
49
|
+
await Promise.all(Array.from(all).map(b => b.close(...args)));
|
|
50
|
+
}
|
|
44
51
|
async add(config) {
|
|
45
52
|
const res = await this._withFirst(config, b => b.add(config));
|
|
46
53
|
await this._withAll({ ...config, data: res }, b => b.add({ ...config, data: res }));
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export declare class ValtheraClass implements ValtheraCompatible {
|
|
|
40
40
|
version: string;
|
|
41
41
|
constructor(options: DbOpts);
|
|
42
42
|
init(...args: any[]): Promise<any>;
|
|
43
|
+
close(...args: any[]): Promise<any>;
|
|
43
44
|
execute<T>(name: keyof ValtheraCompatible, query: VQuery<any> | string): Promise<T>;
|
|
44
45
|
/**
|
|
45
46
|
* Create a new instance of a Collection class.
|
package/dist/db/valthera.js
CHANGED
|
@@ -30,6 +30,17 @@ export class ValtheraClass {
|
|
|
30
30
|
self.dbAction._inited = true;
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
|
+
async close(...args) {
|
|
34
|
+
if (!this.dbAction._inited)
|
|
35
|
+
return;
|
|
36
|
+
const self = this;
|
|
37
|
+
return await this.executor.addOp(async () => {
|
|
38
|
+
if (!self.dbAction._inited)
|
|
39
|
+
return;
|
|
40
|
+
await self.dbAction.close(...args);
|
|
41
|
+
self.dbAction._inited = false;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
33
44
|
async execute(name, query) {
|
|
34
45
|
await this.init();
|
|
35
46
|
const result = await this.executor.addOp(this.dbAction[name].bind(this.dbAction), query, typeof query === "string" ? query : query.collection);
|
package/dist/types/action.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface ActionsBaseInterface {
|
|
|
4
4
|
_inited: boolean;
|
|
5
5
|
numberId: boolean;
|
|
6
6
|
init(...args: any[]): Promise<void>;
|
|
7
|
+
close(...args: any[]): Promise<void>;
|
|
7
8
|
getCollections(): Promise<string[]>;
|
|
8
9
|
ensureCollection(collection: string): Promise<boolean>;
|
|
9
10
|
issetCollection(collection: string): Promise<boolean>;
|
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/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-alpha.
|
|
1
|
+
export const version = "0.11.1-alpha.2";
|