namirasoft-node 1.4.101 → 1.4.103
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 +1 -0
- package/dist/BaseFilterItemBuilder.js +9 -8
- package/dist/BaseFilterItemBuilder.js.map +1 -1
- package/dist/BaseFilterItemBuilderObject.d.ts +1 -0
- package/dist/BaseFilterItemBuilderObject.js +3 -0
- package/dist/BaseFilterItemBuilderObject.js.map +1 -1
- package/dist/OTPOperation.js +3 -3
- package/dist/OTPOperation.js.map +1 -1
- package/package.json +43 -43
- package/src/AnomalyDetector.ts +84 -84
- package/src/BaseApplication.ts +440 -440
- package/src/BaseApplicationLink.ts +6 -6
- package/src/BaseController.ts +225 -225
- package/src/BaseCron.ts +104 -104
- package/src/BaseDatabase.ts +45 -45
- package/src/BaseEmailService.ts +38 -38
- package/src/BaseFilterItemBuilder.ts +191 -189
- package/src/BaseFilterItemBuilderDatabase.ts +45 -45
- package/src/BaseFilterItemBuilderObject.ts +95 -91
- package/src/BaseTable.ts +137 -137
- package/src/BaseTableColumnOptions.ts +8 -8
- package/src/CommandOperation.ts +32 -32
- package/src/GmailService.ts +22 -22
- 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 +21 -21
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
import { BaseTable } from "./BaseTable";
|
|
2
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
-
import { BaseFilterItemBuilder } from "./BaseFilterItemBuilder";
|
|
4
|
-
import { ErrorOperation, TimeOperation } from "namirasoft-core";
|
|
5
|
-
import { VariableType } from "namirasoft-schema";
|
|
6
|
-
|
|
7
|
-
export abstract class BaseFilterItemBuilderDatabase<WhereOptions> extends BaseFilterItemBuilder<BaseTable<BaseDatabase, any>, WhereOptions>
|
|
8
|
-
{
|
|
9
|
-
constructor(public database: BaseDatabase)
|
|
10
|
-
{
|
|
11
|
-
super();
|
|
12
|
-
}
|
|
13
|
-
public override checkColumn(table_name: string, column_name: string): void
|
|
14
|
-
{
|
|
15
|
-
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
16
|
-
if (column_name != "*")
|
|
17
|
-
t.checkColumn(column_name, false, null);
|
|
18
|
-
}
|
|
19
|
-
public checkValue(table_name: string, column_name: string, value: string)
|
|
20
|
-
{
|
|
21
|
-
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
22
|
-
if (column_name != "*")
|
|
23
|
-
{
|
|
24
|
-
let c = t.getColumn(column_name);
|
|
25
|
-
if (c.type.toLowerCase() === VariableType.Date.toLowerCase())
|
|
26
|
-
if (!TimeOperation.isValidDate(value))
|
|
27
|
-
throw ErrorOperation.getHTTP(400, `Invalid value for Date: ${value}`);
|
|
28
|
-
if (c.type.toLowerCase() === VariableType.DateTime.toLowerCase())
|
|
29
|
-
if (!TimeOperation.isValidDateTime(value))
|
|
30
|
-
throw ErrorOperation.getHTTP(400, `Invalid value for DateTime: ${value}`);
|
|
31
|
-
if (c.type.toLowerCase() === VariableType.Time.toLowerCase())
|
|
32
|
-
if (!TimeOperation.isValidTime(value))
|
|
33
|
-
throw ErrorOperation.getHTTP(400, `Invalid value for Time: ${value}`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
public override getRealColumnName(table_name: string, column_name: string): string
|
|
37
|
-
{
|
|
38
|
-
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
39
|
-
return t.getRealColumnName(column_name);
|
|
40
|
-
}
|
|
41
|
-
public override getAdvancedSearchColumns(table_name: string): string[]
|
|
42
|
-
{
|
|
43
|
-
let t = this.database.getTable(table_name) as BaseTable<BaseDatabase, any>;
|
|
44
|
-
return t.getColumns(false, null, { searchable: true });
|
|
45
|
-
}
|
|
1
|
+
import { BaseTable } from "./BaseTable";
|
|
2
|
+
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
+
import { BaseFilterItemBuilder } from "./BaseFilterItemBuilder";
|
|
4
|
+
import { ErrorOperation, TimeOperation } from "namirasoft-core";
|
|
5
|
+
import { VariableType } from "namirasoft-schema";
|
|
6
|
+
|
|
7
|
+
export abstract class BaseFilterItemBuilderDatabase<WhereOptions> extends BaseFilterItemBuilder<BaseTable<BaseDatabase, any>, WhereOptions>
|
|
8
|
+
{
|
|
9
|
+
constructor(public database: BaseDatabase)
|
|
10
|
+
{
|
|
11
|
+
super();
|
|
12
|
+
}
|
|
13
|
+
public override checkColumn(table_name: string, column_name: string): void
|
|
14
|
+
{
|
|
15
|
+
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
16
|
+
if (column_name != "*")
|
|
17
|
+
t.checkColumn(column_name, false, null);
|
|
18
|
+
}
|
|
19
|
+
public checkValue(table_name: string, column_name: string, value: string)
|
|
20
|
+
{
|
|
21
|
+
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
22
|
+
if (column_name != "*")
|
|
23
|
+
{
|
|
24
|
+
let c = t.getColumn(column_name);
|
|
25
|
+
if (c.type.toLowerCase() === VariableType.Date.toLowerCase())
|
|
26
|
+
if (!TimeOperation.isValidDate(value))
|
|
27
|
+
throw ErrorOperation.getHTTP(400, `Invalid value for Date: ${value}`);
|
|
28
|
+
if (c.type.toLowerCase() === VariableType.DateTime.toLowerCase())
|
|
29
|
+
if (!TimeOperation.isValidDateTime(value))
|
|
30
|
+
throw ErrorOperation.getHTTP(400, `Invalid value for DateTime: ${value}`);
|
|
31
|
+
if (c.type.toLowerCase() === VariableType.Time.toLowerCase())
|
|
32
|
+
if (!TimeOperation.isValidTime(value))
|
|
33
|
+
throw ErrorOperation.getHTTP(400, `Invalid value for Time: ${value}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
public override getRealColumnName(table_name: string, column_name: string): string
|
|
37
|
+
{
|
|
38
|
+
let t = this.database.getTable<BaseTable<BaseDatabase, any>>(table_name);
|
|
39
|
+
return t.getRealColumnName(column_name);
|
|
40
|
+
}
|
|
41
|
+
public override getAdvancedSearchColumns(table_name: string): string[]
|
|
42
|
+
{
|
|
43
|
+
let t = this.database.getTable(table_name) as BaseTable<BaseDatabase, any>;
|
|
44
|
+
return t.getColumns(false, null, { searchable: true });
|
|
45
|
+
}
|
|
46
46
|
}
|
|
@@ -1,92 +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
|
|
17
|
-
{
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
override
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
override
|
|
59
|
-
{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
}
|
|
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
|
+
}
|
|
92
96
|
}
|
package/src/BaseTable.ts
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
import { ArraySchema, BaseTypeSchema, BaseVariableSchema, ObjectSchema } from "namirasoft-schema";
|
|
2
|
-
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
-
import { ErrorOperation, BaseUUID, NamingConvention, BaseMetaColumn } from "namirasoft-core";
|
|
4
|
-
import { BaseTableColumnOptions } from "./BaseTableColumnOptions";
|
|
5
|
-
|
|
6
|
-
export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption extends BaseTableColumnOptions>
|
|
7
|
-
{
|
|
8
|
-
database: D;
|
|
9
|
-
uuid: BaseUUID;
|
|
10
|
-
constructor(database: D)
|
|
11
|
-
{
|
|
12
|
-
this.database = database;
|
|
13
|
-
this.uuid = new BaseUUID(this.getShortName());
|
|
14
|
-
}
|
|
15
|
-
public abstract getName(): string;
|
|
16
|
-
public abstract getShortName(): string;
|
|
17
|
-
public getSecureColumns(): string[]
|
|
18
|
-
{
|
|
19
|
-
let columns: string[] = [];
|
|
20
|
-
this.forEachColumn((name, column: ModelColumnOption) =>
|
|
21
|
-
{
|
|
22
|
-
if (column.secure)
|
|
23
|
-
columns.push(name);
|
|
24
|
-
});
|
|
25
|
-
return columns;
|
|
26
|
-
}
|
|
27
|
-
public getReadOnlyColumns(): string[]
|
|
28
|
-
{
|
|
29
|
-
let columns: string[] = [];
|
|
30
|
-
this.forEachColumn((name, column: ModelColumnOption) =>
|
|
31
|
-
{
|
|
32
|
-
if (column.read_only)
|
|
33
|
-
columns.push(name);
|
|
34
|
-
});
|
|
35
|
-
return columns;
|
|
36
|
-
}
|
|
37
|
-
public abstract getColumnOption(name: string): ModelColumnOption;
|
|
38
|
-
public abstract forEachColumn(handler: (name: string, column: ModelColumnOption) => void): void;
|
|
39
|
-
public abstract getColumn(name: string): BaseMetaColumn;
|
|
40
|
-
public getColumns(secure: boolean | null = false, read_only: boolean | null = null, filter?: any): string[]
|
|
41
|
-
{
|
|
42
|
-
let columns_secure: string[] = this.getSecureColumns();
|
|
43
|
-
let columns_read_only: string[] = this.getReadOnlyColumns();
|
|
44
|
-
let columns: string[] = [];
|
|
45
|
-
this.forEachColumn((name, element) =>
|
|
46
|
-
{
|
|
47
|
-
let keys: string[] = [];
|
|
48
|
-
if (filter)
|
|
49
|
-
keys = Object.keys(filter);
|
|
50
|
-
if (!filter || keys.length == 0 || keys.every(key => filter[key] == (element as any)[key]))
|
|
51
|
-
columns.push(name)
|
|
52
|
-
});
|
|
53
|
-
if (secure !== null)
|
|
54
|
-
columns = columns.filter(name => columns_secure.includes(name) == secure);
|
|
55
|
-
if (read_only !== null)
|
|
56
|
-
columns = columns.filter(name => columns_read_only.includes(name) == read_only);
|
|
57
|
-
return columns;
|
|
58
|
-
}
|
|
59
|
-
public checkColumn(column: string, secure: boolean | null, read_only: boolean | null)
|
|
60
|
-
{
|
|
61
|
-
let columns: string[] = this.getColumns(secure, read_only)
|
|
62
|
-
if (!columns.includes(column))
|
|
63
|
-
ErrorOperation.throwHTTP(404, `Column '${column}' not found`);
|
|
64
|
-
}
|
|
65
|
-
public getRealColumnName(column: string): string
|
|
66
|
-
{
|
|
67
|
-
return column;
|
|
68
|
-
}
|
|
69
|
-
public secure(obj: any)
|
|
70
|
-
{
|
|
71
|
-
if (obj.dataValues)
|
|
72
|
-
obj = obj.dataValues;
|
|
73
|
-
let secureColumns: string[] = this.getSecureColumns();
|
|
74
|
-
secureColumns.forEach(col => delete obj[col]);
|
|
75
|
-
return obj;
|
|
76
|
-
}
|
|
77
|
-
public getArraySchema(require: boolean, name?: string): ArraySchema
|
|
78
|
-
{
|
|
79
|
-
let ans = this.getSchema(require, name);
|
|
80
|
-
return new ArraySchema(require, [ans]);
|
|
81
|
-
}
|
|
82
|
-
public getSchema(require: boolean, name?: string): ObjectSchema
|
|
83
|
-
{
|
|
84
|
-
if (!name)
|
|
85
|
-
name = NamingConvention.lower_case_underscore.convert(this.getName(), NamingConvention.Pascal_Case);
|
|
86
|
-
let columns_secure: string[] = this.getSecureColumns();
|
|
87
|
-
let columns_read_only: string[] = this.getReadOnlyColumns();
|
|
88
|
-
let ans = new ObjectSchema(name, require, null);
|
|
89
|
-
this.forEachColumn((name, element) =>
|
|
90
|
-
{
|
|
91
|
-
if (!columns_secure.includes(name))
|
|
92
|
-
ans.addField(this.getVariableSchema(name, element, columns_read_only.includes(name)));
|
|
93
|
-
});
|
|
94
|
-
return ans;
|
|
95
|
-
}
|
|
96
|
-
private getVariableSchema(name: string, element: ModelColumnOption, read_only: boolean): BaseVariableSchema
|
|
97
|
-
{
|
|
98
|
-
let schema = this.getTypeSchema(element);
|
|
99
|
-
schema.read_only = read_only;
|
|
100
|
-
let es = this.getExamples();
|
|
101
|
-
schema.example = es[name] ?? "";
|
|
102
|
-
return new BaseVariableSchema(name, schema);
|
|
103
|
-
}
|
|
104
|
-
protected abstract getTypeSchema(element: ModelColumnOption): BaseTypeSchema;
|
|
105
|
-
protected getExamples(): { [name: string]: string }
|
|
106
|
-
{
|
|
107
|
-
return {};
|
|
108
|
-
}
|
|
109
|
-
public getSchemaNames(): string[]
|
|
110
|
-
{
|
|
111
|
-
return [];
|
|
112
|
-
}
|
|
113
|
-
public getSchemaByName(require: boolean, name?: string): ObjectSchema
|
|
114
|
-
{
|
|
115
|
-
let ans = this.getSchema(require, name);
|
|
116
|
-
if (name)
|
|
117
|
-
{
|
|
118
|
-
let names = this.getSchemaNames();
|
|
119
|
-
if (!names.includes(name))
|
|
120
|
-
throw new Error("Wrong schema name was provided: " + name);
|
|
121
|
-
this.setSchemaByName(ans);
|
|
122
|
-
}
|
|
123
|
-
return ans;
|
|
124
|
-
}
|
|
125
|
-
public getArraySchemaByName(require: boolean, name?: string): ArraySchema
|
|
126
|
-
{
|
|
127
|
-
let ans = this.getSchemaByName(require, name);
|
|
128
|
-
return new ArraySchema(require, [ans]);
|
|
129
|
-
}
|
|
130
|
-
protected setSchemaByName(_: ObjectSchema): void
|
|
131
|
-
{
|
|
132
|
-
}
|
|
133
|
-
public getNotFoundError(conditions: any | null)
|
|
134
|
-
{
|
|
135
|
-
let name = NamingConvention.lower_case_underscore.convert(this.getName(), NamingConvention.Pascal_Case);
|
|
136
|
-
return ErrorOperation.getHTTP(404, "Could not find " + name + " for " + JSON.stringify(conditions));
|
|
137
|
-
}
|
|
1
|
+
import { ArraySchema, BaseTypeSchema, BaseVariableSchema, ObjectSchema } from "namirasoft-schema";
|
|
2
|
+
import { BaseDatabase } from "./BaseDatabase";
|
|
3
|
+
import { ErrorOperation, BaseUUID, NamingConvention, BaseMetaColumn } from "namirasoft-core";
|
|
4
|
+
import { BaseTableColumnOptions } from "./BaseTableColumnOptions";
|
|
5
|
+
|
|
6
|
+
export abstract class BaseTable<D extends BaseDatabase, ModelColumnOption extends BaseTableColumnOptions>
|
|
7
|
+
{
|
|
8
|
+
database: D;
|
|
9
|
+
uuid: BaseUUID;
|
|
10
|
+
constructor(database: D)
|
|
11
|
+
{
|
|
12
|
+
this.database = database;
|
|
13
|
+
this.uuid = new BaseUUID(this.getShortName());
|
|
14
|
+
}
|
|
15
|
+
public abstract getName(): string;
|
|
16
|
+
public abstract getShortName(): string;
|
|
17
|
+
public getSecureColumns(): string[]
|
|
18
|
+
{
|
|
19
|
+
let columns: string[] = [];
|
|
20
|
+
this.forEachColumn((name, column: ModelColumnOption) =>
|
|
21
|
+
{
|
|
22
|
+
if (column.secure)
|
|
23
|
+
columns.push(name);
|
|
24
|
+
});
|
|
25
|
+
return columns;
|
|
26
|
+
}
|
|
27
|
+
public getReadOnlyColumns(): string[]
|
|
28
|
+
{
|
|
29
|
+
let columns: string[] = [];
|
|
30
|
+
this.forEachColumn((name, column: ModelColumnOption) =>
|
|
31
|
+
{
|
|
32
|
+
if (column.read_only)
|
|
33
|
+
columns.push(name);
|
|
34
|
+
});
|
|
35
|
+
return columns;
|
|
36
|
+
}
|
|
37
|
+
public abstract getColumnOption(name: string): ModelColumnOption;
|
|
38
|
+
public abstract forEachColumn(handler: (name: string, column: ModelColumnOption) => void): void;
|
|
39
|
+
public abstract getColumn(name: string): BaseMetaColumn;
|
|
40
|
+
public getColumns(secure: boolean | null = false, read_only: boolean | null = null, filter?: any): string[]
|
|
41
|
+
{
|
|
42
|
+
let columns_secure: string[] = this.getSecureColumns();
|
|
43
|
+
let columns_read_only: string[] = this.getReadOnlyColumns();
|
|
44
|
+
let columns: string[] = [];
|
|
45
|
+
this.forEachColumn((name, element) =>
|
|
46
|
+
{
|
|
47
|
+
let keys: string[] = [];
|
|
48
|
+
if (filter)
|
|
49
|
+
keys = Object.keys(filter);
|
|
50
|
+
if (!filter || keys.length == 0 || keys.every(key => filter[key] == (element as any)[key]))
|
|
51
|
+
columns.push(name)
|
|
52
|
+
});
|
|
53
|
+
if (secure !== null)
|
|
54
|
+
columns = columns.filter(name => columns_secure.includes(name) == secure);
|
|
55
|
+
if (read_only !== null)
|
|
56
|
+
columns = columns.filter(name => columns_read_only.includes(name) == read_only);
|
|
57
|
+
return columns;
|
|
58
|
+
}
|
|
59
|
+
public checkColumn(column: string, secure: boolean | null, read_only: boolean | null)
|
|
60
|
+
{
|
|
61
|
+
let columns: string[] = this.getColumns(secure, read_only)
|
|
62
|
+
if (!columns.includes(column))
|
|
63
|
+
ErrorOperation.throwHTTP(404, `Column '${column}' not found`);
|
|
64
|
+
}
|
|
65
|
+
public getRealColumnName(column: string): string
|
|
66
|
+
{
|
|
67
|
+
return column;
|
|
68
|
+
}
|
|
69
|
+
public secure(obj: any)
|
|
70
|
+
{
|
|
71
|
+
if (obj.dataValues)
|
|
72
|
+
obj = obj.dataValues;
|
|
73
|
+
let secureColumns: string[] = this.getSecureColumns();
|
|
74
|
+
secureColumns.forEach(col => delete obj[col]);
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
public getArraySchema(require: boolean, name?: string): ArraySchema
|
|
78
|
+
{
|
|
79
|
+
let ans = this.getSchema(require, name);
|
|
80
|
+
return new ArraySchema(require, [ans]);
|
|
81
|
+
}
|
|
82
|
+
public getSchema(require: boolean, name?: string): ObjectSchema
|
|
83
|
+
{
|
|
84
|
+
if (!name)
|
|
85
|
+
name = NamingConvention.lower_case_underscore.convert(this.getName(), NamingConvention.Pascal_Case);
|
|
86
|
+
let columns_secure: string[] = this.getSecureColumns();
|
|
87
|
+
let columns_read_only: string[] = this.getReadOnlyColumns();
|
|
88
|
+
let ans = new ObjectSchema(name, require, null);
|
|
89
|
+
this.forEachColumn((name, element) =>
|
|
90
|
+
{
|
|
91
|
+
if (!columns_secure.includes(name))
|
|
92
|
+
ans.addField(this.getVariableSchema(name, element, columns_read_only.includes(name)));
|
|
93
|
+
});
|
|
94
|
+
return ans;
|
|
95
|
+
}
|
|
96
|
+
private getVariableSchema(name: string, element: ModelColumnOption, read_only: boolean): BaseVariableSchema
|
|
97
|
+
{
|
|
98
|
+
let schema = this.getTypeSchema(element);
|
|
99
|
+
schema.read_only = read_only;
|
|
100
|
+
let es = this.getExamples();
|
|
101
|
+
schema.example = es[name] ?? "";
|
|
102
|
+
return new BaseVariableSchema(name, schema);
|
|
103
|
+
}
|
|
104
|
+
protected abstract getTypeSchema(element: ModelColumnOption): BaseTypeSchema;
|
|
105
|
+
protected getExamples(): { [name: string]: string }
|
|
106
|
+
{
|
|
107
|
+
return {};
|
|
108
|
+
}
|
|
109
|
+
public getSchemaNames(): string[]
|
|
110
|
+
{
|
|
111
|
+
return [];
|
|
112
|
+
}
|
|
113
|
+
public getSchemaByName(require: boolean, name?: string): ObjectSchema
|
|
114
|
+
{
|
|
115
|
+
let ans = this.getSchema(require, name);
|
|
116
|
+
if (name)
|
|
117
|
+
{
|
|
118
|
+
let names = this.getSchemaNames();
|
|
119
|
+
if (!names.includes(name))
|
|
120
|
+
throw new Error("Wrong schema name was provided: " + name);
|
|
121
|
+
this.setSchemaByName(ans);
|
|
122
|
+
}
|
|
123
|
+
return ans;
|
|
124
|
+
}
|
|
125
|
+
public getArraySchemaByName(require: boolean, name?: string): ArraySchema
|
|
126
|
+
{
|
|
127
|
+
let ans = this.getSchemaByName(require, name);
|
|
128
|
+
return new ArraySchema(require, [ans]);
|
|
129
|
+
}
|
|
130
|
+
protected setSchemaByName(_: ObjectSchema): void
|
|
131
|
+
{
|
|
132
|
+
}
|
|
133
|
+
public getNotFoundError(conditions: any | null)
|
|
134
|
+
{
|
|
135
|
+
let name = NamingConvention.lower_case_underscore.convert(this.getName(), NamingConvention.Pascal_Case);
|
|
136
|
+
return ErrorOperation.getHTTP(404, "Could not find " + name + " for " + JSON.stringify(conditions));
|
|
137
|
+
}
|
|
138
138
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export interface BaseTableColumnOptions
|
|
2
|
-
{
|
|
3
|
-
secure?: boolean;
|
|
4
|
-
read_only?: boolean;
|
|
5
|
-
searchable?: boolean;
|
|
6
|
-
tags?: {
|
|
7
|
-
type?: "BaseTypeSchema" | "BaseTypeSchema[]" | "BaseVariableSchema" | "BaseVariableSchema[]"
|
|
8
|
-
}
|
|
1
|
+
export interface BaseTableColumnOptions
|
|
2
|
+
{
|
|
3
|
+
secure?: boolean;
|
|
4
|
+
read_only?: boolean;
|
|
5
|
+
searchable?: boolean;
|
|
6
|
+
tags?: {
|
|
7
|
+
type?: "BaseTypeSchema" | "BaseTypeSchema[]" | "BaseVariableSchema" | "BaseVariableSchema[]"
|
|
8
|
+
}
|
|
9
9
|
};
|
package/src/CommandOperation.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { ExecException, exec, execSync } from 'child_process';
|
|
2
|
-
import { ConsoleOperation } from 'namirasoft-core';
|
|
3
|
-
export class CommandOperation
|
|
4
|
-
{
|
|
5
|
-
static exec(command: string, cwd: string | undefined)
|
|
6
|
-
{
|
|
7
|
-
exec(command, { cwd }, (error: ExecException | null, stdout: string, stderr: string) =>
|
|
8
|
-
{
|
|
9
|
-
if (error)
|
|
10
|
-
{
|
|
11
|
-
ConsoleOperation.error(`error: ${error.message}`);
|
|
12
|
-
return;
|
|
13
|
-
}
|
|
14
|
-
if (stderr)
|
|
15
|
-
{
|
|
16
|
-
ConsoleOperation.error(`stderr: ${stderr}`);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
ConsoleOperation.log(`stdout:\n${stdout}`);
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
static execSync(command: string, cwd: string | undefined)
|
|
23
|
-
{
|
|
24
|
-
try
|
|
25
|
-
{
|
|
26
|
-
return execSync(command, { cwd, encoding: 'utf-8' });
|
|
27
|
-
} catch (error: any)
|
|
28
|
-
{
|
|
29
|
-
ConsoleOperation.error(error.stdout);
|
|
30
|
-
throw error;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
1
|
+
import { ExecException, exec, execSync } from 'child_process';
|
|
2
|
+
import { ConsoleOperation } from 'namirasoft-core';
|
|
3
|
+
export class CommandOperation
|
|
4
|
+
{
|
|
5
|
+
static exec(command: string, cwd: string | undefined)
|
|
6
|
+
{
|
|
7
|
+
exec(command, { cwd }, (error: ExecException | null, stdout: string, stderr: string) =>
|
|
8
|
+
{
|
|
9
|
+
if (error)
|
|
10
|
+
{
|
|
11
|
+
ConsoleOperation.error(`error: ${error.message}`);
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (stderr)
|
|
15
|
+
{
|
|
16
|
+
ConsoleOperation.error(`stderr: ${stderr}`);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
ConsoleOperation.log(`stdout:\n${stdout}`);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
static execSync(command: string, cwd: string | undefined)
|
|
23
|
+
{
|
|
24
|
+
try
|
|
25
|
+
{
|
|
26
|
+
return execSync(command, { cwd, encoding: 'utf-8' });
|
|
27
|
+
} catch (error: any)
|
|
28
|
+
{
|
|
29
|
+
ConsoleOperation.error(error.stdout);
|
|
30
|
+
throw error;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
33
|
}
|