namirasoft-core 1.4.12 → 1.4.13

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 (54) hide show
  1. package/dist/EncryptionOperation.js +17 -7
  2. package/dist/EncryptionOperation.js.map +1 -1
  3. package/dist/HashOperation.js +17 -7
  4. package/dist/HashOperation.js.map +1 -1
  5. package/dist/PhoneOperation.js +17 -7
  6. package/dist/PhoneOperation.js.map +1 -1
  7. package/dist/SortItem.d.ts +24 -0
  8. package/dist/SortItem.js +75 -0
  9. package/dist/SortItem.js.map +1 -0
  10. package/dist/index.d.ts +1 -0
  11. package/dist/index.js +1 -0
  12. package/dist/index.js.map +1 -1
  13. package/package.json +4 -4
  14. package/src/BaseDatabaseRow.ts +6 -6
  15. package/src/BaseMetaColumn.ts +13 -13
  16. package/src/BaseMetaTable.ts +24 -24
  17. package/src/BaseServer.ts +107 -107
  18. package/src/CacheService.ts +57 -57
  19. package/src/ConsoleOperation.ts +68 -68
  20. package/src/ConvertService.ts +100 -100
  21. package/src/CookieService.ts +33 -33
  22. package/src/Countries.ts +486 -486
  23. package/src/Country.ts +21 -21
  24. package/src/CountryOperation.ts +98 -98
  25. package/src/EncodingOperation.ts +12 -12
  26. package/src/EncryptionOperation.ts +40 -40
  27. package/src/EnvService.ts +22 -22
  28. package/src/ErrorOperation.ts +13 -13
  29. package/src/FileOperation.ts +57 -57
  30. package/src/FilterItem.ts +128 -128
  31. package/src/FilterItemColumnType.ts +6 -6
  32. package/src/FilterItemOperator.ts +51 -51
  33. package/src/GeoOperation.ts +18 -18
  34. package/src/HTTPError.ts +8 -8
  35. package/src/HTTPMethod.ts +6 -6
  36. package/src/HashOperation.ts +24 -24
  37. package/src/IStorage.ts +5 -5
  38. package/src/IStorageCookie.ts +52 -52
  39. package/src/IStorageJsonFile.ts +45 -45
  40. package/src/IStorageLocal.ts +16 -16
  41. package/src/IStorageMemory.ts +17 -17
  42. package/src/NamingConvention.ts +107 -107
  43. package/src/ObjectService.ts +27 -27
  44. package/src/PackageService.ts +76 -76
  45. package/src/PhoneOperation.ts +8 -8
  46. package/src/PriceOperation.ts +18 -18
  47. package/src/RegexTemplate.ts +7 -7
  48. package/src/SearchOperation.ts +29 -29
  49. package/src/SortItem.ts +89 -0
  50. package/src/StringOperation.ts +18 -18
  51. package/src/TimeOperation.ts +262 -262
  52. package/src/URLOperation.ts +54 -54
  53. package/src/VersionOperation.ts +46 -46
  54. package/src/index.ts +40 -39
@@ -1,58 +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
- 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
- }
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
+ }
58
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
  }
@@ -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
  }
@@ -1,34 +1,34 @@
1
- import { ConvertService } from "./ConvertService";
2
-
3
- export class CookieService extends ConvertService
4
- {
5
- private cookies: string;
6
- private cookies_object: {
7
- [key: string]: string;
8
- };
9
- private name: string;
10
- constructor(cookies: string, name: string, mandatory: boolean = false)
11
- {
12
- super(mandatory);
13
- this.cookies = cookies;
14
- this.name = name;
15
- this.cookies_object = this.cookies.split(';').reduce((acc: { [key: string]: string }, cookie) =>
16
- {
17
- const [key, value] = cookie.trim().split('=');
18
- acc[key] = decodeURIComponent(value);
19
- return acc;
20
- }, {});
21
- }
22
- override getNullString()
23
- {
24
- let ans = this.cookies_object[this.name];
25
- if (ans)
26
- return ans;
27
- return null;
28
- }
29
- protected override onMandatoryError(): void
30
- {
31
- if (!process.env.NAMIRASOFT_MUTE)
32
- throw new Error(`Cookie value was not provided: ${this.name}`);
33
- }
1
+ import { ConvertService } from "./ConvertService";
2
+
3
+ export class CookieService extends ConvertService
4
+ {
5
+ private cookies: string;
6
+ private cookies_object: {
7
+ [key: string]: string;
8
+ };
9
+ private name: string;
10
+ constructor(cookies: string, name: string, mandatory: boolean = false)
11
+ {
12
+ super(mandatory);
13
+ this.cookies = cookies;
14
+ this.name = name;
15
+ this.cookies_object = this.cookies.split(';').reduce((acc: { [key: string]: string }, cookie) =>
16
+ {
17
+ const [key, value] = cookie.trim().split('=');
18
+ acc[key] = decodeURIComponent(value);
19
+ return acc;
20
+ }, {});
21
+ }
22
+ override getNullString()
23
+ {
24
+ let ans = this.cookies_object[this.name];
25
+ if (ans)
26
+ return ans;
27
+ return null;
28
+ }
29
+ protected override onMandatoryError(): void
30
+ {
31
+ if (!process.env.NAMIRASOFT_MUTE)
32
+ throw new Error(`Cookie value was not provided: ${this.name}`);
33
+ }
34
34
  }