@wxn0brp/db-core 0.11.5 → 0.12.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 +6 -1
- package/dist/base/actions.js +21 -6
- package/dist/base/custom.d.ts +0 -1
- package/dist/base/custom.js +4 -5
- package/dist/customFileCpu.js +4 -6
- package/dist/db/memory.js +8 -6
- package/dist/db/multiStorage.js +24 -16
- package/dist/db/routedStorage.js +16 -6
- package/dist/db/valthera.d.ts +1 -26
- package/dist/db/valthera.js +21 -21
- package/dist/helpers/addId.js +16 -7
- package/dist/helpers/assignDataPush.js +1 -1
- package/dist/helpers/collection.d.ts +0 -3
- package/dist/helpers/collection.js +54 -12
- package/dist/helpers/executor.js +12 -7
- package/dist/helpers/forge.d.ts +0 -6
- package/dist/helpers/forge.js +1 -4
- package/dist/helpers/gen.js +11 -4
- package/dist/helpers/relation.d.ts +4 -1
- package/dist/helpers/relation.js +82 -23
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/types/action.d.ts +3 -1
- package/dist/types/export.d.ts +1 -0
- package/dist/types/fileCpu.d.ts +4 -4
- package/dist/types/options.d.ts +12 -12
- package/dist/types/query.js +1 -5
- package/dist/types/relation.d.ts +4 -1
- package/dist/types/searchOpts.d.ts +10 -13
- package/dist/types/updater.d.ts +0 -12
- package/dist/utils/action.js +69 -13
- package/dist/utils/compare.js +4 -3
- package/dist/utils/hasFieldsAdvanced.js +6 -1
- package/dist/utils/id.d.ts +10 -0
- package/dist/utils/id.js +10 -2
- package/dist/utils/merge.js +7 -3
- package/dist/utils/process.d.ts +3 -0
- package/dist/utils/process.js +10 -3
- package/dist/utils/updateFindObject.js +3 -2
- package/dist/utils/updateObject.d.ts +1 -1
- package/dist/utils/updateObject.js +15 -11
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -41,6 +41,7 @@ export function hasFieldsAdvanced(obj, fields) {
|
|
|
41
41
|
}
|
|
42
42
|
function mainCheck(obj, fields) {
|
|
43
43
|
return _for(fields, obj, {
|
|
44
|
+
ne: (data, value) => data !== value,
|
|
44
45
|
gt: (data, value) => data > value,
|
|
45
46
|
lt: (data, value) => data < value,
|
|
46
47
|
gte: (data, value) => data >= value,
|
|
@@ -51,7 +52,7 @@ function mainCheck(obj, fields) {
|
|
|
51
52
|
exists: (_, shouldExist, key) => {
|
|
52
53
|
if (shouldExist && !(key in obj))
|
|
53
54
|
return false;
|
|
54
|
-
if (!shouldExist &&
|
|
55
|
+
if (!shouldExist && key in obj)
|
|
55
56
|
return false;
|
|
56
57
|
return true;
|
|
57
58
|
},
|
|
@@ -69,6 +70,10 @@ function mainCheck(obj, fields) {
|
|
|
69
70
|
},
|
|
70
71
|
startswith: (data, value) => typeof data === "string" && data.startsWith(value),
|
|
71
72
|
endswith: (data, value) => typeof data === "string" && data.endsWith(value),
|
|
73
|
+
istartswith: (data, value) => typeof data === "string" &&
|
|
74
|
+
data.toLowerCase().startsWith(value.toLowerCase()),
|
|
75
|
+
iendswith: (data, value) => typeof data === "string" &&
|
|
76
|
+
data.toLowerCase().endsWith(value.toLowerCase()),
|
|
72
77
|
between: (data, [min, max]) => typeof data === "number" && data >= min && data <= max,
|
|
73
78
|
arrinc: (data, values) => Array.isArray(data) && values.some((val) => data.includes(val)),
|
|
74
79
|
arrincall: (data, values) => Array.isArray(data) && values.every((val) => data.includes(val)),
|
package/dist/utils/id.d.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
export declare function convertIdToUnix(id: string): number;
|
|
2
|
+
/**
|
|
3
|
+
* Sorts an array of objects by their _id property
|
|
4
|
+
*/
|
|
2
5
|
export declare function sortByIds<T extends {
|
|
3
6
|
_id: string;
|
|
4
7
|
}>(objects: T[]): T[];
|
|
8
|
+
export declare function sortByIds<T extends Record<string, any>>(objects: T[], key: string): T[];
|
|
9
|
+
/**
|
|
10
|
+
* Sorts an array of objects using reference
|
|
11
|
+
* @param objects
|
|
12
|
+
* @param key default "_id"
|
|
13
|
+
*/
|
|
14
|
+
export declare function sortByIdsRef(objects: Record<string, any>[], key?: string): void;
|
|
5
15
|
export declare function compareIds(a: string | number, b: string | number): number;
|
package/dist/utils/id.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
export function convertIdToUnix(id) {
|
|
2
2
|
return parseInt(id.split("-")[0], 36);
|
|
3
3
|
}
|
|
4
|
-
export function sortByIds(objects) {
|
|
5
|
-
return objects.slice().sort((a, b) => compareIds(a
|
|
4
|
+
export function sortByIds(objects, key = "_id") {
|
|
5
|
+
return objects.slice().sort((a, b) => compareIds(a[key], b[key]));
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Sorts an array of objects using reference
|
|
9
|
+
* @param objects
|
|
10
|
+
* @param key default "_id"
|
|
11
|
+
*/
|
|
12
|
+
export function sortByIdsRef(objects, key = "_id") {
|
|
13
|
+
objects.sort((a, b) => compareIds(a[key], b[key]));
|
|
6
14
|
}
|
|
7
15
|
export function compareIds(a, b) {
|
|
8
16
|
if (typeof a === "string" && typeof b === "string")
|
package/dist/utils/merge.js
CHANGED
|
@@ -8,11 +8,15 @@ export function _deepMerge(target, ...sources) {
|
|
|
8
8
|
for (const key in source) {
|
|
9
9
|
if (isObject(source[key])) {
|
|
10
10
|
if (!target[key])
|
|
11
|
-
Object.assign(target, {
|
|
11
|
+
Object.assign(target, {
|
|
12
|
+
[key]: {},
|
|
13
|
+
});
|
|
12
14
|
_deepMerge(target[key], source[key]);
|
|
13
15
|
}
|
|
14
16
|
else {
|
|
15
|
-
Object.assign(target, {
|
|
17
|
+
Object.assign(target, {
|
|
18
|
+
[key]: source[key],
|
|
19
|
+
});
|
|
16
20
|
}
|
|
17
21
|
}
|
|
18
22
|
}
|
|
@@ -22,5 +26,5 @@ export function deepMerge(target, ...sources) {
|
|
|
22
26
|
return _deepMerge(structuredClone(target), ...sources.map(s => structuredClone(s)));
|
|
23
27
|
}
|
|
24
28
|
function isObject(item) {
|
|
25
|
-
return
|
|
29
|
+
return item && typeof item === "object" && !Array.isArray(item);
|
|
26
30
|
}
|
package/dist/utils/process.d.ts
CHANGED
|
@@ -2,4 +2,7 @@ import { Data, DataInternal } from "../types/data.js";
|
|
|
2
2
|
import { VQuery, VQueryT } from "../types/query.js";
|
|
3
3
|
export declare function findObj(config: VQueryT.Find | VQueryT.FindOne, obj: Data): DataInternal | null;
|
|
4
4
|
export declare function matchObj(config: VQuery, obj: Data): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* @returns reference to object or new object
|
|
7
|
+
*/
|
|
5
8
|
export declare function updateObj(config: VQueryT.Update, obj: Data): DataInternal;
|
package/dist/utils/process.js
CHANGED
|
@@ -12,14 +12,21 @@ export function matchObj(config, obj) {
|
|
|
12
12
|
return true;
|
|
13
13
|
if (typeof search === "function" && search(obj, context))
|
|
14
14
|
return true;
|
|
15
|
-
if (typeof search === "object" &&
|
|
15
|
+
if (typeof search === "object" &&
|
|
16
|
+
!Array.isArray(search) &&
|
|
17
|
+
hasFieldsAdvanced(obj, search))
|
|
16
18
|
return true;
|
|
17
19
|
return false;
|
|
18
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @returns reference to object or new object
|
|
23
|
+
*/
|
|
19
24
|
export function updateObj(config, obj) {
|
|
20
25
|
const { updater, context } = config;
|
|
21
|
-
if (typeof updater === "object" && !Array.isArray(updater))
|
|
22
|
-
|
|
26
|
+
if (typeof updater === "object" && !Array.isArray(updater)) {
|
|
27
|
+
updateObjectAdvanced(obj, updater);
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
23
30
|
if (typeof updater === "function") {
|
|
24
31
|
const updateObjValue = updater(obj, context);
|
|
25
32
|
if (updateObjValue)
|
|
@@ -59,7 +59,7 @@ function deleteNested(obj, path) {
|
|
|
59
59
|
* @returns The updated object.
|
|
60
60
|
*/
|
|
61
61
|
export function updateFindObject(obj, findOpts) {
|
|
62
|
-
const { transform, select, exclude
|
|
62
|
+
const { transform, select, exclude } = findOpts;
|
|
63
63
|
if (typeof transform === "function")
|
|
64
64
|
obj = transform(obj);
|
|
65
65
|
if (Array.isArray(exclude)) {
|
|
@@ -72,7 +72,8 @@ export function updateFindObject(obj, findOpts) {
|
|
|
72
72
|
if (Array.isArray(select)) {
|
|
73
73
|
const result = {};
|
|
74
74
|
for (const field of select) {
|
|
75
|
-
if ((typeof field === "string" || Array.isArray(field)) &&
|
|
75
|
+
if ((typeof field === "string" || Array.isArray(field)) &&
|
|
76
|
+
pathExists(obj, field)) {
|
|
76
77
|
setNested(result, field, getValueAt(obj, field));
|
|
77
78
|
}
|
|
78
79
|
}
|
|
@@ -4,4 +4,4 @@ import { UpdaterArg } from "../types/updater.js";
|
|
|
4
4
|
* @param obj - The object to update.
|
|
5
5
|
* @param field - An object containing new values to update in the target object.
|
|
6
6
|
*/
|
|
7
|
-
export declare function updateObjectAdvanced(obj: Record<string, any>, field: UpdaterArg):
|
|
7
|
+
export declare function updateObjectAdvanced(obj: Record<string, any>, field: UpdaterArg): void;
|
|
@@ -8,8 +8,7 @@ export function updateObjectAdvanced(obj, field) {
|
|
|
8
8
|
if (typeof field !== "object" || Array.isArray(field) || field === null)
|
|
9
9
|
throw new Error("Fields must be an object");
|
|
10
10
|
if (Object.keys(field).length === 0)
|
|
11
|
-
return
|
|
12
|
-
const newObj = structuredClone(obj);
|
|
11
|
+
return;
|
|
13
12
|
const $fields = {};
|
|
14
13
|
const subsetFields = {};
|
|
15
14
|
Object.keys(field).forEach(key => {
|
|
@@ -18,10 +17,9 @@ export function updateObjectAdvanced(obj, field) {
|
|
|
18
17
|
else
|
|
19
18
|
subsetFields[key] = field[key];
|
|
20
19
|
});
|
|
21
|
-
mainUpdate(
|
|
22
|
-
const mergedObj = deepMerge(
|
|
20
|
+
mainUpdate(obj, $fields);
|
|
21
|
+
const mergedObj = deepMerge(obj, $fields);
|
|
23
22
|
updateObject(mergedObj, subsetFields);
|
|
24
|
-
return mergedObj;
|
|
25
23
|
}
|
|
26
24
|
function deepMerge(obj, fields) {
|
|
27
25
|
if (!("$deepmerge" in fields))
|
|
@@ -38,7 +36,9 @@ function mainUpdate(obj, fields) {
|
|
|
38
36
|
item.push(updater);
|
|
39
37
|
return item;
|
|
40
38
|
}
|
|
41
|
-
return [
|
|
39
|
+
return [
|
|
40
|
+
updater,
|
|
41
|
+
];
|
|
42
42
|
},
|
|
43
43
|
pushall: (item, updater) => {
|
|
44
44
|
if (Array.isArray(item)) {
|
|
@@ -50,9 +50,13 @@ function mainUpdate(obj, fields) {
|
|
|
50
50
|
pushset: (item, updater) => {
|
|
51
51
|
if (Array.isArray(item)) {
|
|
52
52
|
item.push(updater);
|
|
53
|
-
return [
|
|
53
|
+
return [
|
|
54
|
+
...new Set(item),
|
|
55
|
+
];
|
|
54
56
|
}
|
|
55
|
-
return [
|
|
57
|
+
return [
|
|
58
|
+
updater,
|
|
59
|
+
];
|
|
56
60
|
},
|
|
57
61
|
pull: (item, updater) => {
|
|
58
62
|
if (Array.isArray(item))
|
|
@@ -95,7 +99,7 @@ function mainUpdate(obj, fields) {
|
|
|
95
99
|
unset: (_, __, key, deepObj) => {
|
|
96
100
|
if (key in deepObj)
|
|
97
101
|
delete deepObj[key];
|
|
98
|
-
}
|
|
102
|
+
},
|
|
99
103
|
});
|
|
100
104
|
}
|
|
101
105
|
/**
|
|
@@ -104,8 +108,8 @@ function mainUpdate(obj, fields) {
|
|
|
104
108
|
* @param newVal - An object containing new values to update in the target object.
|
|
105
109
|
*/
|
|
106
110
|
function updateObject(obj, newVal) {
|
|
107
|
-
for (
|
|
108
|
-
if (
|
|
111
|
+
for (const key in newVal)
|
|
112
|
+
if (Object.hasOwn(newVal, key))
|
|
109
113
|
obj[key] = newVal[key];
|
|
110
114
|
return obj;
|
|
111
115
|
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.12.0-alpha.0";
|