inibase 1.0.0-rc.12 → 1.0.0-rc.121

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,205 @@
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 | number | string;
16
+ children?: FieldType | FieldType[] | Schema;
17
+ regex?: string;
18
+ };
19
+ export type Schema = Field[];
20
+ export interface Options {
21
+ page?: number;
22
+ perPage?: number;
23
+ columns?: string[] | string;
24
+ sort?: Record<string, 1 | -1 | "asc" | "ASC" | "desc" | "DESC"> | string[] | string;
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
+ export 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
+ type Entries<T> = {
46
+ [K in keyof T]: [K, T[K]];
47
+ }[keyof T][];
48
+ declare global {
49
+ interface ObjectConstructor {
50
+ entries<T extends object>(o: T): Entries<T>;
51
+ }
52
+ }
53
+ export type ErrorCodes = "FIELD_UNIQUE" | "FIELD_REQUIRED" | "NO_SCHEMA" | "TABLE_EMPTY" | "INVALID_ID" | "INVALID_TYPE" | "INVALID_PARAMETERS" | "NO_ENV" | "TABLE_EXISTS" | "TABLE_NOT_EXISTS" | "INVALID_REGEX_MATCH";
54
+ export type ErrorLang = "en";
55
+ export default class Inibase {
56
+ pageInfo: Record<string, pageInfo>;
57
+ salt: Buffer;
58
+ private databasePath;
59
+ private fileExtension;
60
+ private tablesMap;
61
+ private uniqueMap;
62
+ private totalItems;
63
+ constructor(database: string, mainFolder?: string);
64
+ private static errorMessages;
65
+ createError(code: ErrorCodes, variable?: string | number | (string | number)[], language?: ErrorLang): Error;
66
+ clear(): void;
67
+ private getFileExtension;
68
+ private _schemaToIdsPath;
69
+ /**
70
+ * Create a new table inside database, with predefined schema and config
71
+ *
72
+ * @param {string} tableName
73
+ * @param {Schema} [schema]
74
+ * @param {Config} [config]
75
+ */
76
+ createTable(tableName: string, schema?: Schema, config?: Config): Promise<void>;
77
+ private replaceStringInFile;
78
+ /**
79
+ * Update table schema or config
80
+ *
81
+ * @param {string} tableName
82
+ * @param {Schema} [schema]
83
+ * @param {(Config&{name?: string})} [config]
84
+ */
85
+ updateTable(tableName: string, schema?: Schema, config?: Config & {
86
+ name?: string;
87
+ }): Promise<void>;
88
+ /**
89
+ * Get table schema and config
90
+ *
91
+ * @param {string} tableName
92
+ * @return {*} {Promise<TableObject>}
93
+ */
94
+ getTable(tableName: string, encodeIDs?: boolean): Promise<TableObject>;
95
+ getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema | undefined>;
96
+ private throwErrorIfTableEmpty;
97
+ private _validateData;
98
+ private validateData;
99
+ private cleanObject;
100
+ private formatField;
101
+ private checkUnique;
102
+ private _formatData;
103
+ private formatData;
104
+ private getDefaultValue;
105
+ private _combineObjectsToArray;
106
+ private _CombineData;
107
+ private joinPathesContents;
108
+ private _processSchemaDataHelper;
109
+ private processSchemaData;
110
+ private isSimpleField;
111
+ private processSimpleField;
112
+ private isArrayField;
113
+ private processArrayField;
114
+ private isObjectField;
115
+ private processObjectField;
116
+ private isTableField;
117
+ private processTableField;
118
+ private applyCriteria;
119
+ private _filterSchemaByColumns;
120
+ /**
121
+ * Clear table cache
122
+ *
123
+ * @param {string} tableName
124
+ */
125
+ clearCache(tableName: string): Promise<void>;
126
+ /**
127
+ * Retrieve item(s) from a table
128
+ *
129
+ * @param {string} tableName
130
+ * @param {(string | number | (string | number)[] | Criteria)} [where]
131
+ * @param {Options} [options]
132
+ * @param {boolean} [onlyOne]
133
+ * @param {boolean} [onlyLinesNumbers]
134
+ * @return {*} {(Promise<Data | number | (Data | number)[] | null>)}
135
+ */
136
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers?: false): Promise<Data | null>;
137
+ get(tableName: string, where: string | number, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false): Promise<Data | null>;
138
+ get(tableName: string, where?: string | number | (string | number)[] | Criteria, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false): Promise<Data[] | null>;
139
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: false | undefined, onlyLinesNumbers: true): Promise<number[] | null>;
140
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers: true): Promise<number | null>;
141
+ /**
142
+ * Create new item(s) in a table
143
+ *
144
+ * @param {string} tableName
145
+ * @param {(Data | Data[])} data Can be array of objects or a single object
146
+ * @param {Options} [options] Pagination options, useful when the returnPostedData param is true
147
+ * @param {boolean} [returnPostedData] By default function returns void, if you want to get the posted data, set this param to true
148
+ * @return {*} {Promise<Data | Data[] | null | void>}
149
+ */
150
+ post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void>;
151
+ post(tableName: string, data: Data, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
152
+ post(tableName: string, data: Data[], options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
153
+ /**
154
+ * Update item(s) in a table
155
+ *
156
+ * @param {string} tableName
157
+ * @param {(Data | Data[])} data
158
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
159
+ * @param {Options} [options]
160
+ * @param {false} [returnUpdatedData]
161
+ * @return {*} {Promise<Data | Data[] | null | undefined | void>}
162
+ */
163
+ put(tableName: string, data: Data | Data[], where?: number | string | (number | string)[] | Criteria, options?: Options, returnUpdatedData?: false): Promise<void>;
164
+ put(tableName: string, data: Data, where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data | null>;
165
+ put(tableName: string, data: Data[], where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data[] | null>;
166
+ /**
167
+ * Delete item(s) in a table
168
+ *
169
+ * @param {string} tableName
170
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
171
+ * @return {boolean | null} {(Promise<boolean | null>)}
172
+ */
173
+ delete(tableName: string, where?: number | string | (number | string)[] | Criteria, _id?: string | string[]): Promise<boolean | null>;
174
+ /**
175
+ * Generate sum of column(s) in a table
176
+ *
177
+ * @param {string} tableName
178
+ * @param {string} columns
179
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
180
+ * @return {*} {Promise<number | Record<string, number>>}
181
+ */
182
+ sum(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
183
+ sum(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
184
+ /**
185
+ * Generate max of column(s) in a table
186
+ *
187
+ * @param {string} tableName
188
+ * @param {string} columns
189
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
190
+ * @return {*} {Promise<number>}
191
+ */
192
+ max(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
193
+ max(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
194
+ /**
195
+ * Generate min of column(s) in a table
196
+ *
197
+ * @param {string} tableName
198
+ * @param {string} columns
199
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
200
+ * @return {*} {Promise<number>}
201
+ */
202
+ min(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
203
+ min(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
204
+ }
205
+ export {};