inibase 1.0.0-rc.67 → 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.d.ts +1 -2
- package/dist/index.js +17 -19
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -33,7 +33,7 @@ export interface TableObject {
|
|
|
33
33
|
config: Config;
|
|
34
34
|
}
|
|
35
35
|
export type ComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "*" | "!*" | "[]" | "![]";
|
|
36
|
-
type pageInfo = {
|
|
36
|
+
export type pageInfo = {
|
|
37
37
|
total?: number;
|
|
38
38
|
totalPages?: number;
|
|
39
39
|
} & Options;
|
|
@@ -201,4 +201,3 @@ export default class Inibase {
|
|
|
201
201
|
*/
|
|
202
202
|
sort(tableName: string, columns: string | string[] | Record<string, 1 | -1 | "asc" | "ASC" | "desc" | "DESC">, where?: string | number | (string | number)[] | Criteria, options?: Options): Promise<any[]>;
|
|
203
203
|
}
|
|
204
|
-
export {};
|
package/dist/index.js
CHANGED
|
@@ -689,7 +689,7 @@ export default class Inibase {
|
|
|
689
689
|
if (searchResult) {
|
|
690
690
|
RETURN = Utils.deepMerge(RETURN, Object.fromEntries(Object.entries(searchResult).filter(([_k, v], _i) => Object.keys(v).length ===
|
|
691
691
|
Object.keys(criteria.and ?? {}).length)));
|
|
692
|
-
|
|
692
|
+
criteria.and = undefined;
|
|
693
693
|
RETURN_LineNumbers = lineNumbers;
|
|
694
694
|
}
|
|
695
695
|
else
|
|
@@ -697,7 +697,7 @@ export default class Inibase {
|
|
|
697
697
|
}
|
|
698
698
|
if (criteria.or && Utils.isObject(criteria.or)) {
|
|
699
699
|
const [searchResult, lineNumbers] = await this.applyCriteria(tableName, schema, options, criteria.or, false);
|
|
700
|
-
|
|
700
|
+
criteria.or = undefined;
|
|
701
701
|
if (searchResult) {
|
|
702
702
|
RETURN = Utils.deepMerge(RETURN, searchResult);
|
|
703
703
|
RETURN_LineNumbers = lineNumbers;
|
|
@@ -724,7 +724,7 @@ export default class Inibase {
|
|
|
724
724
|
searchComparedAtValue = searchCriteria.map((single_or) => single_or[1]);
|
|
725
725
|
searchLogicalOperator = "or";
|
|
726
726
|
}
|
|
727
|
-
|
|
727
|
+
value.or = undefined;
|
|
728
728
|
}
|
|
729
729
|
if (value?.and &&
|
|
730
730
|
Array.isArray(value?.and)) {
|
|
@@ -738,7 +738,7 @@ export default class Inibase {
|
|
|
738
738
|
searchComparedAtValue = searchCriteria.map((single_and) => single_and[1]);
|
|
739
739
|
searchLogicalOperator = "and";
|
|
740
740
|
}
|
|
741
|
-
|
|
741
|
+
value.and = undefined;
|
|
742
742
|
}
|
|
743
743
|
}
|
|
744
744
|
else if (Array.isArray(value)) {
|
|
@@ -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)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inibase",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.69",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Karim Amahtil",
|
|
@@ -69,16 +69,17 @@
|
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/node": "^20.12.11",
|
|
72
|
-
"tinybench": "^2.6.0"
|
|
72
|
+
"tinybench": "^2.6.0",
|
|
73
|
+
"typescript": "^5.4.5"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
76
|
"dotenv": "^16.4.5",
|
|
76
77
|
"inison": "^1.0.0-rc.2"
|
|
77
78
|
},
|
|
78
79
|
"scripts": {
|
|
79
|
-
"build": "tsc",
|
|
80
|
-
"benchmark": "tsx ./benchmark/index",
|
|
81
|
-
"benchmark:single": "tsx --expose-gc ./benchmark/single",
|
|
82
|
-
"benchmark:bulk": "tsx --expose-gc ./benchmark/bulk"
|
|
80
|
+
"build": "npx tsc",
|
|
81
|
+
"benchmark": "npx tsx ./benchmark/index",
|
|
82
|
+
"benchmark:single": "npx tsx --expose-gc ./benchmark/single",
|
|
83
|
+
"benchmark:bulk": "npx tsx --expose-gc ./benchmark/bulk"
|
|
83
84
|
}
|
|
84
85
|
}
|