inibase 1.0.0-rc.5 → 1.0.0-rc.51
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.
- package/README.md +160 -98
- package/dist/config.d.ts +3 -0
- package/dist/config.js +3 -0
- package/dist/file.d.ts +145 -0
- package/dist/file.js +595 -0
- package/dist/file.thread.d.ts +1 -0
- package/dist/file.thread.js +5 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +1220 -0
- package/dist/index.thread.d.ts +1 -0
- package/dist/index.thread.js +6 -0
- package/dist/utils.d.ts +184 -0
- package/dist/utils.js +411 -0
- package/dist/utils.server.d.ts +94 -0
- package/dist/utils.server.js +256 -0
- package/package.json +74 -18
- package/file.ts +0 -477
- package/index.test.ts +0 -248
- package/index.ts +0 -1541
- package/tsconfig.json +0 -7
- package/utils.ts +0 -165
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
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
|
+
order?: Record<string, "asc" | "desc">;
|
|
24
|
+
}
|
|
25
|
+
export type ComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "*" | "!*" | "[]" | "![]";
|
|
26
|
+
type pageInfo = {
|
|
27
|
+
total?: number;
|
|
28
|
+
totalPages?: number;
|
|
29
|
+
} & Options;
|
|
30
|
+
export type Criteria = ({
|
|
31
|
+
[logic in "and" | "or"]?: Criteria | (string | number | boolean | null)[];
|
|
32
|
+
} & {
|
|
33
|
+
[key: string]: string | number | boolean | undefined | Criteria;
|
|
34
|
+
}) | null;
|
|
35
|
+
declare global {
|
|
36
|
+
type Entries<T> = {
|
|
37
|
+
[K in keyof T]: [K, T[K]];
|
|
38
|
+
}[keyof T][];
|
|
39
|
+
interface ObjectConstructor {
|
|
40
|
+
entries<T extends object>(o: T): Entries<T>;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export type ErrorCodes = "FIELD_UNIQUE" | "FIELD_REQUIRED" | "NO_SCHEMA" | "NO_ITEMS" | "NO_RESULTS" | "INVALID_ID" | "INVALID_TYPE" | "INVALID_PARAMETERS";
|
|
44
|
+
export type ErrorLang = "en";
|
|
45
|
+
export default class Inibase {
|
|
46
|
+
folder: string;
|
|
47
|
+
database: string;
|
|
48
|
+
table: string | null;
|
|
49
|
+
pageInfo: Record<string, pageInfo>;
|
|
50
|
+
private checkIFunique;
|
|
51
|
+
private isThreadEnabled;
|
|
52
|
+
private totalItems;
|
|
53
|
+
salt: Buffer;
|
|
54
|
+
constructor(database: string, mainFolder?: string, _table?: string | null, _totalItems?: Record<string, number>, _pageInfo?: Record<string, pageInfo>, _isThreadEnabled?: boolean);
|
|
55
|
+
private throwError;
|
|
56
|
+
createWorker(functionName: "get" | "post" | "put" | "delete" | "sum" | "min" | "max" | "sort", arg: any[]): Promise<any>;
|
|
57
|
+
private _schemaToIdsPath;
|
|
58
|
+
setTableSchema(tableName: string, schema: Schema): Promise<void>;
|
|
59
|
+
getTableSchema(tableName: string, encodeIDs?: boolean): Promise<Schema | undefined>;
|
|
60
|
+
getSchemaWhenTableNotEmpty(tableName: string, schema?: Schema): Promise<never | Schema>;
|
|
61
|
+
private validateData;
|
|
62
|
+
private formatField;
|
|
63
|
+
private checkUnique;
|
|
64
|
+
private formatData;
|
|
65
|
+
private getDefaultValue;
|
|
66
|
+
private _combineObjectsToArray;
|
|
67
|
+
private _CombineData;
|
|
68
|
+
private _addPathToKeys;
|
|
69
|
+
joinPathesContents(mainPath: string, data: Data | Data[]): {
|
|
70
|
+
[key: string]: string[];
|
|
71
|
+
};
|
|
72
|
+
private _getItemsFromSchemaHelper;
|
|
73
|
+
private getItemsFromSchema;
|
|
74
|
+
private applyCriteria;
|
|
75
|
+
private _filterSchemaByColumns;
|
|
76
|
+
clearCache(tablePath: string): Promise<void>;
|
|
77
|
+
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: true, onlyLinesNumbers?: undefined, tableSchema?: Schema, skipIdColumn?: boolean): Promise<Data | null>;
|
|
78
|
+
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: boolean | undefined, onlyLinesNumbers?: true, tableSchema?: Schema, skipIdColumn?: boolean): Promise<number[]>;
|
|
79
|
+
post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void>;
|
|
80
|
+
post(tableName: string, data: Data, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
|
|
81
|
+
post(tableName: string, data: Data[], options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
|
|
82
|
+
put(tableName: string, data: Data | Data[], where?: number | string | (number | string)[] | Criteria, options?: Options, returnUpdatedData?: false): Promise<void>;
|
|
83
|
+
put(tableName: string, data: Data, where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data | null>;
|
|
84
|
+
put(tableName: string, data: Data[], where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnUpdatedData: true): Promise<Data[] | null>;
|
|
85
|
+
delete(tableName: string, where?: number | string, _id?: string | string[]): Promise<string | null>;
|
|
86
|
+
delete(tableName: string, where?: (number | string)[] | Criteria, _id?: string | string[]): Promise<string[] | null>;
|
|
87
|
+
sum(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
|
|
88
|
+
sum(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
|
|
89
|
+
max(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
|
|
90
|
+
max(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
|
|
91
|
+
min(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
|
|
92
|
+
min(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
|
|
93
|
+
sort(tableName: string, columns: string | string[] | Record<string, 1 | -1 | "asc" | "ASC" | "desc" | "DESC">, where?: string | number | (string | number)[] | Criteria, options?: Options): Promise<any[]>;
|
|
94
|
+
}
|
|
95
|
+
export {};
|