inibase 1.0.0-rc.48 → 1.0.0-rc.49
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/README.md +2 -1
- package/dist/file.js +5 -1
- package/dist/index.js +23 -13
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,7 +108,8 @@ Ps: Testing by default with `user` table, with username, email, password fields
|
|
|
108
108
|
- [x] JSON
|
|
109
109
|
- [ ] TO-DO:
|
|
110
110
|
- [x] Improve caching
|
|
111
|
-
- [
|
|
111
|
+
- [ ] Commenting the code
|
|
112
|
+
- [ ] Add property "unique" for schema fields
|
|
112
113
|
- [ ] Add Backup feature (generate a tar.gz)
|
|
113
114
|
- [ ] Add Custom field validation property to schema (using RegEx?)
|
|
114
115
|
- [ ] Features:
|
package/dist/file.js
CHANGED
|
@@ -107,7 +107,11 @@ const secureString = (input) => {
|
|
|
107
107
|
* @param input - A value or array of values (string, number, boolean, null).
|
|
108
108
|
* @returns The secured and/or joined string.
|
|
109
109
|
*/
|
|
110
|
-
export const encode = (input) => Array.isArray(input)
|
|
110
|
+
export const encode = (input) => Array.isArray(input)
|
|
111
|
+
? input.every((_input) => typeof _input === "string" && isJSON(_input))
|
|
112
|
+
? `[${input.join(",")}]`
|
|
113
|
+
: Inison.stringify(input)
|
|
114
|
+
: secureString(input);
|
|
111
115
|
/**
|
|
112
116
|
* Reverses the encoding done by 'secureString'. Replaces encoded characters with their original symbols.
|
|
113
117
|
*
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import Utils from "./utils.js";
|
|
|
8
8
|
import UtilsServer from "./utils.server.js";
|
|
9
9
|
import Config from "./config.js";
|
|
10
10
|
import { inspect } from "node:util";
|
|
11
|
+
import Inison from "inison";
|
|
11
12
|
export default class Inibase {
|
|
12
13
|
folder;
|
|
13
14
|
database;
|
|
@@ -261,6 +262,10 @@ export default class Inibase {
|
|
|
261
262
|
return Utils.isNumber(value)
|
|
262
263
|
? value
|
|
263
264
|
: UtilsServer.decodeID(value, this.salt);
|
|
265
|
+
case "json":
|
|
266
|
+
return typeof value !== "string" || !Utils.isJSON(value)
|
|
267
|
+
? Inison.stringify(value)
|
|
268
|
+
: value;
|
|
264
269
|
default:
|
|
265
270
|
return value;
|
|
266
271
|
}
|
|
@@ -323,12 +328,12 @@ export default class Inibase {
|
|
|
323
328
|
result[key].push(value);
|
|
324
329
|
return result;
|
|
325
330
|
}, {});
|
|
326
|
-
_CombineData = (
|
|
331
|
+
_CombineData = (data, prefix) => {
|
|
327
332
|
let RETURN = {};
|
|
328
|
-
if (Utils.isArrayOfObjects(
|
|
329
|
-
RETURN = this._combineObjectsToArray(
|
|
333
|
+
if (Utils.isArrayOfObjects(data))
|
|
334
|
+
RETURN = this._combineObjectsToArray(data.map((single_data) => this._CombineData(single_data)));
|
|
330
335
|
else
|
|
331
|
-
for (const [key, value] of Object.entries(
|
|
336
|
+
for (const [key, value] of Object.entries(data)) {
|
|
332
337
|
if (Utils.isObject(value))
|
|
333
338
|
Object.assign(RETURN, this._CombineData(value, `${key}.`));
|
|
334
339
|
else if (Utils.isArrayOfObjects(value)) {
|
|
@@ -431,16 +436,21 @@ export default class Inibase {
|
|
|
431
436
|
RETURN[index][field.key] = item;
|
|
432
437
|
else {
|
|
433
438
|
RETURN[index][field.key] = [];
|
|
434
|
-
Object.entries(item).forEach(([key, value]) => {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
Utils.isArrayOfNulls(value[_i])))
|
|
439
|
-
continue;
|
|
440
|
-
if (!RETURN[index][field.key][_i])
|
|
441
|
-
RETURN[index][field.key][_i] = {};
|
|
442
|
-
RETURN[index][field.key][_i][key] = value[_i];
|
|
439
|
+
Object.entries(item).forEach(([key, value], _ind) => {
|
|
440
|
+
if (!Array.isArray(value)) {
|
|
441
|
+
RETURN[index][field.key][_ind] = {};
|
|
442
|
+
RETURN[index][field.key][_ind][key] = value;
|
|
443
443
|
}
|
|
444
|
+
else
|
|
445
|
+
for (let _i = 0; _i < value.length; _i++) {
|
|
446
|
+
if (value[_i] === null ||
|
|
447
|
+
(Array.isArray(value[_i]) &&
|
|
448
|
+
Utils.isArrayOfNulls(value[_i])))
|
|
449
|
+
continue;
|
|
450
|
+
if (!RETURN[index][field.key][_i])
|
|
451
|
+
RETURN[index][field.key][_i] = {};
|
|
452
|
+
RETURN[index][field.key][_i][key] = value[_i];
|
|
453
|
+
}
|
|
444
454
|
});
|
|
445
455
|
}
|
|
446
456
|
}
|
package/dist/utils.d.ts
CHANGED
|
@@ -204,5 +204,6 @@ export default class Utils {
|
|
|
204
204
|
static FormatObjectCriteriaValue: typeof FormatObjectCriteriaValue;
|
|
205
205
|
static swapKeyValue: <K extends ValidKey, V extends ValidKey>(object: Record<K, V>) => Record<V, K>;
|
|
206
206
|
static getField: typeof getField;
|
|
207
|
+
static isJSON: (str: string) => boolean;
|
|
207
208
|
}
|
|
208
209
|
export {};
|
package/dist/utils.js
CHANGED