inibase 1.0.0-rc.12 → 1.0.0-rc.120

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