inibase 1.0.0-rc.121 → 1.0.0-rc.122

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.
Files changed (2) hide show
  1. package/dist/index.js +7 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -20,10 +20,7 @@ export default class Inibase {
20
20
  totalItems;
21
21
  constructor(database, mainFolder = ".") {
22
22
  this.databasePath = join(mainFolder, database);
23
- this.tablesMap = new Map();
24
- this.totalItems = new Map();
25
- this.pageInfo = {};
26
- this.uniqueMap = new Map();
23
+ this.clear();
27
24
  if (!process.env.INIBASE_SECRET) {
28
25
  if (existsSync(".env") &&
29
26
  readFileSync(".env").includes("INIBASE_SECRET="))
@@ -437,18 +434,20 @@ export default class Inibase {
437
434
  const tablePath = join(this.databasePath, tableName);
438
435
  const flattenSchema = Utils.flattenSchema(this.tablesMap.get(tableName).schema);
439
436
  for await (const [_uniqueID, valueObject] of this.uniqueMap) {
440
- let valueExisted = false;
437
+ let index = 0;
441
438
  for await (const [columnID, values] of valueObject.columnsValues) {
439
+ index++;
442
440
  const field = flattenSchema.find(({ id }) => id === columnID);
443
- const [searchResult, totalLines] = await File.search(join(tablePath, `${columnID}${this.getFileExtension(tableName)}`), "[]", values, undefined, valueObject.exclude, field.type, field.children, 1, undefined, false, this.salt);
441
+ const [searchResult, totalLines] = await File.search(join(tablePath, `${field.key}${this.getFileExtension(tableName)}`), "[]", values, undefined, valueObject.exclude, field.type, field.children, 1, undefined, false, this.salt);
444
442
  if (searchResult && totalLines > 0) {
445
- if (valueExisted)
443
+ if (index === valueObject.columnsValues.size)
446
444
  throw this.createError("FIELD_UNIQUE", [
447
445
  field.key,
448
446
  Array.isArray(values) ? values.join(", ") : values,
449
447
  ]);
450
- valueExisted = true;
451
448
  }
449
+ else
450
+ continue;
452
451
  }
453
452
  }
454
453
  this.uniqueMap = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.121",
3
+ "version": "1.0.0-rc.122",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",