inibase 1.1.18 → 1.1.20
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/index.d.ts +2 -1
- package/dist/index.js +8 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +25 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -149,7 +149,8 @@ export default class Inibase {
|
|
|
149
149
|
* @param {boolean} [returnPostedData] By default function returns void, if you want to get the posted data, set this param to true
|
|
150
150
|
* @return {*} {Promise<Data | Data[] | null | void>}
|
|
151
151
|
*/
|
|
152
|
-
post<TData extends Record<string, any> & Partial<Data>>(tableName: string, data:
|
|
152
|
+
post<TData extends Record<string, any> & Partial<Data>>(tableName: string, data: Data & TData, options?: Options, returnPostedData?: boolean): Promise<string>;
|
|
153
|
+
post<TData extends Record<string, any> & Partial<Data>>(tableName: string, data: (Data & TData)[], options?: Options, returnPostedData?: boolean): Promise<string[]>;
|
|
153
154
|
post<TData extends Record<string, any> & Partial<Data>>(tableName: string, data: Data & TData, options: Options | undefined, returnPostedData: true): Promise<(Data & TData) | null>;
|
|
154
155
|
post<TData extends Record<string, any> & Partial<Data>>(tableName: string, data: (Data & TData)[], options: Options | undefined, returnPostedData: true): Promise<(Data & TData)[] | null>;
|
|
155
156
|
/**
|
package/dist/index.js
CHANGED
|
@@ -947,6 +947,7 @@ export default class Inibase {
|
|
|
947
947
|
if (Object.keys(criteria).length > 0) {
|
|
948
948
|
if (allTrue === undefined)
|
|
949
949
|
allTrue = true;
|
|
950
|
+
criteria = Utils.toDotNotation(criteria, ["or", "and"]);
|
|
950
951
|
let index = -1;
|
|
951
952
|
for await (const [key, value] of Object.entries(criteria)) {
|
|
952
953
|
const field = Utils.getField(key, this.tablesMap.get(tableName).schema);
|
|
@@ -1038,7 +1039,8 @@ export default class Inibase {
|
|
|
1038
1039
|
RETURN = Utils.deepMerge(RETURN, searchResult);
|
|
1039
1040
|
if (!Object.keys(RETURN).length)
|
|
1040
1041
|
RETURN = {};
|
|
1041
|
-
RETURN = Object.fromEntries(Object.entries(RETURN).filter(([_index, item]) => Object.keys(item).filter((key) => Object.keys(criteriaOR).includes(key)
|
|
1042
|
+
RETURN = Object.fromEntries(Object.entries(RETURN).filter(([_index, item]) => Object.keys(item).filter((key) => Object.keys(criteriaOR).includes(key) ||
|
|
1043
|
+
Object.keys(criteriaOR).some((criteriaKey) => criteriaKey.startsWith(`${key}.`))).length));
|
|
1042
1044
|
if (!Object.keys(RETURN).length)
|
|
1043
1045
|
RETURN = {};
|
|
1044
1046
|
searchIn = lineNumbers;
|
|
@@ -1378,6 +1380,11 @@ export default class Inibase {
|
|
|
1378
1380
|
.toReversed()
|
|
1379
1381
|
: this.totalItems.get(`${tableName}-*`), options, !Utils.isArrayOfObjects(clonedData), // return only one item if data is not array of objects
|
|
1380
1382
|
undefined, true);
|
|
1383
|
+
return Array.isArray(clonedData)
|
|
1384
|
+
? (this.tablesMap.get(tableName).config.prepend
|
|
1385
|
+
? clonedData.toReversed()
|
|
1386
|
+
: clonedData).map(({ id }) => UtilsServer.encodeID(id, this.salt))
|
|
1387
|
+
: UtilsServer.encodeID(clonedData.id, this.salt);
|
|
1381
1388
|
}
|
|
1382
1389
|
finally {
|
|
1383
1390
|
if (renameList.length)
|
package/dist/utils.d.ts
CHANGED
|
@@ -200,3 +200,4 @@ export declare const setField: (keyPath: string, schema: Schema, field: Omit<Fie
|
|
|
200
200
|
* @param {Schema} schema
|
|
201
201
|
*/
|
|
202
202
|
export declare const unsetField: (keyPath: string, schema: Schema) => Field;
|
|
203
|
+
export declare function toDotNotation(obj: Record<string, any>, skipKeys?: string[], currentPath?: string): Record<string, any>;
|
package/dist/utils.js
CHANGED
|
@@ -554,3 +554,28 @@ export const unsetField = (keyPath, schema) => {
|
|
|
554
554
|
}
|
|
555
555
|
}
|
|
556
556
|
};
|
|
557
|
+
export function toDotNotation(obj, skipKeys, currentPath = "") {
|
|
558
|
+
const result = {};
|
|
559
|
+
for (const key in obj) {
|
|
560
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
561
|
+
const value = obj[key];
|
|
562
|
+
const newKey = currentPath ? `${currentPath}.${key}` : key;
|
|
563
|
+
if (skipKeys?.includes(key.toLowerCase())) {
|
|
564
|
+
// Preserve "or" and "and" keys with their exact values
|
|
565
|
+
result[newKey] = value;
|
|
566
|
+
}
|
|
567
|
+
else if (typeof value === "object" &&
|
|
568
|
+
value !== null &&
|
|
569
|
+
!Array.isArray(value)) {
|
|
570
|
+
// Recursively process nested objects
|
|
571
|
+
const nested = toDotNotation(value, skipKeys, newKey);
|
|
572
|
+
Object.assign(result, nested);
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
// Add primitive values directly
|
|
576
|
+
result[newKey] = value;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return result;
|
|
581
|
+
}
|