namirasoft-node 1.4.60 → 1.4.62
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/BaseFilterItemBuilder.d.ts +2 -0
- package/dist/BaseFilterItemBuilder.js +13 -1
- package/dist/BaseFilterItemBuilder.js.map +1 -1
- package/dist/BaseFilterItemBuilderDatabase.js +2 -1
- package/dist/BaseFilterItemBuilderDatabase.js.map +1 -1
- package/dist/BaseFilterItemBuilderObject.d.ts +2 -0
- package/dist/BaseFilterItemBuilderObject.js +10 -0
- package/dist/BaseFilterItemBuilderObject.js.map +1 -1
- package/dist/BaseTable.d.ts +1 -1
- package/dist/BaseTable.js +8 -2
- package/dist/BaseTable.js.map +1 -1
- package/package.json +43 -43
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +432 -432
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +205 -205
- package/src/BaseCron.ts +54 -54
- package/src/BaseDatabase.ts +45 -45
- package/src/BaseEmailService.ts +38 -38
- package/src/BaseFilterItemBuilder.ts +169 -152
- package/src/BaseFilterItemBuilderDatabase.ts +21 -20
- package/src/BaseFilterItemBuilderObject.ts +88 -78
- package/src/BaseTable.ts +132 -125
- package/src/CommandOperation.ts +32 -32
- package/src/EmptyDatabase.ts +11 -11
- package/src/GmailService.ts +22 -22
- package/src/IPOperation.ts +38 -38
- package/src/Meta.ts +41 -41
- package/src/OTPOperation.ts +84 -84
- package/src/RequestHeaderService.ts +27 -27
- package/src/SMTPService.ts +26 -26
- package/src/ServerToServerOperation.ts +23 -23
- package/src/index.ts +19 -19
package/src/BaseEmailService.ts
CHANGED
|
@@ -1,39 +1,39 @@
|
|
|
1
|
-
import nodemailer from 'nodemailer';
|
|
2
|
-
import Mail, { AttachmentLike } from "nodemailer/lib/mailer";
|
|
3
|
-
import { Readable } from "stream";
|
|
4
|
-
|
|
5
|
-
export abstract class BaseEmailService
|
|
6
|
-
{
|
|
7
|
-
username: string;
|
|
8
|
-
constructor(username: string)
|
|
9
|
-
{
|
|
10
|
-
this.username = username;
|
|
11
|
-
}
|
|
12
|
-
protected abstract getTransform(): any;
|
|
13
|
-
send(from: string | null, to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void)
|
|
14
|
-
{
|
|
15
|
-
let transform = this.getTransform();
|
|
16
|
-
let transporter = nodemailer.createTransport(transform);
|
|
17
|
-
|
|
18
|
-
let mailOptions: Mail.Options = {
|
|
19
|
-
from: from ?? this.username,
|
|
20
|
-
to,
|
|
21
|
-
subject,
|
|
22
|
-
text,
|
|
23
|
-
html
|
|
24
|
-
};
|
|
25
|
-
if (html)
|
|
26
|
-
mailOptions.html = html;
|
|
27
|
-
|
|
28
|
-
transporter.sendMail(mailOptions, function (error, info)
|
|
29
|
-
{
|
|
30
|
-
if (callback)
|
|
31
|
-
callback(error, info);
|
|
32
|
-
else
|
|
33
|
-
{
|
|
34
|
-
if (error)
|
|
35
|
-
console.log(error);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
1
|
+
import nodemailer from 'nodemailer';
|
|
2
|
+
import Mail, { AttachmentLike } from "nodemailer/lib/mailer";
|
|
3
|
+
import { Readable } from "stream";
|
|
4
|
+
|
|
5
|
+
export abstract class BaseEmailService
|
|
6
|
+
{
|
|
7
|
+
username: string;
|
|
8
|
+
constructor(username: string)
|
|
9
|
+
{
|
|
10
|
+
this.username = username;
|
|
11
|
+
}
|
|
12
|
+
protected abstract getTransform(): any;
|
|
13
|
+
send(from: string | null, to: string, subject: string, text: string, html?: string | Buffer | Readable | AttachmentLike | undefined, callback?: (err: Error | null, info: any) => void)
|
|
14
|
+
{
|
|
15
|
+
let transform = this.getTransform();
|
|
16
|
+
let transporter = nodemailer.createTransport(transform);
|
|
17
|
+
|
|
18
|
+
let mailOptions: Mail.Options = {
|
|
19
|
+
from: from ?? this.username,
|
|
20
|
+
to,
|
|
21
|
+
subject,
|
|
22
|
+
text,
|
|
23
|
+
html
|
|
24
|
+
};
|
|
25
|
+
if (html)
|
|
26
|
+
mailOptions.html = html;
|
|
27
|
+
|
|
28
|
+
transporter.sendMail(mailOptions, function (error, info)
|
|
29
|
+
{
|
|
30
|
+
if (callback)
|
|
31
|
+
callback(error, info);
|
|
32
|
+
else
|
|
33
|
+
{
|
|
34
|
+
if (error)
|
|
35
|
+
console.log(error);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
39
|
}
|
|
@@ -1,153 +1,170 @@
|
|
|
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
|
-
Object.keys(table_joins).forEach(table => { conditions_in_select_main[table] = []; });
|
|
28
|
-
let processed: { [index: number]: boolean } = {};
|
|
29
|
-
|
|
30
|
-
let getCondition_IDInSelect = async (table: string, not: boolean, conditions: WhereOptions[]): Promise<WhereOptions> =>
|
|
31
|
-
{
|
|
32
|
-
let join = table_joins[table];
|
|
33
|
-
return this.getInSelect(table, not, join, conditions);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
for (let i = 0; i < filters.length; i++)
|
|
37
|
-
if (!processed[i])
|
|
38
|
-
{
|
|
39
|
-
const filter = filters[i];
|
|
40
|
-
this.checkColumn(filter.table.name, filter.column.name);
|
|
41
|
-
let join = table_joins[filter.table.name];
|
|
42
|
-
let is_table_main = table_main.getName() === filter.table.name;
|
|
43
|
-
let column_name = this.getRealColumnName(filter.table.name, filter.column.name) ?? filter.column.name;
|
|
44
|
-
|
|
45
|
-
let values = filter.values;
|
|
46
|
-
if (filter.operator.count > 0)
|
|
47
|
-
for (let j = i + 1; j < filters.length; j++)
|
|
48
|
-
{
|
|
49
|
-
const f = filters[j];
|
|
50
|
-
if (filter.table.name == f.table.name)
|
|
51
|
-
if (filter.column.name == f.column.name)
|
|
52
|
-
if (filter.not == f.not)
|
|
53
|
-
if (filter.operator.sign == f.operator.sign)
|
|
54
|
-
{
|
|
55
|
-
processed[j] = true;
|
|
56
|
-
values.push(...f.values);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let getNumbers = () =>
|
|
61
|
-
{
|
|
62
|
-
let nums: number[] = values.map(x => parseFloat(x));
|
|
63
|
-
if (nums.filter(x => isNaN(x)).length > 0)
|
|
64
|
-
ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
|
|
65
|
-
return nums;
|
|
66
|
-
};
|
|
67
|
-
let addCondition = async (res: BaseFilterItemBuilder_Condition<WhereOptions>) =>
|
|
68
|
-
{
|
|
69
|
-
let condition: WhereOptions = res.condition;
|
|
70
|
-
if (is_table_main)
|
|
71
|
-
ans.push(condition);
|
|
72
|
-
else
|
|
73
|
-
{
|
|
74
|
-
if (res.independant || join.getExtraConditions)
|
|
75
|
-
ans.push(await getCondition_IDInSelect(filter.table.name, res.independant?.not ?? false, [condition, ...(join.getExtraConditions?.(filter.column.name) ?? [])]));
|
|
76
|
-
else
|
|
77
|
-
conditions_in_select_main[filter.table.name].push(condition);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
else if (filter.operator == FilterItemOperator.all.
|
|
98
|
-
for (const value of values)
|
|
99
|
-
await addCondition(this.
|
|
100
|
-
else if (filter.operator == FilterItemOperator.all.
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
else if (filter.operator == FilterItemOperator.all.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
+
Object.keys(table_joins).forEach(table => { conditions_in_select_main[table] = []; });
|
|
28
|
+
let processed: { [index: number]: boolean } = {};
|
|
29
|
+
|
|
30
|
+
let getCondition_IDInSelect = async (table: string, not: boolean, conditions: WhereOptions[]): Promise<WhereOptions> =>
|
|
31
|
+
{
|
|
32
|
+
let join = table_joins[table];
|
|
33
|
+
return this.getInSelect(table, not, join, conditions);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < filters.length; i++)
|
|
37
|
+
if (!processed[i])
|
|
38
|
+
{
|
|
39
|
+
const filter = filters[i];
|
|
40
|
+
this.checkColumn(filter.table.name, filter.column.name);
|
|
41
|
+
let join = table_joins[filter.table.name];
|
|
42
|
+
let is_table_main = table_main.getName() === filter.table.name;
|
|
43
|
+
let column_name = this.getRealColumnName(filter.table.name, filter.column.name) ?? filter.column.name;
|
|
44
|
+
|
|
45
|
+
let values = filter.values;
|
|
46
|
+
if (filter.operator.count > 0)
|
|
47
|
+
for (let j = i + 1; j < filters.length; j++)
|
|
48
|
+
{
|
|
49
|
+
const f = filters[j];
|
|
50
|
+
if (filter.table.name == f.table.name)
|
|
51
|
+
if (filter.column.name == f.column.name)
|
|
52
|
+
if (filter.not == f.not)
|
|
53
|
+
if (filter.operator.sign == f.operator.sign)
|
|
54
|
+
{
|
|
55
|
+
processed[j] = true;
|
|
56
|
+
values.push(...f.values);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
let getNumbers = () =>
|
|
61
|
+
{
|
|
62
|
+
let nums: number[] = values.map(x => parseFloat(x));
|
|
63
|
+
if (nums.filter(x => isNaN(x)).length > 0)
|
|
64
|
+
ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
|
|
65
|
+
return nums;
|
|
66
|
+
};
|
|
67
|
+
let addCondition = async (res: BaseFilterItemBuilder_Condition<WhereOptions>) =>
|
|
68
|
+
{
|
|
69
|
+
let condition: WhereOptions = res.condition;
|
|
70
|
+
if (is_table_main)
|
|
71
|
+
ans.push(condition);
|
|
72
|
+
else
|
|
73
|
+
{
|
|
74
|
+
if (res.independant || join.getExtraConditions)
|
|
75
|
+
ans.push(await getCondition_IDInSelect(filter.table.name, res.independant?.not ?? false, [condition, ...(join.getExtraConditions?.(filter.column.name) ?? [])]));
|
|
76
|
+
else
|
|
77
|
+
conditions_in_select_main[filter.table.name].push(condition);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
if (column_name === "*")
|
|
81
|
+
{
|
|
82
|
+
if (filter.operator !== FilterItemOperator.all.equals)
|
|
83
|
+
ErrorOperation.throwHTTP(400, `Invalid operator for all columns (*).`);
|
|
84
|
+
else
|
|
85
|
+
{
|
|
86
|
+
let columns = this.getAdvancedSearchColumns(filter.table.name);
|
|
87
|
+
for (let i = 0; i < values.length; i++)
|
|
88
|
+
{
|
|
89
|
+
const value = values[i];
|
|
90
|
+
let conditions = await this.getAdvancedSearchConditions(columns, value);
|
|
91
|
+
ans.push(...conditions);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (filter.operator == FilterItemOperator.all.equals)
|
|
96
|
+
await addCondition(this.getIn(column_name, filter.not, values));
|
|
97
|
+
else if (filter.operator == FilterItemOperator.all.contains)
|
|
98
|
+
for (const value of values)
|
|
99
|
+
await addCondition(this.getLike(column_name, filter.not, value));
|
|
100
|
+
else if (filter.operator == FilterItemOperator.all.regex)
|
|
101
|
+
for (const value of values)
|
|
102
|
+
await addCondition(this.getRegex(column_name, filter.not, value));
|
|
103
|
+
else if (filter.operator == FilterItemOperator.all.empty)
|
|
104
|
+
await addCondition(this.getEmpty(column_name, filter.not));
|
|
105
|
+
else if (filter.operator == FilterItemOperator.all.exists)
|
|
106
|
+
await addCondition(this.getExists(column_name, filter.not));
|
|
107
|
+
else if (filter.operator == FilterItemOperator.all.includes)
|
|
108
|
+
await addCondition(this.getIncludes(column_name, filter.not, values));
|
|
109
|
+
else if (filter.operator == FilterItemOperator.all.startswith)
|
|
110
|
+
for (const value of values)
|
|
111
|
+
await addCondition(this.getStartsWith(column_name, filter.not, value));
|
|
112
|
+
else if (filter.operator == FilterItemOperator.all.endswith)
|
|
113
|
+
for (const value of values)
|
|
114
|
+
await addCondition(this.getEndsWith(column_name, filter.not, value));
|
|
115
|
+
else if (filter.operator == FilterItemOperator.all.lessthan)
|
|
116
|
+
{
|
|
117
|
+
if (filter.not)
|
|
118
|
+
await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
|
|
119
|
+
else
|
|
120
|
+
await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
|
|
121
|
+
}
|
|
122
|
+
else if (filter.operator == FilterItemOperator.all.lessthanequal)
|
|
123
|
+
{
|
|
124
|
+
if (filter.not)
|
|
125
|
+
await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
|
|
126
|
+
else
|
|
127
|
+
await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
|
|
128
|
+
}
|
|
129
|
+
else if (filter.operator == FilterItemOperator.all.morethan)
|
|
130
|
+
{
|
|
131
|
+
if (filter.not)
|
|
132
|
+
await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
|
|
133
|
+
else
|
|
134
|
+
await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
|
|
135
|
+
}
|
|
136
|
+
else if (filter.operator == FilterItemOperator.all.morethanequal)
|
|
137
|
+
{
|
|
138
|
+
if (filter.not)
|
|
139
|
+
await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
|
|
140
|
+
else
|
|
141
|
+
await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
for (let table of Object.keys(conditions_in_select_main))
|
|
145
|
+
{
|
|
146
|
+
let conditions = conditions_in_select_main[table];
|
|
147
|
+
if (conditions.length > 0)
|
|
148
|
+
ans.push(await getCondition_IDInSelect(table, false, conditions));
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return ans;
|
|
152
|
+
}
|
|
153
|
+
public abstract checkColumn(table_name: string, column_name: string): void;
|
|
154
|
+
public abstract getRealColumnName(table_name: string, column_name: string): string;
|
|
155
|
+
public abstract getAdvancedSearchColumns(table_name: string): string[];
|
|
156
|
+
public abstract getAdvancedSearchConditions(columns: string[], search: string): Promise<WhereOptions[]>;
|
|
157
|
+
public abstract getIn(column_name: string, not: boolean, values: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
158
|
+
public abstract getLike(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
159
|
+
public abstract getRegex(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
160
|
+
public abstract getEmpty(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
161
|
+
public abstract getExists(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
162
|
+
public abstract getIncludes(column_name: string, not: boolean, value: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
163
|
+
public abstract getStartsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
164
|
+
public abstract getEndsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
165
|
+
public abstract getLT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
166
|
+
public abstract getLTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
167
|
+
public abstract getGT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
168
|
+
public abstract getGTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
|
|
169
|
+
public abstract getInSelect(table_name: string, not: boolean, join: BaseFilterItemBuilder_JoinTable<WhereOptions>, conditions: WhereOptions[]): Promise<WhereOptions>;
|
|
153
170
|
}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { BaseTable } from "./BaseTable";
|
|
2
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
-
import { BaseFilterItemBuilder } from "./BaseFilterItemBuilder";
|
|
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 checkColumn(table_name: string, column_name: string): void
|
|
12
|
-
{
|
|
13
|
-
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
import { BaseTable } from "./BaseTable";
|
|
2
|
+
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
+
import { BaseFilterItemBuilder } from "./BaseFilterItemBuilder";
|
|
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 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 getRealColumnName(table_name: string, column_name: string): string
|
|
18
|
+
{
|
|
19
|
+
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
20
|
+
return t.getRealColumnName(column_name);
|
|
21
|
+
}
|
|
21
22
|
}
|
|
@@ -1,79 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
{
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
override
|
|
22
|
-
{
|
|
23
|
-
let
|
|
24
|
-
return
|
|
25
|
-
}
|
|
26
|
-
override
|
|
27
|
-
{
|
|
28
|
-
let condition =
|
|
29
|
-
return { condition };
|
|
30
|
-
}
|
|
31
|
-
override
|
|
32
|
-
{
|
|
33
|
-
let condition = ((this.object[column_name] ?? "")
|
|
34
|
-
return { condition };
|
|
35
|
-
}
|
|
36
|
-
override
|
|
37
|
-
{
|
|
38
|
-
let condition = ((this.object[column_name]
|
|
39
|
-
return { condition };
|
|
40
|
-
}
|
|
41
|
-
override
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
override
|
|
56
|
-
{
|
|
57
|
-
let condition = (
|
|
58
|
-
return { condition };
|
|
59
|
-
}
|
|
60
|
-
override
|
|
61
|
-
{
|
|
62
|
-
let condition = (
|
|
63
|
-
return { condition };
|
|
64
|
-
}
|
|
65
|
-
override
|
|
66
|
-
{
|
|
67
|
-
let condition = (parseFloat(this.object[column_name] ?? "")
|
|
68
|
-
return { condition };
|
|
69
|
-
}
|
|
70
|
-
override
|
|
71
|
-
{
|
|
72
|
-
let condition = (parseFloat(this.object[column_name] ?? "")
|
|
73
|
-
return { condition };
|
|
74
|
-
}
|
|
75
|
-
override
|
|
76
|
-
{
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
import { SearchOperation } from "namirasoft-core";
|
|
2
|
+
import { BaseFilterItemBuilder } from "./BaseFilterItemBuilder";
|
|
3
|
+
|
|
4
|
+
export class BaseFilterItemBuilderObject extends BaseFilterItemBuilder<{ getName: () => string }, boolean>
|
|
5
|
+
{
|
|
6
|
+
constructor(public object: any)
|
|
7
|
+
{
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
public checkColumn(): void
|
|
11
|
+
{
|
|
12
|
+
}
|
|
13
|
+
public getRealColumnName(_: string, column_name: string): string
|
|
14
|
+
{
|
|
15
|
+
return column_name;
|
|
16
|
+
}
|
|
17
|
+
override getAdvancedSearchColumns(): string[]
|
|
18
|
+
{
|
|
19
|
+
return Object.keys(this.object);
|
|
20
|
+
}
|
|
21
|
+
override async getAdvancedSearchConditions(columns: string[], search: string): Promise<boolean[]>
|
|
22
|
+
{
|
|
23
|
+
let text = columns.map(c => this.object[c]).filter(v => v).join(" ");
|
|
24
|
+
return [SearchOperation.match(text, search)];
|
|
25
|
+
}
|
|
26
|
+
override getIn(column_name: string, not: boolean, values: string[])
|
|
27
|
+
{
|
|
28
|
+
let condition = values.includes(this.object[column_name] ?? null) !== not;
|
|
29
|
+
return { condition };
|
|
30
|
+
}
|
|
31
|
+
override getLike(column_name: string, not: boolean, value: string)
|
|
32
|
+
{
|
|
33
|
+
let condition = new RegExp(`.*${value}.*`).test(this.object[column_name] ?? "") !== not;
|
|
34
|
+
return { condition };
|
|
35
|
+
}
|
|
36
|
+
override getRegex(column_name: string, not: boolean, value: string)
|
|
37
|
+
{
|
|
38
|
+
let condition = new RegExp(value).test(this.object[column_name] ?? "") !== not;
|
|
39
|
+
return { condition };
|
|
40
|
+
}
|
|
41
|
+
override getEmpty(column_name: string, not: boolean)
|
|
42
|
+
{
|
|
43
|
+
let condition = ((this.object[column_name] ?? "") == "") !== not;
|
|
44
|
+
return { condition };
|
|
45
|
+
}
|
|
46
|
+
override getExists(column_name: string, not: boolean)
|
|
47
|
+
{
|
|
48
|
+
let condition = ((this.object[column_name]) != null) !== not;
|
|
49
|
+
return { condition };
|
|
50
|
+
}
|
|
51
|
+
override getIncludes(column_name: string, not: boolean, values: string[])
|
|
52
|
+
{
|
|
53
|
+
return this.getExists(column_name, not) && this.getIn(column_name, not, values);
|
|
54
|
+
}
|
|
55
|
+
override getStartsWith(column_name: string, not: boolean, value: string)
|
|
56
|
+
{
|
|
57
|
+
let condition = new RegExp(`${value}.*`).test(this.object[column_name] ?? "") !== not;
|
|
58
|
+
return { condition };
|
|
59
|
+
}
|
|
60
|
+
override getEndsWith(column_name: string, not: boolean, value: string)
|
|
61
|
+
{
|
|
62
|
+
let condition = new RegExp(`.*${value}`).test(this.object[column_name] ?? "") !== not;
|
|
63
|
+
return { condition };
|
|
64
|
+
}
|
|
65
|
+
override getLT(column_name: string, value: any)
|
|
66
|
+
{
|
|
67
|
+
let condition = (parseFloat(this.object[column_name] ?? "") < parseFloat(value));
|
|
68
|
+
return { condition };
|
|
69
|
+
}
|
|
70
|
+
override getLTE(column_name: string, value: any)
|
|
71
|
+
{
|
|
72
|
+
let condition = (parseFloat(this.object[column_name] ?? "") <= parseFloat(value));
|
|
73
|
+
return { condition };
|
|
74
|
+
}
|
|
75
|
+
override getGT(column_name: string, value: any)
|
|
76
|
+
{
|
|
77
|
+
let condition = (parseFloat(this.object[column_name] ?? "") > parseFloat(value));
|
|
78
|
+
return { condition };
|
|
79
|
+
}
|
|
80
|
+
override getGTE(column_name: string, value: any)
|
|
81
|
+
{
|
|
82
|
+
let condition = (parseFloat(this.object[column_name] ?? "") >= parseFloat(value));
|
|
83
|
+
return { condition };
|
|
84
|
+
}
|
|
85
|
+
override async getInSelect(): Promise<boolean>
|
|
86
|
+
{
|
|
87
|
+
throw new Error('Not implemented');
|
|
88
|
+
}
|
|
79
89
|
}
|