@adaas/a-utils 0.1.10 → 0.1.12

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 (125) hide show
  1. package/README.md +87 -32
  2. package/dist/index.d.mts +933 -0
  3. package/dist/index.d.ts +933 -27
  4. package/dist/index.js +1786 -90
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +1764 -0
  7. package/dist/index.mjs.map +1 -0
  8. package/examples/command-examples.ts +268 -0
  9. package/package.json +5 -3
  10. package/src/index.ts +70 -0
  11. package/src/lib/A-Command/A-Command.constants.ts +4 -0
  12. package/src/lib/A-Command/A-Command.entity.ts +31 -13
  13. package/src/lib/A-Command/A-Command.types.ts +6 -1
  14. package/src/lib/A-Command/README.md +645 -0
  15. package/src/lib/A-Logger/A-Logger.component.ts +10 -3
  16. package/src/lib/A-Memory/A-Memory.context.ts +15 -0
  17. package/src/lib/A-Polyfill/A-Polyfill.component.ts +153 -15
  18. package/src/lib/A-Polyfill/A-Polyfill.types.ts +54 -0
  19. package/src/lib/A-Polyfill/classes/A-Buffer-Polyfill.class.ts +85 -0
  20. package/src/lib/A-Polyfill/classes/A-Crypto-Polyfill.class.ts +87 -0
  21. package/src/lib/A-Polyfill/classes/A-FS-Polyfill.class.ts +61 -0
  22. package/src/lib/A-Polyfill/classes/A-Http-Polyfill.class.ts +100 -0
  23. package/src/lib/A-Polyfill/classes/A-Https-Polyfill.class.ts +100 -0
  24. package/src/lib/A-Polyfill/classes/A-Path-Polyfill.class.ts +97 -0
  25. package/src/lib/A-Polyfill/classes/A-Process-Polyfill.class.ts +73 -0
  26. package/src/lib/A-Polyfill/classes/A-Url-Polyfill.class.ts +88 -0
  27. package/tests/A-Command.test.ts +447 -2
  28. package/tests/A-Config.test.ts +5 -5
  29. package/tests/A-Memory.test.ts +189 -0
  30. package/tests/A-Polyfill.test.ts +446 -29
  31. package/tsconfig.json +1 -1
  32. package/tsup.config.ts +15 -0
  33. package/dist/src/constants/errors.constants.d.ts +0 -0
  34. package/dist/src/constants/errors.constants.js +0 -2
  35. package/dist/src/constants/errors.constants.js.map +0 -1
  36. package/dist/src/lib/A-Channel/A-Channel.component.d.ts +0 -22
  37. package/dist/src/lib/A-Channel/A-Channel.component.js +0 -84
  38. package/dist/src/lib/A-Channel/A-Channel.component.js.map +0 -1
  39. package/dist/src/lib/A-Channel/A-Channel.error.d.ts +0 -4
  40. package/dist/src/lib/A-Channel/A-Channel.error.js +0 -9
  41. package/dist/src/lib/A-Channel/A-Channel.error.js.map +0 -1
  42. package/dist/src/lib/A-Channel/A-Channel.types.d.ts +0 -0
  43. package/dist/src/lib/A-Channel/A-Channel.types.js +0 -2
  44. package/dist/src/lib/A-Channel/A-Channel.types.js.map +0 -1
  45. package/dist/src/lib/A-Command/A-Command.constants.d.ts +0 -22
  46. package/dist/src/lib/A-Command/A-Command.constants.js +0 -28
  47. package/dist/src/lib/A-Command/A-Command.constants.js.map +0 -1
  48. package/dist/src/lib/A-Command/A-Command.entity.d.ts +0 -133
  49. package/dist/src/lib/A-Command/A-Command.entity.js +0 -273
  50. package/dist/src/lib/A-Command/A-Command.entity.js.map +0 -1
  51. package/dist/src/lib/A-Command/A-Command.error.d.ts +0 -3
  52. package/dist/src/lib/A-Command/A-Command.error.js +0 -8
  53. package/dist/src/lib/A-Command/A-Command.error.js.map +0 -1
  54. package/dist/src/lib/A-Command/A-Command.types.d.ts +0 -73
  55. package/dist/src/lib/A-Command/A-Command.types.js +0 -4
  56. package/dist/src/lib/A-Command/A-Command.types.js.map +0 -1
  57. package/dist/src/lib/A-Config/A-Config.constants.d.ts +0 -3
  58. package/dist/src/lib/A-Config/A-Config.constants.js +0 -6
  59. package/dist/src/lib/A-Config/A-Config.constants.js.map +0 -1
  60. package/dist/src/lib/A-Config/A-Config.container.d.ts +0 -6
  61. package/dist/src/lib/A-Config/A-Config.container.js +0 -77
  62. package/dist/src/lib/A-Config/A-Config.container.js.map +0 -1
  63. package/dist/src/lib/A-Config/A-Config.context.d.ts +0 -29
  64. package/dist/src/lib/A-Config/A-Config.context.js +0 -63
  65. package/dist/src/lib/A-Config/A-Config.context.js.map +0 -1
  66. package/dist/src/lib/A-Config/A-Config.error.d.ts +0 -4
  67. package/dist/src/lib/A-Config/A-Config.error.js +0 -9
  68. package/dist/src/lib/A-Config/A-Config.error.js.map +0 -1
  69. package/dist/src/lib/A-Config/A-Config.types.d.ts +0 -19
  70. package/dist/src/lib/A-Config/A-Config.types.js +0 -7
  71. package/dist/src/lib/A-Config/A-Config.types.js.map +0 -1
  72. package/dist/src/lib/A-Config/components/ConfigReader.component.d.ts +0 -30
  73. package/dist/src/lib/A-Config/components/ConfigReader.component.js +0 -103
  74. package/dist/src/lib/A-Config/components/ConfigReader.component.js.map +0 -1
  75. package/dist/src/lib/A-Config/components/ENVConfigReader.component.d.ts +0 -14
  76. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js +0 -72
  77. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js.map +0 -1
  78. package/dist/src/lib/A-Config/components/FileConfigReader.component.d.ts +0 -11
  79. package/dist/src/lib/A-Config/components/FileConfigReader.component.js +0 -47
  80. package/dist/src/lib/A-Config/components/FileConfigReader.component.js.map +0 -1
  81. package/dist/src/lib/A-Logger/A-Logger.component.d.ts +0 -29
  82. package/dist/src/lib/A-Logger/A-Logger.component.js +0 -152
  83. package/dist/src/lib/A-Logger/A-Logger.component.js.map +0 -1
  84. package/dist/src/lib/A-Logger/A-Logger.types.d.ts +0 -0
  85. package/dist/src/lib/A-Logger/A-Logger.types.js +0 -2
  86. package/dist/src/lib/A-Logger/A-Logger.types.js.map +0 -1
  87. package/dist/src/lib/A-Manifest/A-Manifest.context.d.ts +0 -52
  88. package/dist/src/lib/A-Manifest/A-Manifest.context.js +0 -154
  89. package/dist/src/lib/A-Manifest/A-Manifest.context.js.map +0 -1
  90. package/dist/src/lib/A-Manifest/A-Manifest.error.d.ts +0 -4
  91. package/dist/src/lib/A-Manifest/A-Manifest.error.js +0 -9
  92. package/dist/src/lib/A-Manifest/A-Manifest.error.js.map +0 -1
  93. package/dist/src/lib/A-Manifest/A-Manifest.types.d.ts +0 -43
  94. package/dist/src/lib/A-Manifest/A-Manifest.types.js +0 -3
  95. package/dist/src/lib/A-Manifest/A-Manifest.types.js.map +0 -1
  96. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.d.ts +0 -14
  97. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js +0 -24
  98. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js.map +0 -1
  99. package/dist/src/lib/A-Memory/A-Memory.context.d.ts +0 -64
  100. package/dist/src/lib/A-Memory/A-Memory.context.js +0 -105
  101. package/dist/src/lib/A-Memory/A-Memory.context.js.map +0 -1
  102. package/dist/src/lib/A-Polyfill/A-Polyfill.component.d.ts +0 -20
  103. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js +0 -53
  104. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js.map +0 -1
  105. package/dist/src/lib/A-Polyfill/A-Polyfill.types.d.ts +0 -9
  106. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js +0 -3
  107. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js.map +0 -1
  108. package/dist/src/lib/A-Polyfill/A-Polyfills.class.d.ts +0 -11
  109. package/dist/src/lib/A-Polyfill/A-Polyfills.class.js +0 -123
  110. package/dist/src/lib/A-Polyfill/A-Polyfills.class.js.map +0 -1
  111. package/dist/src/lib/A-Schedule/A-Deferred.class.d.ts +0 -12
  112. package/dist/src/lib/A-Schedule/A-Deferred.class.js +0 -23
  113. package/dist/src/lib/A-Schedule/A-Deferred.class.js.map +0 -1
  114. package/dist/src/lib/A-Schedule/A-Schedule.component.d.ts +0 -57
  115. package/dist/src/lib/A-Schedule/A-Schedule.component.js +0 -49
  116. package/dist/src/lib/A-Schedule/A-Schedule.component.js.map +0 -1
  117. package/dist/src/lib/A-Schedule/A-Schedule.types.d.ts +0 -10
  118. package/dist/src/lib/A-Schedule/A-Schedule.types.js +0 -3
  119. package/dist/src/lib/A-Schedule/A-Schedule.types.js.map +0 -1
  120. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.d.ts +0 -29
  121. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js +0 -58
  122. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js.map +0 -1
  123. package/index.ts +0 -71
  124. package/src/lib/A-Polyfill/A-Polyfills.class.ts +0 -99
  125. package/tsconfig.build.json +0 -56
@@ -0,0 +1,97 @@
1
+ import { A_Context } from "@adaas/a-concept";
2
+ import { IpathInterface } from "../A-Polyfill.types";
3
+ import { A_Logger } from "../../A-Logger/A-Logger.component";
4
+
5
+ export class A_PathPolyfillClass {
6
+ private _path!: IpathInterface;
7
+ private _initialized: boolean = false;
8
+
9
+ constructor(
10
+ protected logger: A_Logger
11
+ ) {
12
+
13
+ }
14
+
15
+ get isInitialized(): boolean {
16
+ return this._initialized;
17
+ }
18
+
19
+
20
+ async get(): Promise<IpathInterface> {
21
+ if (!this._initialized) {
22
+ await this.init();
23
+ }
24
+ return this._path;
25
+ }
26
+
27
+ private async init(): Promise<void> {
28
+ try {
29
+ if (A_Context.environment === 'server') {
30
+ await this.initServer();
31
+ } else {
32
+ this.initBrowser();
33
+ }
34
+ this._initialized = true;
35
+ } catch (error) {
36
+ this.initBrowser();
37
+ this._initialized = true;
38
+ }
39
+ }
40
+
41
+ private async initServer(): Promise<void> {
42
+ this._path = await import('path') as IpathInterface;
43
+ }
44
+
45
+ private initBrowser(): void {
46
+ this._path = {
47
+ join: (...paths: string[]) => {
48
+ return paths.join('/').replace(/\/+/g, '/');
49
+ },
50
+ resolve: (...paths: string[]) => {
51
+ let resolvedPath = '';
52
+ for (const path of paths) {
53
+ if (path.startsWith('/')) {
54
+ resolvedPath = path;
55
+ } else {
56
+ resolvedPath = this._path.join(resolvedPath, path);
57
+ }
58
+ }
59
+ return resolvedPath || '/';
60
+ },
61
+ dirname: (path: string) => {
62
+ const parts = path.split('/');
63
+ return parts.slice(0, -1).join('/') || '/';
64
+ },
65
+ basename: (path: string, ext?: string) => {
66
+ const base = path.split('/').pop() || '';
67
+ return ext && base.endsWith(ext) ? base.slice(0, -ext.length) : base;
68
+ },
69
+ extname: (path: string) => {
70
+ const parts = path.split('.');
71
+ return parts.length > 1 ? '.' + parts.pop() : '';
72
+ },
73
+ relative: (from: string, to: string) => {
74
+ // Simplified relative path calculation
75
+ return to.replace(from, '').replace(/^\//, '');
76
+ },
77
+ normalize: (path: string) => {
78
+ return path.replace(/\/+/g, '/').replace(/\/$/, '') || '/';
79
+ },
80
+ isAbsolute: (path: string) => {
81
+ return path.startsWith('/') || /^[a-zA-Z]:/.test(path);
82
+ },
83
+ parse: (path: string) => {
84
+ const ext = this._path.extname(path);
85
+ const base = this._path.basename(path);
86
+ const name = this._path.basename(path, ext);
87
+ const dir = this._path.dirname(path);
88
+ return { root: '/', dir, base, ext, name };
89
+ },
90
+ format: (pathObject: any) => {
91
+ return this._path.join(pathObject.dir || '', pathObject.base || '');
92
+ },
93
+ sep: '/',
94
+ delimiter: ':'
95
+ };
96
+ }
97
+ }
@@ -0,0 +1,73 @@
1
+ import { A_Context } from "@adaas/a-concept";
2
+ import { IprocessInterface } from "../A-Polyfill.types";
3
+ import { A_Logger } from "../../A-Logger/A-Logger.component";
4
+
5
+ export class A_ProcessPolyfillClass {
6
+ private _process!: IprocessInterface;
7
+ private _initialized: boolean = false;
8
+
9
+ get isInitialized(): boolean {
10
+ return this._initialized;
11
+ }
12
+
13
+ constructor(
14
+ protected logger: A_Logger
15
+ ) {
16
+
17
+ }
18
+
19
+ async get(): Promise<IprocessInterface> {
20
+ if (!this._initialized) {
21
+ await this.init();
22
+ }
23
+ return this._process;
24
+ }
25
+
26
+ private async init(): Promise<void> {
27
+ try {
28
+ if (A_Context.environment === 'server') {
29
+ this.initServer();
30
+ } else {
31
+ this.initBrowser();
32
+ }
33
+ this._initialized = true;
34
+ } catch (error) {
35
+ this.initBrowser();
36
+ this._initialized = true;
37
+ }
38
+ }
39
+
40
+ private initServer(): void {
41
+ this._process = {
42
+ env: process.env as Record<string, string>,
43
+ argv: process.argv,
44
+ platform: process.platform,
45
+ version: process.version,
46
+ versions: process.versions as Record<string, string>,
47
+ cwd: process.cwd,
48
+ exit: process.exit,
49
+ nextTick: process.nextTick
50
+ };
51
+ }
52
+
53
+ private initBrowser(): void {
54
+ this._process = {
55
+ env: {
56
+ NODE_ENV: 'browser',
57
+ ...((globalThis as any).process?.env || {})
58
+ },
59
+ argv: ['browser'],
60
+ platform: 'browser',
61
+ version: 'browser',
62
+ versions: { node: 'browser' },
63
+ cwd: () => '/',
64
+ exit: (code?: number) => {
65
+ this.logger.warning('process.exit not available in browser');
66
+ throw new Error(`Process exit with code ${code}`);
67
+ },
68
+ nextTick: (callback: Function, ...args: any[]) => {
69
+ setTimeout(() => callback(...args), 0);
70
+ }
71
+ };
72
+ }
73
+ }
@@ -0,0 +1,88 @@
1
+ import { A_Context } from "@adaas/a-concept";
2
+ import { IurlInterface } from "../A-Polyfill.types";
3
+ import { A_Logger } from "../../A-Logger/A-Logger.component";
4
+
5
+ export class A_UrlPolyfillClass {
6
+ private _url!: IurlInterface;
7
+ private _initialized: boolean = false;
8
+
9
+ get isInitialized(): boolean {
10
+ return this._initialized;
11
+ }
12
+
13
+ constructor(
14
+ protected logger: A_Logger
15
+ ) {
16
+
17
+ }
18
+
19
+ async get(): Promise<IurlInterface> {
20
+ if (!this._initialized) {
21
+ await this.init();
22
+ }
23
+ return this._url;
24
+ }
25
+
26
+ private async init(): Promise<void> {
27
+ try {
28
+ if (A_Context.environment === 'server') {
29
+ await this.initServer();
30
+ } else {
31
+ this.initBrowser();
32
+ }
33
+ this._initialized = true;
34
+ } catch (error) {
35
+ this.initBrowser();
36
+ this._initialized = true;
37
+ }
38
+ }
39
+
40
+ private async initServer(): Promise<void> {
41
+ const urlModule = await import('url');
42
+ this._url = {
43
+ parse: urlModule.parse,
44
+ format: urlModule.format,
45
+ resolve: urlModule.resolve,
46
+ URL: (urlModule.URL || globalThis.URL) as any,
47
+ URLSearchParams: (urlModule.URLSearchParams || globalThis.URLSearchParams) as any
48
+ };
49
+ }
50
+
51
+ private initBrowser(): void {
52
+ this._url = {
53
+ parse: (urlString: string) => {
54
+ try {
55
+ const url = new URL(urlString);
56
+ return {
57
+ protocol: url.protocol,
58
+ hostname: url.hostname,
59
+ port: url.port,
60
+ pathname: url.pathname,
61
+ search: url.search,
62
+ hash: url.hash,
63
+ host: url.host,
64
+ href: url.href
65
+ };
66
+ } catch {
67
+ return {};
68
+ }
69
+ },
70
+ format: (urlObject: any) => {
71
+ try {
72
+ return new URL('', urlObject.href || `${urlObject.protocol}//${urlObject.host}${urlObject.pathname}${urlObject.search}${urlObject.hash}`).href;
73
+ } catch {
74
+ return '';
75
+ }
76
+ },
77
+ resolve: (from: string, to: string) => {
78
+ try {
79
+ return new URL(to, from).href;
80
+ } catch {
81
+ return to;
82
+ }
83
+ },
84
+ URL: globalThis.URL,
85
+ URLSearchParams: globalThis.URLSearchParams
86
+ };
87
+ }
88
+ }