namirasoft-core 1.3.76 → 1.3.78

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.
Files changed (41) hide show
  1. package/dist/CacheService.d.ts +1 -1
  2. package/dist/CacheService.js.map +1 -1
  3. package/dist/EncodingOperation.js +2 -1
  4. package/dist/EncodingOperation.js.map +1 -1
  5. package/package.json +2 -1
  6. package/src/BaseDatabaseRow.ts +6 -6
  7. package/src/BaseMetaColumn.ts +13 -13
  8. package/src/BaseMetaTable.ts +24 -24
  9. package/src/BaseServer.ts +104 -104
  10. package/src/CacheService.ts +57 -58
  11. package/src/ConsoleOperation.ts +68 -68
  12. package/src/ConvertService.ts +100 -100
  13. package/src/Countries.ts +486 -486
  14. package/src/Country.ts +21 -21
  15. package/src/CountryOperation.ts +98 -98
  16. package/src/EncodingOperation.ts +12 -10
  17. package/src/EncryptionOperation.ts +40 -40
  18. package/src/ErrorOperation.ts +13 -13
  19. package/src/FileOperation.ts +57 -57
  20. package/src/FilterItem.ts +116 -116
  21. package/src/FilterItemColumnType.ts +6 -6
  22. package/src/FilterItemOperator.ts +51 -51
  23. package/src/GeoOperation.ts +18 -18
  24. package/src/HTTPError.ts +8 -8
  25. package/src/HTTPMethod.ts +6 -6
  26. package/src/HashOperation.ts +24 -24
  27. package/src/IStorage.ts +5 -5
  28. package/src/IStorageCookie.ts +52 -52
  29. package/src/IStorageLocal.ts +16 -16
  30. package/src/IStorageMemory.ts +17 -17
  31. package/src/NamingConvention.ts +107 -107
  32. package/src/ObjectService.ts +23 -23
  33. package/src/PackageService.ts +76 -76
  34. package/src/PhoneOperation.ts +8 -8
  35. package/src/PriceOperation.ts +18 -18
  36. package/src/RegexTemplate.ts +7 -7
  37. package/src/StringOperation.ts +18 -18
  38. package/src/TimeOperation.ts +262 -262
  39. package/src/URLOperation.ts +54 -54
  40. package/src/VersionOperation.ts +46 -46
  41. package/src/index.ts +35 -35
@@ -7,6 +7,6 @@ export declare class CacheService<DataType> {
7
7
  private onExpired;
8
8
  constructor(name: string, duration_minutes: number, storage: IStorage, getFromSource: () => Promise<DataType>, onExpired: () => void);
9
9
  get(): Promise<DataType>;
10
- private set;
10
+ set(data: DataType): void;
11
11
  del(): void;
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"CacheService.js","sourceRoot":"","sources":["../src/CacheService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQA,MAAa,YAAY;IAOrB,YAAY,IAAY,EAAE,gBAAwB,EAAE,OAAiB,EAAE,aAAsC,EAAE,SAAqB;QAEhI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IACK,GAAG;;YAEL,IAAI,GAAa,CAAC;YAClB,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,KAAK,EACT;gBACI,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAA4B,CAAC;gBACzD,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,EAAE;oBACvC,OAAO,KAAK,CAAC,IAAI,CAAC;aACzB;YACD,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;IACO,GAAG,CAAC,IAAc;QAEtB,IAAI,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACvE,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAGnC,IAAI,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QACxD,IAAI,KAAK,IAAI,CAAC;YACV,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC;QACrB,UAAU,CAAC,GAAG,EAAE;YAEZ,IAAI,IAAI,CAAC,SAAS;gBACd,IAAI,CAAC,SAAS,EAAE,CAAC;QACzB,CAAC,EAAE,KAAK,CAAC,CAAC;IACd,CAAC;IACD,GAAG;QAEC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACJ;AAlDD,oCAkDC"}
1
+ {"version":3,"file":"CacheService.js","sourceRoot":"","sources":["../src/CacheService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAQA,MAAa,YAAY;IAOrB,YAAY,IAAY,EAAE,gBAAwB,EAAE,OAAiB,EAAE,aAAsC,EAAE,SAAqB;QAEhI,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC/B,CAAC;IACK,GAAG;;YAEL,IAAI,GAAa,CAAC;YAClB,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,KAAK,EACT;gBACI,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAA4B,CAAC;gBACzD,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,IAAI,IAAI,EAAE;oBACvC,OAAO,KAAK,CAAC,IAAI,CAAC;aACzB;YACD,GAAG,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;IACD,GAAG,CAAC,IAAc;QAEd,IAAI,UAAU,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,UAAU,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACvE,IAAI,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAEnC,IAAI,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QACxD,IAAI,KAAK,IAAI,CAAC;YACV,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC;QACrB,UAAU,CAAC,GAAG,EAAE;YAEZ,IAAI,IAAI,CAAC,SAAS;gBACd,IAAI,CAAC,SAAS,EAAE,CAAC;QACzB,CAAC,EAAE,KAAK,CAAC,CAAC;IACd,CAAC;IACD,GAAG;QAEC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;CACJ;AAjDD,oCAiDC"}
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EncodingOperation = void 0;
4
+ const buffer_1 = require("buffer");
4
5
  class EncodingOperation {
5
6
  static Base64Encode(message) {
6
- return Buffer.from(message).toString("base64");
7
+ return buffer_1.Buffer.from(message).toString("base64");
7
8
  }
8
9
  static Base64Decode(message) {
9
10
  return atob(message);
@@ -1 +1 @@
1
- {"version":3,"file":"EncodingOperation.js","sourceRoot":"","sources":["../src/EncodingOperation.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAiB;IAE1B,MAAM,CAAC,YAAY,CAAC,OAAe;QAE/B,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IACD,MAAM,CAAC,YAAY,CAAC,OAAe;QAE/B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;CACJ;AAVD,8CAUC"}
1
+ {"version":3,"file":"EncodingOperation.js","sourceRoot":"","sources":["../src/EncodingOperation.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAEhC,MAAa,iBAAiB;IAE1B,MAAM,CAAC,YAAY,CAAC,OAAe;QAE/B,OAAO,eAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IACD,MAAM,CAAC,YAAY,CAAC,OAAe;QAE/B,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC;IACzB,CAAC;CACJ;AAVD,8CAUC"}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "framework": "npm",
9
9
  "application": "package",
10
10
  "private": false,
11
- "version": "1.3.76",
11
+ "version": "1.3.78",
12
12
  "author": "Amir Abolhasani",
13
13
  "license": "MIT",
14
14
  "main": "./dist/index.js",
@@ -19,6 +19,7 @@
19
19
  "dependencies": {
20
20
  "@types/node": "^20.14.11",
21
21
  "axios": "^1.7.2",
22
+ "buffer": "^6.0.3",
22
23
  "moment": "^2.30.1",
23
24
  "phone": "^3.1.49"
24
25
  }
@@ -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
  }
@@ -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
  }
@@ -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,105 +1,105 @@
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
- private onBeforeRequests: ((url: string, config?: AxiosRequestConfig) => void)[] = [];
17
- private onAfterRequests: ((url: string, response: AxiosResponse) => void)[] = [];
18
- protected abstract onBeforeRequest<ReqData = any>(url: string, config?: AxiosRequestConfig<ReqData>): void;
19
- protected abstract onAfterRequest<ResData = any>(url: string, response: AxiosResponse<ResData>): void;
20
- protected abstract onError(error: Error): void;
21
- addOnBeforeRequest(onBeforeRequest: (url: string, config?: AxiosRequestConfig) => void)
22
- {
23
- this.onBeforeRequests.push(onBeforeRequest);
24
- }
25
- addOnAfterRequest(onAfterRequest: (url: string, response: AxiosResponse) => void)
26
- {
27
- this.onAfterRequests.push(onAfterRequest);
28
- }
29
- 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 }>
30
- {
31
- let url: string = URLOperation.getLink(this.domain, sub, query);
32
- if (!config)
33
- config = { headers: {} };
34
- if (sign_header)
35
- if (sign_key)
36
- if (data)
37
- if (config?.headers)
38
- config.headers[sign_header] = HashOperation.SHA256Secret(sign_key, data);
39
- try
40
- {
41
- this.onBeforeRequest(url, config);
42
- this.onBeforeRequests.forEach(onBeforeRequest =>
43
- {
44
- onBeforeRequest(url, config);
45
- });
46
- let response: AxiosResponse<ResData> = await onRequest(url, data, config);
47
- this.onAfterRequest(url, response);
48
- this.onAfterRequests.forEach(onAfterRequest =>
49
- {
50
- onAfterRequest(url, response);
51
- });
52
- return { response, data: response.data };
53
- } catch (error)
54
- {
55
- if (error instanceof Error)
56
- {
57
- if (this.onError)
58
- {
59
- error.message = `Error calling url '${url}' ` + error.message;
60
- this.onError(error);
61
- }
62
- else
63
- {
64
- ConsoleOperation.warning("onError function has not been properly set.");
65
- ConsoleOperation.error(error?.message);
66
- }
67
- if (axios.isAxiosError(error))
68
- if (error?.response?.data)
69
- if (!this.suppressErrors)
70
- ErrorOperation.throwHTTP(error.response.status, `Error calling url '${url}' ` + JSON.stringify(error.response.data));
71
- }
72
- if (!this.suppressErrors)
73
- throw error;
74
- }
75
- return {} as any;
76
- }
77
- protected async _get<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
78
- {
79
- return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
80
- {
81
- return await axios.get(url, config);
82
- }, sub, query, undefined, config);
83
- }
84
- 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 }>
85
- {
86
- return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
87
- {
88
- return await axios.post(url, data, config);
89
- }, sub, query, data, config, sign_header, sign_key);
90
- }
91
- 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 }>
92
- {
93
- return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
94
- {
95
- return await axios.put(url, data, config);
96
- }, sub, query, data, config, sign_header, sign_key);
97
- }
98
- 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 }>
99
- {
100
- return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
101
- {
102
- return await axios.delete(url, config);
103
- }, sub, query, undefined, config, sign_header, sign_key);
104
- }
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
+ private onBeforeRequests: ((url: string, config?: AxiosRequestConfig) => void)[] = [];
17
+ private onAfterRequests: ((url: string, response: AxiosResponse) => void)[] = [];
18
+ protected abstract onBeforeRequest<ReqData = any>(url: string, config?: AxiosRequestConfig<ReqData>): void;
19
+ protected abstract onAfterRequest<ResData = any>(url: string, response: AxiosResponse<ResData>): void;
20
+ protected abstract onError(error: Error): void;
21
+ addOnBeforeRequest(onBeforeRequest: (url: string, config?: AxiosRequestConfig) => void)
22
+ {
23
+ this.onBeforeRequests.push(onBeforeRequest);
24
+ }
25
+ addOnAfterRequest(onAfterRequest: (url: string, response: AxiosResponse) => void)
26
+ {
27
+ this.onAfterRequests.push(onAfterRequest);
28
+ }
29
+ 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 }>
30
+ {
31
+ let url: string = URLOperation.getLink(this.domain, sub, query);
32
+ if (!config)
33
+ config = { headers: {} };
34
+ if (sign_header)
35
+ if (sign_key)
36
+ if (data)
37
+ if (config?.headers)
38
+ config.headers[sign_header] = HashOperation.SHA256Secret(sign_key, data);
39
+ try
40
+ {
41
+ this.onBeforeRequest(url, config);
42
+ this.onBeforeRequests.forEach(onBeforeRequest =>
43
+ {
44
+ onBeforeRequest(url, config);
45
+ });
46
+ let response: AxiosResponse<ResData> = await onRequest(url, data, config);
47
+ this.onAfterRequest(url, response);
48
+ this.onAfterRequests.forEach(onAfterRequest =>
49
+ {
50
+ onAfterRequest(url, response);
51
+ });
52
+ return { response, data: response.data };
53
+ } catch (error)
54
+ {
55
+ if (error instanceof Error)
56
+ {
57
+ if (this.onError)
58
+ {
59
+ error.message = `Error calling url '${url}' ` + error.message;
60
+ this.onError(error);
61
+ }
62
+ else
63
+ {
64
+ ConsoleOperation.warning("onError function has not been properly set.");
65
+ ConsoleOperation.error(error?.message);
66
+ }
67
+ if (axios.isAxiosError(error))
68
+ if (error?.response?.data)
69
+ if (!this.suppressErrors)
70
+ ErrorOperation.throwHTTP(error.response.status, `Error calling url '${url}' ` + JSON.stringify(error.response.data));
71
+ }
72
+ if (!this.suppressErrors)
73
+ throw error;
74
+ }
75
+ return {} as any;
76
+ }
77
+ protected async _get<ResData = any, ReqData = any>(sub: string, query?: { [name: string]: ParsedNameValue }, config?: AxiosRequestConfig<ReqData>): Promise<{ response: AxiosResponse<ResData>, data: ResData }>
78
+ {
79
+ return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
80
+ {
81
+ return await axios.get(url, config);
82
+ }, sub, query, undefined, config);
83
+ }
84
+ 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 }>
85
+ {
86
+ return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
87
+ {
88
+ return await axios.post(url, data, config);
89
+ }, sub, query, data, config, sign_header, sign_key);
90
+ }
91
+ 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 }>
92
+ {
93
+ return await this._request(async (url: string, data: ReqData, config?: AxiosRequestConfig<ReqData>) =>
94
+ {
95
+ return await axios.put(url, data, config);
96
+ }, sub, query, data, config, sign_header, sign_key);
97
+ }
98
+ 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 }>
99
+ {
100
+ return await this._request(async (url: string, _?: any, config?: AxiosRequestConfig<ReqData>) =>
101
+ {
102
+ return await axios.delete(url, config);
103
+ }, sub, query, undefined, config, sign_header, sign_key);
104
+ }
105
105
  }
@@ -1,59 +1,58 @@
1
- import { IStorage } from "./IStorage";
2
-
3
- interface NSCachStorage<DataType>
4
- {
5
- expires_at: Date;
6
- data: DataType;
7
- }
8
-
9
- export class CacheService<DataType>
10
- {
11
- private name: string;
12
- private duration_minutes: number;
13
- private storage: IStorage;
14
- private getFromSource: () => Promise<DataType>;
15
- private onExpired: () => void;
16
- constructor(name: string, duration_minutes: number, storage: IStorage, getFromSource: () => Promise<DataType>, onExpired: () => void)
17
- {
18
- this.name = name;
19
- this.duration_minutes = duration_minutes;
20
- this.storage = storage;
21
- this.getFromSource = getFromSource;
22
- this.onExpired = onExpired;
23
- }
24
- async get(): Promise<DataType>
25
- {
26
- let ans: DataType;
27
- let value = this.storage.get(this.name, "");
28
- if (value)
29
- {
30
- let cache = JSON.parse(value) as NSCachStorage<DataType>;
31
- if (new Date(cache.expires_at) > new Date())
32
- return cache.data;
33
- }
34
- ans = await this.getFromSource();
35
- this.set(ans);
36
- return ans;
37
- }
38
- private set(data: DataType)
39
- {
40
- let expires_at = new Date();
41
- expires_at.setMinutes(expires_at.getMinutes() + this.duration_minutes);
42
- let value = JSON.stringify({ data, expires_at });
43
- this.storage.set(this.name, value);
44
- //
45
-
46
- let sleep = expires_at.getTime() - new Date().getTime();
47
- if (sleep <= 0)
48
- sleep = 5 * 1000;
49
- setTimeout(() =>
50
- {
51
- if (this.onExpired)
52
- this.onExpired();
53
- }, sleep);
54
- }
55
- del()
56
- {
57
- this.storage.del(this.name);
58
- }
1
+ import { IStorage } from "./IStorage";
2
+
3
+ interface NSCachStorage<DataType>
4
+ {
5
+ expires_at: Date;
6
+ data: DataType;
7
+ }
8
+
9
+ export class CacheService<DataType>
10
+ {
11
+ private name: string;
12
+ private duration_minutes: number;
13
+ private storage: IStorage;
14
+ private getFromSource: () => Promise<DataType>;
15
+ private onExpired: () => void;
16
+ constructor(name: string, duration_minutes: number, storage: IStorage, getFromSource: () => Promise<DataType>, onExpired: () => void)
17
+ {
18
+ this.name = name;
19
+ this.duration_minutes = duration_minutes;
20
+ this.storage = storage;
21
+ this.getFromSource = getFromSource;
22
+ this.onExpired = onExpired;
23
+ }
24
+ async get(): Promise<DataType>
25
+ {
26
+ let ans: DataType;
27
+ let value = this.storage.get(this.name, "");
28
+ if (value)
29
+ {
30
+ let cache = JSON.parse(value) as NSCachStorage<DataType>;
31
+ if (new Date(cache.expires_at) > new Date())
32
+ return cache.data;
33
+ }
34
+ ans = await this.getFromSource();
35
+ this.set(ans);
36
+ return ans;
37
+ }
38
+ set(data: DataType)
39
+ {
40
+ let expires_at = new Date();
41
+ expires_at.setMinutes(expires_at.getMinutes() + this.duration_minutes);
42
+ let value = JSON.stringify({ data, expires_at });
43
+ this.storage.set(this.name, value);
44
+ //
45
+ let sleep = expires_at.getTime() - new Date().getTime();
46
+ if (sleep <= 0)
47
+ sleep = 5 * 1000;
48
+ setTimeout(() =>
49
+ {
50
+ if (this.onExpired)
51
+ this.onExpired();
52
+ }, sleep);
53
+ }
54
+ del()
55
+ {
56
+ this.storage.del(this.name);
57
+ }
59
58
  }
@@ -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
  }