inibase 1.0.0-rc.44 → 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 +43 -33
- 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));
|