inibase 1.2.14 → 1.2.16
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 +1 -1
- package/dist/index.js +13 -14
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -68,7 +68,7 @@ export default class Inibase {
|
|
|
68
68
|
fileExtension: string;
|
|
69
69
|
private databasePath;
|
|
70
70
|
private uniqueMap;
|
|
71
|
-
|
|
71
|
+
totalItems: Map<string, number>;
|
|
72
72
|
constructor(database: string, mainFolder?: string, language?: ErrorLang);
|
|
73
73
|
private static errorMessages;
|
|
74
74
|
createError(name: ErrorCodes, variable?: string | number | (string | number)[]): Error;
|
package/dist/index.js
CHANGED
|
@@ -908,7 +908,7 @@ export default class Inibase {
|
|
|
908
908
|
? lineContent
|
|
909
909
|
.map((singleContent) => singleContent
|
|
910
910
|
? Array.isArray(singleContent)
|
|
911
|
-
? singleContent.map(formatLineContent)
|
|
911
|
+
? singleContent.map(formatLineContent).filter(Boolean)
|
|
912
912
|
: items?.find(({ id }) => singleContent === id)
|
|
913
913
|
: singleContent)
|
|
914
914
|
.filter(Boolean)
|
|
@@ -1037,8 +1037,10 @@ export default class Inibase {
|
|
|
1037
1037
|
}
|
|
1038
1038
|
if (criteriaAND && Utils.isObject(criteriaAND)) {
|
|
1039
1039
|
const searchResult = await this.applyCriteria(tableName, options, criteriaAND, true, searchIn);
|
|
1040
|
-
if (searchResult)
|
|
1040
|
+
if (searchResult) {
|
|
1041
|
+
searchIn = new Set(Object.keys(searchResult).map(Number));
|
|
1041
1042
|
RETURN = Utils.deepMerge(RETURN, Object.fromEntries(Object.entries(searchResult).filter(([_k, v], _i) => Object.keys(v).filter((key) => Object.keys(criteriaAND).includes(key)).length)));
|
|
1043
|
+
}
|
|
1042
1044
|
else
|
|
1043
1045
|
return null;
|
|
1044
1046
|
}
|
|
@@ -1230,8 +1232,7 @@ export default class Inibase {
|
|
|
1230
1232
|
: Array.from({ length: options.perPage }, (_, index) => (options.page - 1) * options.perPage +
|
|
1231
1233
|
index +
|
|
1232
1234
|
1), options));
|
|
1233
|
-
|
|
1234
|
-
this.totalItems.set(`${tableName}-*`, pagination[1]);
|
|
1235
|
+
this.totalItems.set(`${tableName}-id`, pagination[1]);
|
|
1235
1236
|
}
|
|
1236
1237
|
else if (((Array.isArray(where) && where.every(Utils.isNumber)) ||
|
|
1237
1238
|
Utils.isNumber(where)) &&
|
|
@@ -1241,8 +1242,7 @@ export default class Inibase {
|
|
|
1241
1242
|
let lineNumbers = where;
|
|
1242
1243
|
if (!Array.isArray(lineNumbers))
|
|
1243
1244
|
lineNumbers = [lineNumbers];
|
|
1244
|
-
|
|
1245
|
-
this.totalItems.set(`${tableName}-*`, lineNumbers.length);
|
|
1245
|
+
this.totalItems.set(`${tableName}-id`, lineNumbers.length);
|
|
1246
1246
|
// useless
|
|
1247
1247
|
if (onlyLinesNumbers)
|
|
1248
1248
|
return lineNumbers;
|
|
@@ -1259,11 +1259,10 @@ export default class Inibase {
|
|
|
1259
1259
|
let Ids = where;
|
|
1260
1260
|
if (!Array.isArray(Ids))
|
|
1261
1261
|
Ids = [Ids];
|
|
1262
|
-
const [lineNumbers, countItems] = await File.search(join(tablePath, `id${this.getFileExtension(tableName)}`), "[]", Ids.map((id) => Utils.isNumber(id) ? Number(id) : UtilsServer.decodeID(id)), undefined, undefined, { key: "BLABLA", type: "number" }, Ids.length, 0, !this.totalItems.has(`${tableName}
|
|
1262
|
+
const [lineNumbers, countItems] = await File.search(join(tablePath, `id${this.getFileExtension(tableName)}`), "[]", Ids.map((id) => Utils.isNumber(id) ? Number(id) : UtilsServer.decodeID(id)), undefined, undefined, { key: "BLABLA", type: "number" }, Ids.length, 0, !this.totalItems.has(`${tableName}-id`));
|
|
1263
1263
|
if (!lineNumbers)
|
|
1264
1264
|
return null;
|
|
1265
|
-
|
|
1266
|
-
this.totalItems.set(`${tableName}-*`, countItems);
|
|
1265
|
+
this.totalItems.set(`${tableName}-id`, countItems);
|
|
1267
1266
|
if (onlyLinesNumbers)
|
|
1268
1267
|
return Object.keys(lineNumbers).length
|
|
1269
1268
|
? Object.keys(lineNumbers).map(Number)
|
|
@@ -1293,10 +1292,9 @@ export default class Inibase {
|
|
|
1293
1292
|
.map(Number), options, onlyOne, undefined, true);
|
|
1294
1293
|
}
|
|
1295
1294
|
}
|
|
1296
|
-
const LineNumberDataObj = await this.applyCriteria(tableName, options, where);
|
|
1295
|
+
const LineNumberDataObj = await this.applyCriteria(tableName, options, structuredClone(where));
|
|
1297
1296
|
if (LineNumberDataObj) {
|
|
1298
|
-
|
|
1299
|
-
this.totalItems.set(`${tableName}-*`, Object.keys(LineNumberDataObj).length);
|
|
1297
|
+
this.totalItems.set(`${tableName}-*`, Object.keys(LineNumberDataObj).length);
|
|
1300
1298
|
if (onlyLinesNumbers)
|
|
1301
1299
|
return onlyOne
|
|
1302
1300
|
? Number(Object.keys(LineNumberDataObj)[0])
|
|
@@ -1309,7 +1307,6 @@ export default class Inibase {
|
|
|
1309
1307
|
Utils.isFieldType(field, "table")), Object.keys(LineNumberDataObj).map(Number), options)));
|
|
1310
1308
|
if (globalConfig[this.databasePath].tables.get(tableName).config.cache)
|
|
1311
1309
|
await writeFile(cachedFilePath, Object.keys(LineNumberDataObj).join(","));
|
|
1312
|
-
this.totalItems.delete(`${tableName}-*`);
|
|
1313
1310
|
}
|
|
1314
1311
|
}
|
|
1315
1312
|
if (!RETURN ||
|
|
@@ -1324,7 +1321,9 @@ export default class Inibase {
|
|
|
1324
1321
|
this.pageInfo[tableName] = {
|
|
1325
1322
|
...(({ columns, ...restOfOptions }) => restOfOptions)(options),
|
|
1326
1323
|
perPage: Array.isArray(RETURN) ? RETURN.length : 1,
|
|
1327
|
-
totalPages:
|
|
1324
|
+
totalPages: options.perPage < 0
|
|
1325
|
+
? undefined
|
|
1326
|
+
: Math.ceil(greatestTotalItems / options.perPage),
|
|
1328
1327
|
total: greatestTotalItems,
|
|
1329
1328
|
};
|
|
1330
1329
|
return onlyOne && Array.isArray(RETURN) ? RETURN[0] : RETURN;
|