inibase 1.0.0-rc.9 → 1.0.0-rc.90

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,192 @@
1
+ import "dotenv/config";
2
+ export interface Data {
3
+ id?: number | string;
4
+ [key: string]: any;
5
+ createdAt?: number;
6
+ updatedAt?: number;
7
+ }
8
+ export type FieldType = "string" | "number" | "boolean" | "date" | "email" | "url" | "table" | "object" | "array" | "password" | "html" | "ip" | "json" | "id";
9
+ export type Field = {
10
+ id?: string | number;
11
+ key: string;
12
+ type: FieldType | FieldType[];
13
+ required?: boolean;
14
+ table?: string;
15
+ unique?: boolean;
16
+ children?: FieldType | FieldType[] | Schema;
17
+ };
18
+ export type Schema = Field[];
19
+ export interface Options {
20
+ page?: number;
21
+ perPage?: number;
22
+ columns?: string[] | string;
23
+ sort?: Record<string, 1 | -1 | "asc" | "ASC" | "desc" | "DESC"> | string[] | string;
24
+ }
25
+ export interface Config {
26
+ compression?: boolean;
27
+ cache?: boolean;
28
+ prepend?: boolean;
29
+ }
30
+ export interface TableObject {
31
+ schema?: Schema;
32
+ config: Config;
33
+ }
34
+ export type ComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "*" | "!*" | "[]" | "![]";
35
+ export type pageInfo = {
36
+ total?: number;
37
+ totalPages?: number;
38
+ } & Options;
39
+ export type Criteria = ({
40
+ [logic in "and" | "or"]?: Criteria | (string | number | boolean | null)[];
41
+ } & {
42
+ [key: string]: string | number | boolean | undefined | Criteria;
43
+ }) | null;
44
+ type Entries<T> = {
45
+ [K in keyof T]: [K, T[K]];
46
+ }[keyof T][];
47
+ declare global {
48
+ interface ObjectConstructor {
49
+ entries<T extends object>(o: T): Entries<T>;
50
+ }
51
+ }
52
+ export type ErrorCodes = "FIELD_UNIQUE" | "FIELD_REQUIRED" | "NO_SCHEMA" | "NO_ITEMS" | "INVALID_ID" | "INVALID_TYPE" | "INVALID_PARAMETERS" | "NO_ENV" | "TABLE_EXISTS" | "TABLE_NOT_EXISTS";
53
+ export type ErrorLang = "en";
54
+ export default class Inibase {
55
+ pageInfo: Record<string, pageInfo>;
56
+ salt: Buffer;
57
+ private databasePath;
58
+ private tables;
59
+ private fileExtension;
60
+ private checkIFunique;
61
+ private totalItems;
62
+ constructor(database: string, mainFolder?: string);
63
+ private throwError;
64
+ private getFileExtension;
65
+ private _schemaToIdsPath;
66
+ /**
67
+ * Create a new table inside database, with predefined schema and config
68
+ *
69
+ * @param {string} tableName
70
+ * @param {Schema} [schema]
71
+ * @param {Config} [config]
72
+ */
73
+ createTable(tableName: string, schema?: Schema, config?: Config): Promise<void>;
74
+ private replaceStringInFile;
75
+ private replaceStringInSchemas;
76
+ /**
77
+ * Update table schema or config
78
+ *
79
+ * @param {string} tableName
80
+ * @param {Schema} [schema]
81
+ * @param {(Config&{name?: string})} [config]
82
+ */
83
+ updateTable(tableName: string, schema?: Schema, config?: Config & {
84
+ name?: string;
85
+ }): Promise<void>;
86
+ /**
87
+ * Get table schema and config
88
+ *
89
+ * @param {string} tableName
90
+ * @return {*} {Promise<TableObject>}
91
+ */
92
+ getTable(tableName: string): Promise<TableObject>;
93
+ getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema | undefined>;
94
+ private throwErrorIfTableEmpty;
95
+ private validateData;
96
+ private formatField;
97
+ private checkUnique;
98
+ private formatData;
99
+ private getDefaultValue;
100
+ private _combineObjectsToArray;
101
+ private _CombineData;
102
+ private joinPathesContents;
103
+ private _getItemsFromSchemaHelper;
104
+ private getItemsFromSchema;
105
+ private applyCriteria;
106
+ private _filterSchemaByColumns;
107
+ /**
108
+ * Clear table cache
109
+ *
110
+ * @param {string} tableName
111
+ */
112
+ clearCache(tableName: string): Promise<void>;
113
+ /**
114
+ * Retrieve item(s) from a table
115
+ *
116
+ * @param {string} tableName
117
+ * @param {(string | number | (string | number)[] | Criteria)} [where]
118
+ * @param {Options} [options]
119
+ * @param {boolean} [onlyOne]
120
+ * @param {boolean} [onlyLinesNumbers]
121
+ * @return {*} {(Promise<Data | number | (Data | number)[] | null>)}
122
+ */
123
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers?: false): Promise<Data | null>;
124
+ get(tableName: string, where: string | number, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false): Promise<Data | null>;
125
+ get(tableName: string, where?: string | number | (string | number)[] | Criteria, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false): Promise<Data[] | null>;
126
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: false | undefined, onlyLinesNumbers: true): Promise<number[] | null>;
127
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers: true): Promise<number | null>;
128
+ /**
129
+ * Create new item(s) in a table
130
+ *
131
+ * @param {string} tableName
132
+ * @param {(Data | Data[])} data Can be array of objects or a single object
133
+ * @param {Options} [options] Pagination options, useful when the returnPostedData param is true
134
+ * @param {boolean} [returnPostedData] By default function returns void, if you want to get the posted data, set this param to true
135
+ * @return {*} {Promise<Data | Data[] | null | void>}
136
+ */
137
+ post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void>;
138
+ post(tableName: string, data: Data, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
139
+ post(tableName: string, data: Data[], options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
140
+ /**
141
+ * Update item(s) in a table
142
+ *
143
+ * @param {string} tableName
144
+ * @param {(Data | Data[])} data
145
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
146
+ * @param {Options} [options]
147
+ * @param {false} [returnUpdatedData]
148
+ * @return {*} {Promise<Data | Data[] | null | undefined | void>}
149
+ */
150
+ put(tableName: string, data: Data | Data[], where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: false): Promise<void>;
151
+ put(tableName: string, data: Data, where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data | null>;
152
+ put(tableName: string, data: Data[], where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data[] | null>;
153
+ /**
154
+ * Delete item(s) in a table
155
+ *
156
+ * @param {string} tableName
157
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
158
+ * @return {boolean | null} {(Promise<boolean | null>)}
159
+ */
160
+ delete(tableName: string, where?: number | string | (number | string)[] | Criteria, _id?: string | string[]): Promise<boolean | null>;
161
+ /**
162
+ * Generate sum of column(s) in a table
163
+ *
164
+ * @param {string} tableName
165
+ * @param {string} columns
166
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
167
+ * @return {*} {Promise<number | Record<string, number>>}
168
+ */
169
+ sum(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
170
+ sum(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
171
+ /**
172
+ * Generate max of column(s) in a table
173
+ *
174
+ * @param {string} tableName
175
+ * @param {string} columns
176
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
177
+ * @return {*} {Promise<number>}
178
+ */
179
+ max(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
180
+ max(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
181
+ /**
182
+ * Generate min of column(s) in a table
183
+ *
184
+ * @param {string} tableName
185
+ * @param {string} columns
186
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
187
+ * @return {*} {Promise<number>}
188
+ */
189
+ min(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
190
+ min(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
191
+ }
192
+ export {};