inibase 1.0.0-rc.68 → 1.0.0-rc.69
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.js +13 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -850,11 +850,9 @@ export default class Inibase {
|
|
|
850
850
|
if (await File.isExists(join(tablePath, ".pagination")))
|
|
851
851
|
this.totalItems[`${tableName}-*`] = Number((await readFile(join(tablePath, ".pagination"), "utf8")).split(",")[1]);
|
|
852
852
|
else {
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
this.totalItems[`${tableName}-*`] = totalItems;
|
|
857
|
-
await writeFile(join(tablePath, ".pagination"), `${lastId},${totalItems}`);
|
|
853
|
+
const lastId = Number(Object.keys((await File.get(join(tablePath, `id${this.getFileExtension(tableName)}`), -1, "number", undefined, this.salt, true))?.[0] ?? 0));
|
|
854
|
+
this.totalItems[`${tableName}-*`] = await File.count(join(tablePath, `id${this.getFileExtension(tableName)}`));
|
|
855
|
+
await writeFile(join(tablePath, ".pagination"), `${lastId},${this.totalItems[`${tableName}-*`]}`);
|
|
858
856
|
}
|
|
859
857
|
}
|
|
860
858
|
else if ((Array.isArray(where) && where.every(Utils.isNumber)) ||
|
|
@@ -945,19 +943,17 @@ export default class Inibase {
|
|
|
945
943
|
returnPostedData = false;
|
|
946
944
|
let RETURN;
|
|
947
945
|
const keys = UtilsServer.hashString(Object.keys(Array.isArray(data) ? data[0] : data).join("."));
|
|
948
|
-
let lastId = 0,
|
|
946
|
+
let lastId = 0, renameList = [];
|
|
949
947
|
try {
|
|
950
948
|
await File.lock(join(tablePath, ".tmp"), keys);
|
|
951
949
|
if (await File.isExists(join(tablePath, `id${this.getFileExtension(tableName)}`))) {
|
|
952
950
|
if (await File.isExists(join(tablePath, ".pagination")))
|
|
953
|
-
[lastId, totalItems] = (await readFile(join(tablePath, ".pagination"), "utf8"))
|
|
951
|
+
[lastId, this.totalItems[`${tableName}-*`]] = (await readFile(join(tablePath, ".pagination"), "utf8"))
|
|
954
952
|
.split(",")
|
|
955
953
|
.map(Number);
|
|
956
954
|
else {
|
|
957
|
-
|
|
958
|
-
[
|
|
959
|
-
if (lastIdObj)
|
|
960
|
-
lastId = Number(Object.keys(lastIdObj)?.[0] ?? 0);
|
|
955
|
+
const lastId = Number(Object.keys((await File.get(join(tablePath, `id${this.getFileExtension(tableName)}`), -1, "number", undefined, this.salt, true))?.[0] ?? 0));
|
|
956
|
+
this.totalItems[`${tableName}-*`] = await File.count(join(tablePath, `id${this.getFileExtension(tableName)}`));
|
|
961
957
|
}
|
|
962
958
|
}
|
|
963
959
|
if (Utils.isArrayOfObjects(data))
|
|
@@ -985,18 +981,20 @@ export default class Inibase {
|
|
|
985
981
|
: await File.append(path, content))));
|
|
986
982
|
await Promise.all(renameList.map(async ([tempPath, filePath]) => rename(tempPath, filePath)));
|
|
987
983
|
renameList = [];
|
|
988
|
-
totalItems += Array.isArray(RETURN)
|
|
984
|
+
this.totalItems[`${tableName}-*`] += Array.isArray(RETURN)
|
|
985
|
+
? RETURN.length
|
|
986
|
+
: 1;
|
|
989
987
|
if (this.tables[tableName].config.cache)
|
|
990
988
|
await this.clearCache(tableName);
|
|
991
|
-
await writeFile(join(tablePath, ".pagination"), `${lastId},${totalItems}`);
|
|
989
|
+
await writeFile(join(tablePath, ".pagination"), `${lastId},${this.totalItems[`${tableName}-*`]}`);
|
|
992
990
|
if (returnPostedData)
|
|
993
991
|
return this.get(tableName, this.tables[tableName].config.prepend
|
|
994
992
|
? Array.isArray(RETURN)
|
|
995
993
|
? RETURN.map((_, index) => index + 1)
|
|
996
994
|
: 1
|
|
997
995
|
: Array.isArray(RETURN)
|
|
998
|
-
? RETURN.map((_, index) => totalItems - index)
|
|
999
|
-
: totalItems, options, !Utils.isArrayOfObjects(data));
|
|
996
|
+
? RETURN.map((_, index) => this.totalItems[`${tableName}-*`] - index)
|
|
997
|
+
: this.totalItems[`${tableName}-*`], options, !Utils.isArrayOfObjects(data));
|
|
1000
998
|
}
|
|
1001
999
|
finally {
|
|
1002
1000
|
if (renameList.length)
|