@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
@@ -1,67 +1,484 @@
1
1
  import './jest.setup';
2
- import { A_Scope } from '@adaas/a-concept';
2
+ import { A_Context, A_Scope } from '@adaas/a-concept';
3
+ import { A_Logger } from '@adaas/a-utils/lib/A-Logger/A-Logger.component';
3
4
  import { A_Polyfill } from '@adaas/a-utils/lib/A-Polyfill/A-Polyfill.component';
4
5
  import { config } from 'dotenv';
5
6
  config();
6
7
  jest.retryTimes(0);
7
8
 
8
9
  describe('A-Polyfill Tests', () => {
9
- it('It Should allow to create A-polyfill component', async () => {
10
- const testScope = new A_Scope({
11
- components: [A_Polyfill]
10
+ let testScope: A_Scope;
11
+ let polyfill: A_Polyfill;
12
+
13
+ beforeEach(async () => {
14
+ testScope = new A_Scope({
15
+ components: [A_Polyfill, A_Logger],
12
16
  });
17
+ polyfill = testScope.resolve(A_Polyfill);
18
+ await polyfill.load();
19
+ });
13
20
 
14
- const polyfill = testScope.resolve(A_Polyfill);
21
+ describe('Basic Component Tests', () => {
22
+ it('Should create A-polyfill component', async () => {
23
+ expect(polyfill).toBeInstanceOf(A_Polyfill);
24
+ });
15
25
 
16
- await polyfill.load();
26
+ it('Should detect environment correctly', () => {
27
+ const env = A_Context.environment;
28
+ expect(env).toMatch(/^(server|browser)$/);
29
+ expect(env).toBe('server');
30
+ });
31
+ });
17
32
 
18
- expect(polyfill).toBeInstanceOf(A_Polyfill);
33
+ describe('FS Polyfill Tests', () => {
34
+ it('Should return fs polyfill', async () => {
35
+ const fs = await polyfill.fs();
36
+ expect(fs).toBeDefined();
37
+ expect(fs.readFileSync).toBeDefined();
38
+ expect(fs.existsSync).toBeDefined();
39
+ expect(fs.createReadStream).toBeDefined();
40
+ });
41
+
42
+ it('Should check if file exists', async () => {
43
+ const fs = await polyfill.fs();
44
+ const exists = fs.existsSync('./package.json');
45
+ expect(typeof exists).toBe('boolean');
46
+ expect(exists).toBe(true); // package.json should exist
47
+ });
19
48
 
49
+ it('Should read file content', async () => {
50
+ const fs = await polyfill.fs();
51
+ const content = fs.readFileSync('./package.json', 'utf8');
52
+ expect(typeof content).toBe('string');
53
+ expect(content.length).toBeGreaterThan(0);
54
+ });
20
55
  });
21
56
 
22
- it('It Should return fs', async () => {
57
+ describe('Crypto Polyfill Tests', () => {
58
+ it('Should return crypto polyfill', async () => {
59
+ const crypto = await polyfill.crypto();
60
+ expect(crypto).toBeDefined();
61
+ expect(crypto.createTextHash).toBeDefined();
62
+ expect(crypto.createFileHash).toBeDefined();
63
+ });
23
64
 
24
- const testScope = new A_Scope({
25
- components: [A_Polyfill]
65
+ it('Should create text hash', async () => {
66
+ const crypto = await polyfill.crypto();
67
+ const hash = await crypto.createTextHash('test content', 'sha256');
68
+ expect(hash).toBeDefined();
69
+ expect(typeof hash).toBe('string');
70
+ expect(hash).toContain('sha256-');
26
71
  });
27
72
 
28
- const polyfill = testScope.resolve(A_Polyfill);
29
- await polyfill.load();
73
+ it('Should create file hash', async () => {
74
+ const crypto = await polyfill.crypto();
75
+ const hash = await crypto.createFileHash('./package.json', 'sha256');
76
+ expect(hash).toBeDefined();
77
+ expect(typeof hash).toBe('string');
78
+ expect(hash).toContain('sha256-');
79
+ });
80
+
81
+ it('Should create consistent hashes for same content', async () => {
82
+ const crypto = await polyfill.crypto();
83
+ const hash1 = await crypto.createTextHash('test', 'sha256');
84
+ const hash2 = await crypto.createTextHash('test', 'sha256');
85
+ expect(hash1).toBe(hash2);
86
+ });
87
+ });
88
+
89
+ describe('HTTP Polyfill Tests', () => {
90
+ it('Should return http polyfill', async () => {
91
+ const http = await polyfill.http();
92
+ expect(http).toBeDefined();
93
+ expect(http.request).toBeDefined();
94
+ expect(http.get).toBeDefined();
95
+ expect(http.createServer).toBeDefined();
96
+ });
97
+
98
+ it('Should create http request object', async () => {
99
+ const http = await polyfill.http();
100
+
101
+ let req;
102
+
103
+ const response = await new Promise((resolve, reject) => {
104
+ req = http.request(
105
+ {
106
+ hostname: "jsonplaceholder.typicode.com",
107
+ path: "/posts/1",
108
+ method: "GET",
109
+ port: 80,
110
+ },
111
+ (res) => {
112
+ let data = "";
113
+
114
+ // Collect response chunks
115
+ res.on("data", (chunk) => {
116
+ data += chunk;
117
+ });
118
+
119
+ // When finished, resolve promise
120
+ res.on("end", () => {
121
+ try {
122
+ resolve(data);
123
+ } catch (err) {
124
+ reject(err);
125
+ }
126
+ });
127
+ }
128
+ );
129
+
130
+ req.on('error', (err) => {
131
+ reject(err);
132
+ });
30
133
 
31
- const fs = await polyfill.fs();
134
+ // Important: send the request
135
+ req.end();
136
+ });
32
137
 
33
- expect(fs).toBeDefined();
138
+ // Parse and validate response
139
+ const json = JSON.parse(response as string);
140
+
141
+ expect(json).toBeDefined();
142
+ expect(json).toHaveProperty("id", 1);
143
+ expect(typeof json.title).toBe("string");
144
+
145
+ expect(req).toBeDefined();
146
+ expect(req.end).toBeDefined();
147
+ expect(req.write).toBeDefined();
148
+ expect(req.on).toBeDefined();
149
+ // Don't actually make the request in tests
150
+ });
34
151
  });
35
- it('It Should return crypto', async () => {
36
152
 
37
- const testScope = new A_Scope({
38
- components: [A_Polyfill]
153
+ describe('HTTPS Polyfill Tests', () => {
154
+ it('Should return https polyfill', async () => {
155
+ const https = await polyfill.https();
156
+ expect(https).toBeDefined();
157
+ expect(https.request).toBeDefined();
158
+ expect(https.get).toBeDefined();
159
+ expect(https.createServer).toBeDefined();
39
160
  });
40
161
 
41
- const polyfill = testScope.resolve(A_Polyfill);
42
- await polyfill.load();
162
+ it('Should create https request object', async () => {
163
+ const https = await polyfill.https();
164
+ let req;
165
+
166
+ const response = await new Promise((resolve, reject) => {
167
+ req = https.request(
168
+ {
169
+ hostname: "jsonplaceholder.typicode.com",
170
+ path: "/posts/1",
171
+ method: "GET",
172
+ },
173
+ (res) => {
174
+ let data = "";
175
+
176
+ // Collect response chunks
177
+ res.on("data", (chunk) => {
178
+ data += chunk;
179
+ });
180
+
181
+ // When finished, resolve promise
182
+ res.on("end", () => {
183
+ try {
184
+ resolve(data);
185
+ } catch (err) {
186
+ reject(err);
187
+ }
188
+ });
189
+ }
190
+ );
43
191
 
44
- const crypto = await polyfill.crypto();
192
+ req.on('error', (err) => {
193
+ reject(err);
194
+ });
45
195
 
46
- expect(crypto).toBeDefined();
196
+ // Important: send the request
197
+ req.end();
198
+ });
199
+
200
+ // Parse and validate response
201
+ const json = JSON.parse(response as string);
202
+
203
+ expect(json).toBeDefined();
204
+ expect(json).toHaveProperty("id", 1);
205
+ expect(typeof json.title).toBe("string");
206
+
207
+ expect(req).toBeDefined();
208
+ expect(req.end).toBeDefined();
209
+ expect(req.write).toBeDefined();
210
+ expect(req.on).toBeDefined();
211
+ });
47
212
  });
48
213
 
49
- it('Crypto should calculate Hash', async () => {
214
+ describe('Path Polyfill Tests', () => {
215
+ it('Should return path polyfill', async () => {
216
+ const path = await polyfill.path();
217
+ expect(path).toBeDefined();
218
+ expect(path.join).toBeDefined();
219
+ expect(path.resolve).toBeDefined();
220
+ expect(path.dirname).toBeDefined();
221
+ expect(path.basename).toBeDefined();
222
+ expect(path.extname).toBeDefined();
223
+ });
50
224
 
51
- const testScope = new A_Scope({
52
- components: [A_Polyfill]
225
+ it('Should join paths correctly', async () => {
226
+ const path = await polyfill.path();
227
+ const joined = path.join('/', 'home', 'user', 'file.txt');
228
+ expect(joined).toBe('/home/user/file.txt');
53
229
  });
54
230
 
55
- const polyfill = testScope.resolve(A_Polyfill);
56
- await polyfill.load();
231
+ it('Should get dirname correctly', async () => {
232
+ const path = await polyfill.path();
233
+ const dir = path.dirname('/home/user/file.txt');
234
+ expect(dir).toBe('/home/user');
235
+ });
57
236
 
58
- const crypto = await polyfill.crypto();
237
+ it('Should get basename correctly', async () => {
238
+ const path = await polyfill.path();
239
+ const base = path.basename('/home/user/file.txt');
240
+ expect(base).toBe('file.txt');
241
+ });
59
242
 
60
- const hash = await crypto.createFileHash('./index.ts', 'sha-256');
243
+ it('Should get extension correctly', async () => {
244
+ const path = await polyfill.path();
245
+ const ext = path.extname('/home/user/file.txt');
246
+ expect(ext).toBe('.txt');
247
+ });
61
248
 
62
- expect(hash).toBeDefined();
249
+ it('Should check if path is absolute', async () => {
250
+ const path = await polyfill.path();
251
+ expect(path.isAbsolute('/home/user')).toBe(true);
252
+ expect(path.isAbsolute('relative/path')).toBe(false);
253
+ });
63
254
 
255
+ it('Should parse path correctly', async () => {
256
+ const path = await polyfill.path();
257
+ const parsed = path.parse('/home/user/file.txt');
258
+ expect(parsed.dir).toBe('/home/user');
259
+ expect(parsed.base).toBe('file.txt');
260
+ expect(parsed.ext).toBe('.txt');
261
+ expect(parsed.name).toBe('file');
262
+ });
64
263
  });
65
264
 
265
+ describe('URL Polyfill Tests', () => {
266
+ it('Should return url polyfill', async () => {
267
+ const url = await polyfill.url();
268
+ expect(url).toBeDefined();
269
+ expect(url.parse).toBeDefined();
270
+ expect(url.format).toBeDefined();
271
+ expect(url.resolve).toBeDefined();
272
+ expect(url.URL).toBeDefined();
273
+ expect(url.URLSearchParams).toBeDefined();
274
+ });
275
+
276
+ it('Should parse URL correctly', async () => {
277
+ const url = await polyfill.url();
278
+ const parsed = url.parse('https://example.com:8080/path?query=value#fragment');
279
+ expect(parsed.protocol).toBe('https:');
280
+ expect(parsed.hostname).toBe('example.com');
281
+ expect(parsed.port).toBe('8080');
282
+ expect(parsed.pathname).toBe('/path');
283
+ });
284
+
285
+ it('Should resolve URLs correctly', async () => {
286
+ const url = await polyfill.url();
287
+ const resolved = url.resolve('https://example.com/path/', 'file.html');
288
+ expect(resolved).toBe('https://example.com/path/file.html');
289
+ });
66
290
 
291
+ it('Should work with URL constructor', async () => {
292
+ const url = await polyfill.url();
293
+ const urlObj = new url.URL('https://example.com/path');
294
+ expect(urlObj.hostname).toBe('example.com');
295
+ expect(urlObj.pathname).toBe('/path');
296
+ });
297
+ });
298
+
299
+ describe('Buffer Polyfill Tests', () => {
300
+ it('Should return buffer polyfill', async () => {
301
+ const buffer = await polyfill.buffer();
302
+ expect(buffer).toBeDefined();
303
+ expect(buffer.from).toBeDefined();
304
+ expect(buffer.alloc).toBeDefined();
305
+ expect(buffer.concat).toBeDefined();
306
+ expect(buffer.isBuffer).toBeDefined();
307
+ });
308
+
309
+ it('Should create buffer from string', async () => {
310
+ const buffer = await polyfill.buffer();
311
+ const buf = buffer.from('hello world', 'utf8');
312
+ expect(buf).toBeDefined();
313
+ expect(buf.length).toBeGreaterThan(0);
314
+ });
315
+
316
+ it('Should allocate buffer', async () => {
317
+ const buffer = await polyfill.buffer();
318
+ const buf = buffer.alloc(10);
319
+ expect(buf).toBeDefined();
320
+ expect(buf.length).toBe(10);
321
+ });
322
+
323
+ it('Should concatenate buffers', async () => {
324
+ const buffer = await polyfill.buffer();
325
+ const buf1 = buffer.from('hello ');
326
+ const buf2 = buffer.from('world');
327
+ const combined = buffer.concat([buf1, buf2]);
328
+ expect(combined).toBeDefined();
329
+ expect(combined.length).toBe(buf1.length + buf2.length);
330
+ });
331
+
332
+ it('Should identify buffers', async () => {
333
+ const buffer = await polyfill.buffer();
334
+ const buf = buffer.from('test');
335
+ expect(buffer.isBuffer(buf)).toBe(true);
336
+ expect(buffer.isBuffer('not a buffer')).toBe(false);
337
+ });
338
+ });
339
+
340
+ describe('Process Polyfill Tests', () => {
341
+ it('Should return process polyfill', async () => {
342
+ const process = await polyfill.process();
343
+ expect(process).toBeDefined();
344
+ expect(process.env).toBeDefined();
345
+ expect(process.argv).toBeDefined();
346
+ expect(process.platform).toBeDefined();
347
+ expect(process.version).toBeDefined();
348
+ expect(process.cwd).toBeDefined();
349
+ });
350
+
351
+ it('Should have environment variables', async () => {
352
+ const process = await polyfill.process();
353
+ expect(typeof process.env).toBe('object');
354
+ expect(process.env).not.toBeNull();
355
+ });
356
+
357
+ it('Should have argv array', async () => {
358
+ const process = await polyfill.process();
359
+ expect(Array.isArray(process.argv)).toBe(true);
360
+ });
361
+
362
+ it('Should have platform string', async () => {
363
+ const process = await polyfill.process();
364
+ expect(typeof process.platform).toBe('string');
365
+ });
366
+
367
+ it('Should have working cwd function', async () => {
368
+ const process = await polyfill.process();
369
+ const cwd = process.cwd();
370
+ expect(typeof cwd).toBe('string');
371
+ expect(cwd.length).toBeGreaterThan(0);
372
+ });
373
+
374
+ it('Should have nextTick function', async () => {
375
+ const process = await polyfill.process();
376
+ expect(typeof process.nextTick).toBe('function');
377
+
378
+ return new Promise<void>((resolve) => {
379
+ let called = false;
380
+ process.nextTick(() => {
381
+ called = true;
382
+ expect(called).toBe(true);
383
+ resolve();
384
+ });
385
+ });
386
+ });
387
+ });
388
+
389
+ describe('Integration Tests', () => {
390
+ it('Should work with all polyfills simultaneously', async () => {
391
+ const [fs, crypto, http, https, path, url, buffer, process] = await Promise.all([
392
+ polyfill.fs(),
393
+ polyfill.crypto(),
394
+ polyfill.http(),
395
+ polyfill.https(),
396
+ polyfill.path(),
397
+ polyfill.url(),
398
+ polyfill.buffer(),
399
+ polyfill.process()
400
+ ]);
401
+
402
+ expect(fs).toBeDefined();
403
+ expect(crypto).toBeDefined();
404
+ expect(http).toBeDefined();
405
+ expect(https).toBeDefined();
406
+ expect(path).toBeDefined();
407
+ expect(url).toBeDefined();
408
+ expect(buffer).toBeDefined();
409
+ expect(process).toBeDefined();
410
+ });
411
+
412
+ it('Should handle file operations with path utilities', async () => {
413
+ const fs = await polyfill.fs();
414
+ const path = await polyfill.path();
415
+
416
+ const filePath = path.join('.', 'package.json');
417
+ const exists = fs.existsSync(filePath);
418
+ expect(exists).toBe(true);
419
+
420
+ if (exists) {
421
+ const content = fs.readFileSync(filePath, 'utf8');
422
+ expect(content.length).toBeGreaterThan(0);
423
+ expect(content).toContain('"name"');
424
+ }
425
+ });
426
+
427
+ it('Should create hash of existing file using multiple polyfills', async () => {
428
+ // Create a fresh polyfill instance to avoid interference
429
+ const freshScope = new A_Scope({
430
+ components: [A_Polyfill, A_Logger]
431
+ });
432
+ const freshPolyfill = freshScope.resolve(A_Polyfill);
433
+
434
+ // Only initialize the needed polyfills
435
+ const crypto = await freshPolyfill.crypto();
436
+ const path = await freshPolyfill.path();
437
+ const fs = await freshPolyfill.fs();
438
+
439
+ const filePath = path.resolve('./package.json');
440
+
441
+
442
+ const exists = fs.existsSync(filePath);
443
+
444
+ if (exists) {
445
+ const hash = await crypto.createFileHash(filePath, 'sha256');
446
+ expect(hash).toBeDefined();
447
+ expect(hash).toContain('sha256-');
448
+ } else {
449
+ // If package.json doesn't exist, create a test with text hash instead
450
+ const hash = await crypto.createTextHash('test content', 'sha256');
451
+ expect(hash).toBeDefined();
452
+ expect(hash).toContain('sha256-');
453
+ }
454
+ });
455
+ });
456
+
457
+ describe('Error Handling Tests', () => {
458
+ it('Should handle non-existent file gracefully', async () => {
459
+ const fs = await polyfill.fs();
460
+ const exists = fs.existsSync('./non-existent-file.txt');
461
+ expect(exists).toBe(false);
462
+ });
463
+
464
+ it('Should handle invalid hash algorithms gracefully', async () => {
465
+ const crypto = await polyfill.crypto();
466
+
467
+ try {
468
+ await crypto.createTextHash('test', 'invalid-algorithm');
469
+ // If it doesn't throw, it should still return a string
470
+ } catch (error) {
471
+ // Error is expected for invalid algorithms
472
+ expect(error).toBeDefined();
473
+ }
474
+ });
475
+
476
+ it('Should handle malformed URLs gracefully', async () => {
477
+ const url = await polyfill.url();
478
+ const parsed = url.parse('not-a-valid-url');
479
+
480
+ // Should return an object even for invalid URLs
481
+ expect(typeof parsed).toBe('object');
482
+ });
483
+ });
67
484
  });
package/tsconfig.json CHANGED
@@ -49,7 +49,7 @@
49
49
  "tests/**/*",
50
50
  "examples/**/*",
51
51
  "examples/*",
52
- "index.ts"
52
+ "src/index.ts"
53
53
  ],
54
54
  "exclude": [
55
55
  "node_modules/**/*",
package/tsup.config.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { defineConfig } from "tsup";
2
+
3
+ export default defineConfig({
4
+ entry: ["src/index.ts"], // 👈 adjust if your main file is elsewhere
5
+ format: ["esm", "cjs"], // both Node (CJS) and ESM builds
6
+ dts: true, // generate declaration files
7
+ sourcemap: true, // helpful for debugging
8
+ clean: true, // clear dist/ before build
9
+ target: "es2020", // good for both Node 18+ and browsers
10
+ treeshake: true, // ✅ enable tree-shaking
11
+ skipNodeModulesBundle: true, // do NOT bundle node_modules (leave them external)
12
+ splitting: false, // one file per format (simpler)
13
+ minify: false, // optional: turn on if you want smaller bundle
14
+ platform: "neutral", // 👈 important: works in Node & browser
15
+ });
File without changes
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=errors.constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.constants.js","sourceRoot":"","sources":["../../../src/constants/errors.constants.ts"],"names":[],"mappings":""}
@@ -1,22 +0,0 @@
1
- import { A_Component } from "@adaas/a-concept";
2
- export declare class A_Channel extends A_Component {
3
- /**
4
- * Indicates whether the channel is processing requests
5
- */
6
- protected _processing: boolean;
7
- /**
8
- * Indicates whether the channel is connected
9
- */
10
- protected _initialized?: Promise<void>;
11
- /**
12
- * Indicates whether the channel is processing requests
13
- */
14
- get processing(): boolean;
15
- /**
16
- * Indicates whether the channel is connected
17
- */
18
- get initialize(): Promise<void>;
19
- connect(): Promise<void>;
20
- request(params: any): Promise<any>;
21
- send(message: any): Promise<void>;
22
- }
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.A_Channel = void 0;
19
- const a_concept_1 = require("@adaas/a-concept");
20
- const A_Channel_error_1 = require("./A-Channel.error");
21
- class A_Channel extends a_concept_1.A_Component {
22
- constructor() {
23
- super(...arguments);
24
- /**
25
- * Indicates whether the channel is processing requests
26
- */
27
- this._processing = false;
28
- }
29
- /**
30
- * Indicates whether the channel is processing requests
31
- */
32
- get processing() {
33
- return this._processing;
34
- }
35
- /**
36
- * Indicates whether the channel is connected
37
- */
38
- get initialize() {
39
- if (!this._initialized) {
40
- this._initialized = this.connect();
41
- }
42
- return this._initialized;
43
- }
44
- connect() {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- throw new A_Channel_error_1.A_ChannelError(A_Channel_error_1.A_ChannelError.MethodNotImplemented, `The connect method is not implemented in ${this.constructor.name} channel. This method is required to initialize the channel before use. So please implement it in the derived class.`);
47
- });
48
- }
49
- request(params) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- throw new A_Channel_error_1.A_ChannelError(A_Channel_error_1.A_ChannelError.MethodNotImplemented, `The request method is not implemented in ${this.constructor.name} channel.`);
52
- });
53
- }
54
- send(message) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- throw new A_Channel_error_1.A_ChannelError(A_Channel_error_1.A_ChannelError.MethodNotImplemented, `The send method is not implemented in ${this.constructor.name} channel.`);
57
- });
58
- }
59
- }
60
- exports.A_Channel = A_Channel;
61
- __decorate([
62
- a_concept_1.A_Feature.Define()
63
- /**
64
- * Initializes the channel before use
65
- */
66
- ], A_Channel.prototype, "connect", null);
67
- __decorate([
68
- a_concept_1.A_Feature.Define()
69
- /**
70
- * Allows to send a request through the channel
71
- *
72
- * @param req - The request parameters
73
- * @returns The response from the channel
74
- */
75
- ], A_Channel.prototype, "request", null);
76
- __decorate([
77
- a_concept_1.A_Feature.Define()
78
- /**
79
- * Uses for Fire-and-Forget messaging through the channel
80
- *
81
- * @param message - can be of any type depending on the channel implementation
82
- */
83
- ], A_Channel.prototype, "send", null);
84
- //# sourceMappingURL=A-Channel.component.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"A-Channel.component.js","sourceRoot":"","sources":["../../../../src/lib/A-Channel/A-Channel.component.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,gDAA0D;AAC1D,uDAAmD;AAInD,MAAa,SAAU,SAAQ,uBAAW;IAA1C;;QAEI;;WAEG;QACO,gBAAW,GAAY,KAAK,CAAC;IAgE3C,CAAC;IA1DG;;QAEI;IACJ,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IACD;;OAEG;IACH,IAAI,UAAU;QACV,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACrB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QACvC,CAAC;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IAOK,OAAO;;YACT,MAAM,IAAI,gCAAc,CACpB,gCAAc,CAAC,oBAAoB,EACnC,4CAA4C,IAAI,CAAC,WAAW,CAAC,IAAI,sHAAsH,CAC1L,CAAC;QACN,CAAC;KAAA;IAUK,OAAO,CAAC,MAAW;;YACrB,MAAM,IAAI,gCAAc,CACpB,gCAAc,CAAC,oBAAoB,EACnC,4CAA4C,IAAI,CAAC,WAAW,CAAC,IAAI,WAAW,CAC/E,CAAC;QACN,CAAC;KAAA;IAUK,IAAI,CAAC,OAAY;;YACnB,MAAM,IAAI,gCAAc,CACpB,gCAAc,CAAC,oBAAoB,EACnC,yCAAyC,IAAI,CAAC,WAAW,CAAC,IAAI,WAAW,CAC5E,CAAC;QACN,CAAC;KAAA;CAEJ;AArED,8BAqEC;AArCS;IAJL,qBAAS,CAAC,MAAM,EAAE;IACnB;;OAEG;wCAMF;AAUK;IAPL,qBAAS,CAAC,MAAM,EAAE;IACnB;;;;;OAKG;wCAMF;AAUK;IANL,qBAAS,CAAC,MAAM,EAAE;IACnB;;;;OAIG;qCAMF"}
@@ -1,4 +0,0 @@
1
- import { A_Error } from "@adaas/a-concept";
2
- export declare class A_ChannelError extends A_Error {
3
- static readonly MethodNotImplemented = "A-Channel Method Not Implemented";
4
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.A_ChannelError = void 0;
4
- const a_concept_1 = require("@adaas/a-concept");
5
- class A_ChannelError extends a_concept_1.A_Error {
6
- }
7
- exports.A_ChannelError = A_ChannelError;
8
- A_ChannelError.MethodNotImplemented = 'A-Channel Method Not Implemented';
9
- //# sourceMappingURL=A-Channel.error.js.map