@adaas/a-utils 0.1.27 → 0.1.28
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/dist/index.cjs +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +8 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/lib/A-Channel/A-Channel.component.ts +8 -3
- package/src/lib/A-Execution/A-Execution.context.ts +2 -2
- package/src/lib/A-Logger/A-Logger.component.ts +13 -8
- package/src/lib/A-Memory/A-Memory.component.ts +16 -6
- package/tests/A-Memory.test.ts +23 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaas/a-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.28",
|
|
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
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"build": "tsup --config tsup.config.ts"
|
|
81
81
|
},
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@adaas/a-concept": "^0.1.
|
|
83
|
+
"@adaas/a-concept": "^0.1.48"
|
|
84
84
|
},
|
|
85
85
|
"devDependencies": {
|
|
86
86
|
"@types/chai": "^4.3.14",
|
|
@@ -398,7 +398,8 @@ export class A_Channel extends A_Component {
|
|
|
398
398
|
// Create isolated scope for this request
|
|
399
399
|
const requestScope = new A_Scope({
|
|
400
400
|
name: `a-channel@scope:request:${A_IdentityHelper.generateTimeId()}`
|
|
401
|
-
})
|
|
401
|
+
})
|
|
402
|
+
.inherit(A_Context.scope(this));
|
|
402
403
|
|
|
403
404
|
// Create request context
|
|
404
405
|
const context = new A_ChannelRequest<_ParamsType, _ResultType>(params);
|
|
@@ -487,7 +488,9 @@ export class A_Channel extends A_Component {
|
|
|
487
488
|
// Create isolated scope for this send operation
|
|
488
489
|
const requestScope = new A_Scope({
|
|
489
490
|
name: `a-channel@scope:send:${A_IdentityHelper.generateTimeId()}`
|
|
490
|
-
})
|
|
491
|
+
})
|
|
492
|
+
.inherit(A_Context.scope(this));
|
|
493
|
+
|
|
491
494
|
|
|
492
495
|
// Create request context for the message
|
|
493
496
|
const context = new A_OperationContext('send', message);
|
|
@@ -533,7 +536,9 @@ export class A_Channel extends A_Component {
|
|
|
533
536
|
|
|
534
537
|
this._processing = true;
|
|
535
538
|
|
|
536
|
-
const requestScope = new A_Scope({ name: `a-channel@scope:consume:${A_IdentityHelper.generateTimeId()}` })
|
|
539
|
+
const requestScope = new A_Scope({ name: `a-channel@scope:consume:${A_IdentityHelper.generateTimeId()}` })
|
|
540
|
+
.inherit(A_Context.scope(this));
|
|
541
|
+
|
|
537
542
|
|
|
538
543
|
const context = new A_OperationContext('consume', {} as T);
|
|
539
544
|
|
|
@@ -33,11 +33,11 @@ export class A_ExecutionContext<
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
get(key:
|
|
36
|
+
get<K extends keyof _MetaType>(key: K): _MetaType[K] | undefined {
|
|
37
37
|
return this._meta.get(key);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
set(key:
|
|
40
|
+
set<K extends keyof _MetaType>(key: K, value: _MetaType[K]): void {
|
|
41
41
|
this._meta.set(key, value);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A_Component, A_Error, A_Inject, A_Scope } from "@adaas/a-concept";
|
|
1
|
+
import { A_Component, A_Context, A_Error, A_Inject, A_Scope } from "@adaas/a-concept";
|
|
2
2
|
import { A_Config } from "../A-Config/A-Config.context";
|
|
3
3
|
import { A_LoggerEnvVariablesType } from "./A-Logger.env";
|
|
4
4
|
import { A_LoggerLevel } from "./A-Logger.types";
|
|
@@ -111,15 +111,15 @@ export class A_Logger extends A_Component {
|
|
|
111
111
|
super();
|
|
112
112
|
this.COLORS = A_LOGGER_COLORS;
|
|
113
113
|
this.STANDARD_SCOPE_LENGTH = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_LENGTH) || A_LOGGER_DEFAULT_SCOPE_LENGTH;
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
// Get colors from config or generate deterministic colors based on scope name
|
|
116
116
|
const configScopeColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_SCOPE_COLOR) as keyof typeof A_LOGGER_COLORS;
|
|
117
117
|
const configLogColor = config?.get(A_LOGGER_ENV_KEYS.DEFAULT_LOG_COLOR) as keyof typeof A_LOGGER_COLORS;
|
|
118
|
-
|
|
118
|
+
|
|
119
119
|
if (configScopeColor || configLogColor) {
|
|
120
120
|
// If any color is configured, use config values or fallback to scope-based selection
|
|
121
121
|
this.DEFAULT_SCOPE_COLOR = configScopeColor || this.generateColorFromScopeName(this.scope.name);
|
|
122
|
-
this.DEFAULT_LOG_COLOR = configLogColor || this.generateColorFromScopeName(this.scope.name
|
|
122
|
+
this.DEFAULT_LOG_COLOR = configLogColor || this.generateColorFromScopeName(this.scope.name);
|
|
123
123
|
} else {
|
|
124
124
|
// If no colors configured, generate complementary pair based on scope name
|
|
125
125
|
const complementaryColors = this.generateComplementaryColorsFromScope(this.scope.name);
|
|
@@ -184,7 +184,7 @@ export class A_Logger extends A_Component {
|
|
|
184
184
|
{ scopeColor: 'cornflower' as const, logColor: 'powder' as const },
|
|
185
185
|
{ scopeColor: 'slate' as const, logColor: 'smoke' as const },
|
|
186
186
|
];
|
|
187
|
-
|
|
187
|
+
|
|
188
188
|
const hash = this.simpleHash(scopeName);
|
|
189
189
|
const pairIndex = hash % colorPairs.length;
|
|
190
190
|
return colorPairs[pairIndex];
|
|
@@ -219,17 +219,17 @@ export class A_Logger extends A_Component {
|
|
|
219
219
|
get formattedScope(): string {
|
|
220
220
|
const scopeName = this.scope.name;
|
|
221
221
|
const totalLength = this.STANDARD_SCOPE_LENGTH;
|
|
222
|
-
|
|
222
|
+
|
|
223
223
|
// If scope name is longer than standard length, truncate it
|
|
224
224
|
if (scopeName.length >= totalLength) {
|
|
225
225
|
return scopeName.substring(0, totalLength);
|
|
226
226
|
}
|
|
227
|
-
|
|
227
|
+
|
|
228
228
|
// Calculate padding for centering
|
|
229
229
|
const totalPadding = totalLength - scopeName.length;
|
|
230
230
|
const leftPadding = Math.floor(totalPadding / 2);
|
|
231
231
|
const rightPadding = totalPadding - leftPadding;
|
|
232
|
-
|
|
232
|
+
|
|
233
233
|
return ' '.repeat(leftPadding) + scopeName + ' '.repeat(rightPadding);
|
|
234
234
|
}
|
|
235
235
|
|
|
@@ -301,6 +301,11 @@ export class A_Logger extends A_Component {
|
|
|
301
301
|
* @returns Formatted object string
|
|
302
302
|
*/
|
|
303
303
|
private formatObject(obj: any, shouldAddNewline: boolean, scopePadding: string): string {
|
|
304
|
+
|
|
305
|
+
// in case it's browser, just return the object as is to use native console object rendering
|
|
306
|
+
if (A_Context.environment === 'browser')
|
|
307
|
+
return obj;
|
|
308
|
+
|
|
304
309
|
let jsonString: string;
|
|
305
310
|
try {
|
|
306
311
|
jsonString = JSON.stringify(obj, null, 2);
|
|
@@ -100,8 +100,12 @@ export class A_Memory<
|
|
|
100
100
|
@A_Dependency.Required()
|
|
101
101
|
@A_Inject(A_OperationContext) operation: A_MemoryOperationContext,
|
|
102
102
|
@A_Inject(A_MemoryContext) context: A_MemoryContext<_StorageType>,
|
|
103
|
+
@A_Inject(A_Scope) scope: A_Scope,
|
|
103
104
|
...args: any[]
|
|
104
105
|
): Promise<void> {
|
|
106
|
+
console.log('A_Memory onSet called with key:', scope.name);
|
|
107
|
+
console.log('A_Memory onSet called with key:', scope.parent?.name);
|
|
108
|
+
|
|
105
109
|
// Handle set operation
|
|
106
110
|
context.set(operation.params.key, operation.params.value);
|
|
107
111
|
}
|
|
@@ -222,7 +226,8 @@ export class A_Memory<
|
|
|
222
226
|
const scope = new A_Scope({
|
|
223
227
|
name: 'A-Memory-Get-Operation-Scope',
|
|
224
228
|
fragments: [operation]
|
|
225
|
-
})
|
|
229
|
+
})
|
|
230
|
+
.inherit(A_Context.scope(this));
|
|
226
231
|
|
|
227
232
|
try {
|
|
228
233
|
|
|
@@ -261,7 +266,8 @@ export class A_Memory<
|
|
|
261
266
|
const scope = new A_Scope({
|
|
262
267
|
name: 'A-Memory-Has-Operation-Scope',
|
|
263
268
|
fragments: [operation]
|
|
264
|
-
})
|
|
269
|
+
})
|
|
270
|
+
.inherit(A_Context.scope(this));
|
|
265
271
|
|
|
266
272
|
try {
|
|
267
273
|
|
|
@@ -309,7 +315,8 @@ export class A_Memory<
|
|
|
309
315
|
const scope = new A_Scope({
|
|
310
316
|
name: 'A-Memory-Set-Operation-Scope',
|
|
311
317
|
fragments: [operation]
|
|
312
|
-
})
|
|
318
|
+
})
|
|
319
|
+
.inherit(A_Context.scope(this));
|
|
313
320
|
|
|
314
321
|
try {
|
|
315
322
|
|
|
@@ -345,7 +352,8 @@ export class A_Memory<
|
|
|
345
352
|
const scope = new A_Scope({
|
|
346
353
|
name: 'A-Memory-Drop-Operation-Scope',
|
|
347
354
|
fragments: [operation]
|
|
348
|
-
})
|
|
355
|
+
})
|
|
356
|
+
.inherit(A_Context.scope(this));
|
|
349
357
|
|
|
350
358
|
try {
|
|
351
359
|
|
|
@@ -377,7 +385,8 @@ export class A_Memory<
|
|
|
377
385
|
const scope = new A_Scope({
|
|
378
386
|
name: 'A-Memory-Clear-Operation-Scope',
|
|
379
387
|
fragments: [operation]
|
|
380
|
-
})
|
|
388
|
+
})
|
|
389
|
+
.inherit(A_Context.scope(this));
|
|
381
390
|
|
|
382
391
|
try {
|
|
383
392
|
|
|
@@ -412,7 +421,8 @@ export class A_Memory<
|
|
|
412
421
|
const scope = new A_Scope({
|
|
413
422
|
name: 'A-Memory-Serialize-Operation-Scope',
|
|
414
423
|
fragments: [operation]
|
|
415
|
-
})
|
|
424
|
+
})
|
|
425
|
+
.inherit(A_Context.scope(this));
|
|
416
426
|
|
|
417
427
|
try {
|
|
418
428
|
|
package/tests/A-Memory.test.ts
CHANGED
|
@@ -17,29 +17,36 @@ describe('A-Memory tests', () => {
|
|
|
17
17
|
|
|
18
18
|
expect(memory).toBeInstanceOf(A_Memory);
|
|
19
19
|
expect(memory).toBeInstanceOf(A_Component);
|
|
20
|
-
|
|
20
|
+
|
|
21
21
|
// Test that memory can be initialized
|
|
22
22
|
await memory.ready;
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
it('Should allow to initialize and set initial values', async () => {
|
|
26
|
-
const memory = new A_Memory<{
|
|
27
|
-
key1: string;
|
|
28
|
-
key2: number;
|
|
29
|
-
key3: { nested: string };
|
|
30
|
-
}>();
|
|
31
|
-
A_Context.root.register(memory);
|
|
32
26
|
|
|
33
|
-
|
|
27
|
+
try {
|
|
34
28
|
|
|
35
|
-
// Set initial values after initialization
|
|
36
|
-
await memory.set('key1', 'value1');
|
|
37
|
-
await memory.set('key2', 42);
|
|
38
|
-
await memory.set('key3', { nested: 'object' });
|
|
39
29
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
const memory = new A_Memory<{
|
|
31
|
+
key1: string;
|
|
32
|
+
key2: number;
|
|
33
|
+
key3: { nested: string };
|
|
34
|
+
}>();
|
|
35
|
+
A_Context.root.register(memory);
|
|
36
|
+
|
|
37
|
+
await memory.ready;
|
|
38
|
+
|
|
39
|
+
// Set initial values after initialization
|
|
40
|
+
await memory.set('key1', 'value1');
|
|
41
|
+
await memory.set('key2', 42);
|
|
42
|
+
await memory.set('key3', { nested: 'object' });
|
|
43
|
+
|
|
44
|
+
expect(await memory.get('key1')).toBe('value1');
|
|
45
|
+
expect(await memory.get('key2')).toBe(42);
|
|
46
|
+
expect(await memory.get('key3')).toEqual({ nested: 'object' });
|
|
47
|
+
} catch (error) {
|
|
48
|
+
console.error('Error during memory initialization test:', error);
|
|
49
|
+
}
|
|
43
50
|
});
|
|
44
51
|
|
|
45
52
|
it('Should allow to set and get values', async () => {
|
|
@@ -161,7 +168,7 @@ describe('A-Memory tests', () => {
|
|
|
161
168
|
const memory = new A_Memory();
|
|
162
169
|
await A_Context.root.register(memory);
|
|
163
170
|
await memory.ready;
|
|
164
|
-
|
|
171
|
+
|
|
165
172
|
// Set some values
|
|
166
173
|
await memory.set('stringProp', 'test');
|
|
167
174
|
await memory.set('numberProp', 42);
|