inibase 1.2.10 → 1.2.12
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.js +23 -19
- package/dist/utils.server.d.ts +2 -1
- package/dist/utils.server.js +4 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -696,19 +696,19 @@ export default class Inibase {
|
|
|
696
696
|
for (const field of schema) {
|
|
697
697
|
// If the field is of simple type (non-recursive), process it directly
|
|
698
698
|
if (this.isSimpleField(field.type)) {
|
|
699
|
-
await this.processSimpleField(tableName, field,
|
|
699
|
+
await this.processSimpleField(tableName, field, RETURN, linesNumber, prefix);
|
|
700
700
|
}
|
|
701
701
|
else if (this.isArrayField(field.type)) {
|
|
702
702
|
// Process array fields (recursive if needed)
|
|
703
|
-
await this.processArrayField(tableName, field,
|
|
703
|
+
await this.processArrayField(tableName, field, RETURN, linesNumber, options, prefix);
|
|
704
704
|
}
|
|
705
705
|
else if (this.isObjectField(field.type)) {
|
|
706
706
|
// Process object fields (recursive if needed)
|
|
707
|
-
await this.processObjectField(tableName, field,
|
|
707
|
+
await this.processObjectField(tableName, field, RETURN, linesNumber, options, prefix);
|
|
708
708
|
}
|
|
709
709
|
else if (this.isTableField(field.type)) {
|
|
710
710
|
// Process table reference fields
|
|
711
|
-
await this.processTableField(tableName, field,
|
|
711
|
+
await this.processTableField(tableName, field, RETURN, linesNumber, options, prefix);
|
|
712
712
|
}
|
|
713
713
|
}
|
|
714
714
|
return RETURN;
|
|
@@ -721,7 +721,7 @@ export default class Inibase {
|
|
|
721
721
|
return !complexTypes.includes(fieldType);
|
|
722
722
|
}
|
|
723
723
|
// Process a simple field (non-recursive)
|
|
724
|
-
async processSimpleField(tableName, field,
|
|
724
|
+
async processSimpleField(tableName, field, RETURN, linesNumber, prefix) {
|
|
725
725
|
const fieldPath = join(this.databasePath, tableName, `${prefix ?? ""}${field.key}${this.getFileExtension(tableName)}`);
|
|
726
726
|
if (await File.isExists(fieldPath)) {
|
|
727
727
|
const items = await File.get(fieldPath, linesNumber, {
|
|
@@ -751,13 +751,13 @@ export default class Inibase {
|
|
|
751
751
|
fieldType === "array");
|
|
752
752
|
}
|
|
753
753
|
// Process array fields (recursive if needed)
|
|
754
|
-
async processArrayField(tableName, field,
|
|
754
|
+
async processArrayField(tableName, field, RETURN, linesNumber, options, prefix) {
|
|
755
755
|
if (Array.isArray(field.children)) {
|
|
756
756
|
if (this.isSimpleField(field.children)) {
|
|
757
|
-
await this.processSimpleField(tableName, field,
|
|
757
|
+
await this.processSimpleField(tableName, field, RETURN, linesNumber, prefix);
|
|
758
758
|
}
|
|
759
759
|
else if (this.isTableField(field.children)) {
|
|
760
|
-
await this.processTableField(tableName, field,
|
|
760
|
+
await this.processTableField(tableName, field, RETURN, linesNumber, options, prefix);
|
|
761
761
|
}
|
|
762
762
|
else {
|
|
763
763
|
let _fieldChildren = field.children;
|
|
@@ -835,10 +835,10 @@ export default class Inibase {
|
|
|
835
835
|
}
|
|
836
836
|
else if (this.isSimpleField(field.children)) {
|
|
837
837
|
// If `children` is FieldType, handle it as an array of simple types (no recursion needed here)
|
|
838
|
-
await this.processSimpleField(tableName, field,
|
|
838
|
+
await this.processSimpleField(tableName, field, RETURN, linesNumber, prefix);
|
|
839
839
|
}
|
|
840
840
|
else if (this.isTableField(field.children)) {
|
|
841
|
-
await this.processTableField(tableName, field,
|
|
841
|
+
await this.processTableField(tableName, field, RETURN, linesNumber, options, prefix);
|
|
842
842
|
}
|
|
843
843
|
}
|
|
844
844
|
// Helper function to check if the field type is object
|
|
@@ -849,7 +849,7 @@ export default class Inibase {
|
|
|
849
849
|
fieldType.includes("object")));
|
|
850
850
|
}
|
|
851
851
|
// Process object fields (recursive if needed)
|
|
852
|
-
async processObjectField(tableName, field,
|
|
852
|
+
async processObjectField(tableName, field, RETURN, linesNumber, options, prefix) {
|
|
853
853
|
if (Array.isArray(field.children)) {
|
|
854
854
|
// If `children` is a Schema (array of Field objects), recurse
|
|
855
855
|
const items = await this.processSchemaData(tableName, field.children, linesNumber, options, `${prefix ?? ""}${field.key}.`);
|
|
@@ -873,7 +873,7 @@ export default class Inibase {
|
|
|
873
873
|
fieldType.includes("table")));
|
|
874
874
|
}
|
|
875
875
|
// Process table reference fields
|
|
876
|
-
async processTableField(tableName, field,
|
|
876
|
+
async processTableField(tableName, field, RETURN, linesNumber, options, prefix) {
|
|
877
877
|
if (field.table &&
|
|
878
878
|
(await File.isExists(join(this.databasePath, field.table)))) {
|
|
879
879
|
const fieldPath = join(this.databasePath, tableName, `${prefix ?? ""}${field.key}${this.getFileExtension(tableName)}`);
|
|
@@ -899,7 +899,7 @@ export default class Inibase {
|
|
|
899
899
|
.flat()
|
|
900
900
|
.filter((item) => item), {
|
|
901
901
|
...options,
|
|
902
|
-
perPage:
|
|
902
|
+
perPage: -1,
|
|
903
903
|
columns: options.columns
|
|
904
904
|
?.filter((column) => column.includes(`${field.key}.`))
|
|
905
905
|
.map((column) => column.replace(`${field.key}.`, "")),
|
|
@@ -960,7 +960,7 @@ export default class Inibase {
|
|
|
960
960
|
if (field.table && Utils.isObject(value)) {
|
|
961
961
|
const items = await this.get(field.table, value, {
|
|
962
962
|
columns: "id",
|
|
963
|
-
perPage:
|
|
963
|
+
perPage: -1,
|
|
964
964
|
});
|
|
965
965
|
if (items?.length)
|
|
966
966
|
value = `[]${items.map(({ id }) => id)}`;
|
|
@@ -1013,8 +1013,10 @@ export default class Inibase {
|
|
|
1013
1013
|
...field,
|
|
1014
1014
|
databasePath: this.databasePath,
|
|
1015
1015
|
table: field.table ?? tableName,
|
|
1016
|
-
}, options.perPage
|
|
1017
|
-
|
|
1016
|
+
}, options.perPage < 0 ? undefined : options.perPage, options.perPage < 0
|
|
1017
|
+
? undefined
|
|
1018
|
+
: (options.page - 1) * options.perPage +
|
|
1019
|
+
(options.page > 1 ? 1 : 0), true);
|
|
1018
1020
|
if (!searchResult) {
|
|
1019
1021
|
if (allTrue)
|
|
1020
1022
|
return null;
|
|
@@ -1223,9 +1225,11 @@ export default class Inibase {
|
|
|
1223
1225
|
}
|
|
1224
1226
|
if (!where) {
|
|
1225
1227
|
// Display all data
|
|
1226
|
-
RETURN = Object.values(await this.processSchemaData(tableName, schema,
|
|
1227
|
-
|
|
1228
|
-
1)
|
|
1228
|
+
RETURN = Object.values(await this.processSchemaData(tableName, schema, options.perPage < 0
|
|
1229
|
+
? undefined
|
|
1230
|
+
: Array.from({ length: options.perPage }, (_, index) => (options.page - 1) * options.perPage +
|
|
1231
|
+
index +
|
|
1232
|
+
1), options));
|
|
1229
1233
|
if (!this.totalItems.has(`${tableName}-*`))
|
|
1230
1234
|
this.totalItems.set(`${tableName}-*`, pagination[1]);
|
|
1231
1235
|
}
|
package/dist/utils.server.d.ts
CHANGED
|
@@ -23,7 +23,8 @@ export declare const hashPassword: (password: string) => string;
|
|
|
23
23
|
*/
|
|
24
24
|
export declare const comparePassword: (hash: string, password: string) => boolean;
|
|
25
25
|
export declare const encodeID: (id: number | string) => string;
|
|
26
|
-
export declare
|
|
26
|
+
export declare function decodeID(input: string, raw: true): string;
|
|
27
|
+
export declare function decodeID(input?: string, raw?: false): number;
|
|
27
28
|
export declare const extractIdsFromSchema: (schema: Schema) => number[];
|
|
28
29
|
/**
|
|
29
30
|
* Finds the last ID number in a schema, potentially decoding it if encrypted.
|
package/dist/utils.server.js
CHANGED
|
@@ -54,18 +54,17 @@ const getKeyAndIv = () => {
|
|
|
54
54
|
}
|
|
55
55
|
return { key, iv: key.subarray(0, 16) };
|
|
56
56
|
};
|
|
57
|
-
// Optimized encodeID
|
|
58
57
|
export const encodeID = (id) => {
|
|
59
58
|
const { key, iv } = getKeyAndIv();
|
|
60
59
|
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
|
61
60
|
return cipher.update(id.toString(), "utf8", "hex") + cipher.final("hex");
|
|
62
61
|
};
|
|
63
|
-
|
|
64
|
-
export const decodeID = (input) => {
|
|
62
|
+
export function decodeID(input, raw) {
|
|
65
63
|
const { key, iv } = getKeyAndIv();
|
|
66
64
|
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const rawData = decipher.update(input, "hex", "utf8") + decipher.final("utf8");
|
|
66
|
+
return raw ? rawData : Number(rawData);
|
|
67
|
+
}
|
|
69
68
|
// Function to recursively flatten an array of objects and their nested children
|
|
70
69
|
export const extractIdsFromSchema = (schema) => {
|
|
71
70
|
const result = [];
|