inibase 1.0.0-rc.51 → 1.0.0-rc.53

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
@@ -57,7 +57,7 @@ export default class Inibase {
57
57
  private _schemaToIdsPath;
58
58
  setTableSchema(tableName: string, schema: Schema): Promise<void>;
59
59
  getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema | undefined>;
60
- getSchemaWhenTableNotEmpty(tableName: string, schema?: Schema): Promise<never | Schema>;
60
+ private getSchemaWhenTableNotEmpty;
61
61
  private validateData;
62
62
  private formatField;
63
63
  private checkUnique;
@@ -66,9 +66,7 @@ export default class Inibase {
66
66
  private _combineObjectsToArray;
67
67
  private _CombineData;
68
68
  private _addPathToKeys;
69
- joinPathesContents(mainPath: string, data: Data | Data[]): {
70
- [key: string]: string[];
71
- };
69
+ private joinPathesContents;
72
70
  private _getItemsFromSchemaHelper;
73
71
  private getItemsFromSchema;
74
72
  private applyCriteria;
package/dist/index.js CHANGED
@@ -343,29 +343,28 @@ export default class Inibase {
343
343
  }
344
344
  _combineObjectsToArray = (input) => input.reduce((result, current) => {
345
345
  for (const [key, value] of Object.entries(current))
346
- if (!result[key])
347
- result[key] = [value];
348
- else
346
+ if (Object.hasOwn(result, key) && Array.isArray(result[key]))
349
347
  result[key].push(value);
348
+ else
349
+ result[key] = [value];
350
350
  return result;
351
351
  }, {});
352
352
  _CombineData = (data, prefix) => {
353
- let RETURN = {};
354
353
  if (Utils.isArrayOfObjects(data))
355
- RETURN = this._combineObjectsToArray(data.map((single_data) => this._CombineData(single_data)));
356
- else
357
- for (const [key, value] of Object.entries(data)) {
358
- if (Utils.isObject(value))
359
- Object.assign(RETURN, this._CombineData(value, `${key}.`));
360
- else if (Utils.isArrayOfObjects(value)) {
361
- Object.assign(RETURN, this._CombineData(this._combineObjectsToArray(value), `${(prefix ?? "") + key}.`));
362
- }
363
- else if (Utils.isArrayOfArrays(value) &&
364
- value.every(Utils.isArrayOfObjects))
365
- Object.assign(RETURN, this._CombineData(this._combineObjectsToArray(value.map(this._combineObjectsToArray)), `${(prefix ?? "") + key}.`));
366
- else
367
- RETURN[(prefix ?? "") + key] = File.encode(value);
354
+ return this._combineObjectsToArray(data.map((single_data) => this._CombineData(single_data)));
355
+ const RETURN = {};
356
+ for (const [key, value] of Object.entries(data)) {
357
+ if (Utils.isObject(value))
358
+ Object.assign(RETURN, this._CombineData(value, `${key}.`));
359
+ else if (Utils.isArrayOfObjects(value)) {
360
+ Object.assign(RETURN, this._CombineData(this._combineObjectsToArray(value), `${(prefix ?? "") + key}.`));
368
361
  }
362
+ else if (Utils.isArrayOfArrays(value) &&
363
+ value.every(Utils.isArrayOfObjects))
364
+ Object.assign(RETURN, this._CombineData(this._combineObjectsToArray(value.map(this._combineObjectsToArray)), `${(prefix ?? "") + key}.`));
365
+ else
366
+ RETURN[(prefix ?? "") + key] = File.encode(value);
367
+ }
369
368
  return RETURN;
370
369
  };
371
370
  _addPathToKeys = (obj, path) => {
@@ -573,7 +572,7 @@ export default class Inibase {
573
572
  if (searchResult) {
574
573
  RETURN = Utils.deepMerge(RETURN, Object.fromEntries(Object.entries(searchResult).filter(([_k, v], _i) => Object.keys(v).length ===
575
574
  Object.keys(criteria.and ?? {}).length)));
576
- criteria.and = undefined;
575
+ delete criteria.and;
577
576
  RETURN_LineNumbers = lineNumbers;
578
577
  }
579
578
  else
@@ -581,7 +580,7 @@ export default class Inibase {
581
580
  }
582
581
  if (criteria.or && Utils.isObject(criteria.or)) {
583
582
  const [searchResult, lineNumbers] = await this.applyCriteria(tableName, schema, options, criteria.or, false);
584
- criteria.or = undefined;
583
+ delete criteria.or;
585
584
  if (searchResult) {
586
585
  RETURN = Utils.deepMerge(RETURN, searchResult);
587
586
  RETURN_LineNumbers = lineNumbers;
@@ -608,7 +607,7 @@ export default class Inibase {
608
607
  searchComparedAtValue = searchCriteria.map((single_or) => single_or[1]);
609
608
  searchLogicalOperator = "or";
610
609
  }
611
- value.or = undefined;
610
+ delete value.or;
612
611
  }
613
612
  if (value?.and &&
614
613
  Array.isArray(value?.and)) {
@@ -622,7 +621,7 @@ export default class Inibase {
622
621
  searchComparedAtValue = searchCriteria.map((single_and) => single_and[1]);
623
622
  searchLogicalOperator = "and";
624
623
  }
625
- value.and = undefined;
624
+ delete value.and;
626
625
  }
627
626
  }
628
627
  else if (Array.isArray(value)) {
package/dist/utils.js CHANGED
@@ -253,24 +253,26 @@ export const detectFieldType = (input, availableTypes) => {
253
253
  if (availableTypes.includes("number"))
254
254
  return "number";
255
255
  }
256
- else if (availableTypes.includes("table") && isValidID(input))
257
- return "table";
258
- else if (input.startsWith("[") && availableTypes.includes("array"))
259
- return "array";
260
- else if (availableTypes.includes("email") && isEmail(input))
261
- return "email";
262
- else if (availableTypes.includes("url") && isURL(input))
263
- return "url";
264
- else if (availableTypes.includes("password") && isPassword(input))
265
- return "password";
266
- else if (availableTypes.includes("json") && isJSON(input))
267
- return "json";
268
- else if (availableTypes.includes("json") && isDate(input))
269
- return "json";
270
- else if (availableTypes.includes("string") && isString(input))
271
- return "string";
272
- else if (availableTypes.includes("ip") && isIP(input))
273
- return "ip";
256
+ else if (typeof input === "string") {
257
+ if (availableTypes.includes("table") && isValidID(input))
258
+ return "table";
259
+ if (input.startsWith("[") && availableTypes.includes("array"))
260
+ return "array";
261
+ if (availableTypes.includes("email") && isEmail(input))
262
+ return "email";
263
+ if (availableTypes.includes("url") && isURL(input))
264
+ return "url";
265
+ if (availableTypes.includes("password") && isPassword(input))
266
+ return "password";
267
+ if (availableTypes.includes("json") && isJSON(input))
268
+ return "json";
269
+ if (availableTypes.includes("json") && isDate(input))
270
+ return "json";
271
+ if (availableTypes.includes("string") && isString(input))
272
+ return "string";
273
+ if (availableTypes.includes("ip") && isIP(input))
274
+ return "ip";
275
+ }
274
276
  }
275
277
  else
276
278
  return "array";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.51",
3
+ "version": "1.0.0-rc.53",
4
4
  "author": {
5
5
  "name": "Karim Amahtil",
6
6
  "email": "karim.amahtil@gmail.com"