namirasoft-node 1.4.67 → 1.4.68

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.
@@ -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,175 +1,175 @@
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
- if (filter.operator.count > 0)
51
- for (let j = i + 1; j < filters.length; j++)
52
- {
53
- const f = filters[j];
54
- if (filter.table.name == f.table.name)
55
- if (filter.column.name == f.column.name)
56
- if (filter.not == f.not)
57
- if (filter.operator.sign == f.operator.sign)
58
- {
59
- processed[j] = true;
60
- values.push(...f.values);
61
- }
62
- }
63
-
64
- let getNumbers = () =>
65
- {
66
- let nums: number[] = values.map(x => parseFloat(x));
67
- if (nums.filter(x => isNaN(x)).length > 0)
68
- ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
69
- return nums;
70
- };
71
- let addCondition = async (res: BaseFilterItemBuilder_Condition<WhereOptions>) =>
72
- {
73
- let condition: WhereOptions = res.condition;
74
- if (is_table_main)
75
- ans.push(condition);
76
- else
77
- {
78
- let join = table_joins[filter.table.name];
79
- if (res.independant || join?.getExtraConditions)
80
- ans.push(await getCondition_IDInSelect(filter.table.name, res.independant?.not ?? false, [condition, ...(join?.getExtraConditions?.(filter.column.name) ?? [])]));
81
- else
82
- get_conditions_in_select_main(filter.table.name).push(condition);
83
- }
84
- };
85
- if (column_name === "*")
86
- {
87
- if (filter.operator !== FilterItemOperator.all.equals)
88
- ErrorOperation.throwHTTP(400, `Invalid operator for all columns (*).`);
89
- else
90
- {
91
- let columns = this.getAdvancedSearchColumns(filter.table.name);
92
- for (let i = 0; i < values.length; i++)
93
- {
94
- const value = values[i];
95
- let conditions = await this.getAdvancedSearchConditions(columns, value);
96
- ans.push(...conditions);
97
- }
98
- }
99
- }
100
- else if (filter.operator == FilterItemOperator.all.equals)
101
- await addCondition(this.getIn(column_name, filter.not, values));
102
- else if (filter.operator == FilterItemOperator.all.contains)
103
- for (const value of values)
104
- await addCondition(this.getLike(column_name, filter.not, value));
105
- else if (filter.operator == FilterItemOperator.all.regex)
106
- for (const value of values)
107
- await addCondition(this.getRegex(column_name, filter.not, value));
108
- else if (filter.operator == FilterItemOperator.all.empty)
109
- await addCondition(this.getEmpty(column_name, filter.not));
110
- else if (filter.operator == FilterItemOperator.all.exists)
111
- await addCondition(this.getExists(column_name, filter.not));
112
- else if (filter.operator == FilterItemOperator.all.includes)
113
- await addCondition(this.getIncludes(column_name, filter.not, values));
114
- else if (filter.operator == FilterItemOperator.all.startswith)
115
- for (const value of values)
116
- await addCondition(this.getStartsWith(column_name, filter.not, value));
117
- else if (filter.operator == FilterItemOperator.all.endswith)
118
- for (const value of values)
119
- await addCondition(this.getEndsWith(column_name, filter.not, value));
120
- else if (filter.operator == FilterItemOperator.all.lessthan)
121
- {
122
- if (filter.not)
123
- await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
124
- else
125
- await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
126
- }
127
- else if (filter.operator == FilterItemOperator.all.lessthanequal)
128
- {
129
- if (filter.not)
130
- await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
131
- else
132
- await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
133
- }
134
- else if (filter.operator == FilterItemOperator.all.morethan)
135
- {
136
- if (filter.not)
137
- await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
138
- else
139
- await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
140
- }
141
- else if (filter.operator == FilterItemOperator.all.morethanequal)
142
- {
143
- if (filter.not)
144
- await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
145
- else
146
- await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
147
- }
148
- }
149
- for (let table of Object.keys(conditions_in_select_main))
150
- {
151
- let conditions = conditions_in_select_main[table];
152
- if (conditions.length > 0)
153
- ans.push(await getCondition_IDInSelect(table, false, conditions));
154
- }
155
- }
156
- return ans;
157
- }
158
- public abstract checkColumn(table_name: string, column_name: string): void;
159
- public abstract getRealColumnName(table_name: string, column_name: string): string;
160
- public abstract getAdvancedSearchColumns(table_name: string): string[];
161
- public abstract getAdvancedSearchConditions(columns: string[], search: string): Promise<WhereOptions[]>;
162
- public abstract getIn(column_name: string, not: boolean, values: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
163
- public abstract getLike(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
164
- public abstract getRegex(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
165
- public abstract getEmpty(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
166
- public abstract getExists(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
167
- public abstract getIncludes(column_name: string, not: boolean, value: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
168
- public abstract getStartsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
169
- public abstract getEndsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
170
- public abstract getLT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
171
- public abstract getLTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
172
- public abstract getGT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
173
- public abstract getGTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
174
- 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
+ if (filter.operator.count > 0)
51
+ for (let j = i + 1; j < filters.length; j++)
52
+ {
53
+ const f = filters[j];
54
+ if (filter.table.name == f.table.name)
55
+ if (filter.column.name == f.column.name)
56
+ if (filter.not == f.not)
57
+ if (filter.operator.sign == f.operator.sign)
58
+ {
59
+ processed[j] = true;
60
+ values.push(...f.values);
61
+ }
62
+ }
63
+
64
+ let getNumbers = () =>
65
+ {
66
+ let nums: number[] = values.map(x => parseFloat(x));
67
+ if (nums.filter(x => isNaN(x)).length > 0)
68
+ ErrorOperation.throwHTTP(400, `Invalid number values for: '${values.join(",")}'`);
69
+ return nums;
70
+ };
71
+ let addCondition = async (res: BaseFilterItemBuilder_Condition<WhereOptions>) =>
72
+ {
73
+ let condition: WhereOptions = res.condition;
74
+ if (is_table_main)
75
+ ans.push(condition);
76
+ else
77
+ {
78
+ let join = table_joins[filter.table.name];
79
+ if (res.independant || join?.getExtraConditions)
80
+ ans.push(await getCondition_IDInSelect(filter.table.name, res.independant?.not ?? false, [condition, ...(join?.getExtraConditions?.(filter.column.name) ?? [])]));
81
+ else
82
+ get_conditions_in_select_main(filter.table.name).push(condition);
83
+ }
84
+ };
85
+ if (column_name === "*")
86
+ {
87
+ if (filter.operator !== FilterItemOperator.all.equals)
88
+ ErrorOperation.throwHTTP(400, `Invalid operator for all columns (*).`);
89
+ else
90
+ {
91
+ let columns = this.getAdvancedSearchColumns(filter.table.name);
92
+ for (let i = 0; i < values.length; i++)
93
+ {
94
+ const value = values[i];
95
+ let conditions = await this.getAdvancedSearchConditions(columns, value);
96
+ ans.push(...conditions);
97
+ }
98
+ }
99
+ }
100
+ else if (filter.operator == FilterItemOperator.all.equals)
101
+ await addCondition(this.getIn(column_name, filter.not, values));
102
+ else if (filter.operator == FilterItemOperator.all.contains)
103
+ for (const value of values)
104
+ await addCondition(this.getLike(column_name, filter.not, value));
105
+ else if (filter.operator == FilterItemOperator.all.regex)
106
+ for (const value of values)
107
+ await addCondition(this.getRegex(column_name, filter.not, value));
108
+ else if (filter.operator == FilterItemOperator.all.empty)
109
+ await addCondition(this.getEmpty(column_name, filter.not));
110
+ else if (filter.operator == FilterItemOperator.all.exists)
111
+ await addCondition(this.getExists(column_name, filter.not));
112
+ else if (filter.operator == FilterItemOperator.all.includes)
113
+ await addCondition(this.getIncludes(column_name, filter.not, values));
114
+ else if (filter.operator == FilterItemOperator.all.startswith)
115
+ for (const value of values)
116
+ await addCondition(this.getStartsWith(column_name, filter.not, value));
117
+ else if (filter.operator == FilterItemOperator.all.endswith)
118
+ for (const value of values)
119
+ await addCondition(this.getEndsWith(column_name, filter.not, value));
120
+ else if (filter.operator == FilterItemOperator.all.lessthan)
121
+ {
122
+ if (filter.not)
123
+ await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
124
+ else
125
+ await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
126
+ }
127
+ else if (filter.operator == FilterItemOperator.all.lessthanequal)
128
+ {
129
+ if (filter.not)
130
+ await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
131
+ else
132
+ await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
133
+ }
134
+ else if (filter.operator == FilterItemOperator.all.morethan)
135
+ {
136
+ if (filter.not)
137
+ await addCondition(this.getLTE(column_name, Math.max(...getNumbers())));
138
+ else
139
+ await addCondition(this.getGT(column_name, Math.max(...getNumbers())));
140
+ }
141
+ else if (filter.operator == FilterItemOperator.all.morethanequal)
142
+ {
143
+ if (filter.not)
144
+ await addCondition(this.getLT(column_name, Math.max(...getNumbers())));
145
+ else
146
+ await addCondition(this.getGTE(column_name, Math.max(...getNumbers())));
147
+ }
148
+ }
149
+ for (let table of Object.keys(conditions_in_select_main))
150
+ {
151
+ let conditions = conditions_in_select_main[table];
152
+ if (conditions.length > 0)
153
+ ans.push(await getCondition_IDInSelect(table, false, conditions));
154
+ }
155
+ }
156
+ return ans;
157
+ }
158
+ public abstract checkColumn(table_name: string, column_name: string): void;
159
+ public abstract getRealColumnName(table_name: string, column_name: string): string;
160
+ public abstract getAdvancedSearchColumns(table_name: string): string[];
161
+ public abstract getAdvancedSearchConditions(columns: string[], search: string): Promise<WhereOptions[]>;
162
+ public abstract getIn(column_name: string, not: boolean, values: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
163
+ public abstract getLike(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
164
+ public abstract getRegex(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
165
+ public abstract getEmpty(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
166
+ public abstract getExists(column_name: string, not: boolean): BaseFilterItemBuilder_Condition<WhereOptions>;
167
+ public abstract getIncludes(column_name: string, not: boolean, value: string[]): BaseFilterItemBuilder_Condition<WhereOptions>;
168
+ public abstract getStartsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
169
+ public abstract getEndsWith(column_name: string, not: boolean, value: string): BaseFilterItemBuilder_Condition<WhereOptions>;
170
+ public abstract getLT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
171
+ public abstract getLTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
172
+ public abstract getGT(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
173
+ public abstract getGTE(column_name: string, value: any): BaseFilterItemBuilder_Condition<WhereOptions>;
174
+ public abstract getInSelect(table_name: string, not: boolean, join: BaseFilterItemBuilder_JoinTable<WhereOptions>, conditions: WhereOptions[]): Promise<WhereOptions>;
175
175
  }
@@ -1,27 +1,27 @@
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
- }
22
- public override getAdvancedSearchColumns(table_name: string): string[]
23
- {
24
- let t = this.database.getTable(table_name) as BaseTable<BaseDatabase, any>;
25
- return t.getColumns(false, null, { searchable: true });
26
- }
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
+ }
22
+ public override getAdvancedSearchColumns(table_name: string): string[]
23
+ {
24
+ let t = this.database.getTable(table_name) as BaseTable<BaseDatabase, any>;
25
+ return t.getColumns(false, null, { searchable: true });
26
+ }
27
27
  }