inibase 1.0.0-rc.10 → 1.0.0-rc.100

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