inibase 1.5.4 → 1.5.6

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
@@ -197,12 +197,12 @@ rl.on("line", async (input) => {
197
197
  console.log(`${textRed(" Err:")} Please specify table name`);
198
198
  break;
199
199
  }
200
- let where = undefined;
201
- let page = undefined;
202
- let perPage = undefined;
203
- let columns = undefined;
204
- let sort = undefined;
205
- let data = undefined;
200
+ let where;
201
+ let page;
202
+ let perPage;
203
+ let columns;
204
+ let sort;
205
+ let data;
206
206
  if (splitedInput.toSpliced(0, 1).length) {
207
207
  const parsedArgs = parseArgs({
208
208
  args: splitedInput.toSpliced(0, table ? 1 : 2),
package/dist/index.d.ts CHANGED
@@ -151,8 +151,8 @@ export default class Inibase {
151
151
  get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers?: false, _whereIsLinesNumbers?: boolean): Promise<(Data & TData) | null>;
152
152
  get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false, _whereIsLinesNumbers?: boolean): Promise<(Data & TData) | null>;
153
153
  get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where?: string | number | (string | number)[] | Criteria, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false, _whereIsLinesNumbers?: boolean): Promise<(Data & TData)[] | null>;
154
- get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: false | undefined, onlyLinesNumbers: true, _whereIsLinesNumbers?: boolean): Promise<number[] | null>;
155
- get<TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers: true, _whereIsLinesNumbers?: boolean): Promise<number | null>;
154
+ get<_TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: false | undefined, onlyLinesNumbers: true, _whereIsLinesNumbers?: boolean): Promise<number[] | null>;
155
+ get<_TData extends Record<string, any> & Partial<Data>>(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers: true, _whereIsLinesNumbers?: boolean): Promise<number | null>;
156
156
  /**
157
157
  * Create new item(s) in a table
158
158
  *
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import "dotenv/config";
2
2
  import { randomBytes, scryptSync } from "node:crypto";
3
3
  import { appendFileSync, existsSync, readFileSync } from "node:fs";
4
- import { glob, mkdir, readFile, readdir, rename, rm, unlink, writeFile, } from "node:fs/promises";
4
+ import { glob, mkdir, readdir, readFile, rename, rm, unlink, writeFile, } from "node:fs/promises";
5
5
  import { join, parse } from "node:path";
6
6
  import { inspect } from "node:util";
7
7
  import Inison from "inison";
@@ -195,7 +195,7 @@ export default class Inibase {
195
195
  await writeFile(join(tablePath, "0.schema"), "");
196
196
  await writeFile(join(tablePath, "0-0.pagination"), "");
197
197
  }
198
- // Function to replace the string in one schema.json file
198
+ // Function to replace the string in one schema file
199
199
  async replaceStringInFile(filePath, targetString, replaceString) {
200
200
  const data = await readFile(filePath, "utf8");
201
201
  if (data.includes(targetString)) {
@@ -223,7 +223,7 @@ export default class Inibase {
223
223
  value: schemaIdFilePath ? Number(parse(schemaIdFilePath).name) : 0,
224
224
  };
225
225
  schema = Utils.addIdToSchema(schema, lastSchemaID);
226
- // if schema.json exists, update columns files names based on field id
226
+ // if schema file exists, update columns files names based on field id
227
227
  if ((await File.isExists(join(tablePath, `schema.${this.schemaFileExtension}`))) &&
228
228
  table.schema?.length) {
229
229
  const replaceOldPathes = Utils.findChangedProperties(this.schemaToIdsPath(tableName, table.schema), this.schemaToIdsPath(tableName, schema));
@@ -333,7 +333,7 @@ export default class Inibase {
333
333
  throw this.createError("TABLE_NOT_EXISTS", tableName);
334
334
  if (!globalConfig[this.databasePath].tables.has(tableName) ||
335
335
  globalConfig[this.databasePath].tables.get(tableName).timestamp !==
336
- (await File.getFileDate(join(tablePath, "schema.json"))))
336
+ (await File.getFileDate(join(tablePath, `schema.${this.schemaFileExtension}`))))
337
337
  globalConfig[this.databasePath].tables.set(tableName, {
338
338
  schema: await this.getTableSchema(tableName),
339
339
  config: {
@@ -342,7 +342,7 @@ export default class Inibase {
342
342
  prepend: await File.isExists(join(tablePath, ".prepend.config")),
343
343
  decodeID: await File.isExists(join(tablePath, ".decodeID.config")),
344
344
  },
345
- timestamp: await File.getFileDate(join(tablePath, "schema.json")),
345
+ timestamp: await File.getFileDate(join(tablePath, `schema.${this.schemaFileExtension}`)),
346
346
  });
347
347
  return globalConfig[this.databasePath].tables.get(tableName);
348
348
  }
@@ -1018,9 +1018,9 @@ export default class Inibase {
1018
1018
  else if (allTrue)
1019
1019
  return null;
1020
1020
  }
1021
- let searchOperator = undefined;
1022
- let searchComparedAtValue = undefined;
1023
- let searchLogicalOperator = undefined;
1021
+ let searchOperator;
1022
+ let searchComparedAtValue;
1023
+ let searchLogicalOperator;
1024
1024
  if (Utils.isObject(value)) {
1025
1025
  /* nested object with .and / .or inside */
1026
1026
  const nestedAnd = value.and;
@@ -1149,6 +1149,7 @@ export default class Inibase {
1149
1149
  options.columns = options.columns || [];
1150
1150
  options.page = options.page || 1;
1151
1151
  options.perPage = options.perPage || 15;
1152
+ let total;
1152
1153
  let RETURN;
1153
1154
  let schema = structuredClone((await this.getTable(tableName)).schema);
1154
1155
  if (!schema)
@@ -1345,6 +1346,12 @@ export default class Inibase {
1345
1346
  .map(({ id }) => id);
1346
1347
  RETURN = Object.values(Utils.deepMerge(LineNumberDataObj, await this.processSchemaData(tableName, Utils.filterSchema(schema, (field) => !alreadyExistsColumnsIDs.includes(field.id) ||
1347
1348
  Utils.isFieldType(field, "table")), Object.keys(LineNumberDataObj).map(Number), options)));
1349
+ total = Math.min(...[...this.totalItems.entries()]
1350
+ .filter(([k]) => k.startsWith(`${tableName}-`))
1351
+ .map(([, v]) => v));
1352
+ for (const [key] of this.totalItems)
1353
+ if (key.startsWith(`${tableName}-`) && key !== `${tableName}-id`)
1354
+ this.totalItems.delete(key);
1348
1355
  if (globalConfig[this.databasePath].tables.get(tableName).config.cache)
1349
1356
  await writeFile(cachedFilePath, Object.keys(LineNumberDataObj).join(","));
1350
1357
  }
@@ -1353,18 +1360,17 @@ export default class Inibase {
1353
1360
  (Utils.isObject(RETURN) && !Object.keys(RETURN).length) ||
1354
1361
  (Array.isArray(RETURN) && !RETURN.length))
1355
1362
  return null;
1356
- const greatestTotalItems = this.totalItems.has(`${tableName}-*`)
1357
- ? this.totalItems.get(`${tableName}-*`)
1358
- : Math.max(...[...this.totalItems.entries()]
1359
- .filter(([k]) => k.startsWith(`${tableName}-`))
1360
- .map(([, v]) => v));
1363
+ if (total === undefined)
1364
+ total = this.totalItems.has(`${tableName}-*`)
1365
+ ? this.totalItems.get(`${tableName}-*`)
1366
+ : Math.max(...[...this.totalItems.entries()]
1367
+ .filter(([k]) => k.startsWith(`${tableName}-`))
1368
+ .map(([, v]) => v));
1361
1369
  this.pageInfo[tableName] = {
1362
1370
  ...(({ columns, ...restOfOptions }) => restOfOptions)(options),
1363
1371
  perPage: Array.isArray(RETURN) ? RETURN.length : 1,
1364
- totalPages: options.perPage < 0
1365
- ? 1
1366
- : Math.ceil(greatestTotalItems / options.perPage),
1367
- total: greatestTotalItems,
1372
+ totalPages: options.perPage < 0 ? 1 : Math.ceil(total / options.perPage),
1373
+ total,
1368
1374
  };
1369
1375
  return onlyOne && Array.isArray(RETURN) ? RETURN[0] : RETURN;
1370
1376
  }
package/dist/utils.js CHANGED
@@ -64,7 +64,7 @@ export const isNumber = (input) => {
64
64
  return false;
65
65
  };
66
66
  // As a literal (no double-escaping).
67
- const emailPattern = /^[A-Za-z0-9!#%&'*+\/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#%&'*+\/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/;
67
+ const emailPattern = /^[A-Za-z0-9!#%&'*+/=?^_`{|}~-]+(?:\.[A-Za-z0-9!#%&'*+/=?^_`{|}~-]+)*@(?:[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?\.)+[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/;
68
68
  /**
69
69
  * Checks if the input is a valid email format.
70
70
  *
@@ -566,7 +566,7 @@ export const unsetField = (keyPath, schema) => {
566
566
  export function toDotNotation(obj, skipKeys, currentPath = "") {
567
567
  const result = {};
568
568
  for (const key in obj) {
569
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
569
+ if (Object.hasOwn(obj, key)) {
570
570
  const value = obj[key];
571
571
  const newKey = currentPath ? `${currentPath}.${key}` : key;
572
572
  if (skipKeys?.includes(key.toLowerCase())) {
@@ -3,10 +3,10 @@ import { execFile as execFileSync, exec as execSync } from "node:child_process";
3
3
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scryptSync, } from "node:crypto";
4
4
  import { promisify } from "node:util";
5
5
  import { gunzip as gunzipSync, gzip as gzipSync } from "node:zlib";
6
+ import Inison from "inison";
6
7
  import RE2 from "re2";
7
8
  import { globalConfig } from "./index.js";
8
9
  import { detectFieldType, isNumber, isPassword } from "./utils.js";
9
- import Inison from "inison";
10
10
  export const exec = promisify(execSync);
11
11
  export const execFile = promisify(execFileSync);
12
12
  export const gzip = promisify(gzipSync);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.5.4",
3
+ "version": "1.5.6",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",