inibase 1.0.0-rc.33 → 1.0.0-rc.34

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 CHANGED
@@ -77,6 +77,7 @@ export default class Inibase {
77
77
  private getItemsFromSchema;
78
78
  private applyCriteria;
79
79
  private _filterSchemaByColumns;
80
+ clearCache(tablePath: string): Promise<void>;
80
81
  get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: true, onlyLinesNumbers?: undefined, tableSchema?: Schema): Promise<Data | null>;
81
82
  get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: boolean | undefined, onlyLinesNumbers?: true, tableSchema?: Schema): Promise<number[] | null>;
82
83
  post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void | null>;
package/dist/index.js CHANGED
@@ -589,6 +589,11 @@ export default class Inibase {
589
589
  })
590
590
  .filter((i) => i);
591
591
  }
592
+ async clearCache(tablePath) {
593
+ await Promise.all((await readdir(join(tablePath, ".tmp")))
594
+ ?.filter((fileName) => !["pagination.inib", "locked.inib"].includes(fileName))
595
+ .map(async (file) => unlink(join(tablePath, ".tmp", file))));
596
+ }
592
597
  async get(tableName, where, options = {
593
598
  page: 1,
594
599
  perPage: 15,
@@ -632,6 +637,7 @@ export default class Inibase {
632
637
  }
633
638
  else if ((Array.isArray(where) && where.every(Utils.isNumber)) ||
634
639
  (Utils.isNumber(where) && !onlyLinesNumbers)) {
640
+ // "where" in this case, is the lineNumbers instead of IDs
635
641
  let lineNumbers = where;
636
642
  if (!Array.isArray(lineNumbers))
637
643
  lineNumbers = [lineNumbers];
@@ -752,12 +758,12 @@ export default class Inibase {
752
758
  await Promise.all(Object.entries(pathesContents).map(async ([path, content]) => renameList.push(await File.append(path, content))));
753
759
  await Promise.all(renameList.map(async ([tempPath, filePath]) => rename(tempPath, filePath)));
754
760
  renameList = [];
755
- if (Config.isCacheEnabled)
761
+ if (Config.isCacheEnabled) {
762
+ await this.clearCache(tablePath);
756
763
  await File.write(join(tablePath, ".tmp", "pagination.inib"), `${lastId},${totalItems + (Array.isArray(RETURN) ? RETURN.length : 1)}`, true);
764
+ }
757
765
  if (returnPostedData)
758
- return this.get(tableName, Utils.isArrayOfObjects(RETURN)
759
- ? RETURN.map((data) => Number(data.id))
760
- : RETURN.id, options, !Utils.isArrayOfObjects(data), // return only one item if data is not array of objects
766
+ return this.get(tableName, Array.isArray(RETURN) ? RETURN.map((_, index) => index + 1) : 1, options, !Utils.isArrayOfObjects(data), // return only one item if data is not array of objects
761
767
  undefined, schema);
762
768
  }
763
769
  finally {
@@ -806,9 +812,7 @@ export default class Inibase {
806
812
  await Promise.all(Object.entries(pathesContents).map(async ([path, content]) => renameList.push(await File.replace(path, content))));
807
813
  await Promise.all(renameList.map(async ([tempPath, filePath]) => rename(tempPath, filePath)));
808
814
  if (Config.isCacheEnabled)
809
- await Promise.all((await readdir(join(tablePath, ".tmp")))
810
- ?.filter((fileName) => !["pagination.inib", "locked.inib"].includes(fileName))
811
- .map(async (file) => unlink(join(tablePath, ".tmp", file))));
815
+ await this.clearCache(join(tablePath, ".tmp"));
812
816
  if (returnPostedData)
813
817
  return this.get(tableName, where, options, undefined, undefined, schema);
814
818
  }
@@ -849,9 +853,7 @@ export default class Inibase {
849
853
  await Promise.all(renameList.map(async ([tempPath, filePath]) => rename(tempPath, filePath)));
850
854
  renameList = [];
851
855
  if (Config.isCacheEnabled)
852
- await Promise.all((await readdir(join(tablePath, ".tmp")))
853
- ?.filter((fileName) => !["pagination.inib", "locked.inib"].includes(fileName))
854
- .map(async (file) => unlink(join(tablePath, ".tmp", file))));
856
+ await this.clearCache(tablePath);
855
857
  if (returnPostedData)
856
858
  return this.get(tableName, where, options, !Array.isArray(where), undefined, schema);
857
859
  }
@@ -886,9 +888,7 @@ export default class Inibase {
886
888
  ?.filter((fileName) => fileName.endsWith(".inib"))
887
889
  .map(async (file) => unlink(join(tablePath, file))));
888
890
  if (Config.isCacheEnabled)
889
- await Promise.all((await readdir(join(tablePath, ".tmp")))
890
- ?.filter((fileName) => !["pagination.inib", "locked.inib"].includes(fileName))
891
- .map(async (file) => unlink(join(tablePath, ".tmp", file))));
891
+ await this.clearCache(tablePath);
892
892
  }
893
893
  finally {
894
894
  await File.unlock(join(tablePath, ".tmp"));
@@ -920,9 +920,7 @@ export default class Inibase {
920
920
  await Promise.all(files.map(async (file) => renameList.push(await File.remove(join(tablePath, file), where))));
921
921
  await Promise.all(renameList.map(async ([tempPath, filePath]) => rename(tempPath, filePath)));
922
922
  if (Config.isCacheEnabled) {
923
- await Promise.all((await readdir(join(tablePath, ".tmp")))
924
- ?.filter((fileName) => !["pagination.inib", "locked.inib"].includes(fileName))
925
- .map(async (file) => unlink(join(tablePath, ".tmp", file))));
923
+ await this.clearCache(tablePath);
926
924
  if (await File.isExists(join(tablePath, ".tmp", "pagination.inib"))) {
927
925
  let [lastId, totalItems] = (await File.read(join(tablePath, ".tmp", "pagination.inib"), true))
928
926
  .split(",")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.33",
3
+ "version": "1.0.0-rc.34",
4
4
  "author": {
5
5
  "name": "Karim Amahtil",
6
6
  "email": "karim.amahtil@gmail.com"