namirasoft-core 1.3.68 → 1.3.69
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/BaseServer.js +4 -2
- package/dist/BaseServer.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseDatabaseRow.ts +6 -6
- package/src/BaseMetaColumn.ts +13 -13
- package/src/BaseMetaTable.ts +24 -24
- package/src/BaseServer.ts +86 -83
- package/src/ConsoleOperation.ts +68 -68
- package/src/ConvertService.ts +100 -100
- package/src/Countries.ts +486 -486
- package/src/Country.ts +21 -21
- package/src/CountryOperation.ts +98 -98
- package/src/EncodingOperation.ts +10 -10
- package/src/EncryptionOperation.ts +40 -40
- package/src/ErrorOperation.ts +13 -13
- package/src/FileOperation.ts +57 -57
- package/src/FilterItem.ts +105 -105
- package/src/FilterItemColumnType.ts +6 -6
- package/src/FilterItemOperator.ts +51 -51
- package/src/GeoOperation.ts +18 -18
- package/src/HTTPError.ts +8 -8
- package/src/HTTPMethod.ts +6 -6
- package/src/HashOperation.ts +24 -24
- package/src/IStorage.ts +5 -5
- package/src/IStorageCookie.ts +52 -52
- package/src/IStorageLocal.ts +16 -16
- package/src/IStorageMemory.ts +17 -17
- package/src/NamingConvention.ts +107 -107
- package/src/ObjectService.ts +23 -23
- package/src/PackageService.ts +76 -76
- package/src/PhoneOperation.ts +8 -8
- package/src/PriceOperation.ts +18 -18
- package/src/RegexTemplate.ts +7 -7
- package/src/StringOperation.ts +18 -18
- package/src/TimeOperation.ts +262 -262
- package/src/URLOperation.ts +54 -54
- package/src/VersionOperation.ts +46 -46
- package/src/index.ts +34 -34
- package/dist/ConsoleColor.d.ts +0 -9
- package/dist/ConsoleColor.js +0 -38
- package/dist/ConsoleColor.js.map +0 -10
- package/dist/ConsoleColorService.d.ts +0 -9
- package/dist/ConsoleColorService.js +0 -41
- package/dist/ConsoleColorService.js.map +0 -10
package/dist/BaseServer.js
CHANGED
|
@@ -42,8 +42,10 @@ class BaseServer {
|
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
44
|
if (error instanceof Error) {
|
|
45
|
-
if (this.onError)
|
|
45
|
+
if (this.onError) {
|
|
46
|
+
error.message = `Error calling url '${url}' ` + error.message;
|
|
46
47
|
this.onError(error);
|
|
48
|
+
}
|
|
47
49
|
else {
|
|
48
50
|
ConsoleOperation_1.ConsoleOperation.warning("onError function has not been properly set.");
|
|
49
51
|
ConsoleOperation_1.ConsoleOperation.error(error === null || error === void 0 ? void 0 : error.message);
|
|
@@ -51,7 +53,7 @@ class BaseServer {
|
|
|
51
53
|
if (axios_1.default.isAxiosError(error))
|
|
52
54
|
if ((_a = error === null || error === void 0 ? void 0 : error.response) === null || _a === void 0 ? void 0 : _a.data)
|
|
53
55
|
if (!this.suppressErrors)
|
|
54
|
-
ErrorOperation_1.ErrorOperation.throwHTTP(error.response.status, error.response.data);
|
|
56
|
+
ErrorOperation_1.ErrorOperation.throwHTTP(error.response.status, `Error calling url '${url}' ` + JSON.stringify(error.response.data));
|
|
55
57
|
}
|
|
56
58
|
if (!this.suppressErrors)
|
|
57
59
|
throw error;
|
package/dist/BaseServer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseServer.js","sourceRoot":"","sources":["../src/BaseServer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAiE;AACjE,mDAAgD;AAChD,iDAA8C;AAC9C,qDAAkD;AAElD,yDAAsD;AAEtD,MAAsB,UAAU;IAI5B,YAAY,MAAc;QADnB,mBAAc,GAAY,KAAK,CAAC;QAGnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAIa,QAAQ,CAA+B,SAA6G,EAAE,GAAW,EAAE,KAA2C,EAAE,IAAc,EAAE,MAAoC,EAAE,WAAoB,EAAE,QAAiB;;;YAEvT,IAAI,GAAG,GAAW,2BAAY,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,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E,WAAW,EAAE,QAAQ,CAAC,CAAC;QACxD,CAAC;KAAA;IACe,OAAO,CAA+B,GAAW,EAAE,KAA2C,EAAE,MAAoC,EAAE,WAAoB,EAAE,QAAiB;;YAEzL,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAO,GAAW,EAAE,CAAO,EAAE,MAAoC,EAAE,EAAE;gBAE5F,OAAO,MAAM,eAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YAC3C,CAAC,CAAA,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC7D,CAAC;KAAA;CACJ;AA/ED,gCA+EC"}
|
package/package.json
CHANGED
package/src/BaseDatabaseRow.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export type BaseDatabaseRow<ID> =
|
|
2
|
-
{
|
|
3
|
-
id: ID;
|
|
4
|
-
createdAt: string;
|
|
5
|
-
updatedAt: string;
|
|
6
|
-
deletedAt: string;
|
|
1
|
+
export type BaseDatabaseRow<ID> =
|
|
2
|
+
{
|
|
3
|
+
id: ID;
|
|
4
|
+
createdAt: string;
|
|
5
|
+
updatedAt: string;
|
|
6
|
+
deletedAt: string;
|
|
7
7
|
}
|
package/src/BaseMetaColumn.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export class BaseMetaColumn
|
|
2
|
-
{
|
|
3
|
-
name: string;
|
|
4
|
-
text: string;
|
|
5
|
-
type: string;
|
|
6
|
-
required: boolean;
|
|
7
|
-
constructor(name: string, text: string, type: string, required: boolean)
|
|
8
|
-
{
|
|
9
|
-
this.name = name;
|
|
10
|
-
this.text = text;
|
|
11
|
-
this.type = type;
|
|
12
|
-
this.required = required;
|
|
13
|
-
}
|
|
1
|
+
export class BaseMetaColumn
|
|
2
|
+
{
|
|
3
|
+
name: string;
|
|
4
|
+
text: string;
|
|
5
|
+
type: string;
|
|
6
|
+
required: boolean;
|
|
7
|
+
constructor(name: string, text: string, type: string, required: boolean)
|
|
8
|
+
{
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.text = text;
|
|
11
|
+
this.type = type;
|
|
12
|
+
this.required = required;
|
|
13
|
+
}
|
|
14
14
|
}
|
package/src/BaseMetaTable.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { BaseMetaColumn } from "./BaseMetaColumn";
|
|
2
|
-
|
|
3
|
-
export class BaseMetaTable
|
|
4
|
-
{
|
|
5
|
-
name: string;
|
|
6
|
-
text: string;
|
|
7
|
-
constructor(name: string, text: string)
|
|
8
|
-
{
|
|
9
|
-
this.name = name;
|
|
10
|
-
this.text = text;
|
|
11
|
-
}
|
|
12
|
-
public getColumns(): BaseMetaColumn[]
|
|
13
|
-
{
|
|
14
|
-
let ans: BaseMetaColumn[] = [];
|
|
15
|
-
let columns = (this as any).columns;
|
|
16
|
-
if (columns)
|
|
17
|
-
for (let key of Object.keys(columns))
|
|
18
|
-
{
|
|
19
|
-
let object = columns[key];
|
|
20
|
-
if (object instanceof BaseMetaColumn)
|
|
21
|
-
ans.push(object);
|
|
22
|
-
}
|
|
23
|
-
return ans;
|
|
24
|
-
}
|
|
1
|
+
import { BaseMetaColumn } from "./BaseMetaColumn";
|
|
2
|
+
|
|
3
|
+
export class BaseMetaTable
|
|
4
|
+
{
|
|
5
|
+
name: string;
|
|
6
|
+
text: string;
|
|
7
|
+
constructor(name: string, text: string)
|
|
8
|
+
{
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.text = text;
|
|
11
|
+
}
|
|
12
|
+
public getColumns(): BaseMetaColumn[]
|
|
13
|
+
{
|
|
14
|
+
let ans: BaseMetaColumn[] = [];
|
|
15
|
+
let columns = (this as any).columns;
|
|
16
|
+
if (columns)
|
|
17
|
+
for (let key of Object.keys(columns))
|
|
18
|
+
{
|
|
19
|
+
let object = columns[key];
|
|
20
|
+
if (object instanceof BaseMetaColumn)
|
|
21
|
+
ans.push(object);
|
|
22
|
+
}
|
|
23
|
+
return ans;
|
|
24
|
+
}
|
|
25
25
|
}
|
package/src/BaseServer.ts
CHANGED
|
@@ -1,84 +1,87 @@
|
|
|
1
|
-
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
-
import { HashOperation } from "./HashOperation";
|
|
3
|
-
import { URLOperation } from "./URLOperation";
|
|
4
|
-
import { ErrorOperation } from "./ErrorOperation";
|
|
5
|
-
import { ParsedNameValue } from "./ParsedNameValue";
|
|
6
|
-
import { ConsoleOperation } from "./ConsoleOperation";
|
|
7
|
-
|
|
8
|
-
export abstract class BaseServer
|
|
9
|
-
{
|
|
10
|
-
protected domain: string;
|
|
11
|
-
public suppressErrors: boolean = false;
|
|
12
|
-
constructor(domain: string)
|
|
13
|
-
{
|
|
14
|
-
this.domain = domain;
|
|
15
|
-
}
|
|
16
|
-
protected abstract onBeforeRequest<ReqData = any>(url: string, config?: AxiosRequestConfig<ReqData>): void;
|
|
17
|
-
protected abstract onAfterRequest<ResData = any>(url: string, response: AxiosResponse<ResData>): void;
|
|
18
|
-
protected abstract onError(error: Error): void;
|
|
19
|
-
private async _request<ResData = any, ReqData = any>(onRequest: (url: string, data?: any, config?: AxiosRequestConfig<ReqData>) => Promise<AxiosResponse<ResData>>, sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
20
|
-
{
|
|
21
|
-
let url: string = URLOperation.getLink(this.domain, sub, query);
|
|
22
|
-
if (!config)
|
|
23
|
-
config = { headers: {} };
|
|
24
|
-
if (sign_header)
|
|
25
|
-
if (sign_key)
|
|
26
|
-
if (data)
|
|
27
|
-
if (config?.headers)
|
|
28
|
-
config.headers[sign_header] = HashOperation.SHA256Secret(sign_key, data);
|
|
29
|
-
try
|
|
30
|
-
{
|
|
31
|
-
this.onBeforeRequest(url, config);
|
|
32
|
-
let response: AxiosResponse<ResData> = await onRequest(url, data, config);
|
|
33
|
-
this.onAfterRequest(url, response);
|
|
34
|
-
return { response, data: response.data };
|
|
35
|
-
} catch (error)
|
|
36
|
-
{
|
|
37
|
-
if (error instanceof Error)
|
|
38
|
-
{
|
|
39
|
-
if (this.onError)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
1
|
+
import axios, { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
|
+
import { HashOperation } from "./HashOperation";
|
|
3
|
+
import { URLOperation } from "./URLOperation";
|
|
4
|
+
import { ErrorOperation } from "./ErrorOperation";
|
|
5
|
+
import { ParsedNameValue } from "./ParsedNameValue";
|
|
6
|
+
import { ConsoleOperation } from "./ConsoleOperation";
|
|
7
|
+
|
|
8
|
+
export abstract class BaseServer
|
|
9
|
+
{
|
|
10
|
+
protected domain: string;
|
|
11
|
+
public suppressErrors: boolean = false;
|
|
12
|
+
constructor(domain: string)
|
|
13
|
+
{
|
|
14
|
+
this.domain = domain;
|
|
15
|
+
}
|
|
16
|
+
protected abstract onBeforeRequest<ReqData = any>(url: string, config?: AxiosRequestConfig<ReqData>): void;
|
|
17
|
+
protected abstract onAfterRequest<ResData = any>(url: string, response: AxiosResponse<ResData>): void;
|
|
18
|
+
protected abstract onError(error: Error): void;
|
|
19
|
+
private async _request<ResData = any, ReqData = any>(onRequest: (url: string, data?: any, config?: AxiosRequestConfig<ReqData>) => Promise<AxiosResponse<ResData>>, sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
20
|
+
{
|
|
21
|
+
let url: string = URLOperation.getLink(this.domain, sub, query);
|
|
22
|
+
if (!config)
|
|
23
|
+
config = { headers: {} };
|
|
24
|
+
if (sign_header)
|
|
25
|
+
if (sign_key)
|
|
26
|
+
if (data)
|
|
27
|
+
if (config?.headers)
|
|
28
|
+
config.headers[sign_header] = HashOperation.SHA256Secret(sign_key, data);
|
|
29
|
+
try
|
|
30
|
+
{
|
|
31
|
+
this.onBeforeRequest(url, config);
|
|
32
|
+
let response: AxiosResponse<ResData> = await onRequest(url, data, config);
|
|
33
|
+
this.onAfterRequest(url, response);
|
|
34
|
+
return { response, data: response.data };
|
|
35
|
+
} catch (error)
|
|
36
|
+
{
|
|
37
|
+
if (error instanceof Error)
|
|
38
|
+
{
|
|
39
|
+
if (this.onError)
|
|
40
|
+
{
|
|
41
|
+
error.message = `Error calling url '${url}' ` + error.message;
|
|
42
|
+
this.onError(error);
|
|
43
|
+
}
|
|
44
|
+
else
|
|
45
|
+
{
|
|
46
|
+
ConsoleOperation.warning("onError function has not been properly set.");
|
|
47
|
+
ConsoleOperation.error(error?.message);
|
|
48
|
+
}
|
|
49
|
+
if (axios.isAxiosError(error))
|
|
50
|
+
if (error?.response?.data)
|
|
51
|
+
if (!this.suppressErrors)
|
|
52
|
+
ErrorOperation.throwHTTP(error.response.status, `Error calling url '${url}' ` + JSON.stringify(error.response.data));
|
|
53
|
+
}
|
|
54
|
+
if (!this.suppressErrors)
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
return {} as any;
|
|
58
|
+
}
|
|
59
|
+
protected async _get<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
60
|
+
{
|
|
61
|
+
return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
|
|
62
|
+
{
|
|
63
|
+
return await axios.get(url, config);
|
|
64
|
+
}, sub, query, undefined, config);
|
|
65
|
+
}
|
|
66
|
+
protected async _post<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
67
|
+
{
|
|
68
|
+
return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
|
|
69
|
+
{
|
|
70
|
+
return await axios.post(url, data, config);
|
|
71
|
+
}, sub, query, data, config, sign_header, sign_key);
|
|
72
|
+
}
|
|
73
|
+
protected async _put<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, data?: ReqData, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
74
|
+
{
|
|
75
|
+
return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
|
|
76
|
+
{
|
|
77
|
+
return await axios.put(url, data, config);
|
|
78
|
+
}, sub, query, data, config, sign_header, sign_key);
|
|
79
|
+
}
|
|
80
|
+
protected async _delete<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>, sign_header?: string, sign_key?: string): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
|
|
81
|
+
{
|
|
82
|
+
return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
|
|
83
|
+
{
|
|
84
|
+
return await axios.delete(url, config);
|
|
85
|
+
}, sub, query, undefined, config, sign_header, sign_key);
|
|
86
|
+
}
|
|
84
87
|
}
|
package/src/ConsoleOperation.ts
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
export class ConsoleOperation
|
|
2
|
-
{
|
|
3
|
-
public static colors = {
|
|
4
|
-
reset: '\x1b[0m',
|
|
5
|
-
red: '\x1b[31m',
|
|
6
|
-
green: '\x1b[32m',
|
|
7
|
-
yellow: '\x1b[33m',
|
|
8
|
-
blue: '\x1b[34m',
|
|
9
|
-
magenta: '\x1b[35m',
|
|
10
|
-
cyan: '\x1b[36m',
|
|
11
|
-
white: '\x1b[37m',
|
|
12
|
-
};
|
|
13
|
-
static formatLogColor(message: string)
|
|
14
|
-
{
|
|
15
|
-
return (ConsoleOperation.colors.white + message + ConsoleOperation.colors.reset);
|
|
16
|
-
}
|
|
17
|
-
static formatInfoColor(message: string)
|
|
18
|
-
{
|
|
19
|
-
return (ConsoleOperation.colors.cyan + message + ConsoleOperation.colors.reset);
|
|
20
|
-
}
|
|
21
|
-
static formatTraceColor(message: string)
|
|
22
|
-
{
|
|
23
|
-
return (ConsoleOperation.colors.blue + message + ConsoleOperation.colors.reset);
|
|
24
|
-
}
|
|
25
|
-
static formatDebugColor(message: string)
|
|
26
|
-
{
|
|
27
|
-
return (ConsoleOperation.colors.magenta + message + ConsoleOperation.colors.reset);
|
|
28
|
-
}
|
|
29
|
-
static formatSuccessColor(message: string)
|
|
30
|
-
{
|
|
31
|
-
return (ConsoleOperation.colors.green + message + ConsoleOperation.colors.reset);
|
|
32
|
-
}
|
|
33
|
-
static formatWarningColor(message: string)
|
|
34
|
-
{
|
|
35
|
-
return (ConsoleOperation.colors.yellow + message + ConsoleOperation.colors.reset);
|
|
36
|
-
}
|
|
37
|
-
static formatErrorColor(message: string)
|
|
38
|
-
{
|
|
39
|
-
return (ConsoleOperation.colors.red + message + ConsoleOperation.colors.reset);
|
|
40
|
-
}
|
|
41
|
-
static log(message: string)
|
|
42
|
-
{
|
|
43
|
-
console.log(ConsoleOperation.formatLogColor(message));
|
|
44
|
-
}
|
|
45
|
-
static info(message: string)
|
|
46
|
-
{
|
|
47
|
-
console.info(ConsoleOperation.formatInfoColor(message));
|
|
48
|
-
}
|
|
49
|
-
static trace(message: string)
|
|
50
|
-
{
|
|
51
|
-
console.trace(ConsoleOperation.formatTraceColor(message));
|
|
52
|
-
}
|
|
53
|
-
static debug(message: string)
|
|
54
|
-
{
|
|
55
|
-
console.debug(ConsoleOperation.formatDebugColor(message));
|
|
56
|
-
}
|
|
57
|
-
static success(message: string)
|
|
58
|
-
{
|
|
59
|
-
console.info(ConsoleOperation.formatSuccessColor(message));
|
|
60
|
-
}
|
|
61
|
-
static warning(message: string)
|
|
62
|
-
{
|
|
63
|
-
console.warn(ConsoleOperation.formatWarningColor(message));
|
|
64
|
-
}
|
|
65
|
-
static error(message: string)
|
|
66
|
-
{
|
|
67
|
-
console.error(ConsoleOperation.formatErrorColor(message));
|
|
68
|
-
}
|
|
1
|
+
export class ConsoleOperation
|
|
2
|
+
{
|
|
3
|
+
public static colors = {
|
|
4
|
+
reset: '\x1b[0m',
|
|
5
|
+
red: '\x1b[31m',
|
|
6
|
+
green: '\x1b[32m',
|
|
7
|
+
yellow: '\x1b[33m',
|
|
8
|
+
blue: '\x1b[34m',
|
|
9
|
+
magenta: '\x1b[35m',
|
|
10
|
+
cyan: '\x1b[36m',
|
|
11
|
+
white: '\x1b[37m',
|
|
12
|
+
};
|
|
13
|
+
static formatLogColor(message: string)
|
|
14
|
+
{
|
|
15
|
+
return (ConsoleOperation.colors.white + message + ConsoleOperation.colors.reset);
|
|
16
|
+
}
|
|
17
|
+
static formatInfoColor(message: string)
|
|
18
|
+
{
|
|
19
|
+
return (ConsoleOperation.colors.cyan + message + ConsoleOperation.colors.reset);
|
|
20
|
+
}
|
|
21
|
+
static formatTraceColor(message: string)
|
|
22
|
+
{
|
|
23
|
+
return (ConsoleOperation.colors.blue + message + ConsoleOperation.colors.reset);
|
|
24
|
+
}
|
|
25
|
+
static formatDebugColor(message: string)
|
|
26
|
+
{
|
|
27
|
+
return (ConsoleOperation.colors.magenta + message + ConsoleOperation.colors.reset);
|
|
28
|
+
}
|
|
29
|
+
static formatSuccessColor(message: string)
|
|
30
|
+
{
|
|
31
|
+
return (ConsoleOperation.colors.green + message + ConsoleOperation.colors.reset);
|
|
32
|
+
}
|
|
33
|
+
static formatWarningColor(message: string)
|
|
34
|
+
{
|
|
35
|
+
return (ConsoleOperation.colors.yellow + message + ConsoleOperation.colors.reset);
|
|
36
|
+
}
|
|
37
|
+
static formatErrorColor(message: string)
|
|
38
|
+
{
|
|
39
|
+
return (ConsoleOperation.colors.red + message + ConsoleOperation.colors.reset);
|
|
40
|
+
}
|
|
41
|
+
static log(message: string)
|
|
42
|
+
{
|
|
43
|
+
console.log(ConsoleOperation.formatLogColor(message));
|
|
44
|
+
}
|
|
45
|
+
static info(message: string)
|
|
46
|
+
{
|
|
47
|
+
console.info(ConsoleOperation.formatInfoColor(message));
|
|
48
|
+
}
|
|
49
|
+
static trace(message: string)
|
|
50
|
+
{
|
|
51
|
+
console.trace(ConsoleOperation.formatTraceColor(message));
|
|
52
|
+
}
|
|
53
|
+
static debug(message: string)
|
|
54
|
+
{
|
|
55
|
+
console.debug(ConsoleOperation.formatDebugColor(message));
|
|
56
|
+
}
|
|
57
|
+
static success(message: string)
|
|
58
|
+
{
|
|
59
|
+
console.info(ConsoleOperation.formatSuccessColor(message));
|
|
60
|
+
}
|
|
61
|
+
static warning(message: string)
|
|
62
|
+
{
|
|
63
|
+
console.warn(ConsoleOperation.formatWarningColor(message));
|
|
64
|
+
}
|
|
65
|
+
static error(message: string)
|
|
66
|
+
{
|
|
67
|
+
console.error(ConsoleOperation.formatErrorColor(message));
|
|
68
|
+
}
|
|
69
69
|
}
|
package/src/ConvertService.ts
CHANGED
|
@@ -1,101 +1,101 @@
|
|
|
1
|
-
import { ErrorOperation } from "./ErrorOperation";
|
|
2
|
-
import { StringOperation } from "./StringOperation";
|
|
3
|
-
|
|
4
|
-
export abstract class ConvertService
|
|
5
|
-
{
|
|
6
|
-
repair: boolean = true;
|
|
7
|
-
private mandatory: boolean;
|
|
8
|
-
constructor(mandatory: boolean = false)
|
|
9
|
-
{
|
|
10
|
-
this.mandatory = mandatory;
|
|
11
|
-
}
|
|
12
|
-
abstract getNullString(): string | null;
|
|
13
|
-
private checkMandatory<D>(value: D): D
|
|
14
|
-
{
|
|
15
|
-
if (!process.env.NAMIRASOFT_MUTE)
|
|
16
|
-
if (this.mandatory)
|
|
17
|
-
if (value == null || value == undefined)
|
|
18
|
-
this.onMandatoryError();
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
protected onMandatoryError(): void
|
|
22
|
-
{
|
|
23
|
-
if (!process.env.NAMIRASOFT_MUTE)
|
|
24
|
-
ErrorOperation.throwHTTP(500, "Object value can not be converted.");
|
|
25
|
-
}
|
|
26
|
-
getString(_default: string = ""): string
|
|
27
|
-
{
|
|
28
|
-
let ans = this.checkMandatory(this.getNullString()) ?? _default;
|
|
29
|
-
if (this.repair)
|
|
30
|
-
ans = StringOperation.repair(ans);
|
|
31
|
-
return ans;
|
|
32
|
-
}
|
|
33
|
-
getNullInt(): number | null
|
|
34
|
-
{
|
|
35
|
-
let str = this.getString();
|
|
36
|
-
if (str == null)
|
|
37
|
-
return null;
|
|
38
|
-
let ans = parseInt(str);
|
|
39
|
-
if (isNaN(ans))
|
|
40
|
-
return null;
|
|
41
|
-
return ans;
|
|
42
|
-
}
|
|
43
|
-
getInt(_default: number = 0): number
|
|
44
|
-
{
|
|
45
|
-
return this.checkMandatory(this.getNullInt()) ?? _default;
|
|
46
|
-
}
|
|
47
|
-
getNullFloat(): number | null
|
|
48
|
-
{
|
|
49
|
-
let str = this.getString();
|
|
50
|
-
if (str == null)
|
|
51
|
-
return null;
|
|
52
|
-
let ans = parseFloat(str);
|
|
53
|
-
if (isNaN(ans))
|
|
54
|
-
return null;
|
|
55
|
-
return ans;
|
|
56
|
-
}
|
|
57
|
-
getFloat(_default: number = 0): number
|
|
58
|
-
{
|
|
59
|
-
return this.checkMandatory(this.getNullFloat()) ?? _default;
|
|
60
|
-
}
|
|
61
|
-
getNullBoolean(): boolean | null
|
|
62
|
-
{
|
|
63
|
-
let str = this.getString();
|
|
64
|
-
if (str == null)
|
|
65
|
-
return null;
|
|
66
|
-
let ans = str.toLowerCase();
|
|
67
|
-
if (ans == "true")
|
|
68
|
-
return true;
|
|
69
|
-
if (ans == "false")
|
|
70
|
-
return false;
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
getBoolean(_default: boolean = false): boolean
|
|
74
|
-
{
|
|
75
|
-
return this.checkMandatory(this.getNullBoolean()) ?? _default;
|
|
76
|
-
}
|
|
77
|
-
getNullEnum<T>(enumObj: { [s: string]: T }): T | null
|
|
78
|
-
{
|
|
79
|
-
let str = this.getString();
|
|
80
|
-
return Object.values(enumObj).find((enumValue) => enumValue === str) as T | null;
|
|
81
|
-
}
|
|
82
|
-
getEnum<T>(enumObj: { [s: string]: T }, _default: T): T
|
|
83
|
-
{
|
|
84
|
-
return this.checkMandatory(this.getNullEnum<T>(enumObj)) ?? _default;
|
|
85
|
-
}
|
|
86
|
-
getStringArray(delimiter: string = ","): string[]
|
|
87
|
-
{
|
|
88
|
-
let ans: string[] = this.getString("").split(delimiter);
|
|
89
|
-
ans = ans.map(v => `${v}`);
|
|
90
|
-
ans = ans.filter(x => x);
|
|
91
|
-
return ans;
|
|
92
|
-
}
|
|
93
|
-
getIntArray(delimiter: string = ","): number[]
|
|
94
|
-
{
|
|
95
|
-
return this.getStringArray(delimiter).map(x => parseInt(x)).filter(x => !isNaN(x));
|
|
96
|
-
}
|
|
97
|
-
getFloatArray(delimiter: string = ","): number[]
|
|
98
|
-
{
|
|
99
|
-
return this.getStringArray(delimiter).map(x => parseFloat(x)).filter(x => !isNaN(x));
|
|
100
|
-
}
|
|
1
|
+
import { ErrorOperation } from "./ErrorOperation";
|
|
2
|
+
import { StringOperation } from "./StringOperation";
|
|
3
|
+
|
|
4
|
+
export abstract class ConvertService
|
|
5
|
+
{
|
|
6
|
+
repair: boolean = true;
|
|
7
|
+
private mandatory: boolean;
|
|
8
|
+
constructor(mandatory: boolean = false)
|
|
9
|
+
{
|
|
10
|
+
this.mandatory = mandatory;
|
|
11
|
+
}
|
|
12
|
+
abstract getNullString(): string | null;
|
|
13
|
+
private checkMandatory<D>(value: D): D
|
|
14
|
+
{
|
|
15
|
+
if (!process.env.NAMIRASOFT_MUTE)
|
|
16
|
+
if (this.mandatory)
|
|
17
|
+
if (value == null || value == undefined)
|
|
18
|
+
this.onMandatoryError();
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
protected onMandatoryError(): void
|
|
22
|
+
{
|
|
23
|
+
if (!process.env.NAMIRASOFT_MUTE)
|
|
24
|
+
ErrorOperation.throwHTTP(500, "Object value can not be converted.");
|
|
25
|
+
}
|
|
26
|
+
getString(_default: string = ""): string
|
|
27
|
+
{
|
|
28
|
+
let ans = this.checkMandatory(this.getNullString()) ?? _default;
|
|
29
|
+
if (this.repair)
|
|
30
|
+
ans = StringOperation.repair(ans);
|
|
31
|
+
return ans;
|
|
32
|
+
}
|
|
33
|
+
getNullInt(): number | null
|
|
34
|
+
{
|
|
35
|
+
let str = this.getString();
|
|
36
|
+
if (str == null)
|
|
37
|
+
return null;
|
|
38
|
+
let ans = parseInt(str);
|
|
39
|
+
if (isNaN(ans))
|
|
40
|
+
return null;
|
|
41
|
+
return ans;
|
|
42
|
+
}
|
|
43
|
+
getInt(_default: number = 0): number
|
|
44
|
+
{
|
|
45
|
+
return this.checkMandatory(this.getNullInt()) ?? _default;
|
|
46
|
+
}
|
|
47
|
+
getNullFloat(): number | null
|
|
48
|
+
{
|
|
49
|
+
let str = this.getString();
|
|
50
|
+
if (str == null)
|
|
51
|
+
return null;
|
|
52
|
+
let ans = parseFloat(str);
|
|
53
|
+
if (isNaN(ans))
|
|
54
|
+
return null;
|
|
55
|
+
return ans;
|
|
56
|
+
}
|
|
57
|
+
getFloat(_default: number = 0): number
|
|
58
|
+
{
|
|
59
|
+
return this.checkMandatory(this.getNullFloat()) ?? _default;
|
|
60
|
+
}
|
|
61
|
+
getNullBoolean(): boolean | null
|
|
62
|
+
{
|
|
63
|
+
let str = this.getString();
|
|
64
|
+
if (str == null)
|
|
65
|
+
return null;
|
|
66
|
+
let ans = str.toLowerCase();
|
|
67
|
+
if (ans == "true")
|
|
68
|
+
return true;
|
|
69
|
+
if (ans == "false")
|
|
70
|
+
return false;
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
getBoolean(_default: boolean = false): boolean
|
|
74
|
+
{
|
|
75
|
+
return this.checkMandatory(this.getNullBoolean()) ?? _default;
|
|
76
|
+
}
|
|
77
|
+
getNullEnum<T>(enumObj: { [s: string]: T }): T | null
|
|
78
|
+
{
|
|
79
|
+
let str = this.getString();
|
|
80
|
+
return Object.values(enumObj).find((enumValue) => enumValue === str) as T | null;
|
|
81
|
+
}
|
|
82
|
+
getEnum<T>(enumObj: { [s: string]: T }, _default: T): T
|
|
83
|
+
{
|
|
84
|
+
return this.checkMandatory(this.getNullEnum<T>(enumObj)) ?? _default;
|
|
85
|
+
}
|
|
86
|
+
getStringArray(delimiter: string = ","): string[]
|
|
87
|
+
{
|
|
88
|
+
let ans: string[] = this.getString("").split(delimiter);
|
|
89
|
+
ans = ans.map(v => `${v}`);
|
|
90
|
+
ans = ans.filter(x => x);
|
|
91
|
+
return ans;
|
|
92
|
+
}
|
|
93
|
+
getIntArray(delimiter: string = ","): number[]
|
|
94
|
+
{
|
|
95
|
+
return this.getStringArray(delimiter).map(x => parseInt(x)).filter(x => !isNaN(x));
|
|
96
|
+
}
|
|
97
|
+
getFloatArray(delimiter: string = ","): number[]
|
|
98
|
+
{
|
|
99
|
+
return this.getStringArray(delimiter).map(x => parseFloat(x)).filter(x => !isNaN(x));
|
|
100
|
+
}
|
|
101
101
|
}
|