@venizia/ignis-docs 0.0.1-1
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/mcp-server/dist/common/config.d.ts +27 -0
- package/mcp-server/dist/common/config.d.ts.map +1 -0
- package/mcp-server/dist/common/config.js +27 -0
- package/mcp-server/dist/common/config.js.map +1 -0
- package/mcp-server/dist/common/index.d.ts +3 -0
- package/mcp-server/dist/common/index.d.ts.map +1 -0
- package/mcp-server/dist/common/index.js +19 -0
- package/mcp-server/dist/common/index.js.map +1 -0
- package/mcp-server/dist/common/paths.d.ts +13 -0
- package/mcp-server/dist/common/paths.d.ts.map +1 -0
- package/mcp-server/dist/common/paths.js +23 -0
- package/mcp-server/dist/common/paths.js.map +1 -0
- package/mcp-server/dist/helpers/docs.helper.d.ts +81 -0
- package/mcp-server/dist/helpers/docs.helper.d.ts.map +1 -0
- package/mcp-server/dist/helpers/docs.helper.js +171 -0
- package/mcp-server/dist/helpers/docs.helper.js.map +1 -0
- package/mcp-server/dist/helpers/index.d.ts +3 -0
- package/mcp-server/dist/helpers/index.d.ts.map +1 -0
- package/mcp-server/dist/helpers/index.js +19 -0
- package/mcp-server/dist/helpers/index.js.map +1 -0
- package/mcp-server/dist/helpers/logger.helper.d.ts +7 -0
- package/mcp-server/dist/helpers/logger.helper.d.ts.map +1 -0
- package/mcp-server/dist/helpers/logger.helper.js +22 -0
- package/mcp-server/dist/helpers/logger.helper.js.map +1 -0
- package/mcp-server/dist/index.d.ts +3 -0
- package/mcp-server/dist/index.d.ts.map +1 -0
- package/mcp-server/dist/index.js +62 -0
- package/mcp-server/dist/index.js.map +1 -0
- package/mcp-server/dist/tools/base.tool.d.ts +98 -0
- package/mcp-server/dist/tools/base.tool.d.ts.map +1 -0
- package/mcp-server/dist/tools/base.tool.js +47 -0
- package/mcp-server/dist/tools/base.tool.js.map +1 -0
- package/mcp-server/dist/tools/get-doc-content.tool.d.ts +30 -0
- package/mcp-server/dist/tools/get-doc-content.tool.d.ts.map +1 -0
- package/mcp-server/dist/tools/get-doc-content.tool.js +127 -0
- package/mcp-server/dist/tools/get-doc-content.tool.js.map +1 -0
- package/mcp-server/dist/tools/get-doc-metadata.tool.d.ts +40 -0
- package/mcp-server/dist/tools/get-doc-metadata.tool.d.ts.map +1 -0
- package/mcp-server/dist/tools/get-doc-metadata.tool.js +121 -0
- package/mcp-server/dist/tools/get-doc-metadata.tool.js.map +1 -0
- package/mcp-server/dist/tools/index.d.ts +8 -0
- package/mcp-server/dist/tools/index.d.ts.map +1 -0
- package/mcp-server/dist/tools/index.js +18 -0
- package/mcp-server/dist/tools/index.js.map +1 -0
- package/mcp-server/dist/tools/list-categories.tool.d.ts +20 -0
- package/mcp-server/dist/tools/list-categories.tool.d.ts.map +1 -0
- package/mcp-server/dist/tools/list-categories.tool.js +105 -0
- package/mcp-server/dist/tools/list-categories.tool.js.map +1 -0
- package/mcp-server/dist/tools/list-docs.tool.d.ts +32 -0
- package/mcp-server/dist/tools/list-docs.tool.d.ts.map +1 -0
- package/mcp-server/dist/tools/list-docs.tool.js +121 -0
- package/mcp-server/dist/tools/list-docs.tool.js.map +1 -0
- package/mcp-server/dist/tools/search-docs.tool.d.ts +32 -0
- package/mcp-server/dist/tools/search-docs.tool.d.ts.map +1 -0
- package/mcp-server/dist/tools/search-docs.tool.js +120 -0
- package/mcp-server/dist/tools/search-docs.tool.js.map +1 -0
- package/package.json +102 -0
- package/wiki/get-started/5-minute-quickstart.md +266 -0
- package/wiki/get-started/best-practices/api-usage-examples.md +222 -0
- package/wiki/get-started/best-practices/architectural-patterns.md +129 -0
- package/wiki/get-started/best-practices/code-style-standards.md +122 -0
- package/wiki/get-started/best-practices/common-pitfalls.md +136 -0
- package/wiki/get-started/best-practices/contribution-workflow.md +145 -0
- package/wiki/get-started/best-practices/deployment-strategies.md +121 -0
- package/wiki/get-started/best-practices/performance-optimization.md +88 -0
- package/wiki/get-started/best-practices/security-guidelines.md +97 -0
- package/wiki/get-started/best-practices/troubleshooting-tips.md +100 -0
- package/wiki/get-started/building-a-crud-api.md +717 -0
- package/wiki/get-started/core-concepts/application.md +168 -0
- package/wiki/get-started/core-concepts/components.md +96 -0
- package/wiki/get-started/core-concepts/controllers.md +441 -0
- package/wiki/get-started/core-concepts/dependency-injection.md +160 -0
- package/wiki/get-started/core-concepts/persistent.md +591 -0
- package/wiki/get-started/core-concepts/services.md +88 -0
- package/wiki/get-started/index.md +65 -0
- package/wiki/get-started/mcp-docs-server.md +840 -0
- package/wiki/get-started/philosophy.md +123 -0
- package/wiki/get-started/prerequisites.md +113 -0
- package/wiki/get-started/quickstart.md +382 -0
- package/wiki/index.md +48 -0
- package/wiki/references/base/application.md +67 -0
- package/wiki/references/base/components.md +80 -0
- package/wiki/references/base/controllers.md +361 -0
- package/wiki/references/base/datasources.md +105 -0
- package/wiki/references/base/dependency-injection.md +83 -0
- package/wiki/references/base/models.md +104 -0
- package/wiki/references/base/repositories.md +118 -0
- package/wiki/references/base/services.md +97 -0
- package/wiki/references/components/authentication.md +224 -0
- package/wiki/references/components/health-check.md +190 -0
- package/wiki/references/components/index.md +61 -0
- package/wiki/references/components/request-tracker.md +35 -0
- package/wiki/references/components/socket-io.md +127 -0
- package/wiki/references/components/swagger.md +175 -0
- package/wiki/references/helpers/cron.md +94 -0
- package/wiki/references/helpers/crypto.md +117 -0
- package/wiki/references/helpers/env.md +67 -0
- package/wiki/references/helpers/error.md +80 -0
- package/wiki/references/helpers/index.md +21 -0
- package/wiki/references/helpers/inversion.md +141 -0
- package/wiki/references/helpers/logger.md +98 -0
- package/wiki/references/helpers/network.md +143 -0
- package/wiki/references/helpers/queue.md +131 -0
- package/wiki/references/helpers/redis.md +121 -0
- package/wiki/references/helpers/socket-io.md +103 -0
- package/wiki/references/helpers/storage.md +130 -0
- package/wiki/references/helpers/testing.md +115 -0
- package/wiki/references/helpers/worker-thread.md +162 -0
- package/wiki/references/src-details/core.md +249 -0
- package/wiki/references/src-details/dev-configs.md +302 -0
- package/wiki/references/src-details/docs.md +61 -0
- package/wiki/references/src-details/helpers.md +211 -0
- package/wiki/references/src-details/inversion.md +345 -0
- package/wiki/references/src-details/mcp-server.md +726 -0
- package/wiki/references/utilities/crypto.md +39 -0
- package/wiki/references/utilities/date.md +72 -0
- package/wiki/references/utilities/index.md +12 -0
- package/wiki/references/utilities/module.md +40 -0
- package/wiki/references/utilities/parse.md +68 -0
- package/wiki/references/utilities/performance.md +64 -0
- package/wiki/references/utilities/promise.md +83 -0
- package/wiki/references/utilities/request.md +66 -0
- package/wiki/references/utilities/schema.md +88 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
# Crypto Helper
|
|
2
|
+
|
|
3
|
+
Cryptographic utilities for AES symmetric encryption, RSA asymmetric encryption, and hashing.
|
|
4
|
+
|
|
5
|
+
## Quick Reference
|
|
6
|
+
|
|
7
|
+
| Class/Function | Algorithm | Use Case |
|
|
8
|
+
|----------------|-----------|----------|
|
|
9
|
+
| **AES** | Symmetric | Fast encryption for data at rest (AES-256-CBC, AES-256-GCM) |
|
|
10
|
+
| **RSA** | Asymmetric | Key exchange, digital signatures (public/private keys) |
|
|
11
|
+
| **hash()** | MD5, SHA256 | Passwords, data integrity (HMAC support) |
|
|
12
|
+
|
|
13
|
+
### AES Algorithms
|
|
14
|
+
|
|
15
|
+
| Algorithm | Mode | Features |
|
|
16
|
+
|-----------|------|----------|
|
|
17
|
+
| `aes-256-cbc` | CBC | Standard block cipher mode |
|
|
18
|
+
| `aes-256-gcm` | GCM | Authenticated encryption |
|
|
19
|
+
|
|
20
|
+
### Common Methods
|
|
21
|
+
|
|
22
|
+
| Operation | AES | RSA |
|
|
23
|
+
|-----------|-----|-----|
|
|
24
|
+
| Encrypt | `aes.encrypt(message, secret)` | `rsa.encrypt(message, publicKey)` |
|
|
25
|
+
| Decrypt | `aes.decrypt(encrypted, secret)` | `rsa.decrypt(encrypted, privateKey)` |
|
|
26
|
+
| Key Generation | N/A (use secret) | `rsa.generateDERKeyPair()` |
|
|
27
|
+
|
|
28
|
+
## AES (Symmetric Encryption)
|
|
29
|
+
|
|
30
|
+
The `AES` class provides an interface for encrypting and decrypting data using the Advanced Encryption Standard.
|
|
31
|
+
|
|
32
|
+
### Creating an AES Instance
|
|
33
|
+
|
|
34
|
+
You can create an `AES` instance by specifying the algorithm (`aes-256-cbc` or `aes-256-gcm`).
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { AES } from '@venizia/ignis';
|
|
38
|
+
|
|
39
|
+
const aes = AES.withAlgorithm('aes-256-cbc');
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Encrypting Data
|
|
43
|
+
|
|
44
|
+
The `encrypt` method takes a message and a secret key.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
const secret = 'a-32-byte-long-secret-key-for-aes';
|
|
48
|
+
const message = 'This is a secret message.';
|
|
49
|
+
|
|
50
|
+
const encryptedMessage = aes.encrypt(message, secret);
|
|
51
|
+
// => Returns a base64 encoded string containing the IV and encrypted data
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Decrypting Data
|
|
55
|
+
|
|
56
|
+
The `decrypt` method takes the encrypted message and the same secret key.
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const decryptedMessage = aes.decrypt(encryptedMessage, secret);
|
|
60
|
+
// => 'This is a secret message.'
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## RSA (Asymmetric Encryption)
|
|
64
|
+
|
|
65
|
+
The `RSA` class provides an interface for encrypting and decrypting data using the RSA algorithm.
|
|
66
|
+
|
|
67
|
+
### Creating an RSA Instance
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { RSA } from '@venizia/ignis';
|
|
71
|
+
|
|
72
|
+
const rsa = RSA.withAlgorithm();
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Generating a Key Pair
|
|
76
|
+
|
|
77
|
+
The `generateDERKeyPair` method creates a new public/private key pair in DER format.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
const { publicKey, privateKey } = rsa.generateDERKeyPair();
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Encrypting Data
|
|
84
|
+
|
|
85
|
+
Encrypt data using the public key.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
const message = 'This is another secret.';
|
|
89
|
+
const encrypted = rsa.encrypt(message, publicKey.toString('base64'));
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Decrypting Data
|
|
93
|
+
|
|
94
|
+
Decrypt data using the private key.
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const decrypted = rsa.decrypt(encrypted, privateKey.toString('base64'));
|
|
98
|
+
// => 'This is another secret.'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Hash Utility
|
|
102
|
+
|
|
103
|
+
In addition to the `Crypto` helper, `Ignis` also provides a standalone `hash` utility function for creating hashes (e.g., for passwords or data integrity checks).
|
|
104
|
+
|
|
105
|
+
```typescript
|
|
106
|
+
import { hash } from '@venizia/ignis';
|
|
107
|
+
|
|
108
|
+
// MD5 Hash
|
|
109
|
+
const md5Hash = hash('some text', { algorithm: 'MD5', outputType: 'hex' });
|
|
110
|
+
|
|
111
|
+
// SHA256 HMAC
|
|
112
|
+
const sha256Hash = hash('some text', {
|
|
113
|
+
algorithm: 'SHA256',
|
|
114
|
+
secret: 'a-secret-key',
|
|
115
|
+
outputType: 'hex',
|
|
116
|
+
});
|
|
117
|
+
```
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Environment Helper
|
|
2
|
+
|
|
3
|
+
Structured access to application-specific environment variables with prefix filtering.
|
|
4
|
+
|
|
5
|
+
## Quick Reference
|
|
6
|
+
|
|
7
|
+
| Feature | Description |
|
|
8
|
+
|---------|-------------|
|
|
9
|
+
| **Singleton** | `applicationEnvironment` - auto-initialized at startup |
|
|
10
|
+
| **Prefix** | Default `APP_ENV_` (customizable via `APPLICATION_ENV_PREFIX`) |
|
|
11
|
+
| **Type-safe** | `get<T>(key)` with type inference |
|
|
12
|
+
| **Isolation** | Filters `process.env` to prevent conflicts |
|
|
13
|
+
|
|
14
|
+
### Common Methods
|
|
15
|
+
|
|
16
|
+
| Method | Purpose | Example |
|
|
17
|
+
|--------|---------|---------|
|
|
18
|
+
| `get<T>(key)` | Get typed environment variable | `get<string>(EnvironmentKeys.APP_ENV_JWT_SECRET)` |
|
|
19
|
+
| `isDevelopment()` | Check if dev environment | `if (env.isDevelopment()) { ... }` |
|
|
20
|
+
|
|
21
|
+
### Key Features
|
|
22
|
+
|
|
23
|
+
- **Prefix-based Filtering**: Isolates app vars (e.g., `APP_ENV_*`)
|
|
24
|
+
- **Type-safe Access**: `get<T>()` with type inference
|
|
25
|
+
- **Centralized Management**: Single consistent access point
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
You can import the `applicationEnvironment` instance and use it to retrieve your configuration values.
|
|
30
|
+
|
|
31
|
+
### Getting Environment Variables
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { applicationEnvironment, EnvironmentKeys } from '@venizia/ignis';
|
|
35
|
+
|
|
36
|
+
// Get the JWT secret
|
|
37
|
+
const jwtSecret = applicationEnvironment.get<string>(EnvironmentKeys.APP_ENV_JWT_SECRET);
|
|
38
|
+
|
|
39
|
+
// Get the server port, parsing it as a number
|
|
40
|
+
const serverPort = applicationEnvironment.get<number>(EnvironmentKeys.APP_ENV_SERVER_PORT);
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Checking the Current Environment
|
|
44
|
+
|
|
45
|
+
You can use the `isDevelopment()` method to check if the application is running in a development environment.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { applicationEnvironment } from '@venizia/ignis';
|
|
49
|
+
|
|
50
|
+
if (applicationEnvironment.isDevelopment()) {
|
|
51
|
+
// Do something only in development
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Configuration
|
|
56
|
+
|
|
57
|
+
The prefix for the environment variables can be configured by setting the `APPLICATION_ENV_PREFIX` variable in your environment.
|
|
58
|
+
|
|
59
|
+
**Example `.env` file:**
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
APPLICATION_ENV_PREFIX=MY_APP_ENV
|
|
63
|
+
|
|
64
|
+
# Now, your application variables should use the new prefix
|
|
65
|
+
MY_APP_ENV_SERVER_HOST=0.0.0.0
|
|
66
|
+
MY_APP_ENV_SERVER_PORT=3000
|
|
67
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Error Helper
|
|
2
|
+
|
|
3
|
+
Standardized error handling with consistent responses across the application.
|
|
4
|
+
|
|
5
|
+
## Quick Reference
|
|
6
|
+
|
|
7
|
+
| Class/Function | Purpose |
|
|
8
|
+
|----------------|---------|
|
|
9
|
+
| **ApplicationError** | Custom error class with `statusCode` and `messageCode` |
|
|
10
|
+
| **getError()** | Utility to create `ApplicationError` instances |
|
|
11
|
+
| **appErrorHandler** | Middleware catching and formatting errors |
|
|
12
|
+
|
|
13
|
+
### Error Response Format
|
|
14
|
+
|
|
15
|
+
| Environment | Includes |
|
|
16
|
+
|-------------|----------|
|
|
17
|
+
| **Production** | `message`, `statusCode`, `requestId` |
|
|
18
|
+
| **Development** | Above + `stack`, `cause`, `url`, `path` |
|
|
19
|
+
|
|
20
|
+
## `ApplicationError`
|
|
21
|
+
|
|
22
|
+
Extends native `Error` with HTTP status codes and machine-readable message codes.
|
|
23
|
+
|
|
24
|
+
### Creating an `ApplicationError`
|
|
25
|
+
|
|
26
|
+
You can create a new `ApplicationError` with a message, status code, and an optional message code.
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { ApplicationError, HTTP } from '@venizia/ignis';
|
|
30
|
+
|
|
31
|
+
// Throw an error for a resource not found
|
|
32
|
+
throw new ApplicationError({
|
|
33
|
+
message: 'User not found',
|
|
34
|
+
statusCode: HTTP.ResultCodes.RS_4.NotFound,
|
|
35
|
+
messageCode: 'USER_NOT_FOUND',
|
|
36
|
+
});
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### `getError()` Utility
|
|
40
|
+
|
|
41
|
+
For convenience, you can use the `getError()` utility function to create `ApplicationError` instances.
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { getError, HTTP } from '@venizia/ignis';
|
|
45
|
+
|
|
46
|
+
throw getError({
|
|
47
|
+
message: 'Invalid credentials',
|
|
48
|
+
statusCode: HTTP.ResultCodes.RS_4.Unauthorized,
|
|
49
|
+
});
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Error Handling Middleware
|
|
53
|
+
|
|
54
|
+
`Ignis` provides a default error handling middleware (`appErrorHandler`) that catches instances of `ApplicationError` (and other errors) and formats them into a consistent JSON response.
|
|
55
|
+
|
|
56
|
+
In development mode, the response will include the stack trace and error cause for easier debugging. In production, these details are omitted.
|
|
57
|
+
|
|
58
|
+
**Example Error Response (Production):**
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"message": "User not found",
|
|
63
|
+
"statusCode": 404,
|
|
64
|
+
"requestId": "some-request-id"
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
**Example Error Response (Development):**
|
|
69
|
+
|
|
70
|
+
```json
|
|
71
|
+
{
|
|
72
|
+
"message": "User not found",
|
|
73
|
+
"statusCode": 404,
|
|
74
|
+
"requestId": "some-request-id",
|
|
75
|
+
"stack": "Error: User not found\n at ...",
|
|
76
|
+
"cause": "...",
|
|
77
|
+
"url": "/api/users/123",
|
|
78
|
+
"path": "/api/users/123"
|
|
79
|
+
}
|
|
80
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Helpers
|
|
2
|
+
|
|
3
|
+
Reusable classes and functions providing common functionality - designed for easy injection and configuration.
|
|
4
|
+
|
|
5
|
+
## Available Helpers
|
|
6
|
+
|
|
7
|
+
| Helper | Purpose | Key Features |
|
|
8
|
+
|--------|---------|--------------|
|
|
9
|
+
| [Cron](./cron.md) | Job scheduling | Cron expressions, task management |
|
|
10
|
+
| [Crypto](./crypto.md) | Cryptographic operations | Hashing, AES/RSA encryption/decryption |
|
|
11
|
+
| [Environment](./env.md) | Environment variables | Centralized config access |
|
|
12
|
+
| [Error](./error.md) | Error handling | `ApplicationError`, consistent responses |
|
|
13
|
+
| [Inversion](./inversion.md) | Dependency injection | DI container implementation |
|
|
14
|
+
| [Logger](./logger.md) | Logging | Winston-based, multiple transports, scopes |
|
|
15
|
+
| [Network](./network.md) | Network requests | HTTP, TCP, UDP helpers |
|
|
16
|
+
| [Queue](./queue.md) | Message queues | BullMQ, MQTT support |
|
|
17
|
+
| [Redis](./redis.md) | Redis operations | Single/cluster, key-value, hashes, JSON, pub/sub |
|
|
18
|
+
| [Socket.IO](./socket-io.md) | Real-time communication | Socket.IO client/server helpers |
|
|
19
|
+
| [Storage](./storage.md) | File storage | In-memory, Minio object storage |
|
|
20
|
+
| [Testing](./testing.md) | Test utilities | Test plan runner, base test classes |
|
|
21
|
+
| [Worker Thread](./worker-thread.md) | Worker threads | Node.js worker management |
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Inversion of Control (IoC) and Dependency Injection (DI)
|
|
2
|
+
|
|
3
|
+
Core DI system enabling loosely coupled, testable, and extensible code.
|
|
4
|
+
|
|
5
|
+
> **Package Architecture Note:** The core DI container functionality has been extracted to a standalone package `@venizia/ignis-inversion`. The `@venizia/ignis-helpers` package extends and re-exports this functionality with application-specific enhancements (logging, framework metadata). All imports from `@venizia/ignis-helpers` or `@venizia/ignis` continue to work as before - backward compatibility is maintained.
|
|
6
|
+
|
|
7
|
+
## Quick Reference
|
|
8
|
+
|
|
9
|
+
| Concept | Description |
|
|
10
|
+
|---------|-------------|
|
|
11
|
+
| **Container** | Central registry for services/dependencies (Application extends Container) |
|
|
12
|
+
| **Binding** | Register class/value with container under a key |
|
|
13
|
+
| **Injection** | Request dependency from container using `@inject` decorator |
|
|
14
|
+
| **MetadataRegistry** | Stores decorator metadata for DI and routing |
|
|
15
|
+
|
|
16
|
+
### Binding Methods
|
|
17
|
+
|
|
18
|
+
| Method | Purpose | Example |
|
|
19
|
+
|--------|---------|---------|
|
|
20
|
+
| `app.service(MyService)` | Bind service | Key: `services.MyService` |
|
|
21
|
+
| `app.controller(MyController)` | Bind controller | Key: `controllers.MyController` |
|
|
22
|
+
| `app.repository(MyRepo)` | Bind repository | Key: `repositories.MyRepo` |
|
|
23
|
+
| `bind().toClass()` | Custom class binding | `bind({ key: 'MyClass' }).toClass(MyClass)` |
|
|
24
|
+
| `bind().toValue()` | Bind constant value | `bind({ key: 'API_KEY' }).toValue('secret')` |
|
|
25
|
+
|
|
26
|
+
### Binding Scopes
|
|
27
|
+
|
|
28
|
+
| Scope | Behavior |
|
|
29
|
+
|-------|----------|
|
|
30
|
+
| `BindingScopes.TRANSIENT` | New instance each request (default) |
|
|
31
|
+
| `BindingScopes.SINGLETON` | Single instance, reused |
|
|
32
|
+
|
|
33
|
+
### Injection Styles
|
|
34
|
+
|
|
35
|
+
| Style | When to Use |
|
|
36
|
+
|-------|-------------|
|
|
37
|
+
| **Constructor Injection** | Recommended - explicit, available at instantiation |
|
|
38
|
+
| **Property Injection** | Alternative - inject as class property |
|
|
39
|
+
|
|
40
|
+
## Binding Dependencies
|
|
41
|
+
|
|
42
|
+
Before a dependency can be injected, it must be bound to the container. The `Application` class provides helper methods for binding common resource types:
|
|
43
|
+
|
|
44
|
+
- `app.component(MyComponent)`
|
|
45
|
+
- `app.controller(MyController)`
|
|
46
|
+
- `app.service(MyService)`
|
|
47
|
+
- `app.repository(MyRepository)`
|
|
48
|
+
- `app.dataSource(MyDataSource)`
|
|
49
|
+
|
|
50
|
+
These methods automatically create a binding for the class with a conventional key (e.g., `services.MyService`).
|
|
51
|
+
|
|
52
|
+
### Advanced Binding
|
|
53
|
+
|
|
54
|
+
For more advanced use cases, you can create custom bindings using the `bind` method on the container.
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// In your application class or a component's binding() method
|
|
58
|
+
|
|
59
|
+
// Bind a class
|
|
60
|
+
this.bind<MyCustomClass>({ key: 'MyCustomClass' }).toClass(MyCustomClass);
|
|
61
|
+
|
|
62
|
+
// Bind a constant value
|
|
63
|
+
this.bind<string>({ key: 'API_KEY' }).toValue('my-secret-api-key');
|
|
64
|
+
|
|
65
|
+
// Bind a provider (for complex creation logic)
|
|
66
|
+
this.bind<DatabaseConnection>({ key: 'DatabaseConnection' }).toProvider(() => {
|
|
67
|
+
return new DatabaseConnection(process.env.DATABASE_URL);
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Binding Scopes
|
|
72
|
+
|
|
73
|
+
You can control the lifecycle of a bound dependency using scopes:
|
|
74
|
+
|
|
75
|
+
- `BindingScopes.TRANSIENT` (default): A new instance is created every time the dependency is requested.
|
|
76
|
+
- `BindingScopes.SINGLETON`: A single instance is created and reused for all subsequent requests.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
this.bind<MySingletonService>({ key: 'services.MySingletonService' })
|
|
80
|
+
.toClass(MySingletonService)
|
|
81
|
+
.setScope(BindingScopes.SINGLETON);
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Injecting Dependencies
|
|
85
|
+
|
|
86
|
+
`Ignis` provides an `@inject` decorator to handle dependency injection. You can use it on constructor parameters or class properties.
|
|
87
|
+
|
|
88
|
+
### Constructor Injection
|
|
89
|
+
|
|
90
|
+
This is the recommended way to inject dependencies, as it makes them explicit and ensures they are available when the class is instantiated.
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
import { BaseController, controller, inject } from '@venizia/ignis';
|
|
94
|
+
import { UserService } from '../services/user.service';
|
|
95
|
+
|
|
96
|
+
@controller({ path: '/users' })
|
|
97
|
+
export class UserController extends BaseController {
|
|
98
|
+
constructor(
|
|
99
|
+
@inject({ key: 'services.UserService' }) private userService: UserService
|
|
100
|
+
) {
|
|
101
|
+
super({ scope: UserController.name, path: '/users' });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// ... use this.userService
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Property Injection
|
|
109
|
+
|
|
110
|
+
You can also inject dependencies as class properties.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { BaseController, controller, inject } from '@venizia/ignis';
|
|
114
|
+
import { UserService } from '../services/user.service';
|
|
115
|
+
|
|
116
|
+
@controller({ path: '/users' })
|
|
117
|
+
export class UserController extends BaseController {
|
|
118
|
+
@inject({ key: 'services.UserService' })
|
|
119
|
+
private userService: UserService;
|
|
120
|
+
|
|
121
|
+
constructor() {
|
|
122
|
+
super({ scope: UserController.name, path: '/users' });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ... use this.userService
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## `MetadataRegistry`
|
|
130
|
+
|
|
131
|
+
The `MetadataRegistry` is a crucial part of the DI and routing systems. It's a singleton class responsible for storing and retrieving all the metadata attached by decorators like `@inject`, `@controller`, `@get`, etc.
|
|
132
|
+
|
|
133
|
+
- **Base File:** `packages/inversion/src/registry.ts` (core MetadataRegistry)
|
|
134
|
+
- **Extended File:** `packages/helpers/src/helpers/inversion/registry.ts` (with framework metadata)
|
|
135
|
+
|
|
136
|
+
### Role in DI
|
|
137
|
+
|
|
138
|
+
- When you use a decorator (e.g., `@inject`), it calls a method on the `MetadataRegistry.getInstance()` to store information about the injection (like the binding key and target property/parameter).
|
|
139
|
+
- When the `Container` instantiates a class, it queries the `MetadataRegistry` to find out which dependencies need to be injected and where.
|
|
140
|
+
|
|
141
|
+
You typically won't interact with the `MetadataRegistry` directly, but it's the underlying mechanism that makes the decorator-based DI and routing systems work seamlessly.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Logger Helper
|
|
2
|
+
|
|
3
|
+
Powerful, flexible logging built on Winston - supports multiple transports, log levels, and hierarchical scopes.
|
|
4
|
+
|
|
5
|
+
## Quick Reference
|
|
6
|
+
|
|
7
|
+
| Feature | Description |
|
|
8
|
+
|---------|-------------|
|
|
9
|
+
| **Factory Method** | `LoggerFactory.getLogger(['scope1', 'scope2'])` |
|
|
10
|
+
| **Log Levels** | `error`, `alert`, `emerg`, `warn`, `info`, `http`, `verbose`, `debug`, `silly` |
|
|
11
|
+
| **Transports** | Console (default), DailyRotateFile, UDP/Dgram |
|
|
12
|
+
| **Scopes** | Hierarchical context tracking (e.g., `['MyService', 'MyMethod']`) |
|
|
13
|
+
|
|
14
|
+
### Common Methods
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
logger.info('message'); // Informational
|
|
18
|
+
logger.error('message'); // Error
|
|
19
|
+
logger.warn('message'); // Warning
|
|
20
|
+
logger.debug('message'); // Debug
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Getting a Logger Instance
|
|
24
|
+
|
|
25
|
+
The recommended way to get a logger instance is by using the `LoggerFactory`.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
import { LoggerFactory } from '@venizia/ignis';
|
|
29
|
+
|
|
30
|
+
const logger = LoggerFactory.getLogger(['MyService']);
|
|
31
|
+
|
|
32
|
+
logger.info('This is an informational message.');
|
|
33
|
+
logger.error('This is an error message.');
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Scopes
|
|
37
|
+
|
|
38
|
+
You can provide an array of scopes to the `getLogger` method to create a hierarchical logger. This is useful for identifying the source of log messages.
|
|
39
|
+
|
|
40
|
+
```typescript
|
|
41
|
+
const logger = LoggerFactory.getLogger(['MyService', 'MyMethod']);
|
|
42
|
+
logger.info('This message is from MyService-MyMethod');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Configuration
|
|
46
|
+
|
|
47
|
+
The logger is configured through environment variables and the `defineCustomLogger` function, which sets up the `winston` instance.
|
|
48
|
+
|
|
49
|
+
### Log Levels
|
|
50
|
+
|
|
51
|
+
The logger supports the following log levels (from highest to lowest priority): `error`, `alert`, `emerg`, `warn`, `info`, `http`, `verbose`, `debug`, `silly`.
|
|
52
|
+
|
|
53
|
+
### Transports
|
|
54
|
+
|
|
55
|
+
`Ignis` comes with three main types of transports:
|
|
56
|
+
|
|
57
|
+
1. **Console:** Logs messages to the console. Enabled by default.
|
|
58
|
+
2. **DailyRotateFile:** Logs messages to files that are rotated on a daily or hourly basis.
|
|
59
|
+
3. **Dgram (UDP):** Sends log messages over UDP to a remote log aggregation service.
|
|
60
|
+
|
|
61
|
+
### Environment Variables for Configuration
|
|
62
|
+
|
|
63
|
+
- `APP_ENV_LOGGER_FOLDER_PATH`: The directory to store log files.
|
|
64
|
+
- `APP_ENV_APPLICATION_NAME`: Used as a prefix for log files and as a label in log messages.
|
|
65
|
+
- `APP_ENV_LOGGER_DGRAM_HOST`: The host for the UDP log transport.
|
|
66
|
+
- `APP_ENV_LOGGER_DGRAM_PORT`: The port for the UDP log transport.
|
|
67
|
+
- `APP_ENV_LOGGER_DGRAM_LABEL`: A label to identify the source of UDP logs.
|
|
68
|
+
- `APP_ENV_LOGGER_DGRAM_LEVELS`: A comma-separated list of log levels to be sent via UDP (e.g., `error,warn,info`).
|
|
69
|
+
|
|
70
|
+
**Example `.env` file:**
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
APP_ENV_LOGGER_FOLDER_PATH=./app_data/logs
|
|
74
|
+
APP_ENV_LOGGER_DGRAM_HOST=127.0.0.1
|
|
75
|
+
APP_ENV_LOGGER_DGRAM_PORT=5000
|
|
76
|
+
APP_ENV_LOGGER_DGRAM_LABEL=my-app
|
|
77
|
+
APP_ENV_LOGGER_DGRAM_LEVELS=error,warn,info,debug
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Custom Logger
|
|
81
|
+
|
|
82
|
+
While the default logger is powerful, you can create your own custom logger by extending the `Logger` class and providing a custom `winston.Logger` instance.
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
import { Logger, defineCustomLogger, applicationLogFormatter } from '@venizia/ignis';
|
|
86
|
+
import winston from 'winston';
|
|
87
|
+
|
|
88
|
+
const myCustomWinstonLogger = defineCustomLogger({
|
|
89
|
+
loggerFormatter: applicationLogFormatter,
|
|
90
|
+
transports: {
|
|
91
|
+
info: { file: { prefix: 'my-app', folder: './logs' } },
|
|
92
|
+
error: { file: { prefix: 'my-app-error', folder: './logs' } },
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const myLogger = new Logger({ customLogger: myCustomWinstonLogger });
|
|
97
|
+
myLogger.withScope('CustomScope').info('This is a custom log message.');
|
|
98
|
+
```
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Network Helper
|
|
2
|
+
|
|
3
|
+
Comprehensive network communication utilities for HTTP, TCP, and UDP protocols.
|
|
4
|
+
|
|
5
|
+
## Quick Reference
|
|
6
|
+
|
|
7
|
+
| Helper | Protocol | Type | Use Case |
|
|
8
|
+
|--------|----------|------|----------|
|
|
9
|
+
| **AxiosNetworkRequest** | HTTP/HTTPS | Client | REST API calls (axios-based) |
|
|
10
|
+
| **NodeFetchNetworkRequest** | HTTP/HTTPS | Client | REST API calls (native fetch) |
|
|
11
|
+
| **NetworkTcpClient** | TCP/TLS | Client | Raw TCP connections |
|
|
12
|
+
| **NetworkTcpServer** | TCP/TLS | Server | TCP server implementation |
|
|
13
|
+
| **NetworkUdpClient** | UDP | Client | Datagram sockets |
|
|
14
|
+
|
|
15
|
+
### HTTP Methods
|
|
16
|
+
|
|
17
|
+
| Method | Purpose |
|
|
18
|
+
|--------|---------|
|
|
19
|
+
| `get({ url })` | GET request |
|
|
20
|
+
| `post({ url, data })` | POST request |
|
|
21
|
+
| `put({ url, data })` | PUT request |
|
|
22
|
+
| `delete({ url })` | DELETE request |
|
|
23
|
+
|
|
24
|
+
### TCP Operations
|
|
25
|
+
|
|
26
|
+
| Class | Methods |
|
|
27
|
+
|-------|---------|
|
|
28
|
+
| **Client** | `connect()`, `emit({ payload })`, `disconnect()` |
|
|
29
|
+
| **Server** | `broadcast({ message })`, `sendToClient({ id, message })` |
|
|
30
|
+
|
|
31
|
+
## HTTP Request
|
|
32
|
+
|
|
33
|
+
The HTTP request helper provides a flexible and extensible framework for making HTTP requests, supporting both `axios` and the native Node.js `fetch` API as underlying clients.
|
|
34
|
+
|
|
35
|
+
### Creating an HTTP Client
|
|
36
|
+
|
|
37
|
+
You can create a new HTTP client instance by extending either `AxiosNetworkRequest` or `NodeFetchNetworkRequest`.
|
|
38
|
+
|
|
39
|
+
**Using Axios:**
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
import { AxiosNetworkRequest } from '@venizia/ignis';
|
|
43
|
+
|
|
44
|
+
class MyApiClient extends AxiosNetworkRequest {
|
|
45
|
+
constructor() {
|
|
46
|
+
super({
|
|
47
|
+
name: 'MyApiClient',
|
|
48
|
+
networkOptions: {
|
|
49
|
+
baseUrl: 'https://api.example.com',
|
|
50
|
+
timeout: 5000,
|
|
51
|
+
headers: {
|
|
52
|
+
'X-Custom-Header': 'MyValue',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getUsers() {
|
|
59
|
+
const response = await this.getNetworkService().get({ url: '/users' });
|
|
60
|
+
return response.data;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Using Node.js Fetch:**
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { NodeFetchNetworkRequest } from '@venizia/ignis';
|
|
69
|
+
|
|
70
|
+
class MyApiClient extends NodeFetchNetworkRequest {
|
|
71
|
+
constructor() {
|
|
72
|
+
super({
|
|
73
|
+
name: 'MyApiClient',
|
|
74
|
+
networkOptions: {
|
|
75
|
+
baseUrl: 'https://api.example.com',
|
|
76
|
+
timeout: 5000,
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async getUsers() {
|
|
82
|
+
const response = await this.getNetworkService().get({ url: '/users' });
|
|
83
|
+
return response.json();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## TCP Socket
|
|
89
|
+
|
|
90
|
+
The TCP Socket helpers provide a robust way to create and manage TCP and TLS/SSL connections.
|
|
91
|
+
|
|
92
|
+
### TCP Client
|
|
93
|
+
|
|
94
|
+
```typescript
|
|
95
|
+
import { NetworkTcpClient } from '@venizia/ignis';
|
|
96
|
+
|
|
97
|
+
const tcpClient = new NetworkTcpClient({
|
|
98
|
+
identifier: 'my-tcp-client',
|
|
99
|
+
options: { host: 'localhost', port: 8080 },
|
|
100
|
+
reconnect: true,
|
|
101
|
+
onData: ({ message }) => {
|
|
102
|
+
console.log('Received data:', message.toString());
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
tcpClient.connect({ resetReconnectCounter: true });
|
|
107
|
+
tcpClient.emit({ payload: 'Hello, Server!' });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### TCP Server
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
import { NetworkTcpServer } from '@venizia/ignis';
|
|
114
|
+
|
|
115
|
+
const tcpServer = new NetworkTcpServer({
|
|
116
|
+
identifier: 'my-tcp-server',
|
|
117
|
+
listenOptions: { port: 8080 },
|
|
118
|
+
authenticateOptions: { required: false },
|
|
119
|
+
onClientData: ({ id, data }) => {
|
|
120
|
+
console.log(`Received data from client ${id}:`, data.toString());
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## UDP Socket
|
|
126
|
+
|
|
127
|
+
The UDP Socket helper provides a way to create and manage UDP datagram sockets.
|
|
128
|
+
|
|
129
|
+
### UDP Client
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
import { NetworkUdpClient } from '@venizia/ignis';
|
|
133
|
+
|
|
134
|
+
const udpClient = new NetworkUdpClient({
|
|
135
|
+
identifier: 'my-udp-client',
|
|
136
|
+
port: 8081,
|
|
137
|
+
onData: ({ message, remoteInfo }) => {
|
|
138
|
+
console.log(`Received message from ${remoteInfo.address}:${remoteInfo.port}:`, message.toString());
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
udpClient.connect();
|
|
143
|
+
```
|