inibase 1.0.0-rc.11 → 1.0.0-rc.110

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,200 @@
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" | "TABLE_EMPTY" | "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 Error;
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
+ /**
76
+ * Update table schema or config
77
+ *
78
+ * @param {string} tableName
79
+ * @param {Schema} [schema]
80
+ * @param {(Config&{name?: string})} [config]
81
+ */
82
+ updateTable(tableName: string, schema?: Schema, config?: Config & {
83
+ name?: string;
84
+ }): Promise<void>;
85
+ /**
86
+ * Get table schema and config
87
+ *
88
+ * @param {string} tableName
89
+ * @return {*} {Promise<TableObject>}
90
+ */
91
+ getTable(tableName: string): Promise<TableObject>;
92
+ getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema | undefined>;
93
+ private throwErrorIfTableEmpty;
94
+ private validateData;
95
+ private cleanObject;
96
+ private formatField;
97
+ private checkUnique;
98
+ private formatData;
99
+ private getDefaultValue;
100
+ private _combineObjectsToArray;
101
+ private _CombineData;
102
+ private joinPathesContents;
103
+ private _processSchemaDataHelper;
104
+ private processSchemaData;
105
+ private isSimpleField;
106
+ private processSimpleField;
107
+ private isArrayField;
108
+ private processArrayField;
109
+ private isObjectField;
110
+ private processObjectField;
111
+ private isTableField;
112
+ private processTableField;
113
+ private applyCriteria;
114
+ private _filterSchemaByColumns;
115
+ /**
116
+ * Clear table cache
117
+ *
118
+ * @param {string} tableName
119
+ */
120
+ clearCache(tableName: string): Promise<void>;
121
+ /**
122
+ * Retrieve item(s) from a table
123
+ *
124
+ * @param {string} tableName
125
+ * @param {(string | number | (string | number)[] | Criteria)} [where]
126
+ * @param {Options} [options]
127
+ * @param {boolean} [onlyOne]
128
+ * @param {boolean} [onlyLinesNumbers]
129
+ * @return {*} {(Promise<Data | number | (Data | number)[] | null>)}
130
+ */
131
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers?: false): Promise<Data | null>;
132
+ get(tableName: string, where: string | number, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false): Promise<Data | null>;
133
+ get(tableName: string, where?: string | number | (string | number)[] | Criteria, options?: Options, onlyOne?: boolean, onlyLinesNumbers?: false): Promise<Data[] | null>;
134
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: false | undefined, onlyLinesNumbers: true): Promise<number[] | null>;
135
+ get(tableName: string, where: string | number | (string | number)[] | Criteria | undefined, options: Options | undefined, onlyOne: true, onlyLinesNumbers: true): Promise<number | null>;
136
+ /**
137
+ * Create new item(s) in a table
138
+ *
139
+ * @param {string} tableName
140
+ * @param {(Data | Data[])} data Can be array of objects or a single object
141
+ * @param {Options} [options] Pagination options, useful when the returnPostedData param is true
142
+ * @param {boolean} [returnPostedData] By default function returns void, if you want to get the posted data, set this param to true
143
+ * @return {*} {Promise<Data | Data[] | null | void>}
144
+ */
145
+ post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void>;
146
+ post(tableName: string, data: Data, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
147
+ post(tableName: string, data: Data[], options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
148
+ /**
149
+ * Update item(s) in a table
150
+ *
151
+ * @param {string} tableName
152
+ * @param {(Data | Data[])} data
153
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
154
+ * @param {Options} [options]
155
+ * @param {false} [returnUpdatedData]
156
+ * @return {*} {Promise<Data | Data[] | null | undefined | void>}
157
+ */
158
+ put(tableName: string, data: Data | Data[], where?: number | string | (number | string)[] | Criteria, options?: Options, returnUpdatedData?: false): Promise<void>;
159
+ put(tableName: string, data: Data, where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data | null>;
160
+ put(tableName: string, data: Data[], where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data[] | null>;
161
+ /**
162
+ * Delete item(s) in a table
163
+ *
164
+ * @param {string} tableName
165
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
166
+ * @return {boolean | null} {(Promise<boolean | null>)}
167
+ */
168
+ delete(tableName: string, where?: number | string | (number | string)[] | Criteria, _id?: string | string[]): Promise<boolean | null>;
169
+ /**
170
+ * Generate sum of column(s) in a table
171
+ *
172
+ * @param {string} tableName
173
+ * @param {string} columns
174
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
175
+ * @return {*} {Promise<number | Record<string, number>>}
176
+ */
177
+ sum(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
178
+ sum(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
179
+ /**
180
+ * Generate max of column(s) in a table
181
+ *
182
+ * @param {string} tableName
183
+ * @param {string} columns
184
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
185
+ * @return {*} {Promise<number>}
186
+ */
187
+ max(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
188
+ max(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
189
+ /**
190
+ * Generate min of column(s) in a table
191
+ *
192
+ * @param {string} tableName
193
+ * @param {string} columns
194
+ * @param {(number | string | (number | string)[] | Criteria)} [where]
195
+ * @return {*} {Promise<number>}
196
+ */
197
+ min(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
198
+ min(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
199
+ }
200
+ export {};