@venizia/ignis-docs 0.0.5 → 0.0.6-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/package.json +1 -1
- package/wiki/best-practices/architectural-patterns.md +0 -2
- package/wiki/best-practices/architecture-decisions.md +0 -8
- package/wiki/best-practices/code-style-standards/control-flow.md +1 -1
- package/wiki/best-practices/code-style-standards/index.md +0 -1
- package/wiki/best-practices/code-style-standards/tooling.md +0 -3
- package/wiki/best-practices/contribution-workflow.md +12 -12
- package/wiki/best-practices/index.md +4 -14
- package/wiki/best-practices/performance-optimization.md +3 -3
- package/wiki/best-practices/security-guidelines.md +2 -2
- package/wiki/best-practices/troubleshooting-tips.md +1 -1
- package/wiki/guides/core-concepts/application/bootstrapping.md +6 -7
- package/wiki/guides/core-concepts/components-guide.md +1 -1
- package/wiki/guides/core-concepts/components.md +2 -2
- package/wiki/guides/core-concepts/dependency-injection.md +4 -5
- package/wiki/guides/core-concepts/persistent/datasources.md +4 -5
- package/wiki/guides/core-concepts/services.md +1 -1
- package/wiki/guides/get-started/5-minute-quickstart.md +4 -5
- package/wiki/guides/get-started/philosophy.md +12 -24
- package/wiki/guides/index.md +2 -9
- package/wiki/guides/reference/mcp-docs-server.md +13 -13
- package/wiki/guides/tutorials/building-a-crud-api.md +10 -10
- package/wiki/guides/tutorials/complete-installation.md +11 -12
- package/wiki/guides/tutorials/ecommerce-api.md +3 -3
- package/wiki/guides/tutorials/realtime-chat.md +6 -6
- package/wiki/guides/tutorials/testing.md +4 -5
- package/wiki/index.md +8 -14
- package/wiki/references/base/bootstrapping.md +0 -3
- package/wiki/references/base/components.md +2 -2
- package/wiki/references/base/controllers.md +0 -1
- package/wiki/references/base/datasources.md +1 -1
- package/wiki/references/base/dependency-injection.md +2 -2
- package/wiki/references/base/filter-system/default-filter.md +2 -3
- package/wiki/references/base/filter-system/index.md +1 -1
- package/wiki/references/base/filter-system/quick-reference.md +0 -14
- package/wiki/references/base/middlewares.md +0 -8
- package/wiki/references/base/providers.md +0 -9
- package/wiki/references/base/repositories/advanced.md +1 -1
- package/wiki/references/base/repositories/mixins.md +2 -3
- package/wiki/references/base/services.md +0 -1
- package/wiki/references/components/authentication/api.md +444 -0
- package/wiki/references/components/authentication/errors.md +177 -0
- package/wiki/references/components/authentication/index.md +571 -0
- package/wiki/references/components/authentication/usage.md +781 -0
- package/wiki/references/components/health-check.md +292 -103
- package/wiki/references/components/index.md +14 -12
- package/wiki/references/components/mail/api.md +505 -0
- package/wiki/references/components/mail/errors.md +176 -0
- package/wiki/references/components/mail/index.md +535 -0
- package/wiki/references/components/mail/usage.md +404 -0
- package/wiki/references/components/request-tracker.md +229 -25
- package/wiki/references/components/socket-io/api.md +1051 -0
- package/wiki/references/components/socket-io/errors.md +119 -0
- package/wiki/references/components/socket-io/index.md +410 -0
- package/wiki/references/components/socket-io/usage.md +322 -0
- package/wiki/references/components/static-asset/api.md +261 -0
- package/wiki/references/components/static-asset/errors.md +89 -0
- package/wiki/references/components/static-asset/index.md +617 -0
- package/wiki/references/components/static-asset/usage.md +364 -0
- package/wiki/references/components/swagger.md +390 -110
- package/wiki/references/components/template/api-page.md +125 -0
- package/wiki/references/components/template/errors-page.md +100 -0
- package/wiki/references/components/template/index.md +104 -0
- package/wiki/references/components/template/setup-page.md +134 -0
- package/wiki/references/components/template/single-page.md +132 -0
- package/wiki/references/components/template/usage-page.md +127 -0
- package/wiki/references/components/websocket/api.md +508 -0
- package/wiki/references/components/websocket/errors.md +123 -0
- package/wiki/references/components/websocket/index.md +453 -0
- package/wiki/references/components/websocket/usage.md +475 -0
- package/wiki/references/helpers/cron/index.md +224 -0
- package/wiki/references/helpers/crypto/index.md +537 -0
- package/wiki/references/helpers/env/index.md +214 -0
- package/wiki/references/helpers/error/index.md +232 -0
- package/wiki/references/helpers/index.md +16 -15
- package/wiki/references/helpers/inversion/index.md +608 -0
- package/wiki/references/helpers/logger/index.md +600 -0
- package/wiki/references/helpers/network/api.md +986 -0
- package/wiki/references/helpers/network/index.md +620 -0
- package/wiki/references/helpers/queue/index.md +589 -0
- package/wiki/references/helpers/redis/index.md +495 -0
- package/wiki/references/helpers/socket-io/api.md +497 -0
- package/wiki/references/helpers/socket-io/index.md +513 -0
- package/wiki/references/helpers/storage/api.md +705 -0
- package/wiki/references/helpers/storage/index.md +583 -0
- package/wiki/references/helpers/template/index.md +66 -0
- package/wiki/references/helpers/template/single-page.md +126 -0
- package/wiki/references/helpers/testing/index.md +510 -0
- package/wiki/references/helpers/types/index.md +512 -0
- package/wiki/references/helpers/uid/index.md +272 -0
- package/wiki/references/helpers/websocket/api.md +736 -0
- package/wiki/references/helpers/websocket/index.md +574 -0
- package/wiki/references/helpers/worker-thread/index.md +470 -0
- package/wiki/references/index.md +2 -9
- package/wiki/references/quick-reference.md +3 -18
- package/wiki/references/utilities/jsx.md +1 -8
- package/wiki/references/utilities/statuses.md +0 -7
- package/wiki/references/components/authentication.md +0 -476
- package/wiki/references/components/mail.md +0 -687
- package/wiki/references/components/socket-io.md +0 -562
- package/wiki/references/components/static-asset.md +0 -1277
- package/wiki/references/helpers/cron.md +0 -108
- package/wiki/references/helpers/crypto.md +0 -132
- package/wiki/references/helpers/env.md +0 -83
- package/wiki/references/helpers/error.md +0 -97
- package/wiki/references/helpers/inversion.md +0 -176
- package/wiki/references/helpers/logger.md +0 -296
- package/wiki/references/helpers/network.md +0 -396
- package/wiki/references/helpers/queue.md +0 -150
- package/wiki/references/helpers/redis.md +0 -142
- package/wiki/references/helpers/socket-io.md +0 -932
- package/wiki/references/helpers/storage.md +0 -665
- package/wiki/references/helpers/testing.md +0 -133
- package/wiki/references/helpers/types.md +0 -167
- package/wiki/references/helpers/uid.md +0 -167
- package/wiki/references/helpers/worker-thread.md +0 -178
- package/wiki/references/src-details/boot.md +0 -379
- package/wiki/references/src-details/core.md +0 -263
- package/wiki/references/src-details/dev-configs.md +0 -298
- package/wiki/references/src-details/docs.md +0 -71
- package/wiki/references/src-details/helpers.md +0 -211
- package/wiki/references/src-details/index.md +0 -86
- package/wiki/references/src-details/inversion.md +0 -340
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# Cron Helper
|
|
2
|
-
|
|
3
|
-
Schedule and manage recurring tasks (cron jobs) using cron patterns.
|
|
4
|
-
|
|
5
|
-
## Quick Reference
|
|
6
|
-
|
|
7
|
-
| Option | Type | Description |
|
|
8
|
-
|--------|------|-------------|
|
|
9
|
-
| `cronTime` | `string` | Cron pattern (e.g., `'0 */1 * * * *'` = every minute) |
|
|
10
|
-
| `onTick` | `Function` | Callback executed on schedule |
|
|
11
|
-
| `autoStart` | `boolean` | Start automatically (default: `false`) |
|
|
12
|
-
| `tz` | `string` | Timezone (e.g., `'America/New_York'`) |
|
|
13
|
-
| `errorHandler` | `Function` | Handle errors in `onTick` |
|
|
14
|
-
|
|
15
|
-
### Common Cron Patterns
|
|
16
|
-
|
|
17
|
-
| Pattern | Description |
|
|
18
|
-
|---------|-------------|
|
|
19
|
-
| `'0 */1 * * * *'` | Every minute |
|
|
20
|
-
| `'0 */5 * * * *'` | Every 5 minutes |
|
|
21
|
-
| `'0 0 * * * *'` | Every hour |
|
|
22
|
-
| `'0 0 0 * * *'` | Every day at midnight |
|
|
23
|
-
| `'0 0 0 * * 1'` | Every Monday at midnight |
|
|
24
|
-
|
|
25
|
-
### Key Methods
|
|
26
|
-
|
|
27
|
-
| Method | Purpose |
|
|
28
|
-
|--------|---------|
|
|
29
|
-
| `start()` | Start the cron job manually |
|
|
30
|
-
| `modifyCronTime({ cronTime })` | Change schedule dynamically |
|
|
31
|
-
| `duplicate({ cronTime })` | Create new job with same config |
|
|
32
|
-
|
|
33
|
-
## Creating a Cron Job
|
|
34
|
-
|
|
35
|
-
To create a cron job, you instantiate the `CronHelper` with your desired options.
|
|
36
|
-
|
|
37
|
-
### `ICronHelperOptions`
|
|
38
|
-
|
|
39
|
-
- `cronTime` (string): The cron pattern that defines when the job should run (e.g., `'0 */1 * * * *'` for every minute).
|
|
40
|
-
- `onTick` (() => void | Promise<void>): The function to be executed when the cron job triggers.
|
|
41
|
-
- `onCompleted` (CronOnCompleteCommand | null, optional): A function to be executed when the job stops.
|
|
42
|
-
- `autoStart` (boolean, optional): If `true`, the job will start automatically. Defaults to `false`.
|
|
43
|
-
- `tz` (string, optional): The timezone to use for the schedule.
|
|
44
|
-
- `errorHandler` ((error: unknown) => void | null, optional): A function to handle errors that occur during the `onTick` execution.
|
|
45
|
-
|
|
46
|
-
### Example
|
|
47
|
-
|
|
48
|
-
Here's how to create a simple cron job that logs a message every minute:
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { CronHelper } from '@venizia/ignis';
|
|
52
|
-
|
|
53
|
-
const myJob = new CronHelper({
|
|
54
|
-
cronTime: '0 */1 * * * *', // Every minute
|
|
55
|
-
onTick: () => {
|
|
56
|
-
console.log('This message will be logged every minute.');
|
|
57
|
-
},
|
|
58
|
-
autoStart: true,
|
|
59
|
-
tz: 'America/New_York',
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
## Managing Cron Jobs
|
|
64
|
-
|
|
65
|
-
The `CronHelper` instance provides several methods for managing the cron job:
|
|
66
|
-
|
|
67
|
-
### `start()`
|
|
68
|
-
|
|
69
|
-
Manually starts the cron job if `autoStart` was set to `false`.
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
myJob.start();
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### `modifyCronTime(opts)`
|
|
76
|
-
|
|
77
|
-
Dynamically changes the schedule of an existing cron job.
|
|
78
|
-
|
|
79
|
-
- `cronTime` (string): The new cron pattern.
|
|
80
|
-
- `shouldFireOnTick` (boolean, optional): If `true`, the `onTick` function will be executed immediately after the time is changed.
|
|
81
|
-
|
|
82
|
-
```typescript
|
|
83
|
-
// Change the job to run every 5 minutes
|
|
84
|
-
myJob.modifyCronTime({ cronTime: '0 */5 * * * *' });
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### `duplicate(opts)`
|
|
88
|
-
|
|
89
|
-
Creates a new `CronHelper` instance with the same configuration but a new `cronTime`.
|
|
90
|
-
|
|
91
|
-
```typescript
|
|
92
|
-
const anotherJob = myJob.duplicate({ cronTime: '0 0 * * *' }); // Runs once at midnight
|
|
93
|
-
anotherJob.start();
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## See Also
|
|
97
|
-
|
|
98
|
-
- **Related Concepts:**
|
|
99
|
-
- [Services](/guides/core-concepts/services) - Scheduling jobs in services
|
|
100
|
-
- [Application](/guides/core-concepts/application/) - Scheduling on app startup
|
|
101
|
-
|
|
102
|
-
- **Other Helpers:**
|
|
103
|
-
- [Helpers Index](./index) - All available helpers
|
|
104
|
-
- [Queue Helper](./queue) - Message queue processing
|
|
105
|
-
|
|
106
|
-
- **External Resources:**
|
|
107
|
-
- [Cron Expression Guide](https://crontab.guru/) - Cron syntax reference
|
|
108
|
-
- [node-cron Documentation](https://github.com/node-cron/node-cron) - Cron library
|
|
@@ -1,132 +0,0 @@
|
|
|
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
|
-
```
|
|
118
|
-
|
|
119
|
-
## See Also
|
|
120
|
-
|
|
121
|
-
- **Related Concepts:**
|
|
122
|
-
- [Services](/guides/core-concepts/services) - Password hashing in user service
|
|
123
|
-
|
|
124
|
-
- **Other Helpers:**
|
|
125
|
-
- [Helpers Index](./index) - All available helpers
|
|
126
|
-
|
|
127
|
-
- **References:**
|
|
128
|
-
- [Crypto Utility](/references/utilities/crypto) - Pure crypto utilities
|
|
129
|
-
- [Authentication Component](/references/components/authentication) - JWT and password verification
|
|
130
|
-
|
|
131
|
-
- **Best Practices:**
|
|
132
|
-
- [Security Guidelines](/best-practices/security-guidelines) - Cryptographic best practices
|
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
```
|
|
68
|
-
|
|
69
|
-
## See Also
|
|
70
|
-
|
|
71
|
-
- **Related Concepts:**
|
|
72
|
-
- [Application](/guides/core-concepts/application/) - Environment validation
|
|
73
|
-
- [DataSources](/guides/core-concepts/persistent/datasources) - Database configuration
|
|
74
|
-
|
|
75
|
-
- **Other Helpers:**
|
|
76
|
-
- [Helpers Index](./index) - All available helpers
|
|
77
|
-
|
|
78
|
-
- **References:**
|
|
79
|
-
- [Environment Variables](/references/configuration/environment-variables) - Complete environment reference
|
|
80
|
-
|
|
81
|
-
- **Best Practices:**
|
|
82
|
-
- [Security Guidelines](/best-practices/security-guidelines) - Environment variable security
|
|
83
|
-
- [Deployment Strategies](/best-practices/deployment-strategies) - Environment management
|
|
@@ -1,97 +0,0 @@
|
|
|
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 { getError, HTTP } from '@venizia/ignis';
|
|
30
|
-
|
|
31
|
-
// Throw an error for a resource not found
|
|
32
|
-
throw getError({
|
|
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
|
-
```
|
|
81
|
-
|
|
82
|
-
## See Also
|
|
83
|
-
|
|
84
|
-
- **Related Concepts:**
|
|
85
|
-
- [Controllers](/guides/core-concepts/controllers) - Throwing errors in controllers
|
|
86
|
-
- [Services](/guides/core-concepts/services) - Error handling in services
|
|
87
|
-
|
|
88
|
-
- **Other Helpers:**
|
|
89
|
-
- [Helpers Index](./index) - All available helpers
|
|
90
|
-
- [Logger Helper](./logger) - Logging errors
|
|
91
|
-
|
|
92
|
-
- **References:**
|
|
93
|
-
- [Middlewares](/references/base/middlewares) - Error handler middleware
|
|
94
|
-
|
|
95
|
-
- **Best Practices:**
|
|
96
|
-
- [Common Pitfalls](/best-practices/common-pitfalls) - Error handling anti-patterns
|
|
97
|
-
- [Troubleshooting Tips](/best-practices/troubleshooting-tips) - Debugging errors
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
# Inversion of Control (IoC) and Dependency Injection (DI)
|
|
2
|
-
|
|
3
|
-
Core DI system enabling loosely coupled, testable, and extensible code.
|
|
4
|
-
|
|
5
|
-
> **Architecture Update:** The core DI container functionality has been extracted to a standalone package `@venizia/ignis-inversion`.
|
|
6
|
-
>
|
|
7
|
-
> * **Standalone Container:** `@venizia/ignis-inversion` (Generic DI)
|
|
8
|
-
> * **Framework Integration:** `@venizia/ignis` (extends Core DI with Framework Metadata)
|
|
9
|
-
>
|
|
10
|
-
> Previously, this module resided in `@venizia/ignis-helpers`. It has now been moved to **Core** (`@venizia/ignis`) to better align with the framework architecture.
|
|
11
|
-
|
|
12
|
-
## Quick Reference
|
|
13
|
-
|
|
14
|
-
| Concept | Description |
|
|
15
|
-
|---------|-------------|
|
|
16
|
-
| **Container** | Central registry for services/dependencies (Application extends Container) |
|
|
17
|
-
| **Binding** | Register class/value with container under a key |
|
|
18
|
-
| **Injection** | Request dependency from container using `@inject` decorator |
|
|
19
|
-
| **MetadataRegistry** | Stores decorator metadata for DI and routing |
|
|
20
|
-
|
|
21
|
-
### Binding Methods
|
|
22
|
-
|
|
23
|
-
| Method | Purpose | Default Key |
|
|
24
|
-
|--------|---------|-------------|
|
|
25
|
-
| `app.service(MyService, opts?)` | Bind service | `services.MyService` |
|
|
26
|
-
| `app.controller(MyController, opts?)` | Bind controller | `controllers.MyController` |
|
|
27
|
-
| `app.repository(MyRepo, opts?)` | Bind repository | `repositories.MyRepo` |
|
|
28
|
-
| `app.component(MyComponent, opts?)` | Bind component | `components.MyComponent` |
|
|
29
|
-
| `app.dataSource(MyDS, opts?)` | Bind datasource | `datasources.MyDS` |
|
|
30
|
-
| `bind().toClass()` | Custom class binding | `bind({ key: 'MyClass' }).toClass(MyClass)` |
|
|
31
|
-
| `bind().toValue()` | Bind constant value | `bind({ key: 'API_KEY' }).toValue('secret')` |
|
|
32
|
-
|
|
33
|
-
All registration methods accept an optional `opts` parameter to customize the binding key:
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
app.controller(UserController, {
|
|
37
|
-
binding: { namespace: 'controllers', key: 'CustomUserController' }
|
|
38
|
-
});
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
### Binding Scopes
|
|
42
|
-
|
|
43
|
-
| Scope | Behavior |
|
|
44
|
-
|-------|----------|
|
|
45
|
-
| `BindingScopes.TRANSIENT` | New instance each request (default) |
|
|
46
|
-
| `BindingScopes.SINGLETON` | Single instance, reused |
|
|
47
|
-
|
|
48
|
-
### Injection Styles
|
|
49
|
-
|
|
50
|
-
| Style | When to Use |
|
|
51
|
-
|-------|-------------|
|
|
52
|
-
| **Constructor Injection** | Recommended - explicit, available at instantiation |
|
|
53
|
-
| **Property Injection** | Alternative - inject as class property |
|
|
54
|
-
|
|
55
|
-
## Binding Dependencies
|
|
56
|
-
|
|
57
|
-
Before a dependency can be injected, it must be bound to the container. The `Application` class provides helper methods for binding common resource types:
|
|
58
|
-
|
|
59
|
-
- `app.component(MyComponent, opts?)`
|
|
60
|
-
- `app.controller(MyController, opts?)`
|
|
61
|
-
- `app.service(MyService, opts?)`
|
|
62
|
-
- `app.repository(MyRepository, opts?)`
|
|
63
|
-
- `app.dataSource(MyDataSource, opts?)`
|
|
64
|
-
|
|
65
|
-
These methods automatically create a binding for the class with a conventional key (e.g., `services.MyService`). Use the optional `opts` parameter to customize binding keys when needed.
|
|
66
|
-
|
|
67
|
-
### Advanced Binding
|
|
68
|
-
|
|
69
|
-
For more advanced use cases, you can create custom bindings using the `bind` method on the container.
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
// In your application class or a component's binding() method
|
|
73
|
-
|
|
74
|
-
// Bind a class
|
|
75
|
-
this.bind<MyCustomClass>({ key: 'MyCustomClass' }).toClass(MyCustomClass);
|
|
76
|
-
|
|
77
|
-
// Bind a constant value
|
|
78
|
-
this.bind<string>({ key: 'API_KEY' }).toValue('my-secret-api-key');
|
|
79
|
-
|
|
80
|
-
// Bind a provider (for complex creation logic)
|
|
81
|
-
this.bind<DatabaseConnection>({ key: 'DatabaseConnection' }).toProvider(() => {
|
|
82
|
-
return new DatabaseConnection(process.env.DATABASE_URL);
|
|
83
|
-
});
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Binding Scopes
|
|
87
|
-
|
|
88
|
-
You can control the lifecycle of a bound dependency using scopes:
|
|
89
|
-
|
|
90
|
-
- `BindingScopes.TRANSIENT` (default): A new instance is created every time the dependency is requested.
|
|
91
|
-
- `BindingScopes.SINGLETON`: A single instance is created and reused for all subsequent requests.
|
|
92
|
-
|
|
93
|
-
```typescript
|
|
94
|
-
this.bind<MySingletonService>({ key: 'services.MySingletonService' })
|
|
95
|
-
.toClass(MySingletonService)
|
|
96
|
-
.setScope(BindingScopes.SINGLETON);
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Injecting Dependencies
|
|
100
|
-
|
|
101
|
-
`Ignis` provides an `@inject` decorator to handle dependency injection. You can use it on constructor parameters or class properties.
|
|
102
|
-
|
|
103
|
-
### Constructor Injection
|
|
104
|
-
|
|
105
|
-
This is the recommended way to inject dependencies, as it makes them explicit and ensures they are available when the class is instantiated.
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
import { BaseController, controller, inject } from '@venizia/ignis';
|
|
109
|
-
import { UserService } from '../services/user.service';
|
|
110
|
-
|
|
111
|
-
@controller({ path: '/users' })
|
|
112
|
-
export class UserController extends BaseController {
|
|
113
|
-
constructor(
|
|
114
|
-
@inject({ key: 'services.UserService' })
|
|
115
|
-
private _userService: UserService
|
|
116
|
-
) {
|
|
117
|
-
super({ scope: UserController.name, path: '/users' });
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// ... use this._userService
|
|
121
|
-
}
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### Property Injection
|
|
125
|
-
|
|
126
|
-
You can also inject dependencies as class properties.
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
import { BaseController, controller, inject } from '@venizia/ignis';
|
|
130
|
-
import { UserService } from '../services/user.service';
|
|
131
|
-
|
|
132
|
-
@controller({ path: '/users' })
|
|
133
|
-
export class UserController extends BaseController {
|
|
134
|
-
@inject({ key: 'services.UserService' })
|
|
135
|
-
private _userService: UserService;
|
|
136
|
-
|
|
137
|
-
constructor() {
|
|
138
|
-
super({ scope: UserController.name, path: '/users' });
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ... use this._userService
|
|
142
|
-
}
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## `MetadataRegistry`
|
|
146
|
-
|
|
147
|
-
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.
|
|
148
|
-
|
|
149
|
-
- **Base File:** `packages/inversion/src/registry.ts` (core MetadataRegistry)
|
|
150
|
-
- **Extended File:** `packages/core/src/helpers/inversion/registry.ts` (with framework metadata)
|
|
151
|
-
|
|
152
|
-
### Role in DI
|
|
153
|
-
|
|
154
|
-
- 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).
|
|
155
|
-
- When the `Container` instantiates a class, it queries the `MetadataRegistry` to find out which dependencies need to be injected and where.
|
|
156
|
-
|
|
157
|
-
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.
|
|
158
|
-
|
|
159
|
-
## See Also
|
|
160
|
-
|
|
161
|
-
- **Related Concepts:**
|
|
162
|
-
- [Dependency Injection Guide](/guides/core-concepts/dependency-injection) - DI fundamentals
|
|
163
|
-
- [Application](/guides/core-concepts/application/) - Application extends Container
|
|
164
|
-
|
|
165
|
-
- **Other Helpers:**
|
|
166
|
-
- [Helpers Index](./index) - All available helpers
|
|
167
|
-
|
|
168
|
-
- **References:**
|
|
169
|
-
- [Dependency Injection API](/references/base/dependency-injection) - Complete DI reference
|
|
170
|
-
- [Glossary](/guides/reference/glossary#dependency-injection-di) - DI concepts
|
|
171
|
-
|
|
172
|
-
- **Tutorials:**
|
|
173
|
-
- [Testing](/guides/tutorials/testing) - Unit testing with DI
|
|
174
|
-
|
|
175
|
-
- **Best Practices:**
|
|
176
|
-
- [Architectural Patterns](/best-practices/architectural-patterns) - DI patterns
|