inibase 1.0.0-rc.47 → 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 +3 -15
- package/dist/index.js +21 -14
- 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
|
@@ -99,13 +99,6 @@ const secureString = (input) => {
|
|
|
99
99
|
// Replace characters using a single regular expression.
|
|
100
100
|
return decodedInput.replace(/\\n/g, "\n").replace(/\n/g, "\\n");
|
|
101
101
|
};
|
|
102
|
-
/**
|
|
103
|
-
* Secures each element in an array or a single value using secureString.
|
|
104
|
-
*
|
|
105
|
-
* @param arr_str - An array or a single value of any type.
|
|
106
|
-
* @returns An array with each element secured, or a single secured value.
|
|
107
|
-
*/
|
|
108
|
-
const secureArray = (arr_str) => Array.isArray(arr_str) ? arr_str.map(secureArray) : secureString(arr_str);
|
|
109
102
|
/**
|
|
110
103
|
* Encodes the input using 'secureString' and 'Inison.stringify' functions.
|
|
111
104
|
* If the input is an array, it is first secured and then joined into a string.
|
|
@@ -115,15 +108,10 @@ const secureArray = (arr_str) => Array.isArray(arr_str) ? arr_str.map(secureArra
|
|
|
115
108
|
* @returns The secured and/or joined string.
|
|
116
109
|
*/
|
|
117
110
|
export const encode = (input) => Array.isArray(input)
|
|
118
|
-
?
|
|
111
|
+
? input.every((_input) => typeof _input === "string" && isJSON(_input))
|
|
112
|
+
? `[${input.join(",")}]`
|
|
113
|
+
: Inison.stringify(input)
|
|
119
114
|
: secureString(input);
|
|
120
|
-
/**
|
|
121
|
-
* Decodes each element in an array or a single value using unSecureString.
|
|
122
|
-
*
|
|
123
|
-
* @param arr_str - An array or a single value of any type.
|
|
124
|
-
* @returns An array with each element decoded, or a single decoded value.
|
|
125
|
-
*/
|
|
126
|
-
const unSecureArray = (arr_str) => Array.isArray(arr_str) ? arr_str.map(unSecureArray) : unSecureString(arr_str);
|
|
127
115
|
/**
|
|
128
116
|
* Reverses the encoding done by 'secureString'. Replaces encoded characters with their original symbols.
|
|
129
117
|
*
|
package/dist/index.js
CHANGED
|
@@ -263,7 +263,9 @@ export default class Inibase {
|
|
|
263
263
|
? value
|
|
264
264
|
: UtilsServer.decodeID(value, this.salt);
|
|
265
265
|
case "json":
|
|
266
|
-
return
|
|
266
|
+
return typeof value !== "string" || !Utils.isJSON(value)
|
|
267
|
+
? Inison.stringify(value)
|
|
268
|
+
: value;
|
|
267
269
|
default:
|
|
268
270
|
return value;
|
|
269
271
|
}
|
|
@@ -326,12 +328,12 @@ export default class Inibase {
|
|
|
326
328
|
result[key].push(value);
|
|
327
329
|
return result;
|
|
328
330
|
}, {});
|
|
329
|
-
_CombineData = (
|
|
331
|
+
_CombineData = (data, prefix) => {
|
|
330
332
|
let RETURN = {};
|
|
331
|
-
if (Utils.isArrayOfObjects(
|
|
332
|
-
RETURN = this._combineObjectsToArray(
|
|
333
|
+
if (Utils.isArrayOfObjects(data))
|
|
334
|
+
RETURN = this._combineObjectsToArray(data.map((single_data) => this._CombineData(single_data)));
|
|
333
335
|
else
|
|
334
|
-
for (const [key, value] of Object.entries(
|
|
336
|
+
for (const [key, value] of Object.entries(data)) {
|
|
335
337
|
if (Utils.isObject(value))
|
|
336
338
|
Object.assign(RETURN, this._CombineData(value, `${key}.`));
|
|
337
339
|
else if (Utils.isArrayOfObjects(value)) {
|
|
@@ -434,16 +436,21 @@ export default class Inibase {
|
|
|
434
436
|
RETURN[index][field.key] = item;
|
|
435
437
|
else {
|
|
436
438
|
RETURN[index][field.key] = [];
|
|
437
|
-
Object.entries(item).forEach(([key, value]) => {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
Utils.isArrayOfNulls(value[_i])))
|
|
442
|
-
continue;
|
|
443
|
-
if (!RETURN[index][field.key][_i])
|
|
444
|
-
RETURN[index][field.key][_i] = {};
|
|
445
|
-
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;
|
|
446
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
|
+
}
|
|
447
454
|
});
|
|
448
455
|
}
|
|
449
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