inibase 1.0.0-rc.90 → 1.0.0-rc.91
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/file.js +3 -3
- package/dist/index.js +45 -19
- package/package.json +1 -1
package/dist/file.js
CHANGED
|
@@ -194,7 +194,7 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
|
|
|
194
194
|
else if (lineNumbers == -1) {
|
|
195
195
|
const command = filePath.endsWith(".gz")
|
|
196
196
|
? `zcat ${filePath} | sed -n '$p'`
|
|
197
|
-
: `sed -n '$p' ${filePath}`, foundedLine = (await exec(command)).stdout.
|
|
197
|
+
: `sed -n '$p' ${filePath}`, foundedLine = (await exec(command)).stdout.trimEnd();
|
|
198
198
|
if (foundedLine)
|
|
199
199
|
lines[linesCount] = decode(foundedLine, fieldType, fieldChildrenType, secretKey);
|
|
200
200
|
}
|
|
@@ -215,7 +215,7 @@ export async function get(filePath, lineNumbers, fieldType, fieldChildrenType, s
|
|
|
215
215
|
}
|
|
216
216
|
const command = filePath.endsWith(".gz")
|
|
217
217
|
? `zcat ${filePath} | sed -n '${lineNumbers.join("p;")}p'`
|
|
218
|
-
: `sed -n '${lineNumbers.join("p;")}p' ${filePath}`, foundedLines = (await exec(command)).stdout.
|
|
218
|
+
: `sed -n '${lineNumbers.join("p;")}p' ${filePath}`, foundedLines = (await exec(command)).stdout.trimEnd().split("\n");
|
|
219
219
|
let index = 0;
|
|
220
220
|
for (const line of foundedLines) {
|
|
221
221
|
lines[lineNumbers[index]] = decode(line, fieldType, fieldChildrenType, secretKey);
|
|
@@ -461,7 +461,7 @@ export const search = async (filePath, operator, comparedAtValue, logicalOperato
|
|
|
461
461
|
* Note: Reads through the file line by line to count the total number of lines.
|
|
462
462
|
*/
|
|
463
463
|
export const count = async (filePath) => {
|
|
464
|
-
// Number((await exec(`wc -l < ${filePath}`)).stdout.
|
|
464
|
+
// Number((await exec(`wc -l < ${filePath}`)).stdout.trimEnd());
|
|
465
465
|
let linesCount = 0;
|
|
466
466
|
if (await isExists(filePath)) {
|
|
467
467
|
let fileHandle = null;
|
package/dist/index.js
CHANGED
|
@@ -602,19 +602,32 @@ export default class Inibase {
|
|
|
602
602
|
if (field.table &&
|
|
603
603
|
(await File.isExists(join(this.databasePath, field.table))) &&
|
|
604
604
|
(await File.isExists(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`)))) {
|
|
605
|
-
const
|
|
606
|
-
if (
|
|
607
|
-
|
|
605
|
+
const itemsIDs = await File.get(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`), linesNumber, field.type, field.children, this.salt);
|
|
606
|
+
if (itemsIDs) {
|
|
607
|
+
const searchableIDs = {};
|
|
608
|
+
for (const [index, item] of Object.entries(itemsIDs)) {
|
|
608
609
|
if (!RETURN[index])
|
|
609
610
|
RETURN[index] = {};
|
|
610
611
|
if (item !== null && item !== undefined)
|
|
611
|
-
|
|
612
|
-
...options,
|
|
613
|
-
columns: options.columns
|
|
614
|
-
?.filter((column) => column.includes(`${field.key}.`))
|
|
615
|
-
.map((column) => column.replace(`${field.key}.`, "")),
|
|
616
|
-
});
|
|
612
|
+
searchableIDs[index] = item;
|
|
617
613
|
}
|
|
614
|
+
if (Object.keys(searchableIDs).length) {
|
|
615
|
+
const items = await this.get(field.table, [].concat(...Object.values(searchableIDs)), {
|
|
616
|
+
...options,
|
|
617
|
+
perPage: Number.POSITIVE_INFINITY,
|
|
618
|
+
columns: options.columns
|
|
619
|
+
?.filter((column) => column.includes(`${field.key}.`))
|
|
620
|
+
.map((column) => column.replace(`${field.key}.`, "")),
|
|
621
|
+
});
|
|
622
|
+
if (items) {
|
|
623
|
+
let cursor = 0;
|
|
624
|
+
for (const [index, Ids] of Object.entries(searchableIDs)) {
|
|
625
|
+
RETURN[index][field.key] = items.slice(cursor, cursor + Ids.length);
|
|
626
|
+
cursor += Ids.length;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
618
631
|
}
|
|
619
632
|
}
|
|
620
633
|
else if (await File.isExists(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`))) {
|
|
@@ -644,19 +657,32 @@ export default class Inibase {
|
|
|
644
657
|
if (field.table &&
|
|
645
658
|
(await File.isExists(join(this.databasePath, field.table))) &&
|
|
646
659
|
(await File.isExists(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`)))) {
|
|
647
|
-
const
|
|
648
|
-
if (
|
|
649
|
-
|
|
660
|
+
const itemsIDs = await File.get(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`), linesNumber, field.type, field.children, this.salt);
|
|
661
|
+
if (itemsIDs) {
|
|
662
|
+
const searchableIDs = {};
|
|
663
|
+
for (const [index, item] of Object.entries(itemsIDs)) {
|
|
650
664
|
if (!RETURN[index])
|
|
651
665
|
RETURN[index] = {};
|
|
652
666
|
if (item !== null && item !== undefined)
|
|
653
|
-
|
|
654
|
-
...options,
|
|
655
|
-
columns: options.columns
|
|
656
|
-
?.filter((column) => column.includes(`${field.key}.`))
|
|
657
|
-
.map((column) => column.replace(`${field.key}.`, "")),
|
|
658
|
-
});
|
|
667
|
+
searchableIDs[index] = item;
|
|
659
668
|
}
|
|
669
|
+
if (Object.keys(searchableIDs).length) {
|
|
670
|
+
const items = await this.get(field.table, Object.values(searchableIDs), {
|
|
671
|
+
...options,
|
|
672
|
+
perPage: Number.POSITIVE_INFINITY,
|
|
673
|
+
columns: options.columns
|
|
674
|
+
?.filter((column) => column.includes(`${field.key}.`))
|
|
675
|
+
.map((column) => column.replace(`${field.key}.`, "")),
|
|
676
|
+
});
|
|
677
|
+
if (items) {
|
|
678
|
+
let cursor = 0;
|
|
679
|
+
for (const [index] of Object.entries(searchableIDs)) {
|
|
680
|
+
RETURN[index][field.key] = items[cursor];
|
|
681
|
+
cursor++;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
660
686
|
}
|
|
661
687
|
}
|
|
662
688
|
else if (await File.isExists(join(tablePath, `${(prefix ?? "") + field.key}${this.getFileExtension(tableName)}`))) {
|
|
@@ -906,7 +932,7 @@ export default class Inibase {
|
|
|
906
932
|
: `${pasteCommand} | ${sortCommand} | ${awkCommand}`, {
|
|
907
933
|
encoding: "utf-8",
|
|
908
934
|
})).stdout
|
|
909
|
-
.
|
|
935
|
+
.trimEnd()
|
|
910
936
|
.split("\n");
|
|
911
937
|
if (where)
|
|
912
938
|
lines = lines.slice((options.page - 1) * options.perPage, options.page * options.perPage);
|