@adaas/a-utils 0.1.10 → 0.1.11

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 (116) hide show
  1. package/dist/index.d.mts +914 -0
  2. package/dist/index.d.ts +914 -27
  3. package/dist/index.js +1760 -90
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1738 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +5 -3
  8. package/src/index.ts +70 -0
  9. package/src/lib/A-Logger/A-Logger.component.ts +10 -3
  10. package/src/lib/A-Polyfill/A-Polyfill.component.ts +153 -15
  11. package/src/lib/A-Polyfill/A-Polyfill.types.ts +54 -0
  12. package/src/lib/A-Polyfill/classes/A-Buffer-Polyfill.class.ts +85 -0
  13. package/src/lib/A-Polyfill/classes/A-Crypto-Polyfill.class.ts +87 -0
  14. package/src/lib/A-Polyfill/classes/A-FS-Polyfill.class.ts +61 -0
  15. package/src/lib/A-Polyfill/classes/A-Http-Polyfill.class.ts +100 -0
  16. package/src/lib/A-Polyfill/classes/A-Https-Polyfill.class.ts +100 -0
  17. package/src/lib/A-Polyfill/classes/A-Path-Polyfill.class.ts +97 -0
  18. package/src/lib/A-Polyfill/classes/A-Process-Polyfill.class.ts +73 -0
  19. package/src/lib/A-Polyfill/classes/A-Url-Polyfill.class.ts +88 -0
  20. package/tests/A-Config.test.ts +5 -5
  21. package/tests/A-Polyfill.test.ts +446 -29
  22. package/tsconfig.json +1 -1
  23. package/tsup.config.ts +15 -0
  24. package/dist/src/constants/errors.constants.d.ts +0 -0
  25. package/dist/src/constants/errors.constants.js +0 -2
  26. package/dist/src/constants/errors.constants.js.map +0 -1
  27. package/dist/src/lib/A-Channel/A-Channel.component.d.ts +0 -22
  28. package/dist/src/lib/A-Channel/A-Channel.component.js +0 -84
  29. package/dist/src/lib/A-Channel/A-Channel.component.js.map +0 -1
  30. package/dist/src/lib/A-Channel/A-Channel.error.d.ts +0 -4
  31. package/dist/src/lib/A-Channel/A-Channel.error.js +0 -9
  32. package/dist/src/lib/A-Channel/A-Channel.error.js.map +0 -1
  33. package/dist/src/lib/A-Channel/A-Channel.types.d.ts +0 -0
  34. package/dist/src/lib/A-Channel/A-Channel.types.js +0 -2
  35. package/dist/src/lib/A-Channel/A-Channel.types.js.map +0 -1
  36. package/dist/src/lib/A-Command/A-Command.constants.d.ts +0 -22
  37. package/dist/src/lib/A-Command/A-Command.constants.js +0 -28
  38. package/dist/src/lib/A-Command/A-Command.constants.js.map +0 -1
  39. package/dist/src/lib/A-Command/A-Command.entity.d.ts +0 -133
  40. package/dist/src/lib/A-Command/A-Command.entity.js +0 -273
  41. package/dist/src/lib/A-Command/A-Command.entity.js.map +0 -1
  42. package/dist/src/lib/A-Command/A-Command.error.d.ts +0 -3
  43. package/dist/src/lib/A-Command/A-Command.error.js +0 -8
  44. package/dist/src/lib/A-Command/A-Command.error.js.map +0 -1
  45. package/dist/src/lib/A-Command/A-Command.types.d.ts +0 -73
  46. package/dist/src/lib/A-Command/A-Command.types.js +0 -4
  47. package/dist/src/lib/A-Command/A-Command.types.js.map +0 -1
  48. package/dist/src/lib/A-Config/A-Config.constants.d.ts +0 -3
  49. package/dist/src/lib/A-Config/A-Config.constants.js +0 -6
  50. package/dist/src/lib/A-Config/A-Config.constants.js.map +0 -1
  51. package/dist/src/lib/A-Config/A-Config.container.d.ts +0 -6
  52. package/dist/src/lib/A-Config/A-Config.container.js +0 -77
  53. package/dist/src/lib/A-Config/A-Config.container.js.map +0 -1
  54. package/dist/src/lib/A-Config/A-Config.context.d.ts +0 -29
  55. package/dist/src/lib/A-Config/A-Config.context.js +0 -63
  56. package/dist/src/lib/A-Config/A-Config.context.js.map +0 -1
  57. package/dist/src/lib/A-Config/A-Config.error.d.ts +0 -4
  58. package/dist/src/lib/A-Config/A-Config.error.js +0 -9
  59. package/dist/src/lib/A-Config/A-Config.error.js.map +0 -1
  60. package/dist/src/lib/A-Config/A-Config.types.d.ts +0 -19
  61. package/dist/src/lib/A-Config/A-Config.types.js +0 -7
  62. package/dist/src/lib/A-Config/A-Config.types.js.map +0 -1
  63. package/dist/src/lib/A-Config/components/ConfigReader.component.d.ts +0 -30
  64. package/dist/src/lib/A-Config/components/ConfigReader.component.js +0 -103
  65. package/dist/src/lib/A-Config/components/ConfigReader.component.js.map +0 -1
  66. package/dist/src/lib/A-Config/components/ENVConfigReader.component.d.ts +0 -14
  67. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js +0 -72
  68. package/dist/src/lib/A-Config/components/ENVConfigReader.component.js.map +0 -1
  69. package/dist/src/lib/A-Config/components/FileConfigReader.component.d.ts +0 -11
  70. package/dist/src/lib/A-Config/components/FileConfigReader.component.js +0 -47
  71. package/dist/src/lib/A-Config/components/FileConfigReader.component.js.map +0 -1
  72. package/dist/src/lib/A-Logger/A-Logger.component.d.ts +0 -29
  73. package/dist/src/lib/A-Logger/A-Logger.component.js +0 -152
  74. package/dist/src/lib/A-Logger/A-Logger.component.js.map +0 -1
  75. package/dist/src/lib/A-Logger/A-Logger.types.d.ts +0 -0
  76. package/dist/src/lib/A-Logger/A-Logger.types.js +0 -2
  77. package/dist/src/lib/A-Logger/A-Logger.types.js.map +0 -1
  78. package/dist/src/lib/A-Manifest/A-Manifest.context.d.ts +0 -52
  79. package/dist/src/lib/A-Manifest/A-Manifest.context.js +0 -154
  80. package/dist/src/lib/A-Manifest/A-Manifest.context.js.map +0 -1
  81. package/dist/src/lib/A-Manifest/A-Manifest.error.d.ts +0 -4
  82. package/dist/src/lib/A-Manifest/A-Manifest.error.js +0 -9
  83. package/dist/src/lib/A-Manifest/A-Manifest.error.js.map +0 -1
  84. package/dist/src/lib/A-Manifest/A-Manifest.types.d.ts +0 -43
  85. package/dist/src/lib/A-Manifest/A-Manifest.types.js +0 -3
  86. package/dist/src/lib/A-Manifest/A-Manifest.types.js.map +0 -1
  87. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.d.ts +0 -14
  88. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js +0 -24
  89. package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js.map +0 -1
  90. package/dist/src/lib/A-Memory/A-Memory.context.d.ts +0 -64
  91. package/dist/src/lib/A-Memory/A-Memory.context.js +0 -105
  92. package/dist/src/lib/A-Memory/A-Memory.context.js.map +0 -1
  93. package/dist/src/lib/A-Polyfill/A-Polyfill.component.d.ts +0 -20
  94. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js +0 -53
  95. package/dist/src/lib/A-Polyfill/A-Polyfill.component.js.map +0 -1
  96. package/dist/src/lib/A-Polyfill/A-Polyfill.types.d.ts +0 -9
  97. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js +0 -3
  98. package/dist/src/lib/A-Polyfill/A-Polyfill.types.js.map +0 -1
  99. package/dist/src/lib/A-Polyfill/A-Polyfills.class.d.ts +0 -11
  100. package/dist/src/lib/A-Polyfill/A-Polyfills.class.js +0 -123
  101. package/dist/src/lib/A-Polyfill/A-Polyfills.class.js.map +0 -1
  102. package/dist/src/lib/A-Schedule/A-Deferred.class.d.ts +0 -12
  103. package/dist/src/lib/A-Schedule/A-Deferred.class.js +0 -23
  104. package/dist/src/lib/A-Schedule/A-Deferred.class.js.map +0 -1
  105. package/dist/src/lib/A-Schedule/A-Schedule.component.d.ts +0 -57
  106. package/dist/src/lib/A-Schedule/A-Schedule.component.js +0 -49
  107. package/dist/src/lib/A-Schedule/A-Schedule.component.js.map +0 -1
  108. package/dist/src/lib/A-Schedule/A-Schedule.types.d.ts +0 -10
  109. package/dist/src/lib/A-Schedule/A-Schedule.types.js +0 -3
  110. package/dist/src/lib/A-Schedule/A-Schedule.types.js.map +0 -1
  111. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.d.ts +0 -29
  112. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js +0 -58
  113. package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js.map +0 -1
  114. package/index.ts +0 -71
  115. package/src/lib/A-Polyfill/A-Polyfills.class.ts +0 -99
  116. 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
+ }
@@ -9,7 +9,7 @@ import { A_Polyfill } from '@adaas/a-utils/lib/A-Polyfill/A-Polyfill.component';
9
9
  import { A_ConfigLoader } from '@adaas/a-utils/lib/A-Config/A-Config.container';
10
10
  import { ENVConfigReader } from '@adaas/a-utils/lib/A-Config/components/ENVConfigReader.component';
11
11
  import { FileConfigReader } from '@adaas/a-utils/lib/A-Config/components/FileConfigReader.component';
12
- import { A_TYPES__ComponentMetaKey } from '@adaas/a-concept/dist/src/global/A-Component/A-Component.constants';
12
+ import { A_Logger } from '@adaas/a-utils/lib/A-Logger/A-Logger.component';
13
13
 
14
14
  jest.retryTimes(0);
15
15
 
@@ -51,7 +51,7 @@ describe('A-Config tests', () => {
51
51
  const configLoader = new A_ConfigLoader({
52
52
  name: 'test-config-loader',
53
53
  fragments: [config],
54
- components: [A_Polyfill, FileConfigReader, ENVConfigReader]
54
+ components: [A_Logger, A_Polyfill, FileConfigReader, ENVConfigReader]
55
55
  })
56
56
 
57
57
  const concept = new A_Concept({
@@ -81,7 +81,7 @@ describe('A-Config tests', () => {
81
81
  const configLoader = new A_ConfigLoader({
82
82
  name: 'test-config-loader',
83
83
  fragments: [config],
84
- components: [A_Polyfill, ENVConfigReader]
84
+ components: [A_Logger, A_Polyfill, ENVConfigReader]
85
85
  })
86
86
 
87
87
  const concept = new A_Concept({
@@ -130,7 +130,7 @@ describe('A-Config tests', () => {
130
130
  const configLoader = new A_ConfigLoader({
131
131
  name: 'test-config-loader',
132
132
  fragments: [config],
133
- components: [A_Polyfill, FileConfigReader]
133
+ components: [A_Logger,A_Polyfill, FileConfigReader]
134
134
  })
135
135
 
136
136
  const concept = new A_Concept({
@@ -163,7 +163,7 @@ describe('A-Config tests', () => {
163
163
  const configLoader = new A_ConfigLoader({
164
164
  name: 'test-config-loader',
165
165
  fragments: [config],
166
- components: [A_Polyfill, FileConfigReader]
166
+ components: [A_Logger,A_Polyfill, FileConfigReader]
167
167
  })
168
168
 
169
169
  const concept = new A_Concept({