@wxn0brp/db-core 0.11.6 → 0.12.0-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/dist/db/memory.js +5 -5
- package/dist/db/valthera.d.ts +1 -26
- package/dist/db/valthera.js +6 -22
- package/dist/helpers/collection.d.ts +0 -3
- package/dist/helpers/collection.js +0 -3
- package/dist/helpers/forge.d.ts +0 -6
- package/dist/helpers/forge.js +0 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/types/action.d.ts +0 -4
- package/dist/types/options.d.ts +2 -15
- package/dist/types/searchOpts.d.ts +0 -12
- package/dist/types/updater.d.ts +0 -12
- package/dist/utils/action.js +14 -9
- package/dist/utils/hasFieldsAdvanced.js +4 -4
- package/dist/utils/process.d.ts +3 -0
- package/dist/utils/process.js +7 -2
- package/dist/utils/updateObject.d.ts +1 -1
- package/dist/utils/updateObject.js +3 -5
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/dist/db/memory.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CustomActionsBase } from "../base/custom.js";
|
|
2
2
|
import { CustomFileCpu } from "../customFileCpu.js";
|
|
3
|
-
import {
|
|
3
|
+
import { forgeTypedValthera } from "../helpers/forge.js";
|
|
4
4
|
import { ValtheraClass } from "./valthera.js";
|
|
5
5
|
export class MemoryAction extends CustomActionsBase {
|
|
6
6
|
memory;
|
|
@@ -13,10 +13,10 @@ export class MemoryAction extends CustomActionsBase {
|
|
|
13
13
|
_readMemory(key) {
|
|
14
14
|
if (!this.memory.has(key))
|
|
15
15
|
return [];
|
|
16
|
-
return this.memory.get(key);
|
|
16
|
+
return structuredClone(this.memory.get(key));
|
|
17
17
|
}
|
|
18
18
|
_writeMemory(key, data) {
|
|
19
|
-
this.memory.set(key, data);
|
|
19
|
+
this.memory.set(key, structuredClone(data));
|
|
20
20
|
}
|
|
21
21
|
async getCollections() {
|
|
22
22
|
const collections = Array.from(this.memory.keys());
|
|
@@ -48,9 +48,9 @@ export class ValtheraMemory extends ValtheraClass {
|
|
|
48
48
|
export function createMemoryValthera(data) {
|
|
49
49
|
const db = new ValtheraMemory();
|
|
50
50
|
if (!data)
|
|
51
|
-
return
|
|
51
|
+
return forgeTypedValthera(db);
|
|
52
52
|
for (const collection of Object.keys(data)) {
|
|
53
53
|
db.adapter.memory.set(collection, data[collection]);
|
|
54
54
|
}
|
|
55
|
-
return
|
|
55
|
+
return forgeTypedValthera(db);
|
|
56
56
|
}
|
package/dist/db/valthera.d.ts
CHANGED
|
@@ -20,32 +20,10 @@ export declare class ValtheraClass implements ValtheraCompatible {
|
|
|
20
20
|
} & {
|
|
21
21
|
"*": (name: keyof ValtheraCompatible, query: VQuery, result: any) => void;
|
|
22
22
|
}>;
|
|
23
|
-
/** @deprecated typo */
|
|
24
|
-
emiter: VEE<{
|
|
25
|
-
c: (query: VQuery, result: Collection<unknown>) => void;
|
|
26
|
-
getCollections: (query: VQuery, result: string[]) => void;
|
|
27
|
-
ensureCollection: (query: VQuery, result: boolean) => void;
|
|
28
|
-
issetCollection: (query: VQuery, result: boolean) => void;
|
|
29
|
-
add: (query: VQuery, result: unknown) => void;
|
|
30
|
-
find: (query: VQuery, result: unknown[]) => void;
|
|
31
|
-
findOne: (query: VQuery, result: unknown) => void;
|
|
32
|
-
update: (query: VQuery, result: unknown[]) => void;
|
|
33
|
-
updateOne: (query: VQuery, result: unknown) => void;
|
|
34
|
-
remove: (query: VQuery, result: unknown[]) => void;
|
|
35
|
-
removeOne: (query: VQuery, result: unknown) => void;
|
|
36
|
-
removeCollection: (query: VQuery, result: boolean) => void;
|
|
37
|
-
updateOneOrAdd: (query: VQuery, result: VQueryT.UpdateOneOrAddResult<unknown>) => void;
|
|
38
|
-
toggleOne: (query: VQuery, result: VQueryT.ToggleOneResult<unknown>) => void;
|
|
39
|
-
} & {
|
|
40
|
-
"*": (name: keyof ValtheraCompatible, query: VQuery, result: any) => void;
|
|
41
|
-
}>;
|
|
42
23
|
version: string;
|
|
43
24
|
_plugins: ValtheraPlugin[];
|
|
25
|
+
_collections: Map<string, Collection<any>>;
|
|
44
26
|
plugin(p: ValtheraPlugin): () => void;
|
|
45
|
-
/** @deprecated use `adapter` */
|
|
46
|
-
get dbAction(): ActionsBase;
|
|
47
|
-
/** @deprecated use `adapter` */
|
|
48
|
-
set dbAction(action: ActionsBase);
|
|
49
27
|
constructor(options: DbOpts);
|
|
50
28
|
init(...args: any[]): Promise<any>;
|
|
51
29
|
close(...args: any[]): Promise<any>;
|
|
@@ -100,9 +78,6 @@ export declare class ValtheraClass implements ValtheraCompatible {
|
|
|
100
78
|
updateOneOrAdd<T = Data>(query: VQueryT.UpdateOneOrAdd<T>): Promise<VQueryT.UpdateOneOrAddResult<T>>;
|
|
101
79
|
/**
|
|
102
80
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
103
|
-
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
104
|
-
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
105
|
-
* after the operation.
|
|
106
81
|
*/
|
|
107
82
|
toggleOne<T = Data>(query: VQueryT.ToggleOne<T>): Promise<VQueryT.ToggleOneResult<T>>;
|
|
108
83
|
/**
|
package/dist/db/valthera.js
CHANGED
|
@@ -11,10 +11,9 @@ export class ValtheraClass {
|
|
|
11
11
|
adapter;
|
|
12
12
|
executor;
|
|
13
13
|
emitter = new VEE();
|
|
14
|
-
/** @deprecated typo */
|
|
15
|
-
emiter = this.emitter;
|
|
16
14
|
version = version;
|
|
17
15
|
_plugins = [];
|
|
16
|
+
_collections = new Map();
|
|
18
17
|
plugin(p) {
|
|
19
18
|
p.init?.(this);
|
|
20
19
|
this._plugins.push(p);
|
|
@@ -24,25 +23,9 @@ export class ValtheraClass {
|
|
|
24
23
|
this._plugins.splice(i, 1);
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
|
-
/** @deprecated use `adapter` */
|
|
28
|
-
get dbAction() {
|
|
29
|
-
return this.adapter;
|
|
30
|
-
}
|
|
31
|
-
/** @deprecated use `adapter` */
|
|
32
|
-
set dbAction(action) {
|
|
33
|
-
this.adapter = action;
|
|
34
|
-
}
|
|
35
26
|
constructor(options) {
|
|
36
27
|
this.options = options;
|
|
37
28
|
this.executor = options.executor || new SmartExecutor(undefined, false);
|
|
38
|
-
options.adapter ??= options.dbAction;
|
|
39
|
-
options.dbAction ??= options.adapter;
|
|
40
|
-
options.adapterOpts ??= {};
|
|
41
|
-
if (options.numberId !== undefined &&
|
|
42
|
-
options.adapterOpts.numberId === undefined)
|
|
43
|
-
options.adapterOpts.numberId = options.numberId;
|
|
44
|
-
if (options.idKey !== undefined && options.adapterOpts.idKey === undefined)
|
|
45
|
-
options.adapterOpts.idKey = options.idKey;
|
|
46
29
|
if (typeof options.adapter === "function")
|
|
47
30
|
return;
|
|
48
31
|
else {
|
|
@@ -109,7 +92,11 @@ export class ValtheraClass {
|
|
|
109
92
|
* Create a new instance of a Collection class.
|
|
110
93
|
*/
|
|
111
94
|
c(collection) {
|
|
112
|
-
|
|
95
|
+
if (this._collections.has(collection))
|
|
96
|
+
return this._collections.get(collection);
|
|
97
|
+
const col = new Collection(this, collection);
|
|
98
|
+
this._collections.set(collection, col);
|
|
99
|
+
return col;
|
|
113
100
|
}
|
|
114
101
|
/**
|
|
115
102
|
* Get the names of all available databases.
|
|
@@ -201,9 +188,6 @@ export class ValtheraClass {
|
|
|
201
188
|
}
|
|
202
189
|
/**
|
|
203
190
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
204
|
-
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
205
|
-
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
206
|
-
* after the operation.
|
|
207
191
|
*/
|
|
208
192
|
toggleOne(query) {
|
|
209
193
|
query.data ||= {};
|
|
@@ -46,9 +46,6 @@ export declare class Collection<D = Data> {
|
|
|
46
46
|
updateOneOrAdd(search: Search<D>, updater: Updater<D>, { add_arg, context, id_gen }?: UpdateOneOrAdd<D>): Promise<VQueryT.UpdateOneOrAddResult<D>>;
|
|
47
47
|
/**
|
|
48
48
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
49
|
-
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
50
|
-
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
51
|
-
* after the operation.
|
|
52
49
|
*/
|
|
53
50
|
toggleOne(search: Search<D>, data?: Arg<D>, context?: VContext): Promise<VQueryT.ToggleOneResult<D>>;
|
|
54
51
|
}
|
|
@@ -92,9 +92,6 @@ export class Collection {
|
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Asynchronously removes one entry in a database or adds a new one if it doesn't exist. Usage e.g. for toggling a flag.
|
|
95
|
-
* Returns a promise resolving to `false` if the entry was found and removed,
|
|
96
|
-
* or `true` if the entry was added. The returned value reflects the state of the database
|
|
97
|
-
* after the operation.
|
|
98
95
|
*/
|
|
99
96
|
toggleOne(search, data = {}, context = {}) {
|
|
100
97
|
return this.db.toggleOne({
|
package/dist/helpers/forge.d.ts
CHANGED
|
@@ -2,12 +2,6 @@ import { Collection } from "./collection.js";
|
|
|
2
2
|
import { Data } from "../types/data.js";
|
|
3
3
|
import { ValtheraCompatible } from "../types/valthera.js";
|
|
4
4
|
import { ValtheraClass } from "../db/valthera.js";
|
|
5
|
-
export declare function forgeValthera<T extends string>(target: ValtheraClass): ValtheraClass & {
|
|
6
|
-
[K in T]: Collection;
|
|
7
|
-
};
|
|
8
|
-
export declare function forgeValthera<T extends string>(target: ValtheraCompatible): ValtheraCompatible & {
|
|
9
|
-
[K in T]: Collection;
|
|
10
|
-
};
|
|
11
5
|
export declare function forgeTypedValthera<T extends Record<string, Data>>(target: ValtheraClass): ValtheraClass & {
|
|
12
6
|
[K in keyof T]: Collection<T[K]>;
|
|
13
7
|
};
|
package/dist/helpers/forge.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CustomFileCpu } from "./customFileCpu.js";
|
|
2
2
|
export { createMemoryValthera, ValtheraMemory } from "./db/memory.js";
|
|
3
3
|
export { ValtheraClass } from "./db/valthera.js";
|
|
4
|
-
export { forgeTypedValthera
|
|
4
|
+
export { forgeTypedValthera } from "./helpers/forge.js";
|
|
5
5
|
export { genId } from "./helpers/gen.js";
|
|
6
6
|
export { Relation } from "./helpers/relation.js";
|
|
7
7
|
export { convertIdToUnix, sortByIds } from "./utils/id.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CustomFileCpu } from "./customFileCpu.js";
|
|
2
2
|
export { createMemoryValthera, ValtheraMemory } from "./db/memory.js";
|
|
3
3
|
export { ValtheraClass } from "./db/valthera.js";
|
|
4
|
-
export { forgeTypedValthera
|
|
4
|
+
export { forgeTypedValthera } from "./helpers/forge.js";
|
|
5
5
|
export { genId } from "./helpers/gen.js";
|
|
6
6
|
export { Relation } from "./helpers/relation.js";
|
|
7
7
|
export { convertIdToUnix, sortByIds } from "./utils/id.js";
|
package/dist/types/action.d.ts
CHANGED
|
@@ -4,10 +4,6 @@ import { VQueryT } from "./query.js";
|
|
|
4
4
|
export interface ActionsBaseInterface {
|
|
5
5
|
_inited: boolean;
|
|
6
6
|
adapterOpts: AdapterOpts;
|
|
7
|
-
/** @deprecated use `adapterOpts.numberId` */
|
|
8
|
-
numberId: boolean;
|
|
9
|
-
/** @deprecated use `adapterOpts.idKey` */
|
|
10
|
-
idKey: string;
|
|
11
7
|
smartExecutor: boolean;
|
|
12
8
|
init(...args: any[]): Promise<void>;
|
|
13
9
|
close(...args: any[]): Promise<void>;
|
package/dist/types/options.d.ts
CHANGED
|
@@ -2,23 +2,11 @@ import { ActionsBase } from "../base/actions.js";
|
|
|
2
2
|
import { Executor } from "../helpers/executor.js";
|
|
3
3
|
import { KeysMatching } from "./utils.js";
|
|
4
4
|
export type AdapterValue = ActionsBase | (() => Promise<ActionsBase>);
|
|
5
|
-
|
|
5
|
+
export interface DbOpts {
|
|
6
6
|
adapter: AdapterValue;
|
|
7
|
-
/** @deprecated use `adapter` */
|
|
8
|
-
dbAction?: AdapterValue;
|
|
9
|
-
} | {
|
|
10
|
-
adapter?: AdapterValue;
|
|
11
|
-
/** @deprecated use `adapter` */
|
|
12
|
-
dbAction: AdapterValue;
|
|
13
|
-
};
|
|
14
|
-
export type DbOpts = AdapterOption & {
|
|
15
7
|
executor?: Executor;
|
|
16
8
|
adapterOpts?: AdapterOpts;
|
|
17
|
-
|
|
18
|
-
numberId?: boolean;
|
|
19
|
-
/** @deprecated use `adapterOpts.idKey` */
|
|
20
|
-
idKey?: string;
|
|
21
|
-
};
|
|
9
|
+
}
|
|
22
10
|
export interface AdapterOpts {
|
|
23
11
|
numberId?: boolean;
|
|
24
12
|
idKey?: string;
|
|
@@ -46,4 +34,3 @@ export interface FindOpts<T = any> {
|
|
|
46
34
|
exclude?: FieldPath<T>[];
|
|
47
35
|
transform?: Function;
|
|
48
36
|
}
|
|
49
|
-
export {};
|
|
@@ -65,22 +65,10 @@ export type ArrayOperators<T = any> = {
|
|
|
65
65
|
$arrInc?: {
|
|
66
66
|
[K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
|
|
67
67
|
};
|
|
68
|
-
/**
|
|
69
|
-
* @deprecated Use $arrInc instead.
|
|
70
|
-
*/
|
|
71
|
-
$arrinc?: {
|
|
72
|
-
[K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
|
|
73
|
-
};
|
|
74
68
|
/** [1, 2, 3] array includes all elements e.g. [1, 2] */
|
|
75
69
|
$arrIncAll?: {
|
|
76
70
|
[K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
|
|
77
71
|
};
|
|
78
|
-
/**
|
|
79
|
-
* @deprecated Use $arrIncAll instead.
|
|
80
|
-
*/
|
|
81
|
-
$arrincall?: {
|
|
82
|
-
[K in keyof T]?: T[K] extends any[] ? T[K][number][] : T[K][];
|
|
83
|
-
};
|
|
84
72
|
/** [1, 2, 3] has size 3 */
|
|
85
73
|
$size?: NestedValue<T, number>;
|
|
86
74
|
};
|
package/dist/types/updater.d.ts
CHANGED
|
@@ -5,24 +5,12 @@ export type ArrayUpdater<T = any> = {
|
|
|
5
5
|
$push?: NestedValue<T, any>;
|
|
6
6
|
/** [1,2] -> $pushSet 2,3 -> [1,2,3] */
|
|
7
7
|
$pushSet?: NestedValue<T, any>;
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated Use $pushSet instead.
|
|
10
|
-
*/
|
|
11
|
-
$pushset?: NestedValue<T, any>;
|
|
12
8
|
/** [1,2,3] -> $pushAll [2,3] -> [1,2,3] */
|
|
13
9
|
$pushAll?: NestedValue<T, any>;
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated Use $pushAll instead.
|
|
16
|
-
*/
|
|
17
|
-
$pushall?: NestedValue<T, any>;
|
|
18
10
|
/** [1,2,3] -> $pull 2 -> [1,3] */
|
|
19
11
|
$pull?: NestedValue<T, any>;
|
|
20
12
|
/** [1,2,2,3] -> $pullAll [2] -> [1,3] */
|
|
21
13
|
$pullAll?: NestedValue<T, any>;
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated Use $pullAll instead.
|
|
24
|
-
*/
|
|
25
|
-
$pullall?: NestedValue<T, any>;
|
|
26
14
|
};
|
|
27
15
|
/** Objects */
|
|
28
16
|
export type ObjectUpdater<T = any> = {
|
package/dist/utils/action.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { compareSafe } from "./compare.js";
|
|
2
2
|
export async function findUtil(query, fileCpuOrData, files, fileCpuOpts) {
|
|
3
3
|
const { dbFindOpts = {} } = query;
|
|
4
|
-
const { reverse = false, offset = 0,
|
|
4
|
+
const { reverse = false, offset = 0, sortBy, sortAsc = true, min, max, avg, sum, distinct, groupBy, count, } = dbFindOpts;
|
|
5
|
+
let limit = dbFindOpts.limit ?? -1;
|
|
6
|
+
if (limit === Infinity)
|
|
7
|
+
limit = -1;
|
|
5
8
|
const needsAllData = min || max || avg || sum || distinct || groupBy || count || sortBy;
|
|
6
9
|
let datas = [];
|
|
7
10
|
let skippedEntries = 0;
|
|
@@ -54,6 +57,8 @@ export async function findUtil(query, fileCpuOrData, files, fileCpuOpts) {
|
|
|
54
57
|
}
|
|
55
58
|
if (!needsAllData)
|
|
56
59
|
return datas;
|
|
60
|
+
if (datas.length === 0)
|
|
61
|
+
return [];
|
|
57
62
|
const hasAggregations = min || max || avg || sum || groupBy || count;
|
|
58
63
|
if (hasAggregations) {
|
|
59
64
|
const groups = new Map();
|
|
@@ -94,28 +99,28 @@ export async function findUtil(query, fileCpuOrData, files, fileCpuOpts) {
|
|
|
94
99
|
}
|
|
95
100
|
for (const [outKey, srcField] of Object.entries(min ?? {})) {
|
|
96
101
|
const nums = groupItems
|
|
97
|
-
.map(d =>
|
|
98
|
-
.filter(
|
|
102
|
+
.map(d => d[srcField])
|
|
103
|
+
.filter((v) => typeof v === "number");
|
|
99
104
|
result[outKey] = nums.length ? Math.min(...nums) : null;
|
|
100
105
|
}
|
|
101
106
|
for (const [outKey, srcField] of Object.entries(max ?? {})) {
|
|
102
107
|
const nums = groupItems
|
|
103
|
-
.map(d =>
|
|
104
|
-
.filter(
|
|
108
|
+
.map(d => d[srcField])
|
|
109
|
+
.filter((v) => typeof v === "number");
|
|
105
110
|
result[outKey] = nums.length ? Math.max(...nums) : null;
|
|
106
111
|
}
|
|
107
112
|
for (const [outKey, srcField] of Object.entries(avg ?? {})) {
|
|
108
113
|
const nums = groupItems
|
|
109
|
-
.map(d =>
|
|
110
|
-
.filter(
|
|
114
|
+
.map(d => d[srcField])
|
|
115
|
+
.filter((v) => typeof v === "number");
|
|
111
116
|
result[outKey] = nums.length
|
|
112
117
|
? nums.reduce((a, b) => a + b, 0) / nums.length
|
|
113
118
|
: null;
|
|
114
119
|
}
|
|
115
120
|
for (const [outKey, srcField] of Object.entries(sum ?? {})) {
|
|
116
121
|
const nums = groupItems
|
|
117
|
-
.map(d =>
|
|
118
|
-
.filter(
|
|
122
|
+
.map(d => d[srcField])
|
|
123
|
+
.filter((v) => typeof v === "number");
|
|
119
124
|
result[outKey] = nums.length ? nums.reduce((a, b) => a + b, 0) : null;
|
|
120
125
|
}
|
|
121
126
|
aggregated.push(result);
|
|
@@ -42,10 +42,10 @@ export function hasFieldsAdvanced(obj, fields) {
|
|
|
42
42
|
function mainCheck(obj, fields) {
|
|
43
43
|
return _for(fields, obj, {
|
|
44
44
|
ne: (data, value) => data !== value,
|
|
45
|
-
gt: (data, value) => data > value,
|
|
46
|
-
lt: (data, value) => data < value,
|
|
47
|
-
gte: (data, value) => data >= value,
|
|
48
|
-
lte: (data, value) => data <= value,
|
|
45
|
+
gt: (data, value) => typeof data === typeof value && data > value,
|
|
46
|
+
lt: (data, value) => typeof data === typeof value && data < value,
|
|
47
|
+
gte: (data, value) => typeof data === typeof value && data >= value,
|
|
48
|
+
lte: (data, value) => typeof data === typeof value && data <= value,
|
|
49
49
|
in: (data, value) => value.includes(data),
|
|
50
50
|
nin: (data, value) => !value.includes(data),
|
|
51
51
|
type: (data, value) => typeof data === value,
|
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
|
@@ -18,10 +18,15 @@ export function matchObj(config, obj) {
|
|
|
18
18
|
return true;
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* @returns reference to object or new object
|
|
23
|
+
*/
|
|
21
24
|
export function updateObj(config, obj) {
|
|
22
25
|
const { updater, context } = config;
|
|
23
|
-
if (typeof updater === "object" && !Array.isArray(updater))
|
|
24
|
-
|
|
26
|
+
if (typeof updater === "object" && !Array.isArray(updater)) {
|
|
27
|
+
updateObjectAdvanced(obj, updater);
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
25
30
|
if (typeof updater === "function") {
|
|
26
31
|
const updateObjValue = updater(obj, context);
|
|
27
32
|
if (updateObjValue)
|
|
@@ -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))
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.
|
|
1
|
+
export const version = "0.12.0-alpha.1";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wxn0brp/db-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0-alpha.1",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "wxn0brP",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://github.com/wxn0brP/ValtheraDB",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@wxn0brp/event-emitter": "0.0.
|
|
16
|
+
"@wxn0brp/event-emitter": "0.0.6"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@types/bun": "*",
|