inibase 1.0.0-rc.3 → 1.0.0-rc.31
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 +129 -92
- package/dist/config.d.ts +4 -0
- package/dist/config.js +4 -0
- package/dist/file.d.ts +171 -0
- package/dist/file.js +768 -0
- package/dist/index.d.ts +97 -0
- package/dist/index.js +1040 -0
- package/dist/utils.d.ts +203 -0
- package/dist/utils.js +442 -0
- package/dist/utils.server.d.ts +102 -0
- package/dist/utils.server.js +149 -0
- package/package.json +59 -18
- package/file.ts +0 -322
- package/index.ts +0 -1251
- package/tsconfig.json +0 -6
- package/utils.ts +0 -110
package/README.md
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-

|
|
1
|
+
[](https://github.com/inicontent/inibase)
|
|
2
2
|
|
|
3
3
|
# Inibase :pencil:
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.org/package/inibase) [](https://www.npmjs.org/package/inibase) [](./LICENSE) [](https://github.com/inicontent/inibase/pulse) [](https://github.com/inicontent/inibase)
|
|
6
6
|
|
|
7
|
-
>
|
|
7
|
+
> A file-based & memory-efficient, serverless, ACID compliant, relational database management system :fire:
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **Lightweight** 🪶
|
|
12
|
-
- **Minimalist** :white_circle:
|
|
11
|
+
- **Lightweight** 🪶
|
|
12
|
+
- **Minimalist** :white_circle: (but powerful)
|
|
13
13
|
- **TypeScript** :large_blue_diamond:
|
|
14
|
-
- **Super-Fast** :
|
|
15
|
-
- **
|
|
16
|
-
- **
|
|
17
|
-
- **
|
|
14
|
+
- **Super-Fast** :zap: (built-in caching system)
|
|
15
|
+
- **Built-in form-validation** included :sunglasses:
|
|
16
|
+
- **Suitable for large data** :page_with_curl: (tested with 200K row)
|
|
17
|
+
- **Support Compression** :eight_spoked_asterisk: (using built-in nodejs zlib)
|
|
18
|
+
- **Support Table Joins** :link:
|
|
19
|
+
- **Low memory-usage** :chart_with_downwards_trend: (3-5mb)
|
|
20
|
+
- **Safe** :lock: (no sql or javascript injections)
|
|
21
|
+
- **Easy to use** :bread:
|
|
18
22
|
- **...** and much more :rocket:
|
|
19
23
|
|
|
20
24
|
## Usage
|
|
21
25
|
|
|
22
26
|
```js
|
|
23
27
|
import Inibase from "inibase";
|
|
24
|
-
const db = new Inibase("
|
|
28
|
+
const db = new Inibase("database_name");
|
|
25
29
|
|
|
26
30
|
// Get all items from "user" table
|
|
27
31
|
const users = await db.get("user");
|
|
@@ -30,36 +34,86 @@ const users = await db.get("user");
|
|
|
30
34
|
const users = await db.get("user", undefined, { page: 2, per_page: 15 });
|
|
31
35
|
|
|
32
36
|
// Get only required columns to improve speed
|
|
33
|
-
const users = await
|
|
34
|
-
columns: ["username", "address.street", "hobbies
|
|
37
|
+
const users = await db.get("user", undefined, {
|
|
38
|
+
columns: ["username", "address.street", "hobbies.name"],
|
|
35
39
|
});
|
|
36
40
|
|
|
37
|
-
// Get items from "user" table where "favoriteFoods" does not includes "Pizza"
|
|
38
|
-
const users = await
|
|
41
|
+
// Get items from "user" table where "favoriteFoods" does not includes "Pizza" or "Burger"
|
|
42
|
+
const users = await db.get("user", { favoriteFoods: "![]Pizza,Burger" });
|
|
39
43
|
```
|
|
40
44
|
|
|
41
45
|
If you like Inibase, please sponsor: [GitHub Sponsors](https://github.com/sponsors/inicontent) || [Paypal](https://paypal.me/KarimAmahtil).
|
|
42
46
|
|
|
43
|
-
## Sponsors
|
|
44
|
-
|
|
45
|
-
<br>
|
|
46
|
-
<br>
|
|
47
|
-
|
|
48
|
-
Become a sponsor and have your company logo here 👉 [GitHub Sponsors](https://github.com/sponsors/inicontent) || [paypal](https://paypal.me/KarimAmahtil).
|
|
49
|
-
|
|
50
47
|
## Install
|
|
51
48
|
|
|
52
49
|
```js
|
|
53
|
-
|
|
54
|
-
npm install inibase
|
|
55
|
-
|
|
56
|
-
// pnpm
|
|
57
|
-
pnpm add inibase
|
|
50
|
+
<npm|pnpm|yarn> install inibase
|
|
58
51
|
```
|
|
59
52
|
|
|
60
53
|
## How it works?
|
|
61
54
|
|
|
62
|
-
To
|
|
55
|
+
To simplify the idea, each database has tables, each table has columns, each column will be stored in a seperated file. When **POST**ing new data, it will be appended to the _head_ of each file as new line. When **GET**ing data, the file will be readed line-by-line so it can handle large data (without consuming a lot of resources), when **PUT**ing(updating) in a specific column, only one file will be opened and updated
|
|
56
|
+
|
|
57
|
+
## Benchmark
|
|
58
|
+
|
|
59
|
+
### Bulk
|
|
60
|
+
|
|
61
|
+
| | 10 | 100 | 1000 |
|
|
62
|
+
|--------|-----------------|-----------------|-----------------|
|
|
63
|
+
| POST | 11 ms (0.65 mb) | 19 ms (1.00 mb) | 85 ms (4.58 mb) |
|
|
64
|
+
| GET | 14 ms (2.77 mb) | 12 ms (3.16 mb) | 34 ms (1.38 mb) |
|
|
65
|
+
| PUT | 6 ms (1.11 mb) | 5 ms (1.37 mb) | 10 ms (1.12 mb) |
|
|
66
|
+
| DELETE | 17 ms (1.68 mb) | 14 ms (5.45 mb) | 25 ms (5.94 mb) |
|
|
67
|
+
|
|
68
|
+
### Single
|
|
69
|
+
|
|
70
|
+
| | 10 | 100 | 1000 |
|
|
71
|
+
|--------|-------------------|--------------------|--------------------|
|
|
72
|
+
| POST | 43 ms (4.70 mb) | 387 ms (6.36 mb) | 5341 ms (24.73 mb) |
|
|
73
|
+
| GET | 99 ms (12.51 mb) | 846 ms (30.68 mb) | 7103 ms (30.86 mb) |
|
|
74
|
+
| PUT | 33 ms (10.29 mb) | 312 ms (11.06 mb) | 3539 ms (14.87 mb) |
|
|
75
|
+
| DELETE | 134 ms (13.50 mb) | 1224 ms (16.57 mb) | 7339 ms (11.46 mb) |
|
|
76
|
+
|
|
77
|
+
Ps: Testing by default with `user` table, with username, email, password fields _so results include password encryption process_
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
## Roadmap
|
|
81
|
+
|
|
82
|
+
- [x] Actions:
|
|
83
|
+
- [x] GET:
|
|
84
|
+
- [x] Pagination
|
|
85
|
+
- [x] Criteria
|
|
86
|
+
- [x] Columns
|
|
87
|
+
- [ ] Order By
|
|
88
|
+
- [x] POST
|
|
89
|
+
- [x] PUT
|
|
90
|
+
- [x] DELETE
|
|
91
|
+
- [x] SUM
|
|
92
|
+
- [x] MAX
|
|
93
|
+
- [x] MIN
|
|
94
|
+
- [ ] Schema supported types:
|
|
95
|
+
- [x] String
|
|
96
|
+
- [x] Number
|
|
97
|
+
- [x] Boolean
|
|
98
|
+
- [x] Date
|
|
99
|
+
- [x] Email
|
|
100
|
+
- [x] Url
|
|
101
|
+
- [x] Table
|
|
102
|
+
- [x] Object
|
|
103
|
+
- [x] Array
|
|
104
|
+
- [x] Password
|
|
105
|
+
- [x] IP
|
|
106
|
+
- [x] HTML
|
|
107
|
+
- [x] Id
|
|
108
|
+
- [ ] TO-DO:
|
|
109
|
+
- [x] Improve caching
|
|
110
|
+
- [x] Commenting the code
|
|
111
|
+
- [ ] Features:
|
|
112
|
+
- [ ] Encryption
|
|
113
|
+
- [x] Data Compression
|
|
114
|
+
- [x] Caching System
|
|
115
|
+
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
116
|
+
|
|
63
117
|
|
|
64
118
|
## Examples
|
|
65
119
|
|
|
@@ -342,6 +396,11 @@ const users = await db.get("user", { favoriteFoods: "[]Pizza" });
|
|
|
342
396
|
// },
|
|
343
397
|
// ...
|
|
344
398
|
// ]
|
|
399
|
+
|
|
400
|
+
// Get all "user" columns except "username" & "address.street"
|
|
401
|
+
const users = await db.get("user", undefined, {
|
|
402
|
+
columns: ["!username", "!address.street"],
|
|
403
|
+
});
|
|
345
404
|
```
|
|
346
405
|
|
|
347
406
|
</details>
|
|
@@ -384,87 +443,65 @@ await db.put("user", { isActive: false });
|
|
|
384
443
|
|
|
385
444
|
</details>
|
|
386
445
|
|
|
387
|
-
|
|
446
|
+
<details>
|
|
447
|
+
<summary>SUM</summary>
|
|
448
|
+
|
|
449
|
+
```js
|
|
450
|
+
import Inibase from "inibase";
|
|
451
|
+
const db = new Inibase("/database_name");
|
|
452
|
+
|
|
453
|
+
// get the sum of column "age" in "user" table
|
|
454
|
+
await db.sum("user", "age");
|
|
455
|
+
|
|
456
|
+
// get the sum of column "age" by criteria (where "isActive" is equal to "false") in "user" table
|
|
457
|
+
await db.sum("user", ["age", ...], { isActive: false });
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
</details>
|
|
388
461
|
|
|
389
462
|
<details>
|
|
390
|
-
<summary>
|
|
463
|
+
<summary>MAX</summary>
|
|
391
464
|
|
|
392
465
|
```js
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
required?: boolean,
|
|
402
|
-
}
|
|
403
|
-
| {
|
|
404
|
-
type: "array",
|
|
405
|
-
children: FieldType | FieldType[] | Schema,
|
|
406
|
-
}
|
|
407
|
-
| {
|
|
408
|
-
type: "object",
|
|
409
|
-
children: Schema,
|
|
410
|
-
}
|
|
411
|
-
);
|
|
412
|
-
type FieldType =
|
|
413
|
-
| "string"
|
|
414
|
-
| "number"
|
|
415
|
-
| "boolean"
|
|
416
|
-
| "date"
|
|
417
|
-
| "email"
|
|
418
|
-
| "url"
|
|
419
|
-
| "table"
|
|
420
|
-
| "object"
|
|
421
|
-
| "array"
|
|
422
|
-
| "password";
|
|
466
|
+
import Inibase from "inibase";
|
|
467
|
+
const db = new Inibase("/database_name");
|
|
468
|
+
|
|
469
|
+
// get the biggest number of column "age" in "user" table
|
|
470
|
+
await db.max("user", "age");
|
|
471
|
+
|
|
472
|
+
// get the biggest number of column "age" by criteria (where "isActive" is equal to "false") in "user" table
|
|
473
|
+
await db.max("user", ["age", ...], { isActive: false });
|
|
423
474
|
```
|
|
424
475
|
|
|
425
476
|
</details>
|
|
426
477
|
|
|
427
478
|
<details>
|
|
428
|
-
<summary>
|
|
479
|
+
<summary>MIN</summary>
|
|
429
480
|
|
|
430
481
|
```js
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
482
|
+
import Inibase from "inibase";
|
|
483
|
+
const db = new Inibase("/database_name");
|
|
484
|
+
|
|
485
|
+
// get the smallest number of column "age" in "user" table
|
|
486
|
+
await db.min("user", "age");
|
|
487
|
+
|
|
488
|
+
// get the smallest number of column "age" by criteria (where "isActive" is equal to "false") in "user" table
|
|
489
|
+
await db.min("user", ["age", ...], { isActive: false });
|
|
437
490
|
```
|
|
438
491
|
|
|
439
492
|
</details>
|
|
440
493
|
|
|
441
|
-
##
|
|
494
|
+
## Config
|
|
442
495
|
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
- [ ] Schema supported types:
|
|
453
|
-
- [x] String
|
|
454
|
-
- [x] Number
|
|
455
|
-
- [x] Boolean
|
|
456
|
-
- [x] Date
|
|
457
|
-
- [x] Email
|
|
458
|
-
- [x] Url
|
|
459
|
-
- [x] Table
|
|
460
|
-
- [x] Object
|
|
461
|
-
- [x] Array
|
|
462
|
-
- [x] Password
|
|
463
|
-
- [ ] IP
|
|
464
|
-
- [ ] Features:
|
|
465
|
-
- [ ] Encryption
|
|
466
|
-
- [ ] Compress data
|
|
467
|
-
- [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
|
|
496
|
+
The `.env` file supports the following parameters (make sure to run command with flag --env-file=.env)
|
|
497
|
+
|
|
498
|
+
```ini
|
|
499
|
+
# Auto generated secret key, will be using for encrypting the IDs
|
|
500
|
+
INIBASE_SECRET=
|
|
501
|
+
|
|
502
|
+
INIBASE_COMPRESSION=true
|
|
503
|
+
INIBASE_CACHE=true
|
|
504
|
+
```
|
|
468
505
|
|
|
469
506
|
## License
|
|
470
507
|
|
package/dist/config.d.ts
ADDED
package/dist/config.js
ADDED
package/dist/file.d.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { ComparisonOperator, FieldType } from "./index.js";
|
|
3
|
+
export declare const write: (filePath: string, data: any, disableCompression?: boolean) => Promise<void>;
|
|
4
|
+
export declare const read: (filePath: string, disableCompression?: boolean) => Promise<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Checks if a file or directory exists at the specified path.
|
|
7
|
+
*
|
|
8
|
+
* @param path - The path to the file or directory.
|
|
9
|
+
* @returns A Promise that resolves to true if the file/directory exists, false otherwise.
|
|
10
|
+
*/
|
|
11
|
+
export declare const isExists: (path: string) => Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Encodes the input using 'secureString' and 'joinMultidimensionalArray' functions.
|
|
14
|
+
* If the input is an array, it is first secured and then joined into a string.
|
|
15
|
+
* If the input is a single value, it is directly secured.
|
|
16
|
+
*
|
|
17
|
+
* @param input - A value or array of values (string, number, boolean, null).
|
|
18
|
+
* @param secretKey - Optional secret key for encoding, can be a string or Buffer.
|
|
19
|
+
* @returns The secured and/or joined string.
|
|
20
|
+
*/
|
|
21
|
+
export declare const encode: (input: string | number | boolean | null | (string | number | boolean | null)[], secretKey?: string | Buffer) => string | number | boolean | null;
|
|
22
|
+
/**
|
|
23
|
+
* Decodes the input based on the specified field type(s) and an optional secret key.
|
|
24
|
+
* Handles different formats of input, including strings, numbers, and their array representations.
|
|
25
|
+
*
|
|
26
|
+
* @param input - The input to be decoded, can be a string, number, or null.
|
|
27
|
+
* @param fieldType - Optional type of the field to guide decoding (e.g., 'number', 'boolean').
|
|
28
|
+
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
29
|
+
* @param secretKey - Optional secret key for decoding, can be a string or Buffer.
|
|
30
|
+
* @returns Decoded value as a string, number, boolean, or array of these, or null if no fieldType or input is null/empty.
|
|
31
|
+
*/
|
|
32
|
+
export declare const decode: (input: string | null | number, fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[], secretKey?: string | Buffer) => string | number | boolean | null | (string | number | null | boolean)[];
|
|
33
|
+
/**
|
|
34
|
+
* Asynchronously reads and decodes data from a file at specified line numbers.
|
|
35
|
+
* Decodes each line based on specified field types and an optional secret key.
|
|
36
|
+
*
|
|
37
|
+
* @param filePath - Path of the file to be read.
|
|
38
|
+
* @param lineNumbers - Optional line number(s) to read from the file. If -1, reads the last line.
|
|
39
|
+
* @param fieldType - Optional type of the field to guide decoding (e.g., 'number', 'boolean').
|
|
40
|
+
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
41
|
+
* @param secretKey - Optional secret key for decoding, can be a string or Buffer.
|
|
42
|
+
* @returns Promise resolving to a tuple:
|
|
43
|
+
* 1. Record of line numbers and their decoded content or null if no lines are read.
|
|
44
|
+
* 2. Total count of lines processed.
|
|
45
|
+
*/
|
|
46
|
+
export declare function get(filePath: string, lineNumbers?: number | number[], fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[], secretKey?: string | Buffer, readWholeFile?: false): Promise<Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null>;
|
|
47
|
+
export declare function get(filePath: string, lineNumbers: undefined | number | number[], fieldType: undefined | FieldType | FieldType[], fieldChildrenType: undefined | FieldType | FieldType[], secretKey: undefined | string | Buffer, readWholeFile: true): Promise<[
|
|
48
|
+
Record<number, string | number | boolean | null | (string | number | boolean | (string | number | boolean)[] | null)[]> | null,
|
|
49
|
+
number
|
|
50
|
+
]>;
|
|
51
|
+
/**
|
|
52
|
+
* Asynchronously replaces specific lines in a file based on the provided replacements map or string.
|
|
53
|
+
*
|
|
54
|
+
* @param filePath - Path of the file to modify.
|
|
55
|
+
* @param replacements - Map of line numbers to replacement values, or a single replacement value for all lines.
|
|
56
|
+
* Can be a string, number, boolean, null, array of these types, or a Record/Map of line numbers to these types.
|
|
57
|
+
* @returns Promise<string[]>
|
|
58
|
+
*
|
|
59
|
+
* Note: If the file doesn't exist and replacements is an object, it creates a new file with the specified replacements.
|
|
60
|
+
*/
|
|
61
|
+
export declare const replace: (filePath: string, replacements: string | number | boolean | null | (string | number | boolean | null)[] | Record<number, string | boolean | number | null | (string | boolean | number | null)[]>) => Promise<string[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Asynchronously appends data to the beginning of a file.
|
|
64
|
+
*
|
|
65
|
+
* @param filePath - Path of the file to append to.
|
|
66
|
+
* @param data - Data to append. Can be a string, number, or an array of strings/numbers.
|
|
67
|
+
* @returns Promise<string[]>. Modifies the file by appending data.
|
|
68
|
+
*
|
|
69
|
+
*/
|
|
70
|
+
export declare const append: (filePath: string, data: string | number | (string | number)[]) => Promise<string[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Asynchronously removes specified lines from a file.
|
|
73
|
+
*
|
|
74
|
+
* @param filePath - Path of the file from which lines are to be removed.
|
|
75
|
+
* @param linesToDelete - A single line number or an array of line numbers to be deleted.
|
|
76
|
+
* @returns Promise<string[]>. Modifies the file by removing specified lines.
|
|
77
|
+
*
|
|
78
|
+
* Note: Creates a temporary file during the process and replaces the original file with it after removing lines.
|
|
79
|
+
*/
|
|
80
|
+
export declare const remove: (filePath: string, linesToDelete: number | number[]) => Promise<string[]>;
|
|
81
|
+
/**
|
|
82
|
+
* Asynchronously searches a file for lines matching specified criteria, using comparison and logical operators.
|
|
83
|
+
*
|
|
84
|
+
* @param filePath - Path of the file to search.
|
|
85
|
+
* @param operator - Comparison operator(s) for evaluation (e.g., '=', '!=', '>', '<').
|
|
86
|
+
* @param comparedAtValue - Value(s) to compare each line against.
|
|
87
|
+
* @param logicalOperator - Optional logical operator ('and' or 'or') for combining multiple comparisons.
|
|
88
|
+
* @param fieldType - Optional type of the field to guide comparison.
|
|
89
|
+
* @param fieldChildrenType - Optional type for child elements in array inputs.
|
|
90
|
+
* @param limit - Optional limit on the number of results to return.
|
|
91
|
+
* @param offset - Optional offset to start returning results from.
|
|
92
|
+
* @param readWholeFile - Flag to indicate whether to continue reading the file after reaching the limit.
|
|
93
|
+
* @param secretKey - Optional secret key for decoding, can be a string or Buffer.
|
|
94
|
+
* @returns Promise resolving to a tuple:
|
|
95
|
+
* 1. Record of line numbers and their content that match the criteria or null if none.
|
|
96
|
+
* 2. The count of found items or processed items based on the 'readWholeFile' flag.
|
|
97
|
+
*
|
|
98
|
+
* Note: Decodes each line for comparison and can handle complex queries with multiple conditions.
|
|
99
|
+
*/
|
|
100
|
+
export declare const search: (filePath: string, operator: ComparisonOperator | ComparisonOperator[], comparedAtValue: string | number | boolean | null | (string | number | boolean | null)[], logicalOperator?: "and" | "or", fieldType?: FieldType | FieldType[], fieldChildrenType?: FieldType | FieldType[], limit?: number, offset?: number, readWholeFile?: boolean, secretKey?: string | Buffer) => Promise<[
|
|
101
|
+
Record<number, string | number | boolean | null | (string | number | boolean | null)[]> | null,
|
|
102
|
+
number,
|
|
103
|
+
Set<number> | null
|
|
104
|
+
]>;
|
|
105
|
+
/**
|
|
106
|
+
* Asynchronously counts the number of lines in a file.
|
|
107
|
+
*
|
|
108
|
+
* @param filePath - Path of the file to count lines in.
|
|
109
|
+
* @returns Promise<number>. The number of lines in the file.
|
|
110
|
+
*
|
|
111
|
+
* Note: Reads through the file line by line to count the total number of lines.
|
|
112
|
+
*/
|
|
113
|
+
export declare const count: (filePath: string) => Promise<number>;
|
|
114
|
+
/**
|
|
115
|
+
* Asynchronously calculates the sum of numerical values from specified lines in a file.
|
|
116
|
+
*
|
|
117
|
+
* @param filePath - Path of the file to read.
|
|
118
|
+
* @param lineNumbers - Optional specific line number(s) to include in the sum. If not provided, sums all lines.
|
|
119
|
+
* @returns Promise<number>. The sum of numerical values from the specified lines.
|
|
120
|
+
*
|
|
121
|
+
* Note: Decodes each line as a number using the 'decode' function. Non-numeric lines contribute 0 to the sum.
|
|
122
|
+
*/
|
|
123
|
+
export declare const sum: (filePath: string, lineNumbers?: number | number[]) => Promise<number>;
|
|
124
|
+
/**
|
|
125
|
+
* Asynchronously finds the maximum numerical value from specified lines in a file.
|
|
126
|
+
*
|
|
127
|
+
* @param filePath - Path of the file to read.
|
|
128
|
+
* @param lineNumbers - Optional specific line number(s) to consider for finding the maximum value. If not provided, considers all lines.
|
|
129
|
+
* @returns Promise<number>. The maximum numerical value found in the specified lines.
|
|
130
|
+
*
|
|
131
|
+
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the maximum.
|
|
132
|
+
*/
|
|
133
|
+
export declare const max: (filePath: string, lineNumbers?: number | number[]) => Promise<number>;
|
|
134
|
+
/**
|
|
135
|
+
* Asynchronously finds the minimum numerical value from specified lines in a file.
|
|
136
|
+
*
|
|
137
|
+
* @param filePath - Path of the file to read.
|
|
138
|
+
* @param lineNumbers - Optional specific line number(s) to consider for finding the minimum value. If not provided, considers all lines.
|
|
139
|
+
* @returns Promise<number>. The minimum numerical value found in the specified lines.
|
|
140
|
+
*
|
|
141
|
+
* Note: Decodes each line as a number using the 'decode' function. Considers only numerical values for determining the minimum.
|
|
142
|
+
*/
|
|
143
|
+
export declare const min: (filePath: string, lineNumbers?: number | number[]) => Promise<number>;
|
|
144
|
+
/**
|
|
145
|
+
* Asynchronously sorts the lines in a file in the specified direction.
|
|
146
|
+
*
|
|
147
|
+
* @param filePath - Path of the file to be sorted.
|
|
148
|
+
* @param sortDirection - Direction for sorting: 1 or 'asc' for ascending, -1 or 'desc' for descending.
|
|
149
|
+
* @param lineNumbers - Optional specific line numbers to sort. If not provided, sorts all lines.
|
|
150
|
+
* @param _lineNumbersPerChunk - Optional parameter for handling large files, specifying the number of lines per chunk.
|
|
151
|
+
* @returns Promise<void>. Modifies the file by sorting specified lines.
|
|
152
|
+
*
|
|
153
|
+
* Note: The sorting is applied either to the entire file or to the specified lines. Large files are handled in chunks.
|
|
154
|
+
*/
|
|
155
|
+
export declare const sort: (filePath: string, sortDirection: 1 | -1 | "asc" | "desc", lineNumbers?: number | number[], _lineNumbersPerChunk?: number) => Promise<void>;
|
|
156
|
+
export default class File {
|
|
157
|
+
static get: typeof get;
|
|
158
|
+
static remove: (filePath: string, linesToDelete: number | number[]) => Promise<string[]>;
|
|
159
|
+
static search: (filePath: string, operator: ComparisonOperator | ComparisonOperator[], comparedAtValue: string | number | boolean | (string | number | boolean | null)[] | null, logicalOperator?: "and" | "or" | undefined, fieldType?: FieldType | FieldType[] | undefined, fieldChildrenType?: FieldType | FieldType[] | undefined, limit?: number | undefined, offset?: number | undefined, readWholeFile?: boolean | undefined, secretKey?: string | Buffer | undefined) => Promise<[Record<number, string | number | boolean | (string | number | boolean | null)[] | null> | null, number, Set<number> | null]>;
|
|
160
|
+
static replace: (filePath: string, replacements: string | number | boolean | (string | number | boolean | null)[] | Record<number, string | number | boolean | (string | number | boolean | null)[] | null> | null) => Promise<string[]>;
|
|
161
|
+
static encode: (input: string | number | boolean | (string | number | boolean | null)[] | null, secretKey?: string | Buffer | undefined) => string | number | boolean | null;
|
|
162
|
+
static decode: (input: string | number | null, fieldType?: FieldType | FieldType[] | undefined, fieldChildrenType?: FieldType | FieldType[] | undefined, secretKey?: string | Buffer | undefined) => string | number | boolean | (string | number | boolean | null)[] | null;
|
|
163
|
+
static isExists: (path: string) => Promise<boolean>;
|
|
164
|
+
static sum: (filePath: string, lineNumbers?: number | number[] | undefined) => Promise<number>;
|
|
165
|
+
static min: (filePath: string, lineNumbers?: number | number[] | undefined) => Promise<number>;
|
|
166
|
+
static max: (filePath: string, lineNumbers?: number | number[] | undefined) => Promise<number>;
|
|
167
|
+
static append: (filePath: string, data: string | number | (string | number)[]) => Promise<string[]>;
|
|
168
|
+
static count: (filePath: string) => Promise<number>;
|
|
169
|
+
static write: (filePath: string, data: any, disableCompression?: boolean) => Promise<void>;
|
|
170
|
+
static read: (filePath: string, disableCompression?: boolean) => Promise<string>;
|
|
171
|
+
}
|