inibase 1.0.0-rc.4 → 1.0.0-rc.42
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 +161 -91
- package/dist/config.d.ts +5 -0
- package/dist/config.js +5 -0
- package/dist/file.d.ts +176 -0
- package/dist/file.js +625 -0
- package/dist/file.thread.d.ts +1 -0
- package/dist/file.thread.js +5 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +1178 -0
- package/dist/index.thread.d.ts +1 -0
- package/dist/index.thread.js +6 -0
- package/dist/utils.d.ts +206 -0
- package/dist/utils.js +418 -0
- package/dist/utils.server.d.ts +107 -0
- package/dist/utils.server.js +254 -0
- package/package.json +75 -18
- package/file.ts +0 -327
- package/index.ts +0 -1280
- package/tsconfig.json +0 -6
- package/utils.ts +0 -110
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
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
|
+
type FieldDefault = {
|
|
10
|
+
id?: string | number;
|
|
11
|
+
key: string;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type FieldStringType = {
|
|
15
|
+
type: Exclude<FieldType, "array" | "object">;
|
|
16
|
+
children?: never;
|
|
17
|
+
};
|
|
18
|
+
type FieldStringArrayType = {
|
|
19
|
+
type: Array<Exclude<FieldType, "object">>;
|
|
20
|
+
children?: never;
|
|
21
|
+
};
|
|
22
|
+
type FieldArrayType = {
|
|
23
|
+
type: "array";
|
|
24
|
+
children: Exclude<FieldType, "array"> | Array<Exclude<FieldType, "array">> | Schema;
|
|
25
|
+
};
|
|
26
|
+
type FieldArrayArrayType = {
|
|
27
|
+
type: Array<"array" | Exclude<FieldType, "array" | "object">>;
|
|
28
|
+
children: Exclude<FieldType, "array" | "object"> | Array<Exclude<FieldType, "array" | "object">>;
|
|
29
|
+
};
|
|
30
|
+
type FieldObjectType = {
|
|
31
|
+
type: "object";
|
|
32
|
+
children: Schema;
|
|
33
|
+
};
|
|
34
|
+
export type Field = FieldDefault & (FieldStringType | FieldStringArrayType | FieldArrayArrayType | FieldObjectType | FieldArrayType);
|
|
35
|
+
export type Schema = Field[];
|
|
36
|
+
export interface Options {
|
|
37
|
+
page?: number;
|
|
38
|
+
perPage?: number;
|
|
39
|
+
columns?: string[] | string;
|
|
40
|
+
order?: Record<string, "asc" | "desc">;
|
|
41
|
+
}
|
|
42
|
+
export type ComparisonOperator = "=" | "!=" | ">" | "<" | ">=" | "<=" | "*" | "!*" | "[]" | "![]";
|
|
43
|
+
type pageInfo = {
|
|
44
|
+
total?: number;
|
|
45
|
+
totalPages?: number;
|
|
46
|
+
} & Options;
|
|
47
|
+
export type Criteria = ({
|
|
48
|
+
[logic in "and" | "or"]?: Criteria | (string | number | boolean | null)[];
|
|
49
|
+
} & {
|
|
50
|
+
[key: string]: string | number | boolean | undefined | Criteria;
|
|
51
|
+
}) | null;
|
|
52
|
+
declare global {
|
|
53
|
+
type Entries<T> = {
|
|
54
|
+
[K in keyof T]: [K, T[K]];
|
|
55
|
+
}[keyof T][];
|
|
56
|
+
interface ObjectConstructor {
|
|
57
|
+
entries<T extends object>(o: T): Entries<T>;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export type ErrorCodes = "FIELD_REQUIRED" | "NO_SCHEMA" | "NO_ITEMS" | "NO_RESULTS" | "INVALID_ID" | "INVALID_TYPE" | "INVALID_PARAMETERS";
|
|
61
|
+
export type ErrorLang = "en";
|
|
62
|
+
export default class Inibase {
|
|
63
|
+
folder: string;
|
|
64
|
+
database: string;
|
|
65
|
+
table: string | null;
|
|
66
|
+
pageInfo: Record<string, pageInfo>;
|
|
67
|
+
private isThreadEnabled;
|
|
68
|
+
private totalItems;
|
|
69
|
+
salt: Buffer;
|
|
70
|
+
constructor(database: string, mainFolder?: string, _table?: string | null, _totalItems?: Record<string, number>, _pageInfo?: Record<string, pageInfo>, _isThreadEnabled?: boolean);
|
|
71
|
+
private throwError;
|
|
72
|
+
createWorker(functionName: "get" | "post" | "put" | "delete" | "sum" | "min" | "max" | "sort", arg: any[]): Promise<any>;
|
|
73
|
+
private _decodeIdFromSchema;
|
|
74
|
+
private _schemaToIdsPath;
|
|
75
|
+
setTableSchema(tableName: string, schema: Schema): Promise<void>;
|
|
76
|
+
getTableSchema(tableName: string): Promise<Schema | undefined>;
|
|
77
|
+
isTableEmpty(tableName: string): Promise<never | Schema>;
|
|
78
|
+
getField(keyPath: string, schema: Schema): Field | null;
|
|
79
|
+
private validateData;
|
|
80
|
+
private formatField;
|
|
81
|
+
private formatData;
|
|
82
|
+
private getDefaultValue;
|
|
83
|
+
private _combineObjectsToArray;
|
|
84
|
+
private _CombineData;
|
|
85
|
+
private _addPathToKeys;
|
|
86
|
+
joinPathesContents(mainPath: string, data: Data | Data[]): {
|
|
87
|
+
[key: string]: string[];
|
|
88
|
+
};
|
|
89
|
+
private getItemsFromSchema;
|
|
90
|
+
private applyCriteria;
|
|
91
|
+
private _filterSchemaByColumns;
|
|
92
|
+
clearCache(tablePath: string): Promise<void>;
|
|
93
|
+
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: true, onlyLinesNumbers?: undefined, tableSchema?: Schema, skipIdColumn?: boolean): Promise<Data | null>;
|
|
94
|
+
get(tableName: string, where?: string | number | (string | number)[] | Criteria | undefined, options?: Options | undefined, onlyOne?: boolean | undefined, onlyLinesNumbers?: true, tableSchema?: Schema, skipIdColumn?: boolean): Promise<number[]>;
|
|
95
|
+
post(tableName: string, data: Data | Data[], options?: Options, returnPostedData?: boolean): Promise<void | null>;
|
|
96
|
+
post(tableName: string, data: Data, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
|
|
97
|
+
post(tableName: string, data: Data[], options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
|
|
98
|
+
put(tableName: string, data: Data | Data[], where?: number | string | (number | string)[] | Criteria, options?: Options, returnPostedData?: false): Promise<void | null>;
|
|
99
|
+
put(tableName: string, data: Data, where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnPostedData: true): Promise<Data | null>;
|
|
100
|
+
put(tableName: string, data: Data[], where: number | string | (number | string)[] | Criteria | undefined, options: Options | undefined, returnPostedData: true): Promise<Data[] | null>;
|
|
101
|
+
delete(tableName: string, where?: number | string, _id?: string | string[]): Promise<string | null>;
|
|
102
|
+
delete(tableName: string, where?: (number | string)[] | Criteria, _id?: string | string[]): Promise<string[] | null>;
|
|
103
|
+
sum(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
|
|
104
|
+
sum(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
|
|
105
|
+
max(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
|
|
106
|
+
max(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
|
|
107
|
+
min(tableName: string, columns: string, where?: number | string | (number | string)[] | Criteria): Promise<number>;
|
|
108
|
+
min(tableName: string, columns: string[], where?: number | string | (number | string)[] | Criteria): Promise<Record<string, number>>;
|
|
109
|
+
sort(tableName: string, columns: string | string[] | Record<string, 1 | -1 | "asc" | "ASC" | "desc" | "DESC">, where?: string | number | (string | number)[] | Criteria, options?: Options): Promise<any[]>;
|
|
110
|
+
}
|
|
111
|
+
export {};
|