inibase 1.0.0-rc.43 → 1.0.0-rc.45
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 +1 -0
- package/dist/index.js +57 -42
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -132,7 +132,7 @@ export default class Inibase {
|
|
|
132
132
|
type: "id",
|
|
133
133
|
required: true,
|
|
134
134
|
},
|
|
135
|
-
...UtilsServer.addIdToSchema(schema, lastIdNumber, this.salt),
|
|
135
|
+
...UtilsServer.addIdToSchema(schema, lastIdNumber, this.salt, true),
|
|
136
136
|
{
|
|
137
137
|
id: UtilsServer.encodeID(lastIdNumber + 1, this.salt),
|
|
138
138
|
key: "createdAt",
|
|
@@ -318,7 +318,7 @@ export default class Inibase {
|
|
|
318
318
|
children: field.children,
|
|
319
319
|
}),
|
|
320
320
|
]
|
|
321
|
-
:
|
|
321
|
+
: null;
|
|
322
322
|
case "object":
|
|
323
323
|
return Utils.combineObjects(field.children.map((f) => ({
|
|
324
324
|
[f.key]: this.getDefaultValue(f),
|
|
@@ -365,6 +365,46 @@ export default class Inibase {
|
|
|
365
365
|
joinPathesContents(mainPath, data) {
|
|
366
366
|
return this._addPathToKeys(this._CombineData(data), mainPath);
|
|
367
367
|
}
|
|
368
|
+
_getItemsFromSchemaHelper(RETURN, item, index, field) {
|
|
369
|
+
if (Utils.isObject(item)) {
|
|
370
|
+
if (!RETURN[index])
|
|
371
|
+
RETURN[index] = {};
|
|
372
|
+
if (!RETURN[index][field.key])
|
|
373
|
+
RETURN[index][field.key] = [];
|
|
374
|
+
for (const child_field of field.children.filter((children) => children.type === "array" && Utils.isArrayOfObjects(children.children))) {
|
|
375
|
+
if (Utils.isObject(item[child_field.key])) {
|
|
376
|
+
Object.entries(item[child_field.key]).forEach(([key, value]) => {
|
|
377
|
+
for (let _i = 0; _i < value.length; _i++) {
|
|
378
|
+
if ((Array.isArray(value[_i]) && Utils.isArrayOfNulls(value[_i])) ||
|
|
379
|
+
value[_i] === null)
|
|
380
|
+
continue;
|
|
381
|
+
if (!RETURN[index][field.key][_i])
|
|
382
|
+
RETURN[index][field.key][_i] = {};
|
|
383
|
+
if (!RETURN[index][field.key][_i][child_field.key])
|
|
384
|
+
RETURN[index][field.key][_i][child_field.key] = [];
|
|
385
|
+
if (!Array.isArray(value[_i])) {
|
|
386
|
+
if (!RETURN[index][field.key][_i][child_field.key][0])
|
|
387
|
+
RETURN[index][field.key][_i][child_field.key][0] = {};
|
|
388
|
+
RETURN[index][field.key][_i][child_field.key][0][key] =
|
|
389
|
+
value[_i];
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
value[_i].forEach((_element, _index) => {
|
|
393
|
+
// Recursive call
|
|
394
|
+
this._getItemsFromSchemaHelper(RETURN[index][field.key][_i][child_field.key][_index], _element, _index, child_field);
|
|
395
|
+
// Perform property assignments
|
|
396
|
+
if (!RETURN[index][field.key][_i][child_field.key][_index])
|
|
397
|
+
RETURN[index][field.key][_i][child_field.key][_index] = {};
|
|
398
|
+
RETURN[index][field.key][_i][child_field.key][_index][key] =
|
|
399
|
+
_element;
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
368
408
|
async getItemsFromSchema(tableName, schema, linesNumber, options, prefix) {
|
|
369
409
|
const tablePath = join(this.folder, this.database, tableName);
|
|
370
410
|
let RETURN = {};
|
|
@@ -378,37 +418,7 @@ export default class Inibase {
|
|
|
378
418
|
// one of children has array field type and has children array of object = Schema
|
|
379
419
|
Object.entries((await this.getItemsFromSchema(tableName, field.children.filter((children) => children.type === "array" &&
|
|
380
420
|
Utils.isArrayOfObjects(children.children)), linesNumber, options, (prefix ?? "") + field.key + ".")) ?? {}).forEach(([index, item]) => {
|
|
381
|
-
|
|
382
|
-
if (!RETURN[index])
|
|
383
|
-
RETURN[index] = {};
|
|
384
|
-
if (!RETURN[index][field.key])
|
|
385
|
-
RETURN[index][field.key] = [];
|
|
386
|
-
for (const child_field of field.children.filter((children) => children.type === "array" &&
|
|
387
|
-
Utils.isArrayOfObjects(children.children))) {
|
|
388
|
-
if (Utils.isObject(item[child_field.key])) {
|
|
389
|
-
Object.entries(item[child_field.key]).forEach(([key, value]) => {
|
|
390
|
-
if (!Utils.isArrayOfArrays(value))
|
|
391
|
-
value = value.map((_value) => child_field.type === "array"
|
|
392
|
-
? [[_value]]
|
|
393
|
-
: [_value]);
|
|
394
|
-
for (let _i = 0; _i < value.length; _i++) {
|
|
395
|
-
if (Utils.isArrayOfNulls(value[_i]))
|
|
396
|
-
continue;
|
|
397
|
-
if (!RETURN[index][field.key][_i])
|
|
398
|
-
RETURN[index][field.key][_i] = {};
|
|
399
|
-
if (!RETURN[index][field.key][_i][child_field.key])
|
|
400
|
-
RETURN[index][field.key][_i][child_field.key] =
|
|
401
|
-
[];
|
|
402
|
-
value[_i].forEach((_element, _index) => {
|
|
403
|
-
if (!RETURN[index][field.key][_i][child_field.key][_index])
|
|
404
|
-
RETURN[index][field.key][_i][child_field.key][_index] = {};
|
|
405
|
-
RETURN[index][field.key][_i][child_field.key][_index][key] = _element;
|
|
406
|
-
});
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
421
|
+
this._getItemsFromSchemaHelper(RETURN, item, index, field);
|
|
412
422
|
});
|
|
413
423
|
field.children = field.children.filter((children) => children.type !== "array" ||
|
|
414
424
|
!Utils.isArrayOfObjects(children.children));
|
|
@@ -417,16 +427,21 @@ export default class Inibase {
|
|
|
417
427
|
if (!RETURN[index])
|
|
418
428
|
RETURN[index] = {};
|
|
419
429
|
if (Utils.isObject(item)) {
|
|
420
|
-
if (!Object.values(item)
|
|
421
|
-
if (RETURN[index][field.key])
|
|
430
|
+
if (!Utils.isArrayOfNulls(Object.values(item))) {
|
|
431
|
+
if (RETURN[index][field.key])
|
|
422
432
|
Object.entries(item).forEach(([key, value], _index) => {
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
433
|
+
for (let _index = 0; _index < value.length; _index++)
|
|
434
|
+
if (RETURN[index][field.key][_index])
|
|
435
|
+
Object.assign(RETURN[index][field.key][_index], {
|
|
436
|
+
[key]: value[_index],
|
|
437
|
+
});
|
|
438
|
+
else
|
|
439
|
+
RETURN[index][field.key][_index] = {
|
|
440
|
+
[key]: value[_index],
|
|
441
|
+
};
|
|
427
442
|
});
|
|
428
|
-
|
|
429
|
-
|
|
443
|
+
else if (Object.values(item).every((_i) => Utils.isArrayOfArrays(_i) || Array.isArray(_i)) &&
|
|
444
|
+
prefix)
|
|
430
445
|
RETURN[index][field.key] = item;
|
|
431
446
|
else {
|
|
432
447
|
RETURN[index][field.key] = [];
|
|
@@ -434,7 +449,7 @@ export default class Inibase {
|
|
|
434
449
|
for (let _i = 0; _i < value.length; _i++) {
|
|
435
450
|
if (value[_i] === null ||
|
|
436
451
|
(Array.isArray(value[_i]) &&
|
|
437
|
-
value[_i]
|
|
452
|
+
Utils.isArrayOfNulls(value[_i])))
|
|
438
453
|
continue;
|
|
439
454
|
if (!RETURN[index][field.key][_i])
|
|
440
455
|
RETURN[index][field.key][_i] = {};
|