inibase 1.0.0-rc.97 → 1.0.0-rc.99

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 CHANGED
@@ -89,7 +89,7 @@ const secureString = (input) => {
89
89
  decodedInput = decodeURIComponent(input.replace(/%(?![0-9][0-9a-fA-F]+)/g, ""));
90
90
  }
91
91
  // Replace characters using a single regular expression.
92
- return decodedInput.replace(/\\n/g, "\n").replace(/\n/g, "\\n");
92
+ return decodedInput.replace(/\r\n|\r|\n/g, "\\n");
93
93
  };
94
94
  /**
95
95
  * Encodes the input using 'secureString' and 'Inison.stringify' functions.
package/dist/index.js CHANGED
@@ -605,15 +605,15 @@ export default class Inibase {
605
605
  (await File.isExists(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`)))) {
606
606
  const itemsIDs = await File.get(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`), linesNumber, field.type, field.children, this.salt);
607
607
  if (itemsIDs) {
608
- const searchableIDs = {};
609
- for (const [index, item] of Object.entries(itemsIDs)) {
610
- if (!RETURN[index])
611
- RETURN[index] = {};
612
- if (item !== null && item !== undefined)
613
- searchableIDs[index] = item;
608
+ const searchableIDs = new Map();
609
+ for (const [lineNumber, lineContent] of Object.entries(itemsIDs)) {
610
+ if (!RETURN[lineNumber])
611
+ RETURN[lineNumber] = {};
612
+ if (lineContent !== null && lineContent !== undefined)
613
+ searchableIDs.set(lineNumber, lineContent);
614
614
  }
615
- if (Object.keys(searchableIDs).length) {
616
- const items = await this.get(field.table, [].concat(...Object.values(searchableIDs)), {
615
+ if (searchableIDs.size) {
616
+ const items = await this.get(field.table, Array.from(new Set(Array.from(searchableIDs.values()).flat())), {
617
617
  ...options,
618
618
  perPage: Number.POSITIVE_INFINITY,
619
619
  columns: options.columns
@@ -621,10 +621,10 @@ export default class Inibase {
621
621
  .map((column) => column.replace(`${field.key}.`, "")),
622
622
  });
623
623
  if (items) {
624
- let cursor = 0;
625
- for (const [index, Ids] of Object.entries(searchableIDs)) {
626
- RETURN[index][field.key] = items.slice(cursor, cursor + Ids.length);
627
- cursor += Ids.length;
624
+ for (const [lineNumber, lineContent,] of searchableIDs.entries()) {
625
+ const foundedItems = items.filter(({ id }) => lineContent.includes(id));
626
+ if (foundedItems)
627
+ RETURN[lineNumber][field.key] = foundedItems;
628
628
  }
629
629
  }
630
630
  }
@@ -660,15 +660,15 @@ export default class Inibase {
660
660
  (await File.isExists(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`)))) {
661
661
  const itemsIDs = await File.get(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`), linesNumber, field.type, field.children, this.salt);
662
662
  if (itemsIDs) {
663
- const searchableIDs = {};
664
- for (const [index, item] of Object.entries(itemsIDs)) {
665
- if (!RETURN[index])
666
- RETURN[index] = {};
667
- if (item !== null && item !== undefined)
668
- searchableIDs[index] = item;
663
+ const searchableIDs = new Map();
664
+ for (const [lineNumber, lineContent] of Object.entries(itemsIDs)) {
665
+ if (!RETURN[lineNumber])
666
+ RETURN[lineNumber] = {};
667
+ if (lineContent !== null && lineContent !== undefined)
668
+ searchableIDs.set(lineNumber, lineContent);
669
669
  }
670
- if (Object.keys(searchableIDs).length) {
671
- const items = await this.get(field.table, Object.values(searchableIDs), {
670
+ if (searchableIDs.size) {
671
+ const items = await this.get(field.table, Array.from(new Set(searchableIDs.values())), {
672
672
  ...options,
673
673
  perPage: Number.POSITIVE_INFINITY,
674
674
  columns: options.columns
@@ -676,10 +676,10 @@ export default class Inibase {
676
676
  .map((column) => column.replace(`${field.key}.`, "")),
677
677
  });
678
678
  if (items) {
679
- let cursor = 0;
680
- for (const [index] of Object.entries(searchableIDs)) {
681
- RETURN[index][field.key] = items[cursor];
682
- cursor++;
679
+ for (const [lineNumber, lineContent,] of searchableIDs.entries()) {
680
+ const foundedItem = items.find(({ id }) => id === lineContent);
681
+ if (foundedItem)
682
+ RETURN[lineNumber][field.key] = foundedItem;
683
683
  }
684
684
  }
685
685
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.97",
3
+ "version": "1.0.0-rc.99",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",