@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.
- package/README.md +87 -32
- package/dist/index.d.mts +933 -0
- package/dist/index.d.ts +933 -27
- package/dist/index.js +1786 -90
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1764 -0
- package/dist/index.mjs.map +1 -0
- package/examples/command-examples.ts +268 -0
- package/package.json +5 -3
- package/src/index.ts +70 -0
- package/src/lib/A-Command/A-Command.constants.ts +4 -0
- package/src/lib/A-Command/A-Command.entity.ts +31 -13
- package/src/lib/A-Command/A-Command.types.ts +6 -1
- package/src/lib/A-Command/README.md +645 -0
- package/src/lib/A-Logger/A-Logger.component.ts +10 -3
- package/src/lib/A-Memory/A-Memory.context.ts +15 -0
- package/src/lib/A-Polyfill/A-Polyfill.component.ts +153 -15
- package/src/lib/A-Polyfill/A-Polyfill.types.ts +54 -0
- package/src/lib/A-Polyfill/classes/A-Buffer-Polyfill.class.ts +85 -0
- package/src/lib/A-Polyfill/classes/A-Crypto-Polyfill.class.ts +87 -0
- package/src/lib/A-Polyfill/classes/A-FS-Polyfill.class.ts +61 -0
- package/src/lib/A-Polyfill/classes/A-Http-Polyfill.class.ts +100 -0
- package/src/lib/A-Polyfill/classes/A-Https-Polyfill.class.ts +100 -0
- package/src/lib/A-Polyfill/classes/A-Path-Polyfill.class.ts +97 -0
- package/src/lib/A-Polyfill/classes/A-Process-Polyfill.class.ts +73 -0
- package/src/lib/A-Polyfill/classes/A-Url-Polyfill.class.ts +88 -0
- package/tests/A-Command.test.ts +447 -2
- package/tests/A-Config.test.ts +5 -5
- package/tests/A-Memory.test.ts +189 -0
- package/tests/A-Polyfill.test.ts +446 -29
- package/tsconfig.json +1 -1
- package/tsup.config.ts +15 -0
- package/dist/src/constants/errors.constants.d.ts +0 -0
- package/dist/src/constants/errors.constants.js +0 -2
- package/dist/src/constants/errors.constants.js.map +0 -1
- package/dist/src/lib/A-Channel/A-Channel.component.d.ts +0 -22
- package/dist/src/lib/A-Channel/A-Channel.component.js +0 -84
- package/dist/src/lib/A-Channel/A-Channel.component.js.map +0 -1
- package/dist/src/lib/A-Channel/A-Channel.error.d.ts +0 -4
- package/dist/src/lib/A-Channel/A-Channel.error.js +0 -9
- package/dist/src/lib/A-Channel/A-Channel.error.js.map +0 -1
- package/dist/src/lib/A-Channel/A-Channel.types.d.ts +0 -0
- package/dist/src/lib/A-Channel/A-Channel.types.js +0 -2
- package/dist/src/lib/A-Channel/A-Channel.types.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.constants.d.ts +0 -22
- package/dist/src/lib/A-Command/A-Command.constants.js +0 -28
- package/dist/src/lib/A-Command/A-Command.constants.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.entity.d.ts +0 -133
- package/dist/src/lib/A-Command/A-Command.entity.js +0 -273
- package/dist/src/lib/A-Command/A-Command.entity.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.error.d.ts +0 -3
- package/dist/src/lib/A-Command/A-Command.error.js +0 -8
- package/dist/src/lib/A-Command/A-Command.error.js.map +0 -1
- package/dist/src/lib/A-Command/A-Command.types.d.ts +0 -73
- package/dist/src/lib/A-Command/A-Command.types.js +0 -4
- package/dist/src/lib/A-Command/A-Command.types.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.constants.d.ts +0 -3
- package/dist/src/lib/A-Config/A-Config.constants.js +0 -6
- package/dist/src/lib/A-Config/A-Config.constants.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.container.d.ts +0 -6
- package/dist/src/lib/A-Config/A-Config.container.js +0 -77
- package/dist/src/lib/A-Config/A-Config.container.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.context.d.ts +0 -29
- package/dist/src/lib/A-Config/A-Config.context.js +0 -63
- package/dist/src/lib/A-Config/A-Config.context.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.error.d.ts +0 -4
- package/dist/src/lib/A-Config/A-Config.error.js +0 -9
- package/dist/src/lib/A-Config/A-Config.error.js.map +0 -1
- package/dist/src/lib/A-Config/A-Config.types.d.ts +0 -19
- package/dist/src/lib/A-Config/A-Config.types.js +0 -7
- package/dist/src/lib/A-Config/A-Config.types.js.map +0 -1
- package/dist/src/lib/A-Config/components/ConfigReader.component.d.ts +0 -30
- package/dist/src/lib/A-Config/components/ConfigReader.component.js +0 -103
- package/dist/src/lib/A-Config/components/ConfigReader.component.js.map +0 -1
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.d.ts +0 -14
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.js +0 -72
- package/dist/src/lib/A-Config/components/ENVConfigReader.component.js.map +0 -1
- package/dist/src/lib/A-Config/components/FileConfigReader.component.d.ts +0 -11
- package/dist/src/lib/A-Config/components/FileConfigReader.component.js +0 -47
- package/dist/src/lib/A-Config/components/FileConfigReader.component.js.map +0 -1
- package/dist/src/lib/A-Logger/A-Logger.component.d.ts +0 -29
- package/dist/src/lib/A-Logger/A-Logger.component.js +0 -152
- package/dist/src/lib/A-Logger/A-Logger.component.js.map +0 -1
- package/dist/src/lib/A-Logger/A-Logger.types.d.ts +0 -0
- package/dist/src/lib/A-Logger/A-Logger.types.js +0 -2
- package/dist/src/lib/A-Logger/A-Logger.types.js.map +0 -1
- package/dist/src/lib/A-Manifest/A-Manifest.context.d.ts +0 -52
- package/dist/src/lib/A-Manifest/A-Manifest.context.js +0 -154
- package/dist/src/lib/A-Manifest/A-Manifest.context.js.map +0 -1
- package/dist/src/lib/A-Manifest/A-Manifest.error.d.ts +0 -4
- package/dist/src/lib/A-Manifest/A-Manifest.error.js +0 -9
- package/dist/src/lib/A-Manifest/A-Manifest.error.js.map +0 -1
- package/dist/src/lib/A-Manifest/A-Manifest.types.d.ts +0 -43
- package/dist/src/lib/A-Manifest/A-Manifest.types.js +0 -3
- package/dist/src/lib/A-Manifest/A-Manifest.types.js.map +0 -1
- package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.d.ts +0 -14
- package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js +0 -24
- package/dist/src/lib/A-Manifest/classes/A-ManifestChecker.class.js.map +0 -1
- package/dist/src/lib/A-Memory/A-Memory.context.d.ts +0 -64
- package/dist/src/lib/A-Memory/A-Memory.context.js +0 -105
- package/dist/src/lib/A-Memory/A-Memory.context.js.map +0 -1
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.d.ts +0 -20
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.js +0 -53
- package/dist/src/lib/A-Polyfill/A-Polyfill.component.js.map +0 -1
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.d.ts +0 -9
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.js +0 -3
- package/dist/src/lib/A-Polyfill/A-Polyfill.types.js.map +0 -1
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.d.ts +0 -11
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.js +0 -123
- package/dist/src/lib/A-Polyfill/A-Polyfills.class.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-Deferred.class.d.ts +0 -12
- package/dist/src/lib/A-Schedule/A-Deferred.class.js +0 -23
- package/dist/src/lib/A-Schedule/A-Deferred.class.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-Schedule.component.d.ts +0 -57
- package/dist/src/lib/A-Schedule/A-Schedule.component.js +0 -49
- package/dist/src/lib/A-Schedule/A-Schedule.component.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-Schedule.types.d.ts +0 -10
- package/dist/src/lib/A-Schedule/A-Schedule.types.js +0 -3
- package/dist/src/lib/A-Schedule/A-Schedule.types.js.map +0 -1
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.d.ts +0 -29
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js +0 -58
- package/dist/src/lib/A-Schedule/A-ScheduleObject.class.js.map +0 -1
- package/index.ts +0 -71
- package/src/lib/A-Polyfill/A-Polyfills.class.ts +0 -99
- package/tsconfig.build.json +0 -56
package/README.md
CHANGED
|
@@ -59,45 +59,73 @@ const channel = new A_Channel();
|
|
|
59
59
|
|
|
60
60
|
### A-Command
|
|
61
61
|
|
|
62
|
-
A powerful command execution system that provides structured command patterns with lifecycle management, status tracking, and serialization capabilities.
|
|
62
|
+
A powerful command execution system that provides structured command patterns with lifecycle management, event handling, status tracking, and serialization capabilities.
|
|
63
63
|
|
|
64
|
-
**
|
|
64
|
+
> 📚 **[Complete A-Command Documentation](./src/lib/A-Command/README.md)** - Comprehensive guide with examples, API reference, and advanced usage patterns.
|
|
65
|
+
|
|
66
|
+
**Quick Start:**
|
|
65
67
|
```typescript
|
|
66
68
|
import { A_Command } from '@adaas/a-utils';
|
|
69
|
+
import { A_Context } from '@adaas/a-concept';
|
|
67
70
|
|
|
68
|
-
// Create a command
|
|
69
|
-
const command = new A_Command({});
|
|
71
|
+
// Create and execute a simple command
|
|
72
|
+
const command = new A_Command({ action: 'greet', name: 'World' });
|
|
73
|
+
A_Context.root.register(command);
|
|
70
74
|
|
|
71
|
-
// Execute the command
|
|
72
75
|
await command.execute();
|
|
73
76
|
|
|
74
77
|
console.log(command.status); // 'COMPLETED'
|
|
75
78
|
console.log(command.duration); // Execution time in ms
|
|
76
79
|
```
|
|
77
80
|
|
|
78
|
-
**Advanced
|
|
81
|
+
**Advanced Example:**
|
|
79
82
|
```typescript
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
// Typed command with custom logic
|
|
84
|
+
interface UserCreateParams {
|
|
85
|
+
name: string;
|
|
86
|
+
email: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
interface UserCreateResult {
|
|
90
|
+
userId: string;
|
|
91
|
+
createdAt: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
class CreateUserCommand extends A_Command<UserCreateParams, UserCreateResult> {}
|
|
95
|
+
|
|
96
|
+
// Custom execution logic using components
|
|
97
|
+
class UserProcessor extends A_Component {
|
|
98
|
+
@A_Feature.Extend({ scope: [CreateUserCommand] })
|
|
99
|
+
async execute(@A_Inject(A_Memory) memory: A_Memory<UserCreateResult>) {
|
|
100
|
+
// Your business logic here
|
|
101
|
+
await memory.set('userId', 'user-123');
|
|
102
|
+
await memory.set('createdAt', new Date().toISOString());
|
|
85
103
|
}
|
|
86
104
|
}
|
|
87
105
|
|
|
88
|
-
//
|
|
89
|
-
const command = new
|
|
90
|
-
|
|
106
|
+
// Execute with event handling
|
|
107
|
+
const command = new CreateUserCommand({
|
|
108
|
+
name: 'John Doe',
|
|
109
|
+
email: 'john@example.com'
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
command.on('complete', (cmd) => {
|
|
113
|
+
console.log('User created:', cmd.result);
|
|
114
|
+
});
|
|
91
115
|
|
|
92
|
-
|
|
93
|
-
|
|
116
|
+
A_Context.root.register(UserProcessor);
|
|
117
|
+
A_Context.root.register(command);
|
|
118
|
+
await command.execute();
|
|
94
119
|
```
|
|
95
120
|
|
|
96
|
-
**Features:**
|
|
97
|
-
-
|
|
98
|
-
-
|
|
99
|
-
-
|
|
100
|
-
-
|
|
121
|
+
**Key Features:**
|
|
122
|
+
- ✅ **Complete Lifecycle Management** - Automatic progression through init → compile → execute → complete/fail
|
|
123
|
+
- ✅ **Event-Driven Architecture** - Subscribe to lifecycle events and custom events
|
|
124
|
+
- ✅ **State Persistence** - Full serialization/deserialization support
|
|
125
|
+
- ✅ **Type Safety** - Full TypeScript support with generic types
|
|
126
|
+
- ✅ **Error Handling** - Comprehensive error capture and management
|
|
127
|
+
- ✅ **Execution Tracking** - Built-in timing and duration tracking
|
|
128
|
+
- ✅ **Component Integration** - Extensible through A-Component architecture
|
|
101
129
|
- Scope integration with dependency injection
|
|
102
130
|
- Memory management integration
|
|
103
131
|
|
|
@@ -284,13 +312,15 @@ const manifest = new A_Manifest([
|
|
|
284
312
|
|
|
285
313
|
### A-Memory
|
|
286
314
|
|
|
287
|
-
A type-safe memory management system for storing intermediate values and tracking errors during complex operations.
|
|
315
|
+
A type-safe memory management system for storing intermediate values and tracking errors during complex operations. Fully integrated with A-Command for state management.
|
|
316
|
+
|
|
317
|
+
> 💡 **Note:** A-Memory is automatically used by A-Command for result and error storage. See [A-Command Documentation](./src/lib/A-Command/README.md) for integration examples.
|
|
288
318
|
|
|
289
319
|
**Basic Usage:**
|
|
290
320
|
```typescript
|
|
291
321
|
import { A_Memory } from '@adaas/a-utils';
|
|
292
322
|
|
|
293
|
-
// Create memory instance
|
|
323
|
+
// Create typed memory instance
|
|
294
324
|
const memory = new A_Memory<{
|
|
295
325
|
userId: string;
|
|
296
326
|
userData: any;
|
|
@@ -299,16 +329,19 @@ const memory = new A_Memory<{
|
|
|
299
329
|
userId: '12345'
|
|
300
330
|
});
|
|
301
331
|
|
|
302
|
-
// Store values
|
|
303
|
-
memory.set('userData', { name: 'John', email: 'john@example.com' });
|
|
304
|
-
memory.set('processedData', processUserData(memory.get('userData')));
|
|
332
|
+
// Store and retrieve values
|
|
333
|
+
await memory.set('userData', { name: 'John', email: 'john@example.com' });
|
|
334
|
+
await memory.set('processedData', processUserData(memory.get('userData')));
|
|
335
|
+
|
|
336
|
+
// Access values with type safety
|
|
337
|
+
const userId = memory.get('userId'); // string | undefined
|
|
338
|
+
const userData = memory.get('userData'); // any | undefined
|
|
305
339
|
|
|
306
340
|
// Check prerequisites
|
|
307
341
|
const hasRequired = await memory.verifyPrerequisites(['userId', 'userData']);
|
|
308
342
|
console.log(hasRequired); // true
|
|
309
343
|
|
|
310
|
-
//
|
|
311
|
-
const userId = memory.get('userId');
|
|
344
|
+
// Serialize all data
|
|
312
345
|
const allData = memory.toJSON();
|
|
313
346
|
```
|
|
314
347
|
|
|
@@ -318,20 +351,42 @@ import { A_Error } from '@adaas/a-concept';
|
|
|
318
351
|
|
|
319
352
|
const memory = new A_Memory();
|
|
320
353
|
|
|
321
|
-
//
|
|
354
|
+
// Add errors during processing
|
|
322
355
|
try {
|
|
323
356
|
// Some operation that might fail
|
|
324
|
-
throw new
|
|
357
|
+
throw new Error('Something went wrong');
|
|
325
358
|
} catch (error) {
|
|
326
|
-
memory.
|
|
359
|
+
await memory.error(new A_Error({
|
|
360
|
+
title: 'Operation Failed',
|
|
361
|
+
message: error.message
|
|
362
|
+
}));
|
|
327
363
|
}
|
|
328
364
|
|
|
329
365
|
// Check for errors
|
|
330
366
|
if (memory.Errors) {
|
|
331
|
-
console.log('Errors occurred:', memory.Errors);
|
|
367
|
+
console.log('Errors occurred:', Array.from(memory.Errors));
|
|
332
368
|
}
|
|
333
369
|
```
|
|
334
370
|
|
|
371
|
+
**Integration with A-Command:**
|
|
372
|
+
```typescript
|
|
373
|
+
// A-Memory is automatically used by A-Command
|
|
374
|
+
class DataProcessor extends A_Component {
|
|
375
|
+
@A_Feature.Extend({ scope: [MyCommand] })
|
|
376
|
+
async execute(@A_Inject(A_Memory) memory: A_Memory<ResultType>) {
|
|
377
|
+
// Store intermediate results
|
|
378
|
+
await memory.set('step1', 'completed');
|
|
379
|
+
await memory.set('step2', { data: 'processed' });
|
|
380
|
+
|
|
381
|
+
// Access stored values
|
|
382
|
+
const step1Result = memory.get('step1');
|
|
383
|
+
|
|
384
|
+
// Results automatically become command.result
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
```
|
|
388
|
+
```
|
|
389
|
+
|
|
335
390
|
**Features:**
|
|
336
391
|
- Type-safe value storage
|
|
337
392
|
- Prerequisite verification
|