@wxn0brp/db-core 0.9.0 → 0.10.0-alpha.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/dist/base/actions.d.ts +13 -13
- package/dist/base/actions.js +2 -0
- package/dist/base/custom.d.ts +8 -8
- package/dist/base/custom.js +18 -18
- package/dist/customFileCpu.d.ts +6 -8
- package/dist/customFileCpu.js +15 -11
- package/dist/db/memory.d.ts +3 -4
- package/dist/db/memory.js +3 -3
- package/dist/db/multiStorage.d.ts +11 -11
- package/dist/db/multiStorage.js +6 -6
- package/dist/db/routedStorage.d.ts +15 -15
- package/dist/db/routedStorage.js +6 -6
- package/dist/types/action.d.ts +13 -13
- package/dist/types/fileCpu.d.ts +7 -26
- package/dist/types/query.d.ts +1 -0
- package/dist/types/valthera.d.ts +10 -10
- package/dist/utils/action.js +2 -2
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/base/actions.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { ActionsBaseInterface } from "../types/action.js";
|
|
2
2
|
import { DataInternal } from "../types/data.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Query from "../types/query.js";
|
|
4
4
|
export declare abstract class ActionsBase implements ActionsBaseInterface {
|
|
5
5
|
_inited: boolean;
|
|
6
6
|
numberId: boolean;
|
|
7
7
|
init(...args: any[]): Promise<void>;
|
|
8
8
|
abstract getCollections(): Promise<string[]>;
|
|
9
|
-
abstract ensureCollection(
|
|
10
|
-
abstract issetCollection(
|
|
11
|
-
abstract
|
|
12
|
-
abstract
|
|
13
|
-
abstract
|
|
14
|
-
abstract
|
|
15
|
-
abstract
|
|
16
|
-
abstract
|
|
17
|
-
abstract
|
|
18
|
-
abstract
|
|
19
|
-
updateOneOrAdd(config:
|
|
20
|
-
toggleOne(config:
|
|
9
|
+
abstract ensureCollection(collection: string): Promise<boolean>;
|
|
10
|
+
abstract issetCollection(collection: string): Promise<boolean>;
|
|
11
|
+
abstract removeCollection(collection: string): Promise<boolean>;
|
|
12
|
+
abstract add(config: Query.AddQuery): Promise<DataInternal>;
|
|
13
|
+
abstract find(config: Query.FindQuery): Promise<DataInternal[]>;
|
|
14
|
+
abstract findOne(config: Query.FindOneQuery): Promise<DataInternal | null>;
|
|
15
|
+
abstract update(config: Query.UpdateQuery): Promise<DataInternal[]>;
|
|
16
|
+
abstract updateOne(config: Query.UpdateQuery): Promise<DataInternal | null>;
|
|
17
|
+
abstract remove(config: Query.RemoveQuery): Promise<DataInternal[]>;
|
|
18
|
+
abstract removeOne(config: Query.RemoveQuery): Promise<DataInternal | null>;
|
|
19
|
+
updateOneOrAdd(config: Query.UpdateOneOrAddQuery): Promise<Query.UpdateOneOrAddResult<DataInternal>>;
|
|
20
|
+
toggleOne(config: Query.ToggleOneQuery): Promise<Query.ToggleOneResult<DataInternal>>;
|
|
21
21
|
}
|
package/dist/base/actions.js
CHANGED
|
@@ -10,6 +10,7 @@ export class ActionsBase {
|
|
|
10
10
|
data: res,
|
|
11
11
|
type: "updated"
|
|
12
12
|
};
|
|
13
|
+
// transform UpdateOneQuery to AddQuery
|
|
13
14
|
setDataForUpdateOneOrAdd(config);
|
|
14
15
|
return {
|
|
15
16
|
data: await this.add(config),
|
|
@@ -23,6 +24,7 @@ export class ActionsBase {
|
|
|
23
24
|
data: res,
|
|
24
25
|
type: "removed"
|
|
25
26
|
};
|
|
27
|
+
// transform ToggleOneQuery to AddQuery
|
|
26
28
|
setDataForToggleOne(config);
|
|
27
29
|
return {
|
|
28
30
|
data: await this.add(config),
|
package/dist/base/custom.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomFileCpu } from "../customFileCpu.js";
|
|
2
2
|
import { Data } from "../types/data.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Query from "../types/query.js";
|
|
4
4
|
import { ActionsBase } from "./actions.js";
|
|
5
5
|
export declare abstract class CustomActionsBase extends ActionsBase {
|
|
6
6
|
fileCpu: CustomFileCpu;
|
|
@@ -8,29 +8,29 @@ export declare abstract class CustomActionsBase extends ActionsBase {
|
|
|
8
8
|
/**
|
|
9
9
|
* Add a new entry to the specified database.
|
|
10
10
|
*/
|
|
11
|
-
add(query:
|
|
11
|
+
add(query: Query.AddQuery): Promise<import("../types/arg.js").Arg<Data>>;
|
|
12
12
|
/**
|
|
13
13
|
* Find entries in the specified database based on search criteria.
|
|
14
14
|
*/
|
|
15
|
-
find(query:
|
|
15
|
+
find(query: Query.FindQuery): Promise<Data[]>;
|
|
16
16
|
/**
|
|
17
17
|
* Find the first matching entry in the specified database based on search criteria.
|
|
18
18
|
*/
|
|
19
|
-
findOne(
|
|
19
|
+
findOne(query: Query.FindOneQuery): Promise<Data>;
|
|
20
20
|
/**
|
|
21
21
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
22
22
|
*/
|
|
23
|
-
update(
|
|
23
|
+
update(query: Query.UpdateQuery): Promise<Data[]>;
|
|
24
24
|
/**
|
|
25
25
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
26
26
|
*/
|
|
27
|
-
updateOne(
|
|
27
|
+
updateOne(query: Query.UpdateQuery): Promise<Data>;
|
|
28
28
|
/**
|
|
29
29
|
* Remove entries from the specified database based on search criteria.
|
|
30
30
|
*/
|
|
31
|
-
remove(
|
|
31
|
+
remove(query: Query.RemoveQuery): Promise<Data[]>;
|
|
32
32
|
/**
|
|
33
33
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
34
34
|
*/
|
|
35
|
-
removeOne(
|
|
35
|
+
removeOne(query: Query.RemoveQuery): Promise<Data>;
|
|
36
36
|
}
|
package/dist/base/custom.js
CHANGED
|
@@ -10,56 +10,56 @@ export class CustomActionsBase extends ActionsBase {
|
|
|
10
10
|
* Add a new entry to the specified database.
|
|
11
11
|
*/
|
|
12
12
|
async add(query) {
|
|
13
|
-
await this.ensureCollection(query);
|
|
13
|
+
await this.ensureCollection(query.collection);
|
|
14
14
|
await addId(query, this);
|
|
15
15
|
const { collection, data } = query;
|
|
16
|
-
await this.fileCpu.add(collection, data);
|
|
16
|
+
await this.fileCpu.add({ collection, data });
|
|
17
17
|
return data;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
20
|
* Find entries in the specified database based on search criteria.
|
|
21
21
|
*/
|
|
22
22
|
async find(query) {
|
|
23
|
-
await this.ensureCollection(query);
|
|
23
|
+
await this.ensureCollection(query.collection);
|
|
24
24
|
const data = await findUtil(query, this.fileCpu, [query.collection]);
|
|
25
25
|
return data;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Find the first matching entry in the specified database based on search criteria.
|
|
29
29
|
*/
|
|
30
|
-
async findOne(
|
|
31
|
-
await this.ensureCollection(
|
|
32
|
-
let data = await this.fileCpu.findOne(
|
|
30
|
+
async findOne(query) {
|
|
31
|
+
await this.ensureCollection(query.collection);
|
|
32
|
+
let data = await this.fileCpu.findOne(query);
|
|
33
33
|
return data || null;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Update entries in the specified database based on search criteria and an updater function or object.
|
|
37
37
|
*/
|
|
38
|
-
async update(
|
|
39
|
-
await this.ensureCollection(
|
|
40
|
-
return await this.fileCpu.update(
|
|
38
|
+
async update(query) {
|
|
39
|
+
await this.ensureCollection(query.collection);
|
|
40
|
+
return await this.fileCpu.update(query, false);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Update the first matching entry in the specified database based on search criteria and an updater function or object.
|
|
44
44
|
*/
|
|
45
|
-
async updateOne(
|
|
46
|
-
await this.ensureCollection(
|
|
47
|
-
const res = await this.fileCpu.update(
|
|
45
|
+
async updateOne(query) {
|
|
46
|
+
await this.ensureCollection(query.collection);
|
|
47
|
+
const res = await this.fileCpu.update(query, true);
|
|
48
48
|
return res.length ? res[0] : null;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* Remove entries from the specified database based on search criteria.
|
|
52
52
|
*/
|
|
53
|
-
async remove(
|
|
54
|
-
await this.ensureCollection(
|
|
55
|
-
return await this.fileCpu.remove(
|
|
53
|
+
async remove(query) {
|
|
54
|
+
await this.ensureCollection(query.collection);
|
|
55
|
+
return await this.fileCpu.remove(query, false);
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Remove the first matching entry from the specified database based on search criteria.
|
|
59
59
|
*/
|
|
60
|
-
async removeOne(
|
|
61
|
-
await this.ensureCollection(
|
|
62
|
-
const res = await this.fileCpu.remove(
|
|
60
|
+
async removeOne(query) {
|
|
61
|
+
await this.ensureCollection(query.collection);
|
|
62
|
+
const res = await this.fileCpu.remove(query, true);
|
|
63
63
|
return res.length ? res[0] : null;
|
|
64
64
|
}
|
|
65
65
|
}
|
package/dist/customFileCpu.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { Search, Updater } from "./types/arg.js";
|
|
2
1
|
import { Data } from "./types/data.js";
|
|
3
2
|
import { FileCpu } from "./types/fileCpu.js";
|
|
4
|
-
import
|
|
5
|
-
import { VContext } from "./types/types.js";
|
|
3
|
+
import * as Query from "./types/query.js";
|
|
6
4
|
export type WriteFile = (file: string, data: any[]) => Promise<void>;
|
|
7
5
|
export type ReadFile = (file: string) => Promise<any[]>;
|
|
8
6
|
export declare function pathRepair(path: string): string;
|
|
@@ -10,9 +8,9 @@ export declare class CustomFileCpu implements FileCpu {
|
|
|
10
8
|
_readFile: ReadFile;
|
|
11
9
|
_writeFile: WriteFile;
|
|
12
10
|
constructor(readFile: ReadFile, writeFile: WriteFile);
|
|
13
|
-
add(
|
|
14
|
-
find(
|
|
15
|
-
findOne(
|
|
16
|
-
remove(
|
|
17
|
-
update(
|
|
11
|
+
add(config: Query.AddQuery): Promise<void>;
|
|
12
|
+
find(config: Query.FindQuery): Promise<Data[]>;
|
|
13
|
+
findOne(config: Query.FindOneQuery): Promise<Data | false>;
|
|
14
|
+
remove(config: Query.RemoveQuery, one: boolean): Promise<Data[]>;
|
|
15
|
+
update(config: Query.UpdateQuery, one: boolean): Promise<Data[]>;
|
|
18
16
|
}
|
package/dist/customFileCpu.js
CHANGED
|
@@ -11,32 +11,35 @@ export class CustomFileCpu {
|
|
|
11
11
|
this._readFile = readFile;
|
|
12
12
|
this._writeFile = writeFile;
|
|
13
13
|
}
|
|
14
|
-
async add(
|
|
15
|
-
file = pathRepair(
|
|
14
|
+
async add(config) {
|
|
15
|
+
const file = pathRepair(config.collection);
|
|
16
16
|
let entries = await this._readFile(file);
|
|
17
|
-
entries.push(data);
|
|
17
|
+
entries.push(config.data);
|
|
18
18
|
await this._writeFile(file, entries);
|
|
19
19
|
}
|
|
20
|
-
async find(
|
|
21
|
-
file = pathRepair(
|
|
20
|
+
async find(config) {
|
|
21
|
+
const file = pathRepair(config.collection);
|
|
22
22
|
const entries = await this._readFile(file);
|
|
23
|
+
const { search, context = {}, findOpts = {} } = config;
|
|
23
24
|
const results = entries.filter(entry => typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search));
|
|
24
25
|
return results.length ?
|
|
25
26
|
results.map(res => updateFindObject(res, findOpts)) :
|
|
26
27
|
[];
|
|
27
28
|
}
|
|
28
|
-
async findOne(
|
|
29
|
-
file = pathRepair(
|
|
29
|
+
async findOne(config) {
|
|
30
|
+
const file = pathRepair(config.collection);
|
|
30
31
|
const entries = await this._readFile(file);
|
|
32
|
+
const { search, context = {}, findOpts = {} } = config;
|
|
31
33
|
const result = entries.find(entry => typeof search === "function" ? search(entry, context) : hasFieldsAdvanced(entry, search));
|
|
32
34
|
return result ?
|
|
33
35
|
updateFindObject(result, findOpts) :
|
|
34
36
|
false;
|
|
35
37
|
}
|
|
36
|
-
async remove(
|
|
37
|
-
file = pathRepair(
|
|
38
|
+
async remove(config, one) {
|
|
39
|
+
const file = pathRepair(config.collection);
|
|
38
40
|
let entries = await this._readFile(file);
|
|
39
41
|
const removed = [];
|
|
42
|
+
const { search, context = {} } = config;
|
|
40
43
|
entries = entries.filter(entry => {
|
|
41
44
|
if (removed.length && one)
|
|
42
45
|
return true;
|
|
@@ -51,10 +54,11 @@ export class CustomFileCpu {
|
|
|
51
54
|
await this._writeFile(file, entries);
|
|
52
55
|
return removed;
|
|
53
56
|
}
|
|
54
|
-
async update(
|
|
55
|
-
file = pathRepair(
|
|
57
|
+
async update(config, one) {
|
|
58
|
+
const file = pathRepair(config.collection);
|
|
56
59
|
let entries = await this._readFile(file);
|
|
57
60
|
const updated = [];
|
|
61
|
+
const { search, updater, context = {} } = config;
|
|
58
62
|
entries = entries.map(entry => {
|
|
59
63
|
if (updated.length && one)
|
|
60
64
|
return entry;
|
package/dist/db/memory.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { CustomActionsBase } from "../base/custom.js";
|
|
2
2
|
import { Collection } from "../helpers/collection.js";
|
|
3
3
|
import { Data } from "../types/data.js";
|
|
4
|
-
import { VQuery } from "../types/query.js";
|
|
5
4
|
import { ValtheraClass } from "./valthera.js";
|
|
6
5
|
export declare class MemoryAction extends CustomActionsBase {
|
|
7
6
|
memory: Map<string, any[]>;
|
|
@@ -9,9 +8,9 @@ export declare class MemoryAction extends CustomActionsBase {
|
|
|
9
8
|
_readMemory(key: string): any[];
|
|
10
9
|
_writeMemory(key: string, data: any[]): void;
|
|
11
10
|
getCollections(): Promise<string[]>;
|
|
12
|
-
ensureCollection(
|
|
13
|
-
issetCollection(
|
|
14
|
-
removeCollection(
|
|
11
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
12
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
13
|
+
removeCollection(collection: string): Promise<boolean>;
|
|
15
14
|
}
|
|
16
15
|
export declare class ValtheraMemory extends ValtheraClass {
|
|
17
16
|
constructor(...args: any[]);
|
package/dist/db/memory.js
CHANGED
|
@@ -21,16 +21,16 @@ export class MemoryAction extends CustomActionsBase {
|
|
|
21
21
|
const collections = Array.from(this.memory.keys());
|
|
22
22
|
return collections;
|
|
23
23
|
}
|
|
24
|
-
async ensureCollection(
|
|
24
|
+
async ensureCollection(collection) {
|
|
25
25
|
if (this.issetCollection(collection))
|
|
26
26
|
return;
|
|
27
27
|
this.memory.set(collection, []);
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
|
-
async issetCollection(
|
|
30
|
+
async issetCollection(collection) {
|
|
31
31
|
return this.memory.has(collection);
|
|
32
32
|
}
|
|
33
|
-
async removeCollection(
|
|
33
|
+
async removeCollection(collection) {
|
|
34
34
|
this.memory.delete(collection);
|
|
35
35
|
return true;
|
|
36
36
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { ActionsBase } from "../base/actions.js";
|
|
2
|
-
import
|
|
2
|
+
import * as Query from "../types/query.js";
|
|
3
3
|
export declare class MultiBackend extends ActionsBase {
|
|
4
4
|
backends: ActionsBase[];
|
|
5
5
|
primaryBackend: ActionsBase;
|
|
6
6
|
constructor(backends: ActionsBase[], primaryIndex?: number);
|
|
7
7
|
init(...args: any[]): Promise<void>;
|
|
8
|
-
add(config:
|
|
9
|
-
find(config:
|
|
10
|
-
findOne(config:
|
|
11
|
-
update(config:
|
|
12
|
-
updateOne(config:
|
|
13
|
-
remove(config:
|
|
14
|
-
removeOne(config:
|
|
15
|
-
ensureCollection(
|
|
16
|
-
issetCollection(
|
|
17
|
-
removeCollection(
|
|
8
|
+
add(config: Query.AddQuery): Promise<import("../types/data.js").DataInternal>;
|
|
9
|
+
find(config: Query.FindQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
10
|
+
findOne(config: Query.FindOneQuery): Promise<import("../types/data.js").DataInternal>;
|
|
11
|
+
update(config: Query.UpdateQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
12
|
+
updateOne(config: Query.UpdateQuery): Promise<import("../types/data.js").DataInternal>;
|
|
13
|
+
remove(config: Query.RemoveQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
14
|
+
removeOne(config: Query.RemoveQuery): Promise<import("../types/data.js").DataInternal>;
|
|
15
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
16
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
17
|
+
removeCollection(collection: string): Promise<boolean>;
|
|
18
18
|
getCollections(): Promise<string[]>;
|
|
19
19
|
}
|
package/dist/db/multiStorage.js
CHANGED
|
@@ -65,20 +65,20 @@ export class MultiBackend extends ActionsBase {
|
|
|
65
65
|
}
|
|
66
66
|
return null;
|
|
67
67
|
}
|
|
68
|
-
async ensureCollection(
|
|
69
|
-
const results = await Promise.all(this.backends.map(b => b.ensureCollection(
|
|
68
|
+
async ensureCollection(collection) {
|
|
69
|
+
const results = await Promise.all(this.backends.map(b => b.ensureCollection(collection)));
|
|
70
70
|
return results.some(Boolean);
|
|
71
71
|
}
|
|
72
|
-
async issetCollection(
|
|
72
|
+
async issetCollection(collection) {
|
|
73
73
|
for (const backend of this.backends) {
|
|
74
|
-
if (await backend.issetCollection(
|
|
74
|
+
if (await backend.issetCollection(collection)) {
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
return false;
|
|
79
79
|
}
|
|
80
|
-
async removeCollection(
|
|
81
|
-
const results = await Promise.all(this.backends.map(b => b.removeCollection(
|
|
80
|
+
async removeCollection(collection) {
|
|
81
|
+
const results = await Promise.all(this.backends.map(b => b.removeCollection(collection)));
|
|
82
82
|
return results.some(Boolean);
|
|
83
83
|
}
|
|
84
84
|
async getCollections() {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionsBase } from "../base/actions.js";
|
|
2
|
-
import
|
|
3
|
-
export type MatchRule = string | RegExp | ((
|
|
2
|
+
import * as Query from "../types/query.js";
|
|
3
|
+
export type MatchRule = string | RegExp | ((config: Query.VQuery) => boolean);
|
|
4
4
|
export interface RouteEntry {
|
|
5
5
|
match: MatchRule;
|
|
6
6
|
backends: ActionsBase[];
|
|
@@ -9,19 +9,19 @@ export declare class RoutedStorage extends ActionsBase {
|
|
|
9
9
|
rules: RouteEntry[];
|
|
10
10
|
defaultBackend: ActionsBase[];
|
|
11
11
|
constructor(rules: RouteEntry[], defaultBackend: ActionsBase | ActionsBase[]);
|
|
12
|
-
_matchBackends(config: VQuery): ActionsBase[];
|
|
13
|
-
_withAll<T>(config: VQuery, fn: (b: ActionsBase) => Promise<T>, gather?: boolean): Promise<T>;
|
|
14
|
-
_withFirst<T>(config: VQuery, fn: (b: ActionsBase) => Promise<T>): Promise<T>;
|
|
12
|
+
_matchBackends(config: Query.VQuery): ActionsBase[];
|
|
13
|
+
_withAll<T>(config: Query.VQuery | string, fn: (b: ActionsBase) => Promise<T>, gather?: boolean): Promise<T>;
|
|
14
|
+
_withFirst<T>(config: Query.VQuery | string, fn: (b: ActionsBase) => Promise<T>): Promise<T>;
|
|
15
15
|
init(...args: any[]): Promise<void>;
|
|
16
|
-
add(config:
|
|
17
|
-
find(config:
|
|
18
|
-
findOne(config:
|
|
19
|
-
update(config:
|
|
20
|
-
updateOne(config:
|
|
21
|
-
remove(config:
|
|
22
|
-
removeOne(config:
|
|
23
|
-
ensureCollection(
|
|
24
|
-
issetCollection(
|
|
25
|
-
removeCollection(
|
|
16
|
+
add(config: Query.AddQuery): Promise<import("../types/data.js").DataInternal>;
|
|
17
|
+
find(config: Query.FindQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
18
|
+
findOne(config: Query.FindOneQuery): Promise<import("../types/data.js").DataInternal>;
|
|
19
|
+
update(config: Query.UpdateQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
20
|
+
updateOne(config: Query.UpdateQuery): Promise<import("../types/data.js").DataInternal>;
|
|
21
|
+
remove(config: Query.RemoveQuery): Promise<import("../types/data.js").DataInternal[]>;
|
|
22
|
+
removeOne(config: Query.RemoveQuery): Promise<import("../types/data.js").DataInternal>;
|
|
23
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
24
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
25
|
+
removeCollection(collection: string): Promise<boolean>;
|
|
26
26
|
getCollections(): Promise<string[]>;
|
|
27
27
|
}
|
package/dist/db/routedStorage.js
CHANGED
|
@@ -64,14 +64,14 @@ export class RoutedStorage extends ActionsBase {
|
|
|
64
64
|
async removeOne(config) {
|
|
65
65
|
return this._withAll(config, b => b.removeOne(config), true);
|
|
66
66
|
}
|
|
67
|
-
async ensureCollection(
|
|
68
|
-
return this._withAll(
|
|
67
|
+
async ensureCollection(collection) {
|
|
68
|
+
return this._withAll(collection, b => b.ensureCollection(collection), true);
|
|
69
69
|
}
|
|
70
|
-
async issetCollection(
|
|
71
|
-
return this._withFirst(
|
|
70
|
+
async issetCollection(collection) {
|
|
71
|
+
return this._withFirst(collection, b => b.issetCollection(collection));
|
|
72
72
|
}
|
|
73
|
-
async removeCollection(
|
|
74
|
-
return this._withAll(
|
|
73
|
+
async removeCollection(collection) {
|
|
74
|
+
return this._withAll(collection, b => b.removeCollection(collection), true);
|
|
75
75
|
}
|
|
76
76
|
async getCollections() {
|
|
77
77
|
const all = await Promise.all(Array.from(new Set(this.rules.flatMap(r => r.backends)))
|
package/dist/types/action.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { DataInternal } from "./data.js";
|
|
2
|
-
import
|
|
2
|
+
import * as Query from "./query.js";
|
|
3
3
|
export interface ActionsBaseInterface {
|
|
4
4
|
_inited: boolean;
|
|
5
5
|
numberId: boolean;
|
|
6
6
|
init(...args: any[]): Promise<void>;
|
|
7
7
|
getCollections(): Promise<string[]>;
|
|
8
|
-
ensureCollection(
|
|
9
|
-
issetCollection(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
updateOneOrAdd(
|
|
19
|
-
toggleOne(
|
|
8
|
+
ensureCollection(collection: string): Promise<boolean>;
|
|
9
|
+
issetCollection(collection: string): Promise<boolean>;
|
|
10
|
+
removeCollection(collection: string): Promise<boolean>;
|
|
11
|
+
add(query: Query.AddQuery): Promise<DataInternal>;
|
|
12
|
+
find(query: Query.FindQuery): Promise<DataInternal[]>;
|
|
13
|
+
findOne(query: Query.FindOneQuery): Promise<DataInternal | null>;
|
|
14
|
+
update(query: Query.UpdateQuery): Promise<DataInternal[]>;
|
|
15
|
+
updateOne(query: Query.UpdateQuery): Promise<DataInternal | null>;
|
|
16
|
+
remove(query: Query.RemoveQuery): Promise<DataInternal[]>;
|
|
17
|
+
removeOne(query: Query.RemoveQuery): Promise<DataInternal | null>;
|
|
18
|
+
updateOneOrAdd(query: Query.UpdateOneOrAddQuery): Promise<Query.UpdateOneOrAddResult<DataInternal>>;
|
|
19
|
+
toggleOne(query: Query.ToggleOneQuery): Promise<Query.ToggleOneResult<DataInternal>>;
|
|
20
20
|
}
|
package/dist/types/fileCpu.d.ts
CHANGED
|
@@ -1,50 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { FindOpts } from "./options.js";
|
|
4
|
-
import { VContext } from "./types.js";
|
|
1
|
+
import { DataInternal } from "./data.js";
|
|
2
|
+
import * as Query from "./query.js";
|
|
5
3
|
export interface FileCpu {
|
|
6
4
|
/**
|
|
7
5
|
* Asynchronously adds an entry to a file.
|
|
8
|
-
* @param file The path to the file.
|
|
9
|
-
* @param data The data to add.
|
|
10
6
|
* @returns A promise resolving to `void`.
|
|
11
7
|
*/
|
|
12
|
-
add(
|
|
8
|
+
add(config: Query.AddQuery): Promise<void>;
|
|
13
9
|
/**
|
|
14
10
|
* Asynchronously finds multiple entries in a file based on search criteria.
|
|
15
|
-
* @param file The path to the file.
|
|
16
|
-
* @param search The search criteria.
|
|
17
|
-
* @param context Additional context for the search.
|
|
18
|
-
* @param findOpts Additional options for searching.
|
|
19
11
|
* @returns A promise resolving to an array of found entries, or `false` if the file does not exist.
|
|
20
12
|
*/
|
|
21
|
-
find(
|
|
13
|
+
find(config: Query.FindQuery): Promise<DataInternal[]>;
|
|
22
14
|
/**
|
|
23
15
|
* Asynchronously finds one entry in a file based on search criteria.
|
|
24
|
-
* @param file The path to the file.
|
|
25
|
-
* @param search The search criteria.
|
|
26
|
-
* @param context Additional context for the search.
|
|
27
|
-
* @param findOpts Additional options for searching.
|
|
28
16
|
* @returns A promise resolving to the found entry or `false` if not found.
|
|
29
17
|
*/
|
|
30
|
-
findOne(
|
|
18
|
+
findOne(config: Query.FindOneQuery): Promise<DataInternal | false>;
|
|
31
19
|
/**
|
|
32
20
|
* Asynchronously removes entries from a file based on search criteria.
|
|
33
|
-
* @param file The path to the file.
|
|
34
|
-
* @param search The search criteria.
|
|
35
|
-
* @param context Additional context for the operation.
|
|
36
21
|
* @param one If `true`, removes only the first matching entry.
|
|
37
22
|
* @returns A promise resolving to `true` if at least one entry was removed, otherwise `false`.
|
|
38
23
|
*/
|
|
39
|
-
remove(
|
|
24
|
+
remove(config: Query.RemoveQuery, one: boolean): Promise<DataInternal[]>;
|
|
40
25
|
/**
|
|
41
26
|
* Asynchronously updates entries in a file based on search criteria and an updater function or object.
|
|
42
|
-
* @param file The path to the file.
|
|
43
|
-
* @param search The search criteria.
|
|
44
|
-
* @param updater The updater function or object.
|
|
45
|
-
* @param context Additional context for the operation.
|
|
46
27
|
* @param one If `true`, updates only the first matching entry.
|
|
47
28
|
* @returns A promise resolving to `true` if at least one entry was updated, otherwise `false`.
|
|
48
29
|
*/
|
|
49
|
-
update(
|
|
30
|
+
update(config: Query.UpdateQuery, one: boolean): Promise<DataInternal[]>;
|
|
50
31
|
}
|
package/dist/types/query.d.ts
CHANGED
package/dist/types/valthera.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { Collection } from "../helpers/collection.js";
|
|
2
2
|
import { Data } from "./data.js";
|
|
3
|
-
import
|
|
3
|
+
import * as Query from "./query.js";
|
|
4
4
|
export interface ValtheraCompatible {
|
|
5
5
|
c<T = Data>(collection: string): Collection<T>;
|
|
6
6
|
getCollections(): Promise<string[]>;
|
|
7
7
|
ensureCollection(collection: string): Promise<boolean>;
|
|
8
8
|
issetCollection(collection: string): Promise<boolean>;
|
|
9
|
-
add<T = Data>(query: AddQuery<T>): Promise<T>;
|
|
10
|
-
find<T = Data>(query: FindQuery<T>): Promise<T[]>;
|
|
11
|
-
findOne<T = Data>(query: FindOneQuery<T>): Promise<T | null>;
|
|
12
|
-
update<T = Data>(query: UpdateQuery<T>): Promise<T[]>;
|
|
13
|
-
updateOne<T = Data>(query: UpdateQuery<T>): Promise<T | null>;
|
|
14
|
-
remove<T = Data>(query: RemoveQuery<T>): Promise<T[]>;
|
|
15
|
-
removeOne<T = Data>(query: RemoveQuery<T>): Promise<T | null>;
|
|
9
|
+
add<T = Data>(query: Query.AddQuery<T>): Promise<T>;
|
|
10
|
+
find<T = Data>(query: Query.FindQuery<T>): Promise<T[]>;
|
|
11
|
+
findOne<T = Data>(query: Query.FindOneQuery<T>): Promise<T | null>;
|
|
12
|
+
update<T = Data>(query: Query.UpdateQuery<T>): Promise<T[]>;
|
|
13
|
+
updateOne<T = Data>(query: Query.UpdateQuery<T>): Promise<T | null>;
|
|
14
|
+
remove<T = Data>(query: Query.RemoveQuery<T>): Promise<T[]>;
|
|
15
|
+
removeOne<T = Data>(query: Query.RemoveQuery<T>): Promise<T | null>;
|
|
16
16
|
removeCollection(collection: string): Promise<boolean>;
|
|
17
|
-
updateOneOrAdd<T = Data>(query: UpdateOneOrAddQuery<T>): Promise<UpdateOneOrAddResult<T>>;
|
|
18
|
-
toggleOne<T = Data>(query: ToggleOneQuery<T>): Promise<ToggleOneResult<T>>;
|
|
17
|
+
updateOneOrAdd<T = Data>(query: Query.UpdateOneOrAddQuery<T>): Promise<Query.UpdateOneOrAddResult<T>>;
|
|
18
|
+
toggleOne<T = Data>(query: Query.ToggleOneQuery<T>): Promise<Query.ToggleOneResult<T>>;
|
|
19
19
|
}
|
package/dist/utils/action.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compareSafe } from "./compare.js";
|
|
2
2
|
export async function findUtil(query, fileCpu, files) {
|
|
3
|
-
const {
|
|
3
|
+
const { dbFindOpts = {} } = query;
|
|
4
4
|
const { reverse = false, offset = 0, limit = -1, sortBy, sortAsc = true } = dbFindOpts;
|
|
5
5
|
if (reverse && !sortBy)
|
|
6
6
|
files.reverse();
|
|
@@ -8,7 +8,7 @@ export async function findUtil(query, fileCpu, files) {
|
|
|
8
8
|
let totalEntries = 0;
|
|
9
9
|
let skippedEntries = 0;
|
|
10
10
|
for (const f of files) {
|
|
11
|
-
let entries = await fileCpu.find(
|
|
11
|
+
let entries = await fileCpu.find(Object.assign({}, query, { collection: f }));
|
|
12
12
|
if (reverse && !sortBy)
|
|
13
13
|
entries.reverse();
|
|
14
14
|
if (!sortBy) {
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.10.0-alpha.0";
|