@adaas/a-utils 0.1.14 → 0.1.16
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.
- package/README.md +92 -18
- package/dist/index.d.mts +335 -71
- package/dist/index.d.ts +335 -71
- package/dist/index.js +491 -210
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +489 -210
- package/dist/index.mjs.map +1 -1
- package/examples/{channel-examples.ts → A-Channel-examples.ts} +15 -15
- package/examples/{command-examples.ts → A-Command-examples.ts} +47 -45
- package/examples/A-Logger-examples.ts +308 -0
- package/examples/config.ts +1 -1
- package/package.json +26 -7
- package/src/index.ts +3 -1
- package/src/lib/A-Channel/A-Channel.component.ts +84 -17
- package/src/lib/A-Channel/A-Channel.error.ts +5 -5
- package/src/lib/A-Channel/A-ChannelRequest.context.ts +1 -1
- package/src/lib/A-Channel/README.md +24 -24
- package/src/lib/A-Command/A-Command.constants.ts +49 -13
- package/src/lib/A-Command/A-Command.entity.ts +21 -15
- package/src/lib/A-Command/A-Command.types.ts +2 -35
- package/src/lib/A-Config/A-Config.container.ts +3 -3
- package/src/lib/A-Config/components/ConfigReader.component.ts +4 -6
- package/src/lib/A-Logger/A-Logger.component.ts +369 -130
- package/src/lib/A-Logger/A-Logger.constants.ts +69 -0
- package/src/lib/A-Logger/A-Logger.env.ts +27 -0
- package/src/lib/A-Logger/A-Logger.types.ts +3 -0
- package/src/lib/A-Logger/README.md +383 -0
- package/src/lib/A-Manifest/A-Manifest.types.ts +1 -2
- package/src/lib/A-Memory/A-Memory.context.ts +1 -1
- package/tests/A-Channel.test.ts +14 -14
- package/tests/A-Command.test.ts +26 -26
- package/tests/A-Logger.test.ts +520 -0
- package/tests/A-Memory.test.ts +5 -5
- package/tests/A-Polyfill.test.ts +3 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.16",
|
|
4
4
|
"description": "A-Utils is a set of utilities that are used across the ADAAS ecosystem. This package is designed to be a collection of utilities that are used across the ADAAS ecosystem.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -27,7 +27,8 @@
|
|
|
27
27
|
"test": "jest ",
|
|
28
28
|
"start": "nodemon ./tests/log.ts",
|
|
29
29
|
"examples:config": "nodemon ./examples/config.ts",
|
|
30
|
-
"
|
|
30
|
+
"examples:logger": "nodemon ./examples/A-Logger-examples.ts",
|
|
31
|
+
"release": "npm run test && npm run build && git add . && git commit -m \"new version created :: $(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g')\" && npm version patch && npm publish --access public",
|
|
31
32
|
"preversion": "echo test",
|
|
32
33
|
"version": "echo git add .",
|
|
33
34
|
"postversion": "git push --no-verify && git push --tags --no-verify && echo \"\n======Version Pushed Successfully=====\n\" ",
|
|
@@ -36,21 +37,39 @@
|
|
|
36
37
|
},
|
|
37
38
|
"repository": {
|
|
38
39
|
"type": "git",
|
|
39
|
-
"url": "git+https://github.com/ADAAS-org/adaas-
|
|
40
|
+
"url": "git+https://github.com/ADAAS-org/adaas-a-utils.git"
|
|
40
41
|
},
|
|
41
42
|
"keywords": [
|
|
42
43
|
"sdk",
|
|
44
|
+
"utilities",
|
|
45
|
+
"typescript",
|
|
46
|
+
"nodejs",
|
|
47
|
+
"command-pattern",
|
|
48
|
+
"channel",
|
|
49
|
+
"configuration",
|
|
50
|
+
"logging",
|
|
51
|
+
"scheduling",
|
|
52
|
+
"memory-management",
|
|
53
|
+
"dependency-injection",
|
|
54
|
+
"component-architecture",
|
|
55
|
+
"adaas",
|
|
56
|
+
"ecosystem",
|
|
43
57
|
"ai",
|
|
44
|
-
"rag"
|
|
58
|
+
"rag",
|
|
59
|
+
"manifest",
|
|
60
|
+
"polyfill",
|
|
61
|
+
"async",
|
|
62
|
+
"lifecycle",
|
|
63
|
+
"error-handling"
|
|
45
64
|
],
|
|
46
65
|
"author": "adaas.org",
|
|
47
66
|
"license": "ISC",
|
|
48
67
|
"bugs": {
|
|
49
|
-
"url": "https://github.com/ADAAS-org/adaas-
|
|
68
|
+
"url": "https://github.com/ADAAS-org/adaas-a-utils/issues"
|
|
50
69
|
},
|
|
51
|
-
"homepage": "https://github.com/ADAAS-org/adaas-
|
|
70
|
+
"homepage": "https://github.com/ADAAS-org/adaas-a-utils#readme",
|
|
52
71
|
"dependencies": {
|
|
53
|
-
"@adaas/a-concept": "^0.1.
|
|
72
|
+
"@adaas/a-concept": "^0.1.28"
|
|
54
73
|
},
|
|
55
74
|
"devDependencies": {
|
|
56
75
|
"@types/chai": "^4.3.14",
|
package/src/index.ts
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// A-Channel Components
|
|
4
4
|
// ============================================================================
|
|
5
5
|
export { A_Channel } from './lib/A-Channel/A-Channel.component';
|
|
6
|
+
export { A_ChannelRequest } from './lib/A-Channel/A-ChannelRequest.context';
|
|
6
7
|
export { A_ChannelError } from './lib/A-Channel/A-Channel.error';
|
|
7
|
-
|
|
8
|
+
export * from './lib/A-Channel/A-Channel.types';
|
|
9
|
+
export * from './lib/A-Channel/A-Channel.constants';
|
|
8
10
|
|
|
9
11
|
|
|
10
12
|
// ============================================================================
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { A_Component, A_Context, A_Error, A_Feature, A_IdentityHelper, A_Inject, A_Scope, A_TYPES__InjectableConstructors, A_TYPES__InjectableTargets } from "@adaas/a-concept";
|
|
2
2
|
import { A_ChannelError } from "./A-Channel.error";
|
|
3
3
|
import { A_ChannelFeatures } from "./A-Channel.constants";
|
|
4
|
-
import {
|
|
4
|
+
import { A_ChannelRequest } from "./A-ChannelRequest.context";
|
|
5
|
+
import { A_Logger } from "../A-Logger/A-Logger.component";
|
|
6
|
+
import { A_Config } from "../A-Config/A-Config.context";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* A-Channel - A powerful, extensible communication channel component
|
|
@@ -37,7 +39,7 @@ import { A_ChannelRequestContext } from "./A-ChannelRequest.context";
|
|
|
37
39
|
* class HttpProcessor extends A_Component {
|
|
38
40
|
* @A_Feature.Extend({ scope: [HttpChannel] })
|
|
39
41
|
* async [A_ChannelFeatures.onRequest](
|
|
40
|
-
* @A_Inject(
|
|
42
|
+
* @A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
41
43
|
* ) {
|
|
42
44
|
* const response = await fetch(context.params.url);
|
|
43
45
|
* (context as any)._result = await response.json();
|
|
@@ -186,7 +188,7 @@ export class A_Channel extends A_Component {
|
|
|
186
188
|
* ```typescript
|
|
187
189
|
* @A_Feature.Extend({ scope: [HttpChannel] })
|
|
188
190
|
* async [A_ChannelFeatures.onBeforeRequest](
|
|
189
|
-
* @A_Inject(
|
|
191
|
+
* @A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
190
192
|
* ) {
|
|
191
193
|
* // Validate required parameters
|
|
192
194
|
* if (!context.params.url) {
|
|
@@ -218,7 +220,7 @@ export class A_Channel extends A_Component {
|
|
|
218
220
|
* ```typescript
|
|
219
221
|
* @A_Feature.Extend({ scope: [HttpChannel] })
|
|
220
222
|
* async [A_ChannelFeatures.onRequest](
|
|
221
|
-
* @A_Inject(
|
|
223
|
+
* @A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
222
224
|
* ) {
|
|
223
225
|
* const response = await fetch(context.params.url);
|
|
224
226
|
* (context as any)._result = await response.json();
|
|
@@ -247,7 +249,7 @@ export class A_Channel extends A_Component {
|
|
|
247
249
|
* ```typescript
|
|
248
250
|
* @A_Feature.Extend({ scope: [HttpChannel] })
|
|
249
251
|
* async [A_ChannelFeatures.onAfterRequest](
|
|
250
|
-
* @A_Inject(
|
|
252
|
+
* @A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
251
253
|
* ) {
|
|
252
254
|
* console.log(`Request completed in ${Date.now() - context.startTime}ms`);
|
|
253
255
|
* await this.cacheResponse(context.params, context.data);
|
|
@@ -276,7 +278,7 @@ export class A_Channel extends A_Component {
|
|
|
276
278
|
* ```typescript
|
|
277
279
|
* @A_Feature.Extend({ scope: [HttpChannel] })
|
|
278
280
|
* async [A_ChannelFeatures.onError](
|
|
279
|
-
* @A_Inject(
|
|
281
|
+
* @A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
280
282
|
* ) {
|
|
281
283
|
* console.error('Request failed:', context.params, context.failed);
|
|
282
284
|
* await this.logError(context);
|
|
@@ -305,7 +307,7 @@ export class A_Channel extends A_Component {
|
|
|
305
307
|
* ```typescript
|
|
306
308
|
* @A_Feature.Extend({ scope: [EventChannel] })
|
|
307
309
|
* async [A_ChannelFeatures.onSend](
|
|
308
|
-
* @A_Inject(
|
|
310
|
+
* @A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
309
311
|
* ) {
|
|
310
312
|
* const { eventType, payload } = context.params;
|
|
311
313
|
* await this.publishEvent(eventType, payload);
|
|
@@ -364,7 +366,7 @@ export class A_Channel extends A_Component {
|
|
|
364
366
|
* @template _ParamsType The type of request parameters
|
|
365
367
|
* @template _ResultType The type of response data
|
|
366
368
|
* @param params The request parameters
|
|
367
|
-
* @returns {Promise<
|
|
369
|
+
* @returns {Promise<A_ChannelRequest<_ParamsType, _ResultType>>} Request context with response
|
|
368
370
|
*
|
|
369
371
|
* @example
|
|
370
372
|
* ```typescript
|
|
@@ -387,7 +389,7 @@ export class A_Channel extends A_Component {
|
|
|
387
389
|
async request<
|
|
388
390
|
_ParamsType extends Record<string, any> = Record<string, any>,
|
|
389
391
|
_ResultType extends Record<string, any> = Record<string, any>,
|
|
390
|
-
>(params: _ParamsType): Promise<
|
|
392
|
+
>(params: _ParamsType): Promise<A_ChannelRequest<_ParamsType, _ResultType>> {
|
|
391
393
|
// Ensure channel is initialized before processing
|
|
392
394
|
await this.initialize;
|
|
393
395
|
|
|
@@ -395,12 +397,12 @@ export class A_Channel extends A_Component {
|
|
|
395
397
|
this._processing = true;
|
|
396
398
|
|
|
397
399
|
// Create isolated scope for this request
|
|
398
|
-
const requestScope = new A_Scope({
|
|
399
|
-
name: `a-channel@scope:request:${A_IdentityHelper.generateTimeId()}`
|
|
400
|
+
const requestScope = new A_Scope({
|
|
401
|
+
name: `a-channel@scope:request:${A_IdentityHelper.generateTimeId()}`
|
|
400
402
|
});
|
|
401
403
|
|
|
402
404
|
// Create request context
|
|
403
|
-
const context = new
|
|
405
|
+
const context = new A_ChannelRequest<_ParamsType, _ResultType>(params);
|
|
404
406
|
|
|
405
407
|
try {
|
|
406
408
|
// Set up dependency injection scope
|
|
@@ -481,12 +483,12 @@ export class A_Channel extends A_Component {
|
|
|
481
483
|
this._processing = true;
|
|
482
484
|
|
|
483
485
|
// Create isolated scope for this send operation
|
|
484
|
-
const requestScope = new A_Scope({
|
|
485
|
-
name: `a-channel@scope:send:${A_IdentityHelper.generateTimeId()}`
|
|
486
|
+
const requestScope = new A_Scope({
|
|
487
|
+
name: `a-channel@scope:send:${A_IdentityHelper.generateTimeId()}`
|
|
486
488
|
});
|
|
487
489
|
|
|
488
490
|
// Create request context for the message
|
|
489
|
-
const context = new
|
|
491
|
+
const context = new A_ChannelRequest<_ParamsType>(message);
|
|
490
492
|
|
|
491
493
|
try {
|
|
492
494
|
// Set up dependency injection scope
|
|
@@ -521,14 +523,14 @@ export class A_Channel extends A_Component {
|
|
|
521
523
|
* For fire-and-forget pattern: Use send()
|
|
522
524
|
* For consumer patterns: Implement custom consumer logic using request() in a loop
|
|
523
525
|
*/
|
|
524
|
-
async consume<T extends Record<string, any> = Record<string, any>>(): Promise<
|
|
526
|
+
async consume<T extends Record<string, any> = Record<string, any>>(): Promise<A_ChannelRequest<any, T>> {
|
|
525
527
|
await this.initialize;
|
|
526
528
|
|
|
527
529
|
this._processing = true;
|
|
528
530
|
|
|
529
531
|
const requestScope = new A_Scope({ name: `a-channel@scope:consume:${A_IdentityHelper.generateTimeId()}` });
|
|
530
532
|
|
|
531
|
-
const context = new
|
|
533
|
+
const context = new A_ChannelRequest<any, T>();
|
|
532
534
|
|
|
533
535
|
try {
|
|
534
536
|
requestScope.inherit(A_Context.scope(this));
|
|
@@ -555,4 +557,69 @@ export class A_Channel extends A_Component {
|
|
|
555
557
|
}
|
|
556
558
|
}
|
|
557
559
|
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
class HttpChannel extends A_Channel {
|
|
566
|
+
|
|
567
|
+
protected baseUrl!: string
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
class SSOChannel extends HttpChannel {
|
|
572
|
+
constructor() {
|
|
573
|
+
super();
|
|
574
|
+
|
|
575
|
+
this.baseUrl = 'https://sso.example.com';
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
class PrstChannel extends HttpChannel {
|
|
581
|
+
|
|
582
|
+
constructor() {
|
|
583
|
+
super();
|
|
584
|
+
|
|
585
|
+
this.baseUrl = 'https://prst.example.com';
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
class PollyspotChannel extends HttpChannel {
|
|
591
|
+
|
|
592
|
+
constructor() {
|
|
593
|
+
super();
|
|
594
|
+
|
|
595
|
+
this.baseUrl = 'https://pollyspot.example.com';
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
|
|
600
|
+
class GlobalErrorhandler extends A_Component {
|
|
601
|
+
|
|
602
|
+
@A_Feature.Extend({
|
|
603
|
+
name: A_ChannelFeatures.onError,
|
|
604
|
+
scope: [PollyspotChannel]
|
|
605
|
+
})
|
|
606
|
+
async handleError(
|
|
607
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest<any, any>,
|
|
608
|
+
@A_Inject(A_Logger) logger: A_Logger,
|
|
609
|
+
@A_Inject(A_Config) config: A_Config
|
|
610
|
+
) {
|
|
611
|
+
// Handle the error
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
@A_Feature.Extend({
|
|
615
|
+
name: A_ChannelFeatures.onError,
|
|
616
|
+
})
|
|
617
|
+
async anotherError(
|
|
618
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest<any, any>,
|
|
619
|
+
@A_Inject(A_Logger) logger: A_Logger,
|
|
620
|
+
@A_Inject(A_Config) config: A_Config
|
|
621
|
+
) {
|
|
622
|
+
// Handle the error
|
|
623
|
+
|
|
624
|
+
}
|
|
558
625
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A_Error, A_TypeGuards } from "@adaas/a-concept";
|
|
2
|
-
import {
|
|
2
|
+
import { A_ChannelRequest } from "./A-ChannelRequest.context";
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export class A_ChannelError extends A_Error {
|
|
@@ -15,7 +15,7 @@ export class A_ChannelError extends A_Error {
|
|
|
15
15
|
// ==================== Properties ==========================
|
|
16
16
|
// ==========================================================
|
|
17
17
|
|
|
18
|
-
protected _context?:
|
|
18
|
+
protected _context?: A_ChannelRequest
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -27,21 +27,21 @@ export class A_ChannelError extends A_Error {
|
|
|
27
27
|
*/
|
|
28
28
|
constructor(
|
|
29
29
|
originalError: string | A_Error | Error | any,
|
|
30
|
-
context?:
|
|
30
|
+
context?: A_ChannelRequest | string
|
|
31
31
|
) {
|
|
32
32
|
if (A_TypeGuards.isString(context))
|
|
33
33
|
super(originalError, context);
|
|
34
34
|
else
|
|
35
35
|
super(originalError);
|
|
36
36
|
|
|
37
|
-
if (context instanceof
|
|
37
|
+
if (context instanceof A_ChannelRequest)
|
|
38
38
|
this._context = context
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
/***
|
|
42
42
|
* Returns Context of the error
|
|
43
43
|
*/
|
|
44
|
-
get context():
|
|
44
|
+
get context(): A_ChannelRequest | undefined {
|
|
45
45
|
return this._context
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -3,7 +3,7 @@ import { A_ChannelRequestStatuses } from "./A-Channel.constants";
|
|
|
3
3
|
import { A_ChannelRequestContext_Serialized } from "./A-Channel.types";
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
export class
|
|
6
|
+
export class A_ChannelRequest<
|
|
7
7
|
_ParamsType extends Record<string, any> = Record<string, any>,
|
|
8
8
|
_ResultType extends Record<string, any> = Record<string, any>,
|
|
9
9
|
> extends A_Fragment {
|
|
@@ -91,7 +91,7 @@ console.log('Message sent successfully');
|
|
|
91
91
|
```typescript
|
|
92
92
|
import { A_Component, A_Feature, A_Inject } from '@adaas/a-concept';
|
|
93
93
|
import { A_ChannelFeatures } from '@adaas/a-utils/lib/A-Channel/A-Channel.constants';
|
|
94
|
-
import {
|
|
94
|
+
import { A_ChannelRequest } from '@adaas/a-utils/lib/A-Channel/A-ChannelRequest.context';
|
|
95
95
|
|
|
96
96
|
// Define typed interfaces
|
|
97
97
|
interface UserRequest {
|
|
@@ -121,7 +121,7 @@ class UserProcessor extends A_Component {
|
|
|
121
121
|
|
|
122
122
|
@A_Feature.Extend({ scope: [UserManagementChannel] })
|
|
123
123
|
async [A_ChannelFeatures.onBeforeRequest](
|
|
124
|
-
@A_Inject(
|
|
124
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest<UserRequest>
|
|
125
125
|
) {
|
|
126
126
|
// Validate request
|
|
127
127
|
const { action, userId } = context.params;
|
|
@@ -133,7 +133,7 @@ class UserProcessor extends A_Component {
|
|
|
133
133
|
|
|
134
134
|
@A_Feature.Extend({ scope: [UserManagementChannel] })
|
|
135
135
|
async [A_ChannelFeatures.onRequest](
|
|
136
|
-
@A_Inject(
|
|
136
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest<UserRequest, UserResponse>
|
|
137
137
|
) {
|
|
138
138
|
const { action, userId, userData } = context.params;
|
|
139
139
|
|
|
@@ -162,7 +162,7 @@ class UserProcessor extends A_Component {
|
|
|
162
162
|
|
|
163
163
|
@A_Feature.Extend({ scope: [UserManagementChannel] })
|
|
164
164
|
async [A_ChannelFeatures.onAfterRequest](
|
|
165
|
-
@A_Inject(
|
|
165
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest<UserRequest, UserResponse>
|
|
166
166
|
) {
|
|
167
167
|
// Log successful completion
|
|
168
168
|
console.log(`Request completed: ${context.data?.message}`);
|
|
@@ -170,7 +170,7 @@ class UserProcessor extends A_Component {
|
|
|
170
170
|
|
|
171
171
|
@A_Feature.Extend({ scope: [UserManagementChannel] })
|
|
172
172
|
async [A_ChannelFeatures.onError](
|
|
173
|
-
@A_Inject(
|
|
173
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest<UserRequest>
|
|
174
174
|
) {
|
|
175
175
|
console.error(`Request failed for action: ${context.params.action}`);
|
|
176
176
|
// Log error, send alerts, etc.
|
|
@@ -238,7 +238,7 @@ class RequestLifecycleProcessor extends A_Component {
|
|
|
238
238
|
|
|
239
239
|
@A_Feature.Extend({ scope: [LifecycleChannel] })
|
|
240
240
|
async [A_ChannelFeatures.onBeforeRequest](
|
|
241
|
-
@A_Inject(
|
|
241
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
242
242
|
) {
|
|
243
243
|
console.log('2. Pre-processing request...');
|
|
244
244
|
// Validate input, authenticate, rate limiting
|
|
@@ -246,7 +246,7 @@ class RequestLifecycleProcessor extends A_Component {
|
|
|
246
246
|
|
|
247
247
|
@A_Feature.Extend({ scope: [LifecycleChannel] })
|
|
248
248
|
async [A_ChannelFeatures.onRequest](
|
|
249
|
-
@A_Inject(
|
|
249
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
250
250
|
) {
|
|
251
251
|
console.log('3. Processing request...');
|
|
252
252
|
// Main business logic
|
|
@@ -254,7 +254,7 @@ class RequestLifecycleProcessor extends A_Component {
|
|
|
254
254
|
|
|
255
255
|
@A_Feature.Extend({ scope: [LifecycleChannel] })
|
|
256
256
|
async [A_ChannelFeatures.onAfterRequest](
|
|
257
|
-
@A_Inject(
|
|
257
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
258
258
|
) {
|
|
259
259
|
console.log('4. Post-processing request...');
|
|
260
260
|
// Logging, analytics, cleanup
|
|
@@ -262,7 +262,7 @@ class RequestLifecycleProcessor extends A_Component {
|
|
|
262
262
|
|
|
263
263
|
@A_Feature.Extend({ scope: [LifecycleChannel] })
|
|
264
264
|
async [A_ChannelFeatures.onError](
|
|
265
|
-
@A_Inject(
|
|
265
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
266
266
|
) {
|
|
267
267
|
console.log('5. Handling error...');
|
|
268
268
|
// Error logging, alerts, recovery
|
|
@@ -281,7 +281,7 @@ class APIProcessor extends A_Component {
|
|
|
281
281
|
|
|
282
282
|
@A_Feature.Extend({ scope: [APIChannel] })
|
|
283
283
|
async [A_ChannelFeatures.onRequest](
|
|
284
|
-
@A_Inject(
|
|
284
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
285
285
|
) {
|
|
286
286
|
const { endpoint, method, body } = context.params;
|
|
287
287
|
|
|
@@ -341,7 +341,7 @@ class EventBroadcaster extends A_Component {
|
|
|
341
341
|
|
|
342
342
|
@A_Feature.Extend({ scope: [EventChannel] })
|
|
343
343
|
async [A_ChannelFeatures.onSend](
|
|
344
|
-
@A_Inject(
|
|
344
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
345
345
|
) {
|
|
346
346
|
const { eventType, payload, recipients } = context.params;
|
|
347
347
|
|
|
@@ -378,7 +378,7 @@ class MessageQueue extends A_Component {
|
|
|
378
378
|
|
|
379
379
|
@A_Feature.Extend({ scope: [QueueChannel] })
|
|
380
380
|
async [A_ChannelFeatures.onSend](
|
|
381
|
-
@A_Inject(
|
|
381
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
382
382
|
) {
|
|
383
383
|
const message = {
|
|
384
384
|
id: Date.now(),
|
|
@@ -436,7 +436,7 @@ class ErrorHandler extends A_Component {
|
|
|
436
436
|
|
|
437
437
|
@A_Feature.Extend({ scope: [RobustChannel] })
|
|
438
438
|
async [A_ChannelFeatures.onRequest](
|
|
439
|
-
@A_Inject(
|
|
439
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
440
440
|
) {
|
|
441
441
|
const { operation } = context.params;
|
|
442
442
|
|
|
@@ -457,7 +457,7 @@ class ErrorHandler extends A_Component {
|
|
|
457
457
|
|
|
458
458
|
@A_Feature.Extend({ scope: [RobustChannel] })
|
|
459
459
|
async [A_ChannelFeatures.onError](
|
|
460
|
-
@A_Inject(
|
|
460
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
461
461
|
) {
|
|
462
462
|
console.log('Error details:', {
|
|
463
463
|
operation: context.params.operation,
|
|
@@ -517,7 +517,7 @@ class DatabaseProcessor extends A_Component {
|
|
|
517
517
|
|
|
518
518
|
@A_Feature.Extend({ scope: [DatabaseChannel] })
|
|
519
519
|
async [A_ChannelFeatures.onRequest](
|
|
520
|
-
@A_Inject(
|
|
520
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest<DatabaseQuery, DatabaseResult>
|
|
521
521
|
) {
|
|
522
522
|
const { table, operation, where, data } = context.params;
|
|
523
523
|
|
|
@@ -602,14 +602,14 @@ class MetricsCollector extends A_Component {
|
|
|
602
602
|
|
|
603
603
|
@A_Feature.Extend({ scope: [AdvancedChannel] })
|
|
604
604
|
async [A_ChannelFeatures.onBeforeRequest](
|
|
605
|
-
@A_Inject(
|
|
605
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
606
606
|
) {
|
|
607
607
|
(context as any)._startTime = Date.now();
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
@A_Feature.Extend({ scope: [AdvancedChannel] })
|
|
611
611
|
async [A_ChannelFeatures.onAfterRequest](
|
|
612
|
-
@A_Inject(
|
|
612
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
613
613
|
) {
|
|
614
614
|
const channel = A_Context.scope(this).resolve(AdvancedChannel);
|
|
615
615
|
const duration = Date.now() - (context as any)._startTime;
|
|
@@ -620,7 +620,7 @@ class MetricsCollector extends A_Component {
|
|
|
620
620
|
|
|
621
621
|
@A_Feature.Extend({ scope: [AdvancedChannel] })
|
|
622
622
|
async [A_ChannelFeatures.onError](
|
|
623
|
-
@A_Inject(
|
|
623
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
624
624
|
) {
|
|
625
625
|
const channel = A_Context.scope(this).resolve(AdvancedChannel);
|
|
626
626
|
channel['metrics'].errors++;
|
|
@@ -632,7 +632,7 @@ class CacheLayer extends A_Component {
|
|
|
632
632
|
|
|
633
633
|
@A_Feature.Extend({ scope: [AdvancedChannel] })
|
|
634
634
|
async [A_ChannelFeatures.onBeforeRequest](
|
|
635
|
-
@A_Inject(
|
|
635
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
636
636
|
) {
|
|
637
637
|
const cacheKey = JSON.stringify(context.params);
|
|
638
638
|
|
|
@@ -645,7 +645,7 @@ class CacheLayer extends A_Component {
|
|
|
645
645
|
|
|
646
646
|
@A_Feature.Extend({ scope: [AdvancedChannel] })
|
|
647
647
|
async [A_ChannelFeatures.onAfterRequest](
|
|
648
|
-
@A_Inject(
|
|
648
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
649
649
|
) {
|
|
650
650
|
if (!(context as any)._cached && context.data) {
|
|
651
651
|
const cacheKey = JSON.stringify(context.params);
|
|
@@ -685,7 +685,7 @@ console.log('Metrics:', advancedChannel.getMetrics());
|
|
|
685
685
|
- `async disconnect(): Promise<void>` - Cleanup and disconnect the channel
|
|
686
686
|
|
|
687
687
|
##### Communication
|
|
688
|
-
- `async request<T, R>(params: T): Promise<
|
|
688
|
+
- `async request<T, R>(params: T): Promise<A_ChannelRequest<T, R>>` - Send request and wait for response
|
|
689
689
|
- `async send<T>(message: T): Promise<void>` - Send fire-and-forget message
|
|
690
690
|
|
|
691
691
|
#### Lifecycle Hooks (Extensible via A_Feature)
|
|
@@ -697,7 +697,7 @@ console.log('Metrics:', advancedChannel.getMetrics());
|
|
|
697
697
|
- `onSend` - Called to process send operation
|
|
698
698
|
- `onError` - Called when any operation fails
|
|
699
699
|
|
|
700
|
-
###
|
|
700
|
+
### A_ChannelRequest Class
|
|
701
701
|
|
|
702
702
|
#### Properties
|
|
703
703
|
- `params: T` - Request parameters
|
|
@@ -750,7 +750,7 @@ class HttpChannel extends A_Channel {
|
|
|
750
750
|
class HttpProcessor extends A_Component {
|
|
751
751
|
@A_Feature.Extend({ scope: [HttpChannel] })
|
|
752
752
|
async [A_ChannelFeatures.onRequest](
|
|
753
|
-
@A_Inject(
|
|
753
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
754
754
|
) {
|
|
755
755
|
const { method, url, body, headers } = context.params;
|
|
756
756
|
|
|
@@ -818,7 +818,7 @@ class WebSocketProcessor extends A_Component {
|
|
|
818
818
|
|
|
819
819
|
@A_Feature.Extend({ scope: [WebSocketChannel] })
|
|
820
820
|
async [A_ChannelFeatures.onSend](
|
|
821
|
-
@A_Inject(
|
|
821
|
+
@A_Inject(A_ChannelRequest) context: A_ChannelRequest
|
|
822
822
|
) {
|
|
823
823
|
const channel = A_Context.scope(this).resolve(WebSocketChannel);
|
|
824
824
|
const message = JSON.stringify(context.params);
|
|
@@ -1,35 +1,71 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
ABSTRACTIONS = 'a-command-abstractions',
|
|
5
|
-
}
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A-Command Statuses
|
|
3
|
+
*/
|
|
7
4
|
export enum A_CONSTANTS__A_Command_Status {
|
|
5
|
+
/**
|
|
6
|
+
* Command has been created but not yet initialized
|
|
7
|
+
*/
|
|
8
8
|
CREATED = 'CREATED',
|
|
9
|
+
/**
|
|
10
|
+
* Command is initializing
|
|
11
|
+
*/
|
|
9
12
|
INITIALIZATION = 'INITIALIZATION',
|
|
13
|
+
/**
|
|
14
|
+
* Command has been initialized
|
|
15
|
+
*/
|
|
10
16
|
INITIALIZED = 'INITIALIZED',
|
|
17
|
+
/**
|
|
18
|
+
* Command is compiling
|
|
19
|
+
*/
|
|
11
20
|
COMPILATION = 'COMPILATION',
|
|
21
|
+
/**
|
|
22
|
+
* Command is compiled
|
|
23
|
+
*/
|
|
12
24
|
COMPILED = 'COMPILED',
|
|
25
|
+
/**
|
|
26
|
+
* Command is executing
|
|
27
|
+
*/
|
|
13
28
|
IN_PROGRESS = 'IN_PROGRESS',
|
|
29
|
+
/**
|
|
30
|
+
* Command has completed successfully
|
|
31
|
+
*/
|
|
14
32
|
COMPLETED = 'COMPLETED',
|
|
33
|
+
/**
|
|
34
|
+
* Command has failed
|
|
35
|
+
*/
|
|
15
36
|
FAILED = 'FAILED',
|
|
16
37
|
}
|
|
17
38
|
|
|
18
39
|
/**
|
|
19
40
|
* A-Command Lifecycle Features
|
|
20
41
|
*/
|
|
21
|
-
export enum
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
42
|
+
export enum A_CommandFeatures {
|
|
43
|
+
/**
|
|
44
|
+
* Allows to extend initialization logic and behavior
|
|
45
|
+
*/
|
|
46
|
+
onInit = 'onInit',
|
|
47
|
+
/**
|
|
48
|
+
* Allows to extend compilation logic and behavior
|
|
49
|
+
*/
|
|
50
|
+
onCompile = 'onCompile',
|
|
51
|
+
/**
|
|
52
|
+
* Allows to extend execution logic and behavior
|
|
53
|
+
*/
|
|
54
|
+
onExecute = 'onExecute',
|
|
55
|
+
/**
|
|
56
|
+
* Allows to extend completion logic and behavior
|
|
57
|
+
*/
|
|
58
|
+
onComplete = 'onComplete',
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
*/
|
|
62
|
+
onFail = 'onFail',
|
|
27
63
|
}
|
|
28
64
|
|
|
29
65
|
|
|
30
66
|
|
|
31
67
|
|
|
32
|
-
export type A_CONSTANTS__A_Command_Event =
|
|
68
|
+
export type A_CONSTANTS__A_Command_Event = keyof typeof A_CommandFeatures;
|
|
33
69
|
|
|
34
70
|
|
|
35
71
|
|