inibase 1.1.11 → 1.1.13

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/cli.js CHANGED
@@ -102,7 +102,7 @@ rl.on("line", async (input) => {
102
102
  const configName = splitedInput[index].toLocaleLowerCase();
103
103
  if (["true", "false"].includes(configName))
104
104
  continue;
105
- if (!["compression", "cache", "prepend"].includes(configName)) {
105
+ if (!["compression", "cache", "prepend", "decodeID"].includes(configName)) {
106
106
  console.log(`${textRed(" Err:")} '${configName}' is not a valid config`);
107
107
  break;
108
108
  }
package/dist/index.js CHANGED
@@ -641,7 +641,8 @@ export default class Inibase {
641
641
  return RETURN;
642
642
  }
643
643
  joinPathesContents(tableName, data) {
644
- const tablePath = join(this.databasePath, tableName), combinedData = this._CombineData(data);
644
+ const tablePath = join(this.databasePath, tableName);
645
+ const combinedData = this._CombineData(data);
645
646
  const newCombinedData = {};
646
647
  for (const [key, value] of Object.entries(combinedData))
647
648
  newCombinedData[join(tablePath, `${key}${this.getFileExtension(tableName)}`)] = value;
@@ -948,7 +949,9 @@ export default class Inibase {
948
949
  for await (const [key, value] of Object.entries(criteria)) {
949
950
  const field = Utils.getField(key, this.tablesMap.get(tableName).schema);
950
951
  index++;
951
- let searchOperator = undefined, searchComparedAtValue = undefined, searchLogicalOperator = undefined;
952
+ let searchOperator = undefined;
953
+ let searchComparedAtValue = undefined;
954
+ let searchLogicalOperator = undefined;
952
955
  if (Utils.isObject(value)) {
953
956
  if (value?.or &&
954
957
  Array.isArray(value?.or)) {
@@ -1002,7 +1005,9 @@ export default class Inibase {
1002
1005
  searchOperator = "=";
1003
1006
  searchComparedAtValue = value;
1004
1007
  }
1005
- const [searchResult, totalLines, linesNumbers] = await File.search(join(tablePath, `${key}${this.getFileExtension(tableName)}`), searchOperator ?? "=", searchComparedAtValue ?? null, searchLogicalOperator, allTrue ? searchIn : undefined, field?.type, field?.children, options.perPage, (options.page - 1) * options.perPage + 1, true, this.salt);
1008
+ const [searchResult, totalLines, linesNumbers] = await File.search(join(tablePath, `${key}${this.getFileExtension(tableName)}`), searchOperator ?? "=", searchComparedAtValue ?? null, searchLogicalOperator, allTrue ? searchIn : undefined, field?.type, field?.children, options.perPage, (options.page - 1) * options.perPage + 1, true, field.key === "id" && this.tablesMap.get(tableName).config.decodeID
1009
+ ? undefined
1010
+ : this.salt);
1006
1011
  if (searchResult) {
1007
1012
  const formatedSearchResult = Object.fromEntries(Object.entries(searchResult).map(([id, value]) => {
1008
1013
  const nestedObj = {};
@@ -1104,7 +1109,8 @@ export default class Inibase {
1104
1109
  (Utils.isObject(where) && !Object.keys(where).length)))
1105
1110
  where = undefined;
1106
1111
  if (options.sort) {
1107
- let sortArray, awkCommand = "";
1112
+ let sortArray;
1113
+ let awkCommand = "";
1108
1114
  if (Utils.isObject(options.sort) && !Array.isArray(options.sort)) {
1109
1115
  // {name: "ASC", age: "DESC"}
1110
1116
  sortArray = Object.entries(options.sort).map(([key, value]) => [
@@ -1133,14 +1139,16 @@ export default class Inibase {
1133
1139
  1)
1134
1140
  .map((lineNumber) => `NR==${lineNumber}`)
1135
1141
  .join(" || ")}'`;
1136
- const filesPathes = [["id", true], ...sortArray].map((column) => join(tablePath, `${column[0]}${this.getFileExtension(tableName)}`));
1142
+ const filesPathes = (sortArray.find(([key]) => key === "id")
1143
+ ? sortArray
1144
+ : [["id", true], ...sortArray]).map((column) => join(tablePath, `${column[0]}${this.getFileExtension(tableName)}`));
1137
1145
  for await (const path of filesPathes.slice(1))
1138
1146
  if (!(await File.isExists(path)))
1139
1147
  return null;
1140
1148
  // Construct the paste command to merge files and filter lines by IDs
1141
1149
  const pasteCommand = `paste '${filesPathes.join("' '")}'`;
1142
1150
  // Construct the sort command dynamically based on the number of files for sorting
1143
- const index = 2;
1151
+ const index = 1;
1144
1152
  const sortColumns = sortArray
1145
1153
  .map(([key, ascending], i) => {
1146
1154
  const field = Utils.getField(key, schema);
@@ -1178,8 +1186,13 @@ export default class Inibase {
1178
1186
  // Extract values for each file, including `id${this.getFileExtension(tableName)}`
1179
1187
  filesPathes.forEach((fileName, index) => {
1180
1188
  const field = Utils.getField(parse(fileName).name, schema);
1181
- if (field)
1182
- outputObject[field.key] = File.decode(splitedFileColumns[index], field?.type, field?.children, this.salt);
1189
+ if (field) {
1190
+ if (field.key === "id" &&
1191
+ this.tablesMap.get(tableName).config.decodeID)
1192
+ outputObject[field.key] = splitedFileColumns[index];
1193
+ else
1194
+ outputObject[field.key] = File.decode(splitedFileColumns[index], field?.type, field?.children, this.salt);
1195
+ }
1183
1196
  });
1184
1197
  return outputObject;
1185
1198
  });
@@ -1187,7 +1200,7 @@ export default class Inibase {
1187
1200
  return restOfColumns
1188
1201
  ? outputArray.map((item) => ({
1189
1202
  ...item,
1190
- ...restOfColumns.find(({ id }) => id === item.id),
1203
+ ...restOfColumns.find(({ id }) => id === (Utils.isNumber(item.id) ? Number(item.id) : item.id)),
1191
1204
  }))
1192
1205
  : outputArray;
1193
1206
  }
@@ -1271,7 +1284,8 @@ export default class Inibase {
1271
1284
  return onlyOne
1272
1285
  ? linesNumbers.values().next().value
1273
1286
  : Array.from(linesNumbers);
1274
- const alreadyExistsColumns = Object.keys(Object.values(LineNumberDataMap)[0]), alreadyExistsColumnsIDs = Utils.flattenSchema(schema)
1287
+ const alreadyExistsColumns = Object.keys(Object.values(LineNumberDataMap)[0]);
1288
+ const alreadyExistsColumnsIDs = Utils.flattenSchema(schema)
1275
1289
  .filter(({ key }) => alreadyExistsColumns.includes(key))
1276
1290
  .map(({ id }) => id);
1277
1291
  RETURN = Object.values(Utils.deepMerge(LineNumberDataMap, await this.processSchemaData(tableName, Utils.filterSchema(schema, ({ id, type, children }) => !alreadyExistsColumnsIDs.includes(id) ||
@@ -1295,15 +1309,6 @@ export default class Inibase {
1295
1309
  totalPages: Math.ceil(greatestTotalItems / options.perPage),
1296
1310
  total: greatestTotalItems,
1297
1311
  };
1298
- // if (this.tablesMap.get(tableName).config.decodeID) {
1299
- // if (Array.isArray(RETURN)) {
1300
- // for (let index = 0; index < RETURN.length; index++)
1301
- // RETURN[index].id = UtilsServer.decodeID(
1302
- // RETURN[index].id as string,
1303
- // this.salt,
1304
- // );
1305
- // } else RETURN.id = UtilsServer.decodeID(RETURN.id as string, this.salt);
1306
- // }
1307
1312
  return onlyOne && Array.isArray(RETURN) ? RETURN[0] : RETURN;
1308
1313
  }
1309
1314
  async post(tableName, data, options, returnPostedData) {
@@ -1469,7 +1474,8 @@ export default class Inibase {
1469
1474
  (Array.isArray(where) && where.every(Utils.isValidID)) ||
1470
1475
  Utils.isValidID(where)) {
1471
1476
  const lineNumbers = await this.get(tableName, where, undefined, undefined, true);
1472
- return this.put(tableName, clonedData, lineNumbers, options, false, true);
1477
+ if (lineNumbers)
1478
+ return this.put(tableName, clonedData, lineNumbers, options, returnUpdatedData, true);
1473
1479
  }
1474
1480
  else if (Utils.isObject(where)) {
1475
1481
  const lineNumbers = await this.get(tableName, where, undefined, undefined, true);
@@ -221,6 +221,9 @@ export const isEqual = (originalValue, comparedValue, fieldType) => {
221
221
  // If both are null-like, treat as equivalent
222
222
  if (isOriginalNullLike && isComparedNullLike)
223
223
  return true;
224
+ // If both are number-like
225
+ if (isNumber(originalValue) && isNumber(comparedValue))
226
+ return Number(originalValue) === Number(comparedValue);
224
227
  // Direct equality check for other cases
225
228
  return originalValue === comparedValue;
226
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",