inibase 1.1.22 → 1.1.23

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
@@ -7,7 +7,7 @@ import { parseArgs } from "node:util";
7
7
  import Inison from "inison";
8
8
  import { isExists } from "./file.js";
9
9
  import Inibase, {} from "./index.js";
10
- import { isStringified, isNumber, setField, unsetField } from "./utils.js";
10
+ import { isNumber, isStringified, setField, unsetField } from "./utils.js";
11
11
  const textGreen = (input) => `\u001b[1;32m${input}\u001b[0m`;
12
12
  const textRed = (input) => `\u001b[1;31m${input}\u001b[0m`;
13
13
  const textBlue = (input) => `\u001b[1;34m${input}\u001b[0m`;
@@ -197,7 +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, page = undefined, perPage = undefined, columns = undefined, sort = undefined, data = undefined;
200
+ let where = undefined;
201
+ let page = undefined;
202
+ let perPage = undefined;
203
+ let columns = undefined;
204
+ let sort = undefined;
205
+ let data = undefined;
201
206
  if (splitedInput.toSpliced(0, 1).length) {
202
207
  const parsedArgs = parseArgs({
203
208
  args: splitedInput.toSpliced(0, table ? 1 : 2),
package/dist/file.js CHANGED
@@ -133,7 +133,6 @@ const unSecureString = (input) => {
133
133
  *
134
134
  * @param value - The value to be decoded, can be string, number, or array.
135
135
  * @param field - Field object config.
136
- * @param fieldChildrenType - Optional type for children elements, used for arrays.
137
136
  * @returns Decoded value, transformed according to the specified field type(s).
138
137
  */
139
138
  const decodeHelper = (value, field) => {
@@ -159,7 +158,7 @@ const decodeHelper = (value, field) => {
159
158
  return isNumber(value) &&
160
159
  (!field.table ||
161
160
  !field.databasePath ||
162
- !globalConfig[field.databasePath].tables.get(field.table).config
161
+ !globalConfig[field.databasePath].tables?.get(field.table)?.config
163
162
  .decodeID)
164
163
  ? encodeID(value)
165
164
  : value;
@@ -217,7 +216,8 @@ export async function get(filePath, lineNumbers, field, readWholeFile = false) {
217
216
  let fileHandle = null;
218
217
  try {
219
218
  fileHandle = await open(filePath, "r");
220
- const rl = createReadLineInternface(filePath, fileHandle), lines = {};
219
+ const rl = createReadLineInternface(filePath, fileHandle);
220
+ const lines = {};
221
221
  let linesCount = 0;
222
222
  if (!lineNumbers) {
223
223
  for await (const line of rl) {
@@ -229,7 +229,8 @@ export async function get(filePath, lineNumbers, field, readWholeFile = false) {
229
229
  const escapedFilePath = escapeShellPath(filePath);
230
230
  const command = filePath.endsWith(".gz")
231
231
  ? `zcat ${escapedFilePath} | sed -n '$p'`
232
- : `sed -n '$p' ${escapedFilePath}`, foundedLine = (await exec(command)).stdout.trimEnd();
232
+ : `sed -n '$p' ${escapedFilePath}`;
233
+ const foundedLine = (await exec(command)).stdout.trimEnd();
233
234
  if (foundedLine)
234
235
  lines[linesCount] = decode(foundedLine, field);
235
236
  }
@@ -251,7 +252,8 @@ export async function get(filePath, lineNumbers, field, readWholeFile = false) {
251
252
  const escapedFilePath = escapeShellPath(filePath);
252
253
  const command = filePath.endsWith(".gz")
253
254
  ? `zcat ${escapedFilePath} | sed -n '${_groupIntoRanges(lineNumbers)}'`
254
- : `sed -n '${_groupIntoRanges(lineNumbers)}' ${escapedFilePath}`, foundedLines = (await exec(command)).stdout.trimEnd().split("\n");
255
+ : `sed -n '${_groupIntoRanges(lineNumbers)}' ${escapedFilePath}`;
256
+ const foundedLines = (await exec(command)).stdout.trimEnd().split("\n");
255
257
  let index = 0;
256
258
  for (const line of foundedLines) {
257
259
  lines[lineNumbers[index]] = decode(line, field);
@@ -589,7 +591,8 @@ export const search = async (filePath, operator, comparedAtValue, logicalOperato
589
591
  * Note: Decodes each line as a number using the 'decode' function. Non-numeric lines contribute 0 to the sum.
590
592
  */
591
593
  export const sum = async (filePath, lineNumbers) => {
592
- let sum = 0, fileHandle = null;
594
+ let sum = 0;
595
+ let fileHandle = null;
593
596
  try {
594
597
  fileHandle = await open(filePath, "r");
595
598
  const rl = createReadLineInternface(filePath, fileHandle);
@@ -625,7 +628,9 @@ export const sum = async (filePath, lineNumbers) => {
625
628
  * Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the maximum.
626
629
  */
627
630
  export const max = async (filePath, lineNumbers) => {
628
- let max = 0, fileHandle = null, rl = null;
631
+ let max = 0;
632
+ let fileHandle = null;
633
+ let rl = null;
629
634
  try {
630
635
  fileHandle = await open(filePath, "r");
631
636
  rl = createReadLineInternface(filePath, fileHandle);
@@ -666,7 +671,8 @@ export const max = async (filePath, lineNumbers) => {
666
671
  * Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the minimum.
667
672
  */
668
673
  export const min = async (filePath, lineNumbers) => {
669
- let min = 0, fileHandle = null;
674
+ let min = 0;
675
+ let fileHandle = null;
670
676
  try {
671
677
  fileHandle = await open(filePath, "r");
672
678
  const rl = createReadLineInternface(filePath, fileHandle);
package/dist/index.js CHANGED
@@ -436,28 +436,30 @@ export default class Inibase {
436
436
  }, {});
437
437
  return Object.keys(cleanedObject).length > 0 ? cleanedObject : null;
438
438
  }
439
- formatField(value, fieldType, fieldChildrenType, _formatOnlyAvailiableKeys) {
439
+ formatField(value, field, _formatOnlyAvailiableKeys) {
440
440
  if (value === null || value === undefined)
441
441
  return value;
442
- if (Array.isArray(fieldType))
443
- fieldType = Utils.detectFieldType(value, fieldType) ?? fieldType[0];
444
- if (Array.isArray(value) && !["array", "json"].includes(fieldType))
442
+ if (Array.isArray(field.type))
443
+ field.type = Utils.detectFieldType(value, field.type) ?? field.type[0];
444
+ if (Array.isArray(value) && !["array", "json"].includes(field.type))
445
445
  value = value[0];
446
- switch (fieldType) {
446
+ switch (field.type) {
447
447
  case "array":
448
- if (!fieldChildrenType)
448
+ if (!field.children)
449
449
  return null;
450
450
  if (!Array.isArray(value))
451
451
  value = [value];
452
- if (Utils.isArrayOfObjects(fieldChildrenType)) {
453
- return this.formatData(value, fieldChildrenType, _formatOnlyAvailiableKeys);
454
- }
452
+ if (Utils.isArrayOfObjects(field.children))
453
+ return this.formatData(value, field.children, _formatOnlyAvailiableKeys);
455
454
  if (!value.length)
456
455
  return null;
457
- return value.map((_value) => this.formatField(_value, fieldChildrenType));
456
+ return value.map((_value) => this.formatField(_value, {
457
+ ...field,
458
+ type: field.children,
459
+ }));
458
460
  case "object":
459
- if (Utils.isArrayOfObjects(fieldChildrenType))
460
- return this.formatData(value, fieldChildrenType, _formatOnlyAvailiableKeys);
461
+ if (Utils.isArrayOfObjects(field.children))
462
+ return this.formatData(value, field.children, _formatOnlyAvailiableKeys);
461
463
  break;
462
464
  case "table":
463
465
  if (Utils.isObject(value)) {
@@ -569,7 +571,7 @@ export default class Inibase {
569
571
  RETURN[field.key] = this.getDefaultValue(field);
570
572
  continue;
571
573
  }
572
- RETURN[field.key] = this.formatField(clonedData[field.key], field.type, field.children, formatOnlyAvailiableKeys);
574
+ RETURN[field.key] = this.formatField(clonedData[field.key], field, formatOnlyAvailiableKeys);
573
575
  }
574
576
  return RETURN;
575
577
  }
@@ -49,8 +49,7 @@ export declare const hashString: (str: string) => string;
49
49
  * @param operator - The comparison operator (e.g., '=', '!=', '>', '<', '>=', '<=', '[]', '![]', '*', '!*').
50
50
  * @param originalValue - The value to compare, can be a single value or an array of values.
51
51
  * @param comparedValue - The value or values to compare against.
52
- * @param field - Field object config.
53
- * @param fieldChildrenType - Optional type for child elements in array inputs.
52
+ * @param fieldType - Optional type of the field.
54
53
  * @returns boolean - Result of the comparison operation.
55
54
  *
56
55
  * Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
@@ -124,8 +124,7 @@ export const hashString = (str) => createHash("sha256").update(str).digest("hex"
124
124
  * @param operator - The comparison operator (e.g., '=', '!=', '>', '<', '>=', '<=', '[]', '![]', '*', '!*').
125
125
  * @param originalValue - The value to compare, can be a single value or an array of values.
126
126
  * @param comparedValue - The value or values to compare against.
127
- * @param field - Field object config.
128
- * @param fieldChildrenType - Optional type for child elements in array inputs.
127
+ * @param fieldType - Optional type of the field.
129
128
  * @returns boolean - Result of the comparison operation.
130
129
  *
131
130
  * Note: Handles various data types and comparison logic, including special handling for passwords and regex patterns.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.1.22",
3
+ "version": "1.1.23",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Karim Amahtil",