inibase 1.1.17 → 1.1.19
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/file.js +2 -3
- package/dist/index.js +14 -12
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +25 -0
- package/package.json +1 -1
package/dist/file.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Transform } from "node:stream";
|
|
|
5
5
|
import { pipeline } from "node:stream/promises";
|
|
6
6
|
import { createGunzip, createGzip } from "node:zlib";
|
|
7
7
|
import Inison from "inison";
|
|
8
|
-
import { detectFieldType, isArrayOfObjects,
|
|
8
|
+
import { detectFieldType, isArrayOfObjects, isNumber, isObject, isStringified, } from "./utils.js";
|
|
9
9
|
import { compare, encodeID, exec, gunzip, gzip } from "./utils.server.js";
|
|
10
10
|
export const lock = async (folderPath, prefix) => {
|
|
11
11
|
let lockFile = null;
|
|
@@ -547,8 +547,7 @@ export const search = async (filePath, operator, comparedAtValue, logicalOperato
|
|
|
547
547
|
const decodedLine = decode(line, fieldType, fieldChildrenType, secretKey);
|
|
548
548
|
// Check if the line meets the specified conditions based on comparison and logical operators.
|
|
549
549
|
const doesMeetCondition = (Array.isArray(decodedLine) &&
|
|
550
|
-
|
|
551
|
-
decodedLine.some(meetsConditions)) ||
|
|
550
|
+
decodedLine.flat().some(meetsConditions)) ||
|
|
552
551
|
meetsConditions(decodedLine);
|
|
553
552
|
// If the line meets the conditions, process it.
|
|
554
553
|
if (doesMeetCondition) {
|
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;
|
|
@@ -1265,18 +1267,18 @@ export default class Inibase {
|
|
|
1265
1267
|
else if (Utils.isObject(where)) {
|
|
1266
1268
|
let cachedFilePath = "";
|
|
1267
1269
|
// Criteria
|
|
1268
|
-
if (this.tablesMap.get(tableName).config.cache)
|
|
1270
|
+
if (this.tablesMap.get(tableName).config.cache) {
|
|
1269
1271
|
cachedFilePath = join(tablePath, ".cache", `${UtilsServer.hashString(inspect(where, { sorted: true }))}${this.fileExtension}`);
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1272
|
+
if (await File.isExists(cachedFilePath)) {
|
|
1273
|
+
const cachedItems = (await readFile(cachedFilePath, "utf8")).split(",");
|
|
1274
|
+
if (!this.totalItems.has(`${tableName}-*`))
|
|
1275
|
+
this.totalItems.set(`${tableName}-*`, cachedItems.length);
|
|
1276
|
+
if (onlyLinesNumbers)
|
|
1277
|
+
return onlyOne ? Number(cachedItems[0]) : cachedItems.map(Number);
|
|
1278
|
+
return this.get(tableName, cachedItems
|
|
1279
|
+
.slice((options.page - 1) * options.perPage, options.page * options.perPage)
|
|
1280
|
+
.map(Number), options, onlyOne, undefined, true);
|
|
1281
|
+
}
|
|
1280
1282
|
}
|
|
1281
1283
|
const [LineNumberDataMap, linesNumbers] = await this.applyCriteria(tableName, options, where);
|
|
1282
1284
|
if (LineNumberDataMap && linesNumbers?.size) {
|
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
|
+
}
|