inibase 1.0.0-rc.6 → 1.0.0-rc.61

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.
@@ -0,0 +1,105 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ import "dotenv/config";
3
+ export interface Data {
4
+ id?: number | string;
5
+ [key: string]: any;
6
+ createdAt?: number;
7
+ updatedAt?: number;
8
+ }
9
+ export type FieldType = "string" | "number" | "boolean" | "date" | "email" | "url" | "table" | "object" | "array" | "password" | "html" | "ip" | "json" | "id";
10
+ export type Field = {
11
+ id?: string | number;
12
+ key: string;
13
+ type: FieldType | FieldType[];
14
+ required?: boolean;
15
+ table?: string;
16
+ unique?: boolean;
17
+ children?: FieldType | FieldType[] | Schema;
18
+ };
19
+ export type Schema = Field[];
20
+ export interface Options {
21
+ page?: number;
22
+ perPage?: number;
23
+ columns?: string[] | string;
24
+ order?: Record<string, "asc" | "desc">;
25
+ }
26
+ export interface Config {
27
+ compression: boolean;
28
+ cache: boolean;
29
+ prepend: boolean;
30
+ }
31
+ export interface TableObject {
32
+ schema?: Schema;
33
+ config: Config;
34
+ }
35
+ export type ComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "*" | "!*" | "[]" | "![]";
36
+ type pageInfo = {
37
+ total?: number;
38
+ totalPages?: number;
39
+ } & Options;
40
+ export type Criteria = ({
41
+ [logic in "and" | "or"]?: Criteria | (string | number | boolean | null)[];
42
+ } & {
43
+ [key: string]: string | number | boolean | undefined | Criteria;
44
+ }) | null;
45
+ declare global {
46
+ type Entries<T> = {
47
+ [K in keyof T]: [K, T[K]];
48
+ }[keyof T][];
49
+ interface ObjectConstructor {
50
+ entries<T extends object>(o: T): Entries<T>;
51
+ }
52
+ }
53
+ export type ErrorCodes = "FIELD_UNIQUE" | "FIELD_REQUIRED" | "NO_SCHEMA" | "NO_ITEMS" | "NO_RESULTS" | "INVALID_ID" | "INVALID_TYPE" | "INVALID_PARAMETERS" | "NO_ENV" | "TABLE_EXISTS" | "TABLE_NOT_EXISTS";
54
+ export type ErrorLang = "en";
55
+ export default class Inibase {
56
+ pageInfo: Record<string, pageInfo>;
57
+ salt: Buffer;
58
+ private databasePath;
59
+ private tables;
60
+ private fileExtension;
61
+ private checkIFunique;
62
+ private totalItems;
63
+ constructor(database: string, mainFolder?: string);
64
+ private throwError;
65
+ private getFileExtension;
66
+ private _schemaToIdsPath;
67
+ createTable(tableName: string, schema?: Schema, config?: Config): Promise<void>;
68
+ updateTable(tableName: string, schema?: Schema, config?: Config): Promise<void>;
69
+ getTable(tableName: string): Promise<TableObject>;
70
+ getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema | undefined>;
71
+ private throwErrorIfTableEmpty;
72
+ private validateData;
73
+ private formatField;
74
+ private checkUnique;
75
+ private formatData;
76
+ private getDefaultValue;
77
+ private _combineObjectsToArray;
78
+ private _CombineData;
79
+ private joinPathesContents;
80
+ private _getItemsFromSchemaHelper;
81
+ private getItemsFromSchema;
82
+ private applyCriteria;
83
+ private _filterSchemaByColumns;
84
+ clearCache(tablePath: string): Promise<void>;
85
+ get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: true, onlyLinesNumbers?: undefined, _skipIdColumn?: boolean): Promise<Data | null>;
86
+ get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: boolean | undefined, onlyLinesNumbers?: true, _skipIdColumn?: boolean): Promise<number[]>;
87
+ post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void>;
88
+ post(tableName: string, data: Data, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
89
+ post(tableName: string, data: Data[], options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
90
+ put(tableName: string, data: Data | Data[], where?: number | string | (number | string)[] | Criteria, options?: Options, returnUpdatedData?: false): Promise<void>;
91
+ put(tableName: string, data: Data, where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data | null>;
92
+ put(tableName: string, data: Data[], where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data[] | null>;
93
+ delete(tableName: string, where?: number | string, _id?: string | string[]): Promise<string | null>;
94
+ delete(tableName: string, where?: (number | string)[] | Criteria, _id?: string | string[]): Promise<string[] | null>;
95
+ delete(tableName: string, where?: number, _id?: string | string[]): Promise<number | null>;
96
+ delete(tableName: string, where?: number[], _id?: string | string[]): Promise<number[] | null>;
97
+ sum(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
98
+ sum(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
99
+ max(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
100
+ max(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
101
+ min(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
102
+ min(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
103
+ sort(tableName: string, columns: string | string[] | Record<string, 1 | -1 | "asc" | "ASC" | "desc" | "DESC">, where?: string | number | (string | number)[] | Criteria, options?: Options): Promise<any[]>;
104
+ }
105
+ export {};