inibase 1.0.0-rc.44 → 1.0.0-rc.46
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 +2 -1
- package/dist/index.js +47 -37
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export default class Inibase {
|
|
|
75
75
|
setTableSchema(tableName: string, schema: Schema): Promise<void>;
|
|
76
76
|
getTableSchema(tableName: string): Promise<Schema | undefined>;
|
|
77
77
|
isTableEmpty(tableName: string): Promise<never | Schema>;
|
|
78
|
-
getField(keyPath: string, schema: Schema): Field | null;
|
|
78
|
+
static getField(keyPath: string, schema: Schema): Field | null;
|
|
79
79
|
private validateData;
|
|
80
80
|
private formatField;
|
|
81
81
|
private formatData;
|
|
@@ -86,6 +86,7 @@ export default class Inibase {
|
|
|
86
86
|
joinPathesContents(mainPath: string, data: Data | Data[]): {
|
|
87
87
|
[key: string]: string[];
|
|
88
88
|
};
|
|
89
|
+
private _getItemsFromSchemaHelper;
|
|
89
90
|
private getItemsFromSchema;
|
|
90
91
|
private applyCriteria;
|
|
91
92
|
private _filterSchemaByColumns;
|
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",
|
|
@@ -155,7 +155,7 @@ export default class Inibase {
|
|
|
155
155
|
throw this.throwError("NO_ITEMS", tableName);
|
|
156
156
|
return schema;
|
|
157
157
|
}
|
|
158
|
-
getField(keyPath, schema) {
|
|
158
|
+
static getField(keyPath, schema) {
|
|
159
159
|
let RETURN = null;
|
|
160
160
|
const keyPathSplited = keyPath.split(".");
|
|
161
161
|
for (const [index, key] of keyPathSplited.entries()) {
|
|
@@ -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));
|
|
@@ -560,7 +570,7 @@ export default class Inibase {
|
|
|
560
570
|
allTrue = true;
|
|
561
571
|
let index = -1;
|
|
562
572
|
for await (const [key, value] of Object.entries(criteria)) {
|
|
563
|
-
const field =
|
|
573
|
+
const field = Inibase.getField(key, schema);
|
|
564
574
|
index++;
|
|
565
575
|
let searchOperator = undefined, searchComparedAtValue = undefined, searchLogicalOperator = undefined;
|
|
566
576
|
if (Utils.isObject(value)) {
|
|
@@ -1128,7 +1138,7 @@ export default class Inibase {
|
|
|
1128
1138
|
let index = 2;
|
|
1129
1139
|
const sortColumns = sortArray
|
|
1130
1140
|
.map(([key, ascending], i) => {
|
|
1131
|
-
const field =
|
|
1141
|
+
const field = Inibase.getField(key, schema);
|
|
1132
1142
|
if (field)
|
|
1133
1143
|
return `-k${i + index},${i + index}${field.type === "number" ? "n" : ""}${!ascending ? "r" : ""}`;
|
|
1134
1144
|
else
|
|
@@ -1161,7 +1171,7 @@ export default class Inibase {
|
|
|
1161
1171
|
const outputObject = {};
|
|
1162
1172
|
// Extract values for each file, including "id.inib"
|
|
1163
1173
|
filesPathes.forEach((fileName, index) => {
|
|
1164
|
-
const Field =
|
|
1174
|
+
const Field = Inibase.getField(parse(fileName).name, schema);
|
|
1165
1175
|
if (Field)
|
|
1166
1176
|
outputObject[Field.key] = File.decode(splitedFileColumns[index], Field?.type, Field?.children, this.salt);
|
|
1167
1177
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inibase",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.46",
|
|
4
4
|
"author": {
|
|
5
5
|
"name": "Karim Amahtil",
|
|
6
6
|
"email": "karim.amahtil@gmail.com"
|
|
@@ -30,13 +30,6 @@
|
|
|
30
30
|
"homepage": "https://github.com/inicontent/inibase#readme",
|
|
31
31
|
"keywords": [
|
|
32
32
|
"nosql",
|
|
33
|
-
"sqlite",
|
|
34
|
-
"sql",
|
|
35
|
-
"supabase",
|
|
36
|
-
"better-sqlite",
|
|
37
|
-
"mongodb",
|
|
38
|
-
"firebase",
|
|
39
|
-
"postgresql",
|
|
40
33
|
"rdms",
|
|
41
34
|
"database",
|
|
42
35
|
"db",
|
|
@@ -46,6 +39,13 @@
|
|
|
46
39
|
"file",
|
|
47
40
|
"storage",
|
|
48
41
|
"json",
|
|
42
|
+
"sqlite",
|
|
43
|
+
"sql",
|
|
44
|
+
"supabase",
|
|
45
|
+
"better-sqlite",
|
|
46
|
+
"mongodb",
|
|
47
|
+
"firebase",
|
|
48
|
+
"postgresql",
|
|
49
49
|
"pocketbase"
|
|
50
50
|
],
|
|
51
51
|
"license": "MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"types": "./dist",
|
|
54
54
|
"typesVersions": {
|
|
55
55
|
"*": {
|
|
56
|
-
"
|
|
56
|
+
".": [
|
|
57
57
|
"./dist/index.d.ts"
|
|
58
58
|
],
|
|
59
59
|
"thread": [
|