inibase 1.0.0-rc.7 → 1.0.0-rc.9
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/README.md +2 -2
- package/file.ts +1 -17
- package/index.ts +20 -44
- package/package.json +5 -5
- package/utils.ts +0 -0
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **Lightweight** 🪶 (~
|
|
11
|
+
- **Lightweight** 🪶 (~80kb)
|
|
12
12
|
- **Minimalist** :white_circle:
|
|
13
13
|
- **TypeScript** :large_blue_diamond:
|
|
14
14
|
- **Super-Fast** :turtle:
|
|
@@ -31,7 +31,7 @@ const users = await db.get("user", undefined, { page: 2, per_page: 15 });
|
|
|
31
31
|
|
|
32
32
|
// Get only required columns to improve speed
|
|
33
33
|
const users = await db.get("user", undefined, {
|
|
34
|
-
columns: ["username", "address.street", "hobbies
|
|
34
|
+
columns: ["username", "address.street", "hobbies.name"],
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
// Get items from "user" table where "favoriteFoods" does not includes "Pizza"
|
package/file.ts
CHANGED
|
@@ -19,16 +19,6 @@ export const isExists = async (path: string) => {
|
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
export const encodeFileName = (fileName: string, extension?: string) => {
|
|
23
|
-
return (
|
|
24
|
-
fileName.replaceAll("%", "%25").replaceAll("*", "%") +
|
|
25
|
-
(extension ? `.${extension}` : "")
|
|
26
|
-
);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const decodeFileName = (fileName: string) => {
|
|
30
|
-
return fileName.replaceAll("%", "*").replaceAll("*25", "%");
|
|
31
|
-
};
|
|
32
22
|
|
|
33
23
|
export const encode = (
|
|
34
24
|
input:
|
|
@@ -377,10 +367,6 @@ export const search = async (
|
|
|
377
367
|
: false;
|
|
378
368
|
case "boolean":
|
|
379
369
|
return Number(originalValue) - Number(comparedAtValue) === 0;
|
|
380
|
-
case "id":
|
|
381
|
-
return secretKey && typeof comparedAtValue === "string"
|
|
382
|
-
? decodeID(comparedAtValue as string, secretKey) === originalValue
|
|
383
|
-
: comparedAtValue === originalValue;
|
|
384
370
|
default:
|
|
385
371
|
return originalValue === comparedAtValue;
|
|
386
372
|
}
|
|
@@ -455,7 +441,7 @@ export const search = async (
|
|
|
455
441
|
crlfDelay: Infinity,
|
|
456
442
|
});
|
|
457
443
|
|
|
458
|
-
const columnName =
|
|
444
|
+
const columnName = parse(filePath).name;
|
|
459
445
|
|
|
460
446
|
for await (const line of rl) {
|
|
461
447
|
lineCount++;
|
|
@@ -511,7 +497,5 @@ export default class File {
|
|
|
511
497
|
static count = count;
|
|
512
498
|
static encode = encode;
|
|
513
499
|
static decode = decode;
|
|
514
|
-
static encodeFileName = encodeFileName;
|
|
515
|
-
static decodeFileName = decodeFileName;
|
|
516
500
|
static isExists = isExists;
|
|
517
501
|
}
|
package/index.ts
CHANGED
|
@@ -266,14 +266,12 @@ export default class Inibase {
|
|
|
266
266
|
RETURN,
|
|
267
267
|
schemaToIdsPath(
|
|
268
268
|
field.children,
|
|
269
|
-
(prefix ?? "") +
|
|
270
|
-
field.key +
|
|
271
|
-
(field.type === "array" ? ".*." : ".")
|
|
269
|
+
(prefix ?? "") + field.key + "."
|
|
272
270
|
)
|
|
273
271
|
);
|
|
274
272
|
} else if (Utils.isValidID(field.id))
|
|
275
273
|
RETURN[UtilsServer.decodeID(field.id, this.salt)] =
|
|
276
|
-
|
|
274
|
+
(prefix ?? "") + field.key + ".inib";
|
|
277
275
|
|
|
278
276
|
return RETURN;
|
|
279
277
|
},
|
|
@@ -597,7 +595,7 @@ export default class Inibase {
|
|
|
597
595
|
RETURN,
|
|
598
596
|
CombineData(
|
|
599
597
|
combineObjectsToArray(value),
|
|
600
|
-
(prefix ?? "") + key + "
|
|
598
|
+
(prefix ?? "") + key + "."
|
|
601
599
|
)
|
|
602
600
|
);
|
|
603
601
|
} else if (
|
|
@@ -608,7 +606,7 @@ export default class Inibase {
|
|
|
608
606
|
RETURN,
|
|
609
607
|
CombineData(
|
|
610
608
|
combineObjectsToArray(value.map(combineObjectsToArray)),
|
|
611
|
-
(prefix ?? "") + key + "
|
|
609
|
+
(prefix ?? "") + key + "."
|
|
612
610
|
)
|
|
613
611
|
);
|
|
614
612
|
else
|
|
@@ -630,8 +628,7 @@ export default class Inibase {
|
|
|
630
628
|
const addPathToKeys = (obj: Record<string, any>, path: string) => {
|
|
631
629
|
const newObject: Record<string, any> = {};
|
|
632
630
|
|
|
633
|
-
for (const key in obj)
|
|
634
|
-
newObject[join(path, File.encodeFileName(key, "inib"))] = obj[key];
|
|
631
|
+
for (const key in obj) newObject[join(path, key + ".inib")] = obj[key];
|
|
635
632
|
|
|
636
633
|
return newObject;
|
|
637
634
|
};
|
|
@@ -740,7 +737,7 @@ export default class Inibase {
|
|
|
740
737
|
Utils.isArrayOfObjects(children.children)
|
|
741
738
|
),
|
|
742
739
|
linesNumber,
|
|
743
|
-
(prefix ?? "") + field.key + "
|
|
740
|
+
(prefix ?? "") + field.key + "."
|
|
744
741
|
)) ?? {}
|
|
745
742
|
).forEach(([index, item]) => {
|
|
746
743
|
if (Utils.isObject(item)) {
|
|
@@ -802,7 +799,7 @@ export default class Inibase {
|
|
|
802
799
|
(field as FieldDefault & (FieldArrayType | FieldArrayArrayType))
|
|
803
800
|
.children as Schema,
|
|
804
801
|
linesNumber,
|
|
805
|
-
(prefix ?? "") + field.key + "
|
|
802
|
+
(prefix ?? "") + field.key + "."
|
|
806
803
|
)) ?? {}
|
|
807
804
|
).forEach(([index, item]) => {
|
|
808
805
|
if (!RETURN[index]) RETURN[index] = {};
|
|
@@ -843,13 +840,10 @@ export default class Inibase {
|
|
|
843
840
|
) {
|
|
844
841
|
if (options.columns)
|
|
845
842
|
options.columns = (options.columns as string[])
|
|
846
|
-
.filter((column) => column.includes(`${field.key}
|
|
847
|
-
.map((column) => column.replace(`${field.key}
|
|
843
|
+
.filter((column) => column.includes(`${field.key}.`))
|
|
844
|
+
.map((column) => column.replace(`${field.key}.`, ""));
|
|
848
845
|
const [items, total_lines] = await File.get(
|
|
849
|
-
join(
|
|
850
|
-
path,
|
|
851
|
-
File.encodeFileName((prefix ?? "") + field.key, "inib")
|
|
852
|
-
),
|
|
846
|
+
join(path, (prefix ?? "") + field.key + ".inib"),
|
|
853
847
|
linesNumber,
|
|
854
848
|
field.type,
|
|
855
849
|
(field as FieldDefault & (FieldArrayType | FieldArrayArrayType))
|
|
@@ -866,17 +860,11 @@ export default class Inibase {
|
|
|
866
860
|
}
|
|
867
861
|
} else if (
|
|
868
862
|
await File.isExists(
|
|
869
|
-
join(
|
|
870
|
-
path,
|
|
871
|
-
File.encodeFileName((prefix ?? "") + field.key, "inib")
|
|
872
|
-
)
|
|
863
|
+
join(path, (prefix ?? "") + field.key + ".inib")
|
|
873
864
|
)
|
|
874
865
|
) {
|
|
875
866
|
const [items, total_lines] = await File.get(
|
|
876
|
-
join(
|
|
877
|
-
path,
|
|
878
|
-
File.encodeFileName((prefix ?? "") + field.key, "inib")
|
|
879
|
-
),
|
|
867
|
+
join(path, (prefix ?? "") + field.key + ".inib"),
|
|
880
868
|
linesNumber,
|
|
881
869
|
field.type,
|
|
882
870
|
(field as any)?.children,
|
|
@@ -911,10 +899,7 @@ export default class Inibase {
|
|
|
911
899
|
join(this.folder, this.database, field.key)
|
|
912
900
|
)) &&
|
|
913
901
|
(await File.isExists(
|
|
914
|
-
join(
|
|
915
|
-
path,
|
|
916
|
-
File.encodeFileName((prefix ?? "") + field.key, "inib")
|
|
917
|
-
)
|
|
902
|
+
join(path, (prefix ?? "") + field.key + ".inib")
|
|
918
903
|
))
|
|
919
904
|
) {
|
|
920
905
|
if (options.columns)
|
|
@@ -922,14 +907,11 @@ export default class Inibase {
|
|
|
922
907
|
.filter(
|
|
923
908
|
(column) =>
|
|
924
909
|
column.includes(`${field.key}.`) &&
|
|
925
|
-
!column.includes(`${field.key}
|
|
910
|
+
!column.includes(`${field.key}.`)
|
|
926
911
|
)
|
|
927
912
|
.map((column) => column.replace(`${field.key}.`, ""));
|
|
928
913
|
const [items, total_lines] = await File.get(
|
|
929
|
-
join(
|
|
930
|
-
path,
|
|
931
|
-
File.encodeFileName((prefix ?? "") + field.key, "inib")
|
|
932
|
-
),
|
|
914
|
+
join(path, (prefix ?? "") + field.key + ".inib"),
|
|
933
915
|
linesNumber,
|
|
934
916
|
"number",
|
|
935
917
|
undefined,
|
|
@@ -944,12 +926,10 @@ export default class Inibase {
|
|
|
944
926
|
}
|
|
945
927
|
}
|
|
946
928
|
} else if (
|
|
947
|
-
await File.isExists(
|
|
948
|
-
join(path, File.encodeFileName((prefix ?? "") + field.key, "inib"))
|
|
949
|
-
)
|
|
929
|
+
await File.isExists(join(path, (prefix ?? "") + field.key + ".inib"))
|
|
950
930
|
) {
|
|
951
931
|
const [items, total_lines] = await File.get(
|
|
952
|
-
join(path,
|
|
932
|
+
join(path, (prefix ?? "") + field.key + ".inib"),
|
|
953
933
|
linesNumber,
|
|
954
934
|
field.type,
|
|
955
935
|
(field as any)?.children,
|
|
@@ -1198,12 +1178,7 @@ export default class Inibase {
|
|
|
1198
1178
|
searchComparedAtValue = value as number | boolean;
|
|
1199
1179
|
}
|
|
1200
1180
|
const [searchResult, total_lines] = await File.search(
|
|
1201
|
-
join(
|
|
1202
|
-
this.folder,
|
|
1203
|
-
this.database,
|
|
1204
|
-
tableName,
|
|
1205
|
-
File.encodeFileName(key, "inib")
|
|
1206
|
-
),
|
|
1181
|
+
join(this.folder, this.database, tableName, key + ".inib"),
|
|
1207
1182
|
searchOperator,
|
|
1208
1183
|
searchComparedAtValue,
|
|
1209
1184
|
searchLogicalOperator,
|
|
@@ -1231,11 +1206,12 @@ export default class Inibase {
|
|
|
1231
1206
|
}
|
|
1232
1207
|
return Object.keys(RETURN).length ? RETURN : null;
|
|
1233
1208
|
};
|
|
1209
|
+
|
|
1234
1210
|
RETURN = await applyCriteria(where as Criteria);
|
|
1235
1211
|
if (RETURN) {
|
|
1236
1212
|
if (onlyLinesNumbers) return Object.keys(RETURN).map(Number);
|
|
1237
1213
|
const alreadyExistsColumns = Object.keys(Object.values(RETURN)[0]).map(
|
|
1238
|
-
(key) =>
|
|
1214
|
+
(key) => parse(key).name
|
|
1239
1215
|
);
|
|
1240
1216
|
RETURN = Object.values(
|
|
1241
1217
|
Utils.deepMerge(
|
package/package.json
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inibase",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.9",
|
|
4
4
|
"description": "File-based Relational Database for large data",
|
|
5
5
|
"main": "index.ts",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"test": "npx tsx watch ./index.test.ts"
|
|
9
|
+
},
|
|
7
10
|
"repository": {
|
|
8
11
|
"type": "git",
|
|
9
12
|
"url": "git+https://github.com/inicontent/inibase.git"
|
|
@@ -31,8 +34,5 @@
|
|
|
31
34
|
"homepage": "https://github.com/inicontent/inibase#readme",
|
|
32
35
|
"devDependencies": {
|
|
33
36
|
"@types/node": "^20.8.6"
|
|
34
|
-
},
|
|
35
|
-
"scripts": {
|
|
36
|
-
"test": "npx tsx watch ./index.test.ts"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|
package/utils.ts
CHANGED
|
File without changes
|