inibase 1.0.0-rc.0 → 1.0.0-rc.3

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.
Files changed (3) hide show
  1. package/README.md +64 -33
  2. package/index.ts +30 -23
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![Inibase banner](./.github/assets/banner.jpg)
2
2
 
3
- # Inibase
3
+ # Inibase :pencil:
4
4
 
5
5
  [![npmjs](https://img.shields.io/npm/dm/inibase.svg?style=flat)](https://www.npmjs.org/package/inibase) [![Node.js Version](https://img.shields.io/badge/node-18.11.0-blue)](https://nodejs.org/) [![License](https://img.shields.io/github/license/inicontent/inibase.svg?style=flat&colorA=18181B&colorB=28CF8D)](./LICENSE) [![Activity](https://img.shields.io/github/commit-activity/m/inicontent/inibase)](https://github.com/inicontent/inibase/pulse) [![GitHub stars](https://img.shields.io/github/stars/inicontent/inibase?style=social)](https://github.com/inicontent/inibase)
6
6
 
@@ -8,12 +8,13 @@
8
8
 
9
9
  ## Features
10
10
 
11
- - **Lightweight** 🪶 (~50kb)
11
+ - **Lightweight** 🪶 (~60kb)
12
12
  - **Minimalist** :white_circle:
13
13
  - **TypeScript** :large_blue_diamond:
14
14
  - **Super-Fast** :turtle:
15
15
  - **Suitable for large data** :page_with_curl:
16
16
  - **Safe** :lock:
17
+ - **Easy to use** :hourglass:
17
18
  - **...** and much more :rocket:
18
19
 
19
20
  ## Usage
@@ -54,14 +55,16 @@ npm install inibase
54
55
 
55
56
  // pnpm
56
57
  pnpm add inibase
57
-
58
- // yarn
59
- yarn add inibase
60
58
  ```
61
59
 
60
+ ## How it works?
61
+
62
+ To semplify the idea, each database has tables, each table has columns, each column will be stored in a seperated file. When POSTing new data, it will be appended to each columns file as new line. When GETing data, the file will be readed line-by-line so it can handle large data (without consuming a lot of resources)
63
+
62
64
  ## Examples
63
65
 
64
- #### POST
66
+ <details>
67
+ <summary>POST</summary>
65
68
 
66
69
  ```js
67
70
  import Inibase from "inibase";
@@ -268,7 +271,10 @@ const product = await db.post("product", product_data);
268
271
  // ]
269
272
  ```
270
273
 
271
- #### GET
274
+ </details>
275
+
276
+ <details>
277
+ <summary>GET</summary>
272
278
 
273
279
  ```js
274
280
  import Inibase from "inibase";
@@ -338,7 +344,10 @@ const users = await db.get("user", { favoriteFoods: "[]Pizza" });
338
344
  // ]
339
345
  ```
340
346
 
341
- #### PUT
347
+ </details>
348
+
349
+ <details>
350
+ <summary>PUT</summary>
342
351
 
343
352
  ```js
344
353
  import Inibase from "inibase";
@@ -354,7 +363,10 @@ await db.put("user", { isActive: false }, "1d88385d4b1581f8fb059334dec30f4c");
354
363
  await db.put("user", { isActive: false }, { isActive: true });
355
364
  ```
356
365
 
357
- #### DELETE
366
+ </details>
367
+
368
+ <details>
369
+ <summary>DELETE</summary>
358
370
 
359
371
  ```js
360
372
  import Inibase from "inibase";
@@ -370,46 +382,62 @@ await db.put("user", "1d88385d4b1581f8fb059334dec30f4c");
370
382
  await db.put("user", { isActive: false });
371
383
  ```
372
384
 
385
+ </details>
386
+
373
387
  ## Typescript
374
388
 
375
- #### Schema
389
+ <details>
390
+ <summary>Schema</summary>
376
391
 
377
392
  ```js
378
- type FieldType =
379
- | "string"
380
- | "number"
381
- | "boolean"
382
- | "date"
383
- | "email"
384
- | "url"
385
- | "table"
386
- | "object"
387
- | "array";
388
- type Field =
393
+ type Schema = Field[];
394
+ type Field = {
395
+ id?: string | number | null | undefined,
396
+ key: string,
397
+ required?: boolean,
398
+ } & (
389
399
  | {
390
- id?: string | number | null | undefined,
391
- key: string,
392
400
  type: Exclude<FieldType, "array" | "object">,
393
401
  required?: boolean,
394
402
  }
395
403
  | {
396
- id?: string | number | null | undefined,
397
- key: string,
398
404
  type: "array",
399
- required?: boolean,
400
405
  children: FieldType | FieldType[] | Schema,
401
406
  }
402
407
  | {
403
- id?: string | number | null | undefined,
404
- key: string,
405
408
  type: "object",
406
- required?: boolean,
407
409
  children: Schema,
408
- };
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";
423
+ ```
409
424
 
410
- type Schema = Field[];
425
+ </details>
426
+
427
+ <details>
428
+ <summary>Data</summary>
429
+
430
+ ```js
431
+ type Data = {
432
+ id?: number | string,
433
+ [key: string]: any,
434
+ created_at?: Date,
435
+ updated_at?: Date,
436
+ };
411
437
  ```
412
438
 
439
+ </details>
440
+
413
441
  ## Roadmap
414
442
 
415
443
  - [x] Actions:
@@ -431,9 +459,12 @@ type Schema = Field[];
431
459
  - [x] Table
432
460
  - [x] Object
433
461
  - [x] Array
434
- - [ ] Password
462
+ - [x] Password
435
463
  - [ ] IP
436
- - [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
464
+ - [ ] Features:
465
+ - [ ] Encryption
466
+ - [ ] Compress data
467
+ - [ ] Suggest [new feature +](https://github.com/inicontent/inibase/discussions/new?category=ideas)
437
468
 
438
469
  ## License
439
470
 
package/index.ts CHANGED
@@ -18,7 +18,6 @@ export { File, Utils };
18
18
  export type Data = {
19
19
  id?: number | string;
20
20
  [key: string]: any;
21
- [id: number]: any;
22
21
  created_at?: Date;
23
22
  updated_at?: Date;
24
23
  };
@@ -32,29 +31,26 @@ export type FieldType =
32
31
  | "url"
33
32
  | "table"
34
33
  | "object"
35
- | "password"
36
- | "array";
37
- type Field =
34
+ | "array"
35
+ | "password";
36
+ type Field = {
37
+ id?: string | number | null | undefined;
38
+ key: string;
39
+ required?: boolean;
40
+ } & (
38
41
  | {
39
- id?: string | number | null | undefined;
40
- key: string;
41
42
  type: Exclude<FieldType, "array" | "object">;
42
43
  required?: boolean;
43
44
  }
44
45
  | {
45
- id?: string | number | null | undefined;
46
- key: string;
47
46
  type: "array";
48
- required?: boolean;
49
47
  children: FieldType | FieldType[] | Schema;
50
48
  }
51
49
  | {
52
- id?: string | number | null | undefined;
53
- key: string;
54
50
  type: "object";
55
- required?: boolean;
56
51
  children: Schema;
57
- };
52
+ }
53
+ );
58
54
 
59
55
  export type Schema = Field[];
60
56
 
@@ -667,8 +663,8 @@ export default class Inibase {
667
663
  schema: Schema,
668
664
  linesNumber: number[],
669
665
  prefix?: string
670
- ): Promise<Data> => {
671
- let RETURN: Data = {};
666
+ ) => {
667
+ let RETURN: Record<number, Data> = {};
672
668
  for (const field of schema) {
673
669
  if (
674
670
  (field.type === "array" || field.type === "object") &&
@@ -706,7 +702,12 @@ export default class Inibase {
706
702
  )) ?? {}
707
703
  ).forEach(([index, item]) => {
708
704
  if (!RETURN[index]) RETURN[index] = {};
709
- RETURN[index][field.key] = item;
705
+ RETURN[index][field.key] =
706
+ field.type === "array" &&
707
+ Utils.isObject(item) &&
708
+ Object.values(item).every((i) => i === null)
709
+ ? []
710
+ : item;
710
711
  });
711
712
  }
712
713
  } else if (field.type === "table") {
@@ -1054,7 +1055,11 @@ export default class Inibase {
1054
1055
 
1055
1056
  public async post(
1056
1057
  tableName: string,
1057
- data: Data | Data[]
1058
+ data: Data | Data[],
1059
+ options: Options = {
1060
+ page: 1,
1061
+ per_page: 15,
1062
+ }
1058
1063
  ): Promise<Data | Data[] | null> {
1059
1064
  const schema = this.getTableSchema(tableName);
1060
1065
  let RETURN: Data | Data[] | null | undefined;
@@ -1092,12 +1097,14 @@ export default class Inibase {
1092
1097
  (Array.isArray(content) ? content.join("\n") : content ?? "") + "\n",
1093
1098
  "utf8"
1094
1099
  );
1095
- return Utils.isArrayOfObjects(RETURN)
1096
- ? RETURN.map((data: Data) => {
1097
- data.id = this.encodeID(data.id as number);
1098
- return data;
1099
- })
1100
- : { ...RETURN, id: this.encodeID((RETURN as Data).id as number) };
1100
+
1101
+ return this.get(
1102
+ tableName,
1103
+ Utils.isArrayOfObjects(RETURN)
1104
+ ? RETURN.map((data: Data) => data.id)
1105
+ : ((RETURN as Data).id as number),
1106
+ options
1107
+ );
1101
1108
  }
1102
1109
 
1103
1110
  public async put(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inibase",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.0-rc.3",
4
4
  "description": "File-based Relational Database for large data",
5
5
  "main": "index.ts",
6
6
  "repository": {