namirasoft-node 1.4.131 → 1.4.133
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/dist/BaseApplication.d.ts +16 -12
- package/dist/BaseApplication.js +121 -81
- package/dist/BaseApplication.js.map +1 -1
- package/dist/BaseTable.d.ts +2 -2
- package/dist/BaseTable.js +2 -2
- package/dist/BaseTable.js.map +1 -1
- package/dist/BaseWorker.d.ts +20 -0
- package/dist/BaseWorker.js +18 -0
- package/dist/BaseWorker.js.map +1 -0
- package/package.json +43 -43
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +587 -530
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +226 -226
- package/src/BaseCron.ts +114 -114
- package/src/BaseDatabase.ts +52 -52
- package/src/BaseEmailService.ts +38 -38
- package/src/BaseFilterItemBuilder.ts +191 -191
- package/src/BaseFilterItemBuilderDatabase.ts +32 -32
- package/src/BaseFilterItemBuilderObject.ts +95 -95
- package/src/BaseTable.ts +150 -150
- package/src/BaseTableColumnOptions.ts +8 -8
- package/src/BaseWorker.ts +35 -0
- package/src/CommandOperation.ts +32 -32
- package/src/EncryptionOperation.ts +40 -40
- package/src/GmailService.ts +22 -22
- package/src/IDatabase.ts +12 -12
- package/src/IPOperation.ts +38 -38
- package/src/Meta.ts +36 -36
- package/src/OTPOperation.ts +94 -94
- package/src/RequestHeaderService.ts +27 -27
- package/src/SMTPService.ts +26 -26
- package/src/ServerToServerOperation.ts +23 -23
- package/src/Timer.ts +17 -17
- package/src/Validator.ts +15 -15
- package/src/index.ts +23 -23
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
import { ErrorOperation, FilterItem, FilterItemOperator } from "namirasoft-core";
|
|
2
|
-
|
|
3
|
-
export interface BaseFilterItemBuilder_JoinTable<WhereOptions>
|
|
4
|
-
{
|
|
5
|
-
main: {
|
|
6
|
-
column: string;
|
|
7
|
-
};
|
|
8
|
-
secondary: {
|
|
9
|
-
column: string;
|
|
10
|
-
};
|
|
11
|
-
getExtraConditions?: (column: string) => WhereOptions[];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export type BaseFilterItemBuilder_Condition<WhereOptions> = {
|
|
15
|
-
condition: WhereOptions;
|
|
16
|
-
independant?: { not: boolean };
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export abstract class BaseFilterItemBuilder<Table extends { getName: () => string; }, WhereOptions>
|
|
20
|
-
{
|
|
21
|
-
public async build(table_main: Table, table_joins: { [table: string]: BaseFilterItemBuilder_JoinTable<WhereOptions> }, filters?: FilterItem[] | undefined): Promise<WhereOptions[]>
|
|
22
|
-
{
|
|
23
|
-
let ans: WhereOptions[] = [];
|
|
24
|
-
if (filters)
|
|
25
|
-
{
|
|
26
|
-
let conditions_in_select_main: { [table: string]: WhereOptions[] } = {};
|
|
27
|
-
function get_conditions_in_select_main(name: string)
|
|
28
|
-
{
|
|
29
|
-
if (!conditions_in_select_main[name])
|
|
30
|
-
conditions_in_select_main[name] = [];
|
|
31
|
-
return conditions_in_select_main[name];
|
|
32
|
-
}
|
|
33
|
-
let processed: { [index: number]: boolean } = {};
|
|
34
|
-
|
|
35
|
-
let getCondition_IDInSelect = async (table: string, not: boolean, conditions: WhereOptions[]): Promise<WhereOptions> =>
|
|
36
|
-
{
|
|
37
|
-
let join = table_joins[table];
|
|
38
|
-
return this.getInSelect(table, not, join, conditions);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
for (let i = 0; i < filters.length; i++)
|
|
42
|
-
if (!processed[i])
|
|
43
|
-
{
|
|
44
|
-
const filter = filters[i];
|
|
45
|
-
this.checkColumn(filter.table.name, filter.column.name);
|
|
46
|
-
let is_table_main = table_main.getName() === filter.table.name;
|
|
47
|
-
let column_name = this.getRealColumnName(filter.table.name, filter.column.name) ?? filter.column.name;
|
|
48
|
-
|
|
49
|
-
let values = filter.values;
|
|
50
|
-
|
|
51
|
-
if ([
|
|
52
|
-
FilterItemOperator.all.equals.sign,
|
|
53
|
-
FilterItemOperator.all.lessthan.sign,
|
|
54
|
-
FilterItemOperator.all.lessthanequal.sign,
|
|
55
|
-
FilterItemOperator.all.morethan.sign,
|
|
56
|
-
FilterItemOperator.all.morethanequal.sign
|
|
57
|
-
].includes(filter.operator.sign))
|
|
58
|
-
for (let v = 0; v < values.length; v++)
|
|
59
|
-
this.checkValue(filter.table.name, filter.column.name, values[i]);
|
|
60
|
-
|
|
61
|
-
if (filter.operator.count > 0)
|
|
62
|
-
for (let j = i + 1; j < filters.length; j++)
|
|
63
|
-
{
|
|
64
|
-
const f = filters[j];
|
|
65
|
-
if (filter.table.name == f.table.name)
|
|
66
|
-
if (filter.column.name == f.column.name)
|
|
67
|
-
if (filter.not == f.not)
|
|
68
|
-
if (filter.operator.sign == f.operator.sign)
|
|
69
|
-
{
|
|
70
|
-
processed[j] = true;
|
|
71
|
-
values.push(...f.values);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
let escapedValues = values.map(v => this.escapeValue(v));
|
|
76
|
-
let getNumbers = () =>
|
|
77
|
-
{
|
|
78
|
-
let nums: number[] = values.map(x => parseFloat(x));
|
|
79
|
-
if (nums.filter(x => isNaN(x)).length > 0)
|
|
80
|
-
ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
|
|
81
|
-
return nums;
|
|
82
|
-
};
|
|
83
|
-
let addCondition = async (res: BaseFilterItemBuilder_Condition<WhereOptions>) =>
|
|
84
|
-
{
|
|
85
|
-
let condition: WhereOptions = res.condition;
|
|
86
|
-
if (is_table_main)
|
|
87
|
-
ans.push(condition);
|
|
88
|
-
else
|
|
89
|
-
{
|
|
90
|
-
let join = table_joins[filter.table.name];
|
|
91
|
-
if (res.independant || join?.getExtraConditions)
|
|
92
|
-
ans.push(await getCondition_IDInSelect(filter.table.name, res.independant?.not ?? false, [condition, ...(join?.getExtraConditions?.(filter.column.name) ?? [])]));
|
|
93
|
-
else
|
|
94
|
-
get_conditions_in_select_main(filter.table.name).push(condition);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
if (column_name === "*")
|
|
98
|
-
{
|
|
99
|
-
if (filter.operator !== FilterItemOperator.all.equals)
|
|
100
|
-
ErrorOperation.throwHTTP(400, `Invalid operator for all columns (*).`);
|
|
101
|
-
else
|
|
102
|
-
{
|
|
103
|
-
let columns = this.getAdvancedSearchColumns(filter.table.name);
|
|
104
|
-
for (let i = 0; i < escapedValues.length; i++)
|
|
105
|
-
{
|
|
106
|
-
const value = escapedValues[i];
|
|
107
|
-
let conditions = await this.getAdvancedSearchConditions(columns, value);
|
|
108
|
-
ans.push(...conditions);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else if (filter.operator == FilterItemOperator.all.equals)
|
|
113
|
-
await addCondition(this.getIn(column_name, filter.not, escapedValues));
|
|
114
|
-
else if (filter.operator == FilterItemOperator.all.contains)
|
|
115
|
-
for (const value of escapedValues)
|
|
116
|
-
await addCondition(this.getLike(column_name, filter.not, value));
|
|
117
|
-
else if (filter.operator == FilterItemOperator.all.regex)
|
|
118
|
-
for (const value of escapedValues)
|
|
119
|
-
await addCondition(this.getRegex(column_name, filter.not, value));
|
|
120
|
-
else if (filter.operator == FilterItemOperator.all.empty)
|
|
121
|
-
await addCondition(this.getEmpty(column_name, filter.not));
|
|
122
|
-
else if (filter.operator == FilterItemOperator.all.exists)
|
|
123
|
-
await addCondition(this.getExists(column_name, filter.not));
|
|
124
|
-
else if (filter.operator == FilterItemOperator.all.includes)
|
|
125
|
-
await addCondition(this.getIncludes(column_name, filter.not, escapedValues));
|
|
126
|
-
else if (filter.operator == FilterItemOperator.all.startswith)
|
|
127
|
-
for (const value of escapedValues)
|
|
128
|
-
await addCondition(this.getStartsWith(column_name, filter.not, value));
|
|
129
|
-
else if (filter.operator == FilterItemOperator.all.endswith)
|
|
130
|
-
for (const value of escapedValues)
|
|
131
|
-
await addCondition(this.getEndsWith(column_name, filter.not, value));
|
|
132
|
-
else if (filter.operator == FilterItemOperator.all.lessthan)
|
|
133
|
-
{
|
|
134
|
-
if (filter.not)
|
|
135
|
-
await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
|
|
136
|
-
else
|
|
137
|
-
await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
|
|
138
|
-
}
|
|
139
|
-
else if (filter.operator == FilterItemOperator.all.lessthanequal)
|
|
140
|
-
{
|
|
141
|
-
if (filter.not)
|
|
142
|
-
await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
|
|
143
|
-
else
|
|
144
|
-
await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
|
|
145
|
-
}
|
|
146
|
-
else if (filter.operator == FilterItemOperator.all.morethan)
|
|
147
|
-
{
|
|
148
|
-
if (filter.not)
|
|
149
|
-
await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
|
|
150
|
-
else
|
|
151
|
-
await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
|
|
152
|
-
}
|
|
153
|
-
else if (filter.operator == FilterItemOperator.all.morethanequal)
|
|
154
|
-
{
|
|
155
|
-
if (filter.not)
|
|
156
|
-
await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
|
|
157
|
-
else
|
|
158
|
-
await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
for (let table of Object.keys(conditions_in_select_main))
|
|
162
|
-
{
|
|
163
|
-
let conditions = conditions_in_select_main[table];
|
|
164
|
-
if (conditions.length > 0)
|
|
165
|
-
ans.push(await getCondition_IDInSelect(table, false, conditions));
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return ans;
|
|
169
|
-
}
|
|
170
|
-
public abstract checkColumn(table_name: string, column_name: string): void;
|
|
171
|
-
public abstract checkValue(table_name: string, column_name: string, value: string): void;
|
|
172
|
-
public abstract escapeValue(value: string): string;
|
|
173
|
-
public abstract getRealColumnName(table_name: string, column_name: string): string;
|
|
174
|
-
public abstract getAdvancedSearchColumns(table_name: string): string[];
|
|
175
|
-
public abstract getAdvancedSearchConditions(columns: string[], search: string): Promise<WhereOptions[]>;
|
|
176
|
-
public abstract getIn(column_name: string, not: boolean, values: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
177
|
-
public abstract getLike(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
178
|
-
public abstract getRegex(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
179
|
-
// Empty means the column exists but the value is undefined, null or ''
|
|
180
|
-
public abstract getEmpty(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
181
|
-
// Exist means the column does not exist or the value is undefined, null or ''
|
|
182
|
-
public abstract getExists(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
183
|
-
// Include is only used when there is a join and it means the column has one of the value
|
|
184
|
-
public abstract getIncludes(column_name: string, not: boolean, values: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
185
|
-
public abstract getStartsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
186
|
-
public abstract getEndsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
187
|
-
public abstract getLT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
188
|
-
public abstract getLTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
189
|
-
public abstract getGT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
190
|
-
public abstract getGTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
191
|
-
public abstract getInSelect(table_name: string, not: boolean, join: BaseFilterItemBuilder_JoinTable<WhereOptions>, conditions: WhereOptions[]): Promise<WhereOptions>;
|
|
1
|
+
import { ErrorOperation, FilterItem, FilterItemOperator } from "namirasoft-core";
|
|
2
|
+
|
|
3
|
+
export interface BaseFilterItemBuilder_JoinTable<WhereOptions>
|
|
4
|
+
{
|
|
5
|
+
main: {
|
|
6
|
+
column: string;
|
|
7
|
+
};
|
|
8
|
+
secondary: {
|
|
9
|
+
column: string;
|
|
10
|
+
};
|
|
11
|
+
getExtraConditions?: (column: string) => WhereOptions[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type BaseFilterItemBuilder_Condition<WhereOptions> = {
|
|
15
|
+
condition: WhereOptions;
|
|
16
|
+
independant?: { not: boolean };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export abstract class BaseFilterItemBuilder<Table extends { getName: () => string; }, WhereOptions>
|
|
20
|
+
{
|
|
21
|
+
public async build(table_main: Table, table_joins: { [table: string]: BaseFilterItemBuilder_JoinTable<WhereOptions> }, filters?: FilterItem[] | undefined): Promise<WhereOptions[]>
|
|
22
|
+
{
|
|
23
|
+
let ans: WhereOptions[] = [];
|
|
24
|
+
if (filters)
|
|
25
|
+
{
|
|
26
|
+
let conditions_in_select_main: { [table: string]: WhereOptions[] } = {};
|
|
27
|
+
function get_conditions_in_select_main(name: string)
|
|
28
|
+
{
|
|
29
|
+
if (!conditions_in_select_main[name])
|
|
30
|
+
conditions_in_select_main[name] = [];
|
|
31
|
+
return conditions_in_select_main[name];
|
|
32
|
+
}
|
|
33
|
+
let processed: { [index: number]: boolean } = {};
|
|
34
|
+
|
|
35
|
+
let getCondition_IDInSelect = async (table: string, not: boolean, conditions: WhereOptions[]): Promise<WhereOptions> =>
|
|
36
|
+
{
|
|
37
|
+
let join = table_joins[table];
|
|
38
|
+
return this.getInSelect(table, not, join, conditions);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
for (let i = 0; i < filters.length; i++)
|
|
42
|
+
if (!processed[i])
|
|
43
|
+
{
|
|
44
|
+
const filter = filters[i];
|
|
45
|
+
this.checkColumn(filter.table.name, filter.column.name);
|
|
46
|
+
let is_table_main = table_main.getName() === filter.table.name;
|
|
47
|
+
let column_name = this.getRealColumnName(filter.table.name, filter.column.name) ?? filter.column.name;
|
|
48
|
+
|
|
49
|
+
let values = filter.values;
|
|
50
|
+
|
|
51
|
+
if ([
|
|
52
|
+
FilterItemOperator.all.equals.sign,
|
|
53
|
+
FilterItemOperator.all.lessthan.sign,
|
|
54
|
+
FilterItemOperator.all.lessthanequal.sign,
|
|
55
|
+
FilterItemOperator.all.morethan.sign,
|
|
56
|
+
FilterItemOperator.all.morethanequal.sign
|
|
57
|
+
].includes(filter.operator.sign))
|
|
58
|
+
for (let v = 0; v < values.length; v++)
|
|
59
|
+
this.checkValue(filter.table.name, filter.column.name, values[i]);
|
|
60
|
+
|
|
61
|
+
if (filter.operator.count > 0)
|
|
62
|
+
for (let j = i + 1; j < filters.length; j++)
|
|
63
|
+
{
|
|
64
|
+
const f = filters[j];
|
|
65
|
+
if (filter.table.name == f.table.name)
|
|
66
|
+
if (filter.column.name == f.column.name)
|
|
67
|
+
if (filter.not == f.not)
|
|
68
|
+
if (filter.operator.sign == f.operator.sign)
|
|
69
|
+
{
|
|
70
|
+
processed[j] = true;
|
|
71
|
+
values.push(...f.values);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
let escapedValues = values.map(v => this.escapeValue(v));
|
|
76
|
+
let getNumbers = () =>
|
|
77
|
+
{
|
|
78
|
+
let nums: number[] = values.map(x => parseFloat(x));
|
|
79
|
+
if (nums.filter(x => isNaN(x)).length > 0)
|
|
80
|
+
ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
|
|
81
|
+
return nums;
|
|
82
|
+
};
|
|
83
|
+
let addCondition = async (res: BaseFilterItemBuilder_Condition<WhereOptions>) =>
|
|
84
|
+
{
|
|
85
|
+
let condition: WhereOptions = res.condition;
|
|
86
|
+
if (is_table_main)
|
|
87
|
+
ans.push(condition);
|
|
88
|
+
else
|
|
89
|
+
{
|
|
90
|
+
let join = table_joins[filter.table.name];
|
|
91
|
+
if (res.independant || join?.getExtraConditions)
|
|
92
|
+
ans.push(await getCondition_IDInSelect(filter.table.name, res.independant?.not ?? false, [condition, ...(join?.getExtraConditions?.(filter.column.name) ?? [])]));
|
|
93
|
+
else
|
|
94
|
+
get_conditions_in_select_main(filter.table.name).push(condition);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
if (column_name === "*")
|
|
98
|
+
{
|
|
99
|
+
if (filter.operator !== FilterItemOperator.all.equals)
|
|
100
|
+
ErrorOperation.throwHTTP(400, `Invalid operator for all columns (*).`);
|
|
101
|
+
else
|
|
102
|
+
{
|
|
103
|
+
let columns = this.getAdvancedSearchColumns(filter.table.name);
|
|
104
|
+
for (let i = 0; i < escapedValues.length; i++)
|
|
105
|
+
{
|
|
106
|
+
const value = escapedValues[i];
|
|
107
|
+
let conditions = await this.getAdvancedSearchConditions(columns, value);
|
|
108
|
+
ans.push(...conditions);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (filter.operator == FilterItemOperator.all.equals)
|
|
113
|
+
await addCondition(this.getIn(column_name, filter.not, escapedValues));
|
|
114
|
+
else if (filter.operator == FilterItemOperator.all.contains)
|
|
115
|
+
for (const value of escapedValues)
|
|
116
|
+
await addCondition(this.getLike(column_name, filter.not, value));
|
|
117
|
+
else if (filter.operator == FilterItemOperator.all.regex)
|
|
118
|
+
for (const value of escapedValues)
|
|
119
|
+
await addCondition(this.getRegex(column_name, filter.not, value));
|
|
120
|
+
else if (filter.operator == FilterItemOperator.all.empty)
|
|
121
|
+
await addCondition(this.getEmpty(column_name, filter.not));
|
|
122
|
+
else if (filter.operator == FilterItemOperator.all.exists)
|
|
123
|
+
await addCondition(this.getExists(column_name, filter.not));
|
|
124
|
+
else if (filter.operator == FilterItemOperator.all.includes)
|
|
125
|
+
await addCondition(this.getIncludes(column_name, filter.not, escapedValues));
|
|
126
|
+
else if (filter.operator == FilterItemOperator.all.startswith)
|
|
127
|
+
for (const value of escapedValues)
|
|
128
|
+
await addCondition(this.getStartsWith(column_name, filter.not, value));
|
|
129
|
+
else if (filter.operator == FilterItemOperator.all.endswith)
|
|
130
|
+
for (const value of escapedValues)
|
|
131
|
+
await addCondition(this.getEndsWith(column_name, filter.not, value));
|
|
132
|
+
else if (filter.operator == FilterItemOperator.all.lessthan)
|
|
133
|
+
{
|
|
134
|
+
if (filter.not)
|
|
135
|
+
await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
|
|
136
|
+
else
|
|
137
|
+
await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
|
|
138
|
+
}
|
|
139
|
+
else if (filter.operator == FilterItemOperator.all.lessthanequal)
|
|
140
|
+
{
|
|
141
|
+
if (filter.not)
|
|
142
|
+
await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
|
|
143
|
+
else
|
|
144
|
+
await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
|
|
145
|
+
}
|
|
146
|
+
else if (filter.operator == FilterItemOperator.all.morethan)
|
|
147
|
+
{
|
|
148
|
+
if (filter.not)
|
|
149
|
+
await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
|
|
150
|
+
else
|
|
151
|
+
await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
|
|
152
|
+
}
|
|
153
|
+
else if (filter.operator == FilterItemOperator.all.morethanequal)
|
|
154
|
+
{
|
|
155
|
+
if (filter.not)
|
|
156
|
+
await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
|
|
157
|
+
else
|
|
158
|
+
await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
for (let table of Object.keys(conditions_in_select_main))
|
|
162
|
+
{
|
|
163
|
+
let conditions = conditions_in_select_main[table];
|
|
164
|
+
if (conditions.length > 0)
|
|
165
|
+
ans.push(await getCondition_IDInSelect(table, false, conditions));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return ans;
|
|
169
|
+
}
|
|
170
|
+
public abstract checkColumn(table_name: string, column_name: string): void;
|
|
171
|
+
public abstract checkValue(table_name: string, column_name: string, value: string): void;
|
|
172
|
+
public abstract escapeValue(value: string): string;
|
|
173
|
+
public abstract getRealColumnName(table_name: string, column_name: string): string;
|
|
174
|
+
public abstract getAdvancedSearchColumns(table_name: string): string[];
|
|
175
|
+
public abstract getAdvancedSearchConditions(columns: string[], search: string): Promise<WhereOptions[]>;
|
|
176
|
+
public abstract getIn(column_name: string, not: boolean, values: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
177
|
+
public abstract getLike(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
178
|
+
public abstract getRegex(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
179
|
+
// Empty means the column exists but the value is undefined, null or ''
|
|
180
|
+
public abstract getEmpty(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
181
|
+
// Exist means the column does not exist or the value is undefined, null or ''
|
|
182
|
+
public abstract getExists(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
183
|
+
// Include is only used when there is a join and it means the column has one of the value
|
|
184
|
+
public abstract getIncludes(column_name: string, not: boolean, values: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
185
|
+
public abstract getStartsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
186
|
+
public abstract getEndsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
187
|
+
public abstract getLT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
188
|
+
public abstract getLTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
189
|
+
public abstract getGT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
190
|
+
public abstract getGTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
191
|
+
public abstract getInSelect(table_name: string, not: boolean, join: BaseFilterItemBuilder_JoinTable<WhereOptions>, conditions: WhereOptions[]): Promise<WhereOptions>;
|
|
192
192
|
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
2
|
-
import { BaseFilterItemBuilder } from "./BaseFilterItemBuilder";
|
|
3
|
-
import { BaseTable } from "./BaseTable";
|
|
4
|
-
|
|
5
|
-
export abstract class BaseFilterItemBuilderDatabase<WhereOptions> extends BaseFilterItemBuilder<BaseTable<BaseDatabase, any>, WhereOptions>
|
|
6
|
-
{
|
|
7
|
-
constructor(public database: BaseDatabase)
|
|
8
|
-
{
|
|
9
|
-
super();
|
|
10
|
-
}
|
|
11
|
-
public override checkColumn(table_name: string, column_name: string): void
|
|
12
|
-
{
|
|
13
|
-
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
14
|
-
if (column_name != "*")
|
|
15
|
-
t.checkColumn(column_name, false, null);
|
|
16
|
-
}
|
|
17
|
-
public checkValue(table_name: string, column_name: string, value: string)
|
|
18
|
-
{
|
|
19
|
-
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
20
|
-
if (column_name != "*")
|
|
21
|
-
t.checkValue(column_name, value);
|
|
22
|
-
}
|
|
23
|
-
public override getRealColumnName(table_name: string, column_name: string): string
|
|
24
|
-
{
|
|
25
|
-
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
26
|
-
return t.getRealColumnName(column_name);
|
|
27
|
-
}
|
|
28
|
-
public override getAdvancedSearchColumns(table_name: string): string[]
|
|
29
|
-
{
|
|
30
|
-
let t = this.database.getTable(table_name) as BaseTable<BaseDatabase, any>;
|
|
31
|
-
return t.getColumns(false, null, { searchable: true });
|
|
32
|
-
}
|
|
1
|
+
import { BaseDatabase } from "./BaseDatabase";
|
|
2
|
+
import { BaseFilterItemBuilder } from "./BaseFilterItemBuilder";
|
|
3
|
+
import { BaseTable } from "./BaseTable";
|
|
4
|
+
|
|
5
|
+
export abstract class BaseFilterItemBuilderDatabase<WhereOptions> extends BaseFilterItemBuilder<BaseTable<BaseDatabase, any>, WhereOptions>
|
|
6
|
+
{
|
|
7
|
+
constructor(public database: BaseDatabase)
|
|
8
|
+
{
|
|
9
|
+
super();
|
|
10
|
+
}
|
|
11
|
+
public override checkColumn(table_name: string, column_name: string): void
|
|
12
|
+
{
|
|
13
|
+
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
14
|
+
if (column_name != "*")
|
|
15
|
+
t.checkColumn(column_name, false, null);
|
|
16
|
+
}
|
|
17
|
+
public checkValue(table_name: string, column_name: string, value: string)
|
|
18
|
+
{
|
|
19
|
+
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
20
|
+
if (column_name != "*")
|
|
21
|
+
t.checkValue(column_name, value);
|
|
22
|
+
}
|
|
23
|
+
public override getRealColumnName(table_name: string, column_name: string): string
|
|
24
|
+
{
|
|
25
|
+
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
26
|
+
return t.getRealColumnName(column_name);
|
|
27
|
+
}
|
|
28
|
+
public override getAdvancedSearchColumns(table_name: string): string[]
|
|
29
|
+
{
|
|
30
|
+
let t = this.database.getTable(table_name) as BaseTable<BaseDatabase, any>;
|
|
31
|
+
return t.getColumns(false, null, { searchable: true });
|
|
32
|
+
}
|
|
33
33
|
}
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { SearchOperation } from "namirasoft-core";
|
|
2
|
-
import { BaseFilterItemBuilder, BaseFilterItemBuilder_JoinTable } from "./BaseFilterItemBuilder";
|
|
3
|
-
|
|
4
|
-
export class BaseFilterItemBuilderObject extends BaseFilterItemBuilder<{ getName: () => string }, boolean>
|
|
5
|
-
{
|
|
6
|
-
constructor(public object: any)
|
|
7
|
-
{
|
|
8
|
-
super();
|
|
9
|
-
}
|
|
10
|
-
public override checkColumn(): void
|
|
11
|
-
{
|
|
12
|
-
}
|
|
13
|
-
public override checkValue(): void
|
|
14
|
-
{
|
|
15
|
-
}
|
|
16
|
-
public override escapeValue(value: string)
|
|
17
|
-
{
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
20
|
-
public getRealColumnName(_: string, column_name: string): string
|
|
21
|
-
{
|
|
22
|
-
return column_name;
|
|
23
|
-
}
|
|
24
|
-
override getAdvancedSearchColumns(): string[]
|
|
25
|
-
{
|
|
26
|
-
return Object.keys(this.object);
|
|
27
|
-
}
|
|
28
|
-
override async getAdvancedSearchConditions(columns: string[], search: string): Promise<boolean[]>
|
|
29
|
-
{
|
|
30
|
-
let text = columns.map(c => this.object[c]).filter(v => v).join(" ");
|
|
31
|
-
return [SearchOperation.match(text, search)];
|
|
32
|
-
}
|
|
33
|
-
override getIn(column_name: string, not: boolean, values: string[])
|
|
34
|
-
{
|
|
35
|
-
let condition = values.includes(this.object[column_name] ?? null) !== not;
|
|
36
|
-
return { condition };
|
|
37
|
-
}
|
|
38
|
-
override getLike(column_name: string, not: boolean, value: string)
|
|
39
|
-
{
|
|
40
|
-
let condition = new RegExp(`.*${value}.*`).test(this.object[column_name] ?? "") !== not;
|
|
41
|
-
return { condition };
|
|
42
|
-
}
|
|
43
|
-
override getRegex(column_name: string, not: boolean, value: string)
|
|
44
|
-
{
|
|
45
|
-
let condition = new RegExp(value).test(this.object[column_name] ?? "") !== not;
|
|
46
|
-
return { condition };
|
|
47
|
-
}
|
|
48
|
-
override getEmpty(column_name: string, not: boolean)
|
|
49
|
-
{
|
|
50
|
-
let condition = ((this.object[column_name] ?? "") == "") !== not;
|
|
51
|
-
return { condition };
|
|
52
|
-
}
|
|
53
|
-
override getExists(column_name: string, not: boolean)
|
|
54
|
-
{
|
|
55
|
-
let condition = ((this.object[column_name]) != null) !== not;
|
|
56
|
-
return { condition };
|
|
57
|
-
}
|
|
58
|
-
override getIncludes(column_name: string, not: boolean, values: string[])
|
|
59
|
-
{
|
|
60
|
-
return this.getExists(column_name, not) && this.getIn(column_name, not, values);
|
|
61
|
-
}
|
|
62
|
-
override getStartsWith(column_name: string, not: boolean, value: string)
|
|
63
|
-
{
|
|
64
|
-
let condition = new RegExp(`${value}.*`).test(this.object[column_name] ?? "") !== not;
|
|
65
|
-
return { condition };
|
|
66
|
-
}
|
|
67
|
-
override getEndsWith(column_name: string, not: boolean, value: string)
|
|
68
|
-
{
|
|
69
|
-
let condition = new RegExp(`.*${value}`).test(this.object[column_name] ?? "") !== not;
|
|
70
|
-
return { condition };
|
|
71
|
-
}
|
|
72
|
-
override getLT(column_name: string, value: any)
|
|
73
|
-
{
|
|
74
|
-
let condition = (parseFloat(this.object[column_name] ?? "") < parseFloat(value));
|
|
75
|
-
return { condition };
|
|
76
|
-
}
|
|
77
|
-
override getLTE(column_name: string, value: any)
|
|
78
|
-
{
|
|
79
|
-
let condition = (parseFloat(this.object[column_name] ?? "") <= parseFloat(value));
|
|
80
|
-
return { condition };
|
|
81
|
-
}
|
|
82
|
-
override getGT(column_name: string, value: any)
|
|
83
|
-
{
|
|
84
|
-
let condition = (parseFloat(this.object[column_name] ?? "") > parseFloat(value));
|
|
85
|
-
return { condition };
|
|
86
|
-
}
|
|
87
|
-
override getGTE(column_name: string, value: any)
|
|
88
|
-
{
|
|
89
|
-
let condition = (parseFloat(this.object[column_name] ?? "") >= parseFloat(value));
|
|
90
|
-
return { condition };
|
|
91
|
-
}
|
|
92
|
-
override async getInSelect(_: string, not: boolean, __: BaseFilterItemBuilder_JoinTable<boolean>, conditions: boolean[]): Promise<boolean>
|
|
93
|
-
{
|
|
94
|
-
return conditions.some(c => !c) === not;
|
|
95
|
-
}
|
|
1
|
+
import { SearchOperation } from "namirasoft-core";
|
|
2
|
+
import { BaseFilterItemBuilder, BaseFilterItemBuilder_JoinTable } from "./BaseFilterItemBuilder";
|
|
3
|
+
|
|
4
|
+
export class BaseFilterItemBuilderObject extends BaseFilterItemBuilder<{ getName: () => string }, boolean>
|
|
5
|
+
{
|
|
6
|
+
constructor(public object: any)
|
|
7
|
+
{
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
public override checkColumn(): void
|
|
11
|
+
{
|
|
12
|
+
}
|
|
13
|
+
public override checkValue(): void
|
|
14
|
+
{
|
|
15
|
+
}
|
|
16
|
+
public override escapeValue(value: string)
|
|
17
|
+
{
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
public getRealColumnName(_: string, column_name: string): string
|
|
21
|
+
{
|
|
22
|
+
return column_name;
|
|
23
|
+
}
|
|
24
|
+
override getAdvancedSearchColumns(): string[]
|
|
25
|
+
{
|
|
26
|
+
return Object.keys(this.object);
|
|
27
|
+
}
|
|
28
|
+
override async getAdvancedSearchConditions(columns: string[], search: string): Promise<boolean[]>
|
|
29
|
+
{
|
|
30
|
+
let text = columns.map(c => this.object[c]).filter(v => v).join(" ");
|
|
31
|
+
return [SearchOperation.match(text, search)];
|
|
32
|
+
}
|
|
33
|
+
override getIn(column_name: string, not: boolean, values: string[])
|
|
34
|
+
{
|
|
35
|
+
let condition = values.includes(this.object[column_name] ?? null) !== not;
|
|
36
|
+
return { condition };
|
|
37
|
+
}
|
|
38
|
+
override getLike(column_name: string, not: boolean, value: string)
|
|
39
|
+
{
|
|
40
|
+
let condition = new RegExp(`.*${value}.*`).test(this.object[column_name] ?? "") !== not;
|
|
41
|
+
return { condition };
|
|
42
|
+
}
|
|
43
|
+
override getRegex(column_name: string, not: boolean, value: string)
|
|
44
|
+
{
|
|
45
|
+
let condition = new RegExp(value).test(this.object[column_name] ?? "") !== not;
|
|
46
|
+
return { condition };
|
|
47
|
+
}
|
|
48
|
+
override getEmpty(column_name: string, not: boolean)
|
|
49
|
+
{
|
|
50
|
+
let condition = ((this.object[column_name] ?? "") == "") !== not;
|
|
51
|
+
return { condition };
|
|
52
|
+
}
|
|
53
|
+
override getExists(column_name: string, not: boolean)
|
|
54
|
+
{
|
|
55
|
+
let condition = ((this.object[column_name]) != null) !== not;
|
|
56
|
+
return { condition };
|
|
57
|
+
}
|
|
58
|
+
override getIncludes(column_name: string, not: boolean, values: string[])
|
|
59
|
+
{
|
|
60
|
+
return this.getExists(column_name, not) && this.getIn(column_name, not, values);
|
|
61
|
+
}
|
|
62
|
+
override getStartsWith(column_name: string, not: boolean, value: string)
|
|
63
|
+
{
|
|
64
|
+
let condition = new RegExp(`${value}.*`).test(this.object[column_name] ?? "") !== not;
|
|
65
|
+
return { condition };
|
|
66
|
+
}
|
|
67
|
+
override getEndsWith(column_name: string, not: boolean, value: string)
|
|
68
|
+
{
|
|
69
|
+
let condition = new RegExp(`.*${value}`).test(this.object[column_name] ?? "") !== not;
|
|
70
|
+
return { condition };
|
|
71
|
+
}
|
|
72
|
+
override getLT(column_name: string, value: any)
|
|
73
|
+
{
|
|
74
|
+
let condition = (parseFloat(this.object[column_name] ?? "") < parseFloat(value));
|
|
75
|
+
return { condition };
|
|
76
|
+
}
|
|
77
|
+
override getLTE(column_name: string, value: any)
|
|
78
|
+
{
|
|
79
|
+
let condition = (parseFloat(this.object[column_name] ?? "") <= parseFloat(value));
|
|
80
|
+
return { condition };
|
|
81
|
+
}
|
|
82
|
+
override getGT(column_name: string, value: any)
|
|
83
|
+
{
|
|
84
|
+
let condition = (parseFloat(this.object[column_name] ?? "") > parseFloat(value));
|
|
85
|
+
return { condition };
|
|
86
|
+
}
|
|
87
|
+
override getGTE(column_name: string, value: any)
|
|
88
|
+
{
|
|
89
|
+
let condition = (parseFloat(this.object[column_name] ?? "") >= parseFloat(value));
|
|
90
|
+
return { condition };
|
|
91
|
+
}
|
|
92
|
+
override async getInSelect(_: string, not: boolean, __: BaseFilterItemBuilder_JoinTable<boolean>, conditions: boolean[]): Promise<boolean>
|
|
93
|
+
{
|
|
94
|
+
return conditions.some(c => !c) === not;
|
|
95
|
+
}
|
|
96
96
|
}
|