@venizia/ignis-docs 0.0.6-0 → 0.0.6-2
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/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/guides/core-concepts/application/bootstrapping.md +6 -7
- package/wiki/guides/core-concepts/dependency-injection.md +3 -4
- package/wiki/guides/core-concepts/persistent/datasources.md +4 -5
- 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 +9 -9
- package/wiki/guides/tutorials/complete-installation.md +11 -12
- package/wiki/guides/tutorials/ecommerce-api.md +1 -1
- package/wiki/guides/tutorials/testing.md +3 -4
- package/wiki/index.md +8 -14
- package/wiki/references/base/bootstrapping.md +0 -1
- package/wiki/references/base/dependency-injection.md +1 -1
- 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/repositories/advanced.md +1 -1
- package/wiki/references/base/repositories/mixins.md +2 -3
- package/wiki/references/index.md +2 -9
- 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,211 +0,0 @@
|
|
|
1
|
-
# Package: `@venizia/ignis-helpers`
|
|
2
|
-
|
|
3
|
-
## Helpers Package Directory: Detailed Breakdown
|
|
4
|
-
|
|
5
|
-
The `@venizia/ignis-helpers` package consolidates a wide array of reusable helper classes and utility functions designed to support various cross-cutting concerns within the Ignis framework. This package promotes modularity by extracting common functionalities into a standalone, easily consumable library.
|
|
6
|
-
|
|
7
|
-
## Project Structure Overview
|
|
8
|
-
|
|
9
|
-
Here's the top-level breakdown of the `src` directory within `@packages/helpers/`:
|
|
10
|
-
|
|
11
|
-
| Folder | Purpose |
|
|
12
|
-
| :-------------- | :----------------------------------------------------------------------------------------------------------- |
|
|
13
|
-
| **`__tests__`** | Contains unit and integration tests for the helper utilities. |
|
|
14
|
-
| **`base`** | Provides foundational helper classes, such as `BaseHelper`. |
|
|
15
|
-
| **`common`** | Stores shared constants and types used across the helpers. |
|
|
16
|
-
| **`helpers`** | A collection of specialized helper modules for various functionalities (e.g., cron, crypto, network, queue). |
|
|
17
|
-
| **`utilities`** | Contains pure, standalone utility functions for common tasks (e.g., parsing, date manipulation). |
|
|
18
|
-
|
|
19
|
-
---
|
|
20
|
-
|
|
21
|
-
## Detailed Sections
|
|
22
|
-
|
|
23
|
-
### `__tests__`
|
|
24
|
-
|
|
25
|
-
This directory is dedicated to the test suite for the `@venizia/ignis-helpers` package.
|
|
26
|
-
|
|
27
|
-
| File/Folder | Purpose/Key Details |
|
|
28
|
-
| :---------------------- | :------------------------------------------------------------------------- |
|
|
29
|
-
| `index.ts` | Entry point for running tests within the helpers package. |
|
|
30
|
-
| `jwt/` | Contains test cases specifically for JWT-related helper functions, if any. |
|
|
31
|
-
| `jwt/test-cases/jwt.ts` | Example: defines `TestCase001` to check JWT creation in a helper context. |
|
|
32
|
-
|
|
33
|
-
### `base`
|
|
34
|
-
|
|
35
|
-
This foundational layer provides base classes that other helpers extend.
|
|
36
|
-
|
|
37
|
-
#### `base/helpers`
|
|
38
|
-
|
|
39
|
-
| File/Folder | Purpose/Key Details |
|
|
40
|
-
| :---------- | :--------------------------------------------------------------------------------------------------------------------------------------- |
|
|
41
|
-
| `base.ts` | Defines `BaseHelper`, a generic base class providing common utilities like a logger instance and scope management for all other helpers. |
|
|
42
|
-
|
|
43
|
-
### `common`
|
|
44
|
-
|
|
45
|
-
This directory holds various shared definitions and constants used throughout the helpers package.
|
|
46
|
-
|
|
47
|
-
| File/Folder | Purpose/Key Details |
|
|
48
|
-
| :----------- | :------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
49
|
-
| `constants/` | Contains application-wide constants such as `HTTP` methods and status codes, `MimeTypes`, `RuntimeModules` (Bun, Node.js), and `DataTypes`. |
|
|
50
|
-
| `types.ts` | Contains general TypeScript utility types like `ValueOrPromise`, `AnyObject`, `IClass`, `TMixinTarget`, and `IProvider`. |
|
|
51
|
-
|
|
52
|
-
### `helpers`
|
|
53
|
-
|
|
54
|
-
This directory groups specialized helper modules by their functionality.
|
|
55
|
-
|
|
56
|
-
#### `helpers/cron/`
|
|
57
|
-
|
|
58
|
-
| File/Folder | Purpose/Key Details |
|
|
59
|
-
| :--------------- | :--------------------------------------------------------------------------- |
|
|
60
|
-
| `cron.helper.ts` | `CronHelper` for scheduling and managing cron jobs using the `cron` library. |
|
|
61
|
-
|
|
62
|
-
#### `helpers/crypto/`
|
|
63
|
-
|
|
64
|
-
Cryptographic utilities.
|
|
65
|
-
|
|
66
|
-
| File/Folder | Purpose/Key Details |
|
|
67
|
-
| :------------ | :------------------------------------------------ |
|
|
68
|
-
| `algorithms/` | AES and RSA encryption/decryption algorithms. |
|
|
69
|
-
| `common/` | Common types and constants for crypto operations. |
|
|
70
|
-
|
|
71
|
-
#### `helpers/env/`
|
|
72
|
-
|
|
73
|
-
| File/Folder | Purpose/Key Details |
|
|
74
|
-
| :----------- | :----------------------------------------------------------------------- |
|
|
75
|
-
| `app-env.ts` | `ApplicationEnvironment` for structured access to environment variables. |
|
|
76
|
-
|
|
77
|
-
#### `helpers/error/`
|
|
78
|
-
|
|
79
|
-
| File/Folder | Purpose/Key Details |
|
|
80
|
-
| :------------- | :-------------------------------------------------------- |
|
|
81
|
-
| `app-error.ts` | `ApplicationError` class for standardized error handling. |
|
|
82
|
-
|
|
83
|
-
#### `helpers/inversion/`
|
|
84
|
-
|
|
85
|
-
Application-enhanced Dependency Injection (DI) module that extends `@venizia/ignis-inversion`.
|
|
86
|
-
|
|
87
|
-
> **Note:** The core DI functionality (Container, Binding, MetadataRegistry base classes) has been extracted to the standalone `@venizia/ignis-inversion` package. This module extends and re-exports that functionality with application-specific enhancements.
|
|
88
|
-
|
|
89
|
-
| File/Folder | Purpose/Key Details |
|
|
90
|
-
| :------------- | :------------------------------------------------------------------------------------------------------------ |
|
|
91
|
-
| `container.ts` | Extended `Container` class with `ApplicationLogger` integration. |
|
|
92
|
-
| `registry.ts` | Extended `MetadataRegistry` with framework-specific metadata (controllers, models, repositories, datasources).|
|
|
93
|
-
| `common/keys.ts`| Framework-specific `MetadataKeys` (CONTROLLER, MODEL, REPOSITORY, etc.) merged with base keys. |
|
|
94
|
-
| `common/types.ts`| Framework-specific interfaces (`IControllerMetadata`, `IModelMetadata`, `IRepositoryMetadata`, etc.). |
|
|
95
|
-
| `index.ts` | Re-exports core classes from `@venizia/ignis-inversion` plus application extensions. |
|
|
96
|
-
|
|
97
|
-
**Re-exported from `@venizia/ignis-inversion`:**
|
|
98
|
-
- `Binding`, `BindingKeys`, `BindingScopes`, `BindingValueTypes`
|
|
99
|
-
|
|
100
|
-
**Application-specific additions:**
|
|
101
|
-
- `Container` with `ApplicationLogger` integration
|
|
102
|
-
- `MetadataRegistry` with `setControllerMetadata`, `setModelMetadata`, `setRepositoryMetadata`, etc.
|
|
103
|
-
- Framework metadata interfaces for controllers, models, repositories, and data sources
|
|
104
|
-
|
|
105
|
-
For standalone DI usage without framework features, import directly from `@venizia/ignis-inversion`.
|
|
106
|
-
|
|
107
|
-
#### `helpers/logger/`
|
|
108
|
-
|
|
109
|
-
Logging solution built on Winston.
|
|
110
|
-
|
|
111
|
-
| File/Folder | Purpose/Key Details |
|
|
112
|
-
| :------------------------------ | :--------------------------------------------------------------------- |
|
|
113
|
-
| `application-logger.ts` | `ApplicationLogger` for structured logging with scopes. |
|
|
114
|
-
| `default-logger.ts` | Default Winston logger configuration with console and file transports. |
|
|
115
|
-
| `factory.ts` | `LoggerFactory` for obtaining logger instances. |
|
|
116
|
-
| `transports/dgram.transport.ts` | UDP transport for log aggregation. |
|
|
117
|
-
| `types.ts` | Log level definitions. |
|
|
118
|
-
|
|
119
|
-
#### `helpers/network/`
|
|
120
|
-
|
|
121
|
-
Utilities for network communication.
|
|
122
|
-
|
|
123
|
-
| File/Folder | Purpose/Key Details |
|
|
124
|
-
| :-------------- | :------------------------------------------------------------------------------ |
|
|
125
|
-
| `http-request/` | HTTP client implementations (`AxiosNetworkRequest`, `NodeFetchNetworkRequest`). |
|
|
126
|
-
| `tcp-socket/` | TCP and TLS socket client/server helpers. |
|
|
127
|
-
| `udp-socket/` | UDP client helper. |
|
|
128
|
-
|
|
129
|
-
#### `helpers/queue/`
|
|
130
|
-
|
|
131
|
-
Message queuing solutions.
|
|
132
|
-
|
|
133
|
-
| File/Folder | Purpose/Key Details |
|
|
134
|
-
| :---------- | :---------------------------------------------- |
|
|
135
|
-
| `bullmq/` | `BullMQHelper` for Redis-backed message queues. |
|
|
136
|
-
| `mqtt/` | `MQTTClientHelper` for MQTT broker interaction. |
|
|
137
|
-
| `internal/` | `QueueHelper` for simple in-memory queues. |
|
|
138
|
-
| `common/` | Common types for queue operations. |
|
|
139
|
-
|
|
140
|
-
#### `helpers/redis/`
|
|
141
|
-
|
|
142
|
-
Redis client helpers.
|
|
143
|
-
|
|
144
|
-
| File/Folder | Purpose/Key Details |
|
|
145
|
-
| :------------------ | :----------------------------------------------------------------- |
|
|
146
|
-
| `cluster.helper.ts` | `RedisClusterHelper` for Redis cluster connections. |
|
|
147
|
-
| `default.helper.ts` | `DefaultRedisHelper` providing a unified API for Redis operations. |
|
|
148
|
-
| `single.helper.ts` | `RedisHelper` for single Redis instance connections. |
|
|
149
|
-
| `types.ts` | Interfaces and types for Redis helpers. |
|
|
150
|
-
|
|
151
|
-
#### `helpers/socket-io/`
|
|
152
|
-
|
|
153
|
-
Socket.IO client and server helpers.
|
|
154
|
-
|
|
155
|
-
| File/Folder | Purpose/Key Details |
|
|
156
|
-
| :---------- | :------------------------------------------------------------ |
|
|
157
|
-
| `client/` | `SocketIOClientHelper` for client-side Socket.IO connections. |
|
|
158
|
-
| `server/` | `SocketIOServerHelper` for server-side Socket.IO management. |
|
|
159
|
-
| `common/` | Common types and constants for Socket.IO. |
|
|
160
|
-
|
|
161
|
-
#### `helpers/storage/`
|
|
162
|
-
|
|
163
|
-
Storage utilities.
|
|
164
|
-
|
|
165
|
-
| File/Folder | Purpose/Key Details |
|
|
166
|
-
| :----------- | :----------------------------------------------------- |
|
|
167
|
-
| `in-memory/` | `MemoryStorageHelper` for in-memory key-value storage. |
|
|
168
|
-
| `minio/` | `MinioHelper` for S3-compatible object storage. |
|
|
169
|
-
|
|
170
|
-
#### `helpers/testing/`
|
|
171
|
-
|
|
172
|
-
Framework for writing and executing tests using `node:test`.
|
|
173
|
-
|
|
174
|
-
| File/Folder | Purpose/Key Details |
|
|
175
|
-
| :------------------ | :---------------------------------------------------------- |
|
|
176
|
-
| `base-test-plan.ts` | Abstract base for test plans. |
|
|
177
|
-
| `common/` | Common types and constants for testing utilities. |
|
|
178
|
-
| `describe.ts` | `TestDescribe` integrates with `node:test` lifecycle hooks. |
|
|
179
|
-
| `test-case.ts` | Defines individual test cases. |
|
|
180
|
-
| `test-handler.ts` | Base class for test case handlers. |
|
|
181
|
-
| `test-plan.ts` | `TestPlan` for organizing test suites. |
|
|
182
|
-
|
|
183
|
-
#### `helpers/worker-thread/`
|
|
184
|
-
|
|
185
|
-
Utilities for Node.js worker threads.
|
|
186
|
-
|
|
187
|
-
| File/Folder | Purpose/Key Details |
|
|
188
|
-
| :--------------- | :---------------------------------------------------------- |
|
|
189
|
-
| `base.ts` | Base classes for workers and worker threads. |
|
|
190
|
-
| `types.ts` | Interfaces and types for worker threads. |
|
|
191
|
-
| `worker-bus.ts` | Helpers for inter-thread communication using `MessagePort`. |
|
|
192
|
-
| `worker-pool.ts` | `WorkerPoolHelper` for managing a pool of worker threads. |
|
|
193
|
-
|
|
194
|
-
### `utilities`
|
|
195
|
-
|
|
196
|
-
This directory contains pure, standalone utility functions that perform common, stateless operations.
|
|
197
|
-
|
|
198
|
-
| File/Folder | Purpose/Key Details |
|
|
199
|
-
| :----------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
200
|
-
| `crypto.utility.ts` | Provides a `hash()` function for cryptographic hashing (SHA256, MD5). |
|
|
201
|
-
| `date.utility.ts` | Date and time manipulation functions (`dayjs` integration, `sleep`, `isWeekday`, `getDateTz`, `hrTime`). |
|
|
202
|
-
| `module.utility.ts` | `validateModule()` to check for module existence at runtime. |
|
|
203
|
-
| `parse.utility.ts` | Functions for type checking (`isInt`, `isFloat`), type conversion (`int`, `float`, `toBoolean`), string/object transformation (`toCamel`, `keysToCamel`), array transformations (`parseArrayToRecordWithKey`, `parseArrayToMapWithKey`), and `getUID()` for unique IDs. |
|
|
204
|
-
| `performance.utility.ts` | Utilities for measuring code execution time (`executeWithPerformanceMeasure`, `getPerformanceCheckpoint`, `getExecutedPerformance`). |
|
|
205
|
-
| `promise.utility.ts` | Helper functions for Promises (`executePromiseWithLimit`, `isPromiseLike`, `transformValueOrPromise`, `getDeepProperty`). |
|
|
206
|
-
| `request.utility.ts` | Utilities for handling HTTP request data, such as `parseMultipartBody` for multipart form data. |
|
|
207
|
-
| `schema.utility.ts` | Helper functions and predefined schemas for `zod` and `@hono/zod-openapi` (`jsonContent`, `jsonResponse`, `requiredString`, `AnyObjectSchema`, `IdParamsSchema`, `UUIDParamsSchema`). |
|
|
208
|
-
|
|
209
|
-
---
|
|
210
|
-
|
|
211
|
-
This detailed breakdown illustrates the modular and layered design of the Ignis framework, emphasizing its extensibility and adherence to robust architectural patterns.
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
# Framework Internals
|
|
2
|
-
|
|
3
|
-
Deep dive into Ignis package structure and source code organization.
|
|
4
|
-
|
|
5
|
-
## Quick Reference
|
|
6
|
-
|
|
7
|
-
| Package | npm | Purpose |
|
|
8
|
-
|---------|-----|---------|
|
|
9
|
-
| `@venizia/ignis` | Core | Main framework with controllers, repositories, components |
|
|
10
|
-
| `@venizia/ignis-boot` | Boot | Auto-discovery and bootstrapping utilities |
|
|
11
|
-
| `@venizia/ignis-helpers` | Helpers | Reusable utilities (logger, crypto, redis, etc.) |
|
|
12
|
-
| `@venizia/ignis-inversion` | Inversion | Standalone dependency injection container |
|
|
13
|
-
| `@venizia/dev-configs` | Dev Configs | TypeScript, ESLint, Prettier configurations |
|
|
14
|
-
| `@venizia/ignis-docs` | Docs | Documentation site and MCP server |
|
|
15
|
-
|
|
16
|
-
## Monorepo Structure
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
ignis/
|
|
20
|
-
├── packages/
|
|
21
|
-
│ ├── core/ → @venizia/ignis (main framework)
|
|
22
|
-
│ ├── boot/ → @venizia/ignis-boot (auto-discovery)
|
|
23
|
-
│ ├── helpers/ → @venizia/ignis-helpers (utilities)
|
|
24
|
-
│ ├── inversion/ → @venizia/ignis-inversion (DI container)
|
|
25
|
-
│ ├── dev-configs/ → @venizia/dev-configs (linting/formatting)
|
|
26
|
-
│ └── docs/ → @venizia/ignis-docs (documentation)
|
|
27
|
-
├── examples/ → Example applications
|
|
28
|
-
└── scripts/ → Build and maintenance scripts
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## Package Dependencies
|
|
32
|
-
|
|
33
|
-
```
|
|
34
|
-
┌─────────────────────────────────────────────────────────┐
|
|
35
|
-
│ @venizia/ignis │
|
|
36
|
-
│ (Core Framework) │
|
|
37
|
-
│ │
|
|
38
|
-
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
|
39
|
-
│ │ base/ │ │ components/ │ │ utilities/ │ │
|
|
40
|
-
│ │ (Controllers,│ │ (Auth, Swagger,│ │ (Crypto, │ │
|
|
41
|
-
│ │ Repos, etc.)│ │ HealthCheck) │ │ Date, etc.) │ │
|
|
42
|
-
│ └──────────────┘ └──────────────┘ └──────────────┘ │
|
|
43
|
-
└────────────────────────┬────────────────────────────────┘
|
|
44
|
-
│ depends on
|
|
45
|
-
┌───────────────┼───────────────┐
|
|
46
|
-
▼ ▼ ▼
|
|
47
|
-
┌────────────────┐ ┌────────────┐ ┌────────────────┐
|
|
48
|
-
│ @vez/ignis-boot│ │@vez/ignis- │ │ @vez/ignis- │
|
|
49
|
-
│ (Auto-Discovery)│ │ helpers │ │ inversion │
|
|
50
|
-
│ │ │ (Logger, │ │ (DI Container) │
|
|
51
|
-
│ │ │ Redis,etc)│ │ │
|
|
52
|
-
└────────────────┘ └─────┬──────┘ └────────────────┘
|
|
53
|
-
│ depends on
|
|
54
|
-
▼
|
|
55
|
-
┌─────────────────────┐
|
|
56
|
-
│ @vez/ignis-inversion│
|
|
57
|
-
│ (Standalone DI) │
|
|
58
|
-
└─────────────────────┘
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
## What's in This Section
|
|
62
|
-
|
|
63
|
-
### Core Package
|
|
64
|
-
- [Core (@venizia/ignis)](./core.md) - Main framework with base classes, components, and utilities
|
|
65
|
-
|
|
66
|
-
### Supporting Packages
|
|
67
|
-
- [Boot (@venizia/ignis-boot)](./boot.md) - Automatic artifact discovery and registration
|
|
68
|
-
- [Helpers (@venizia/ignis-helpers)](./helpers.md) - Reusable helper classes (logger, crypto, redis, etc.)
|
|
69
|
-
- [Inversion (@venizia/ignis-inversion)](./inversion.md) - Standalone dependency injection container
|
|
70
|
-
|
|
71
|
-
### Development Tools
|
|
72
|
-
- [Dev Configs (@venizia/dev-configs)](./dev-configs.md) - Shared TypeScript, ESLint, Prettier configs
|
|
73
|
-
- [Documentation (@venizia/ignis-docs)](./docs.md) - VitePress site and wiki structure
|
|
74
|
-
- [MCP Docs Server](./mcp-server.md) - Model Context Protocol server for AI-assisted development
|
|
75
|
-
|
|
76
|
-
## Package Purposes
|
|
77
|
-
|
|
78
|
-
| Package | When to Use |
|
|
79
|
-
|---------|-------------|
|
|
80
|
-
| **@venizia/ignis** | Building Ignis applications (always needed) |
|
|
81
|
-
| **@venizia/ignis-boot** | Auto-discovery of controllers, services, repositories |
|
|
82
|
-
| **@venizia/ignis-helpers** | Standalone utilities without full framework |
|
|
83
|
-
| **@venizia/ignis-inversion** | DI container without framework dependencies |
|
|
84
|
-
| **@venizia/dev-configs** | Consistent dev tooling across projects |
|
|
85
|
-
|
|
86
|
-
> **Related:** [Core Concepts Guide](../../guides/core-concepts/application/) | [Base Abstractions Reference](../base/)
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
# Package: `@venizia/ignis-inversion`
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
The `@venizia/ignis-inversion` package provides a standalone, lightweight Dependency Injection (DI) and Inversion of Control (IoC) container. This package was extracted from `@venizia/ignis-helpers` to enable independent usage and better modularity.
|
|
6
|
-
|
|
7
|
-
## Package Information
|
|
8
|
-
|
|
9
|
-
| Property | Value |
|
|
10
|
-
|----------|-------|
|
|
11
|
-
| **Package Name** | `@venizia/ignis-inversion` |
|
|
12
|
-
| **Location** | `packages/inversion/` |
|
|
13
|
-
| **Purpose** | Standalone DI/IoC container |
|
|
14
|
-
| **Dependencies** | `lodash`, `reflect-metadata`, `zod` |
|
|
15
|
-
|
|
16
|
-
## Key Features
|
|
17
|
-
|
|
18
|
-
- **Flexible Binding Strategies**: Class, Value, and Provider-based bindings
|
|
19
|
-
- **Scope Management**: Singleton and Transient scopes
|
|
20
|
-
- **Metadata-driven Injection**: Constructor and property injection via decorators
|
|
21
|
-
- **Tag-based Discovery**: Find bindings by tag for modular composition
|
|
22
|
-
- **Type-safe**: Full TypeScript support with generics
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## Core Components
|
|
27
|
-
|
|
28
|
-
### Binding Class
|
|
29
|
-
|
|
30
|
-
The `Binding<T>` class represents a single dependency registration in the container.
|
|
31
|
-
|
|
32
|
-
#### Binding Methods
|
|
33
|
-
|
|
34
|
-
| Method | Description | Returns |
|
|
35
|
-
|--------|-------------|---------|
|
|
36
|
-
| `toClass(cls)` | Bind to a class constructor | `this` |
|
|
37
|
-
| `toValue(value)` | Bind to a static value | `this` |
|
|
38
|
-
| `toProvider(fn)` | Bind to a provider function or class | `this` |
|
|
39
|
-
| `setScope(scope)` | Set binding scope (SINGLETON/TRANSIENT) | `this` |
|
|
40
|
-
| `setTags(...tags)` | Add tags for discovery | `this` |
|
|
41
|
-
| `getValue(container)` | Resolve the bound value | `T` |
|
|
42
|
-
| `clearCache()` | Clear singleton cache | `void` |
|
|
43
|
-
|
|
44
|
-
#### Binding Example
|
|
45
|
-
|
|
46
|
-
```typescript
|
|
47
|
-
import { Binding, BindingScopes } from '@venizia/ignis-inversion';
|
|
48
|
-
|
|
49
|
-
// Create a binding
|
|
50
|
-
const binding = new Binding<MyService>({ key: 'services.MyService' })
|
|
51
|
-
.toClass(MyService)
|
|
52
|
-
.setScope(BindingScopes.SINGLETON)
|
|
53
|
-
.setTags('services', 'core');
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Container Class
|
|
57
|
-
|
|
58
|
-
The `Container` class is the main DI container for managing bindings and resolving dependencies.
|
|
59
|
-
|
|
60
|
-
#### Container Methods
|
|
61
|
-
|
|
62
|
-
| Method | Description | Returns |
|
|
63
|
-
|--------|-------------|---------|
|
|
64
|
-
| `bind<T>({ key })` | Create a new binding | `Binding<T>` |
|
|
65
|
-
| `isBound({ key })` | Check if binding exists | `boolean` |
|
|
66
|
-
| `getBinding<T>({ key })` | Get a specific binding | `Binding<T> \| undefined` |
|
|
67
|
-
| `unbind({ key })` | Remove a binding | `boolean` |
|
|
68
|
-
| `get<T>({ key, isOptional? })` | Resolve a dependency | `T \| undefined` |
|
|
69
|
-
| `resolve<T>(cls)` | Instantiate a class with injection | `T` |
|
|
70
|
-
| `instantiate<T>(cls)` | Same as resolve | `T` |
|
|
71
|
-
| `findByTag<T>({ tag })` | Find bindings by tag | `Binding<T>[]` |
|
|
72
|
-
| `clear()` | Clear singleton caches | `void` |
|
|
73
|
-
| `reset()` | Clear all bindings | `void` |
|
|
74
|
-
|
|
75
|
-
#### Container Example
|
|
76
|
-
|
|
77
|
-
```typescript
|
|
78
|
-
import { Container, BindingScopes } from '@venizia/ignis-inversion';
|
|
79
|
-
|
|
80
|
-
const container = new Container({ scope: 'MyApp' });
|
|
81
|
-
|
|
82
|
-
// Bind a class
|
|
83
|
-
container.bind<UserService>({ key: 'services.UserService' })
|
|
84
|
-
.toClass(UserService)
|
|
85
|
-
.setScope(BindingScopes.SINGLETON);
|
|
86
|
-
|
|
87
|
-
// Bind a value
|
|
88
|
-
container.bind<string>({ key: 'config.apiUrl' })
|
|
89
|
-
.toValue('https://api.example.com');
|
|
90
|
-
|
|
91
|
-
// Bind a provider
|
|
92
|
-
container.bind<DatabaseConnection>({ key: 'database' })
|
|
93
|
-
.toProvider((container) => {
|
|
94
|
-
const config = container.get<Config>({ key: 'config' });
|
|
95
|
-
return new DatabaseConnection(config.dbUrl);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
// Resolve dependencies
|
|
99
|
-
const userService = container.get<UserService>({ key: 'services.UserService' });
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### MetadataRegistry Class
|
|
103
|
-
|
|
104
|
-
The `MetadataRegistry` stores and retrieves decorator metadata for DI.
|
|
105
|
-
|
|
106
|
-
#### Registry Methods
|
|
107
|
-
|
|
108
|
-
| Method | Description |
|
|
109
|
-
|--------|-------------|
|
|
110
|
-
| `define({ target, key, value })` | Define metadata on a target |
|
|
111
|
-
| `get({ target, key })` | Get metadata from a target |
|
|
112
|
-
| `has({ target, key })` | Check if metadata exists |
|
|
113
|
-
| `delete({ target, key })` | Delete metadata |
|
|
114
|
-
| `getKeys({ target })` | Get all metadata keys |
|
|
115
|
-
| `setPropertyMetadata(...)` | Set property injection metadata |
|
|
116
|
-
| `getPropertiesMetadata(...)` | Get all property metadata |
|
|
117
|
-
| `setInjectMetadata(...)` | Set constructor injection metadata |
|
|
118
|
-
| `getInjectMetadata(...)` | Get constructor injection metadata |
|
|
119
|
-
|
|
120
|
-
---
|
|
121
|
-
|
|
122
|
-
## Types and Interfaces
|
|
123
|
-
|
|
124
|
-
### Binding Scopes
|
|
125
|
-
|
|
126
|
-
```typescript
|
|
127
|
-
import { BindingScopes } from '@venizia/ignis-inversion';
|
|
128
|
-
|
|
129
|
-
BindingScopes.SINGLETON // Single instance, reused
|
|
130
|
-
BindingScopes.TRANSIENT // New instance each request (default)
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Binding Value Types
|
|
134
|
-
|
|
135
|
-
```typescript
|
|
136
|
-
import { BindingValueTypes } from '@venizia/ignis-inversion';
|
|
137
|
-
|
|
138
|
-
BindingValueTypes.CLASS // Bind to class constructor
|
|
139
|
-
BindingValueTypes.VALUE // Bind to static value
|
|
140
|
-
BindingValueTypes.PROVIDER // Bind to provider function/class
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
### Provider Interface
|
|
144
|
-
|
|
145
|
-
```typescript
|
|
146
|
-
interface IProvider<T> {
|
|
147
|
-
value(container: Container): T;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Example provider class
|
|
151
|
-
class DatabaseProvider implements IProvider<DatabaseConnection> {
|
|
152
|
-
value(container: Container): DatabaseConnection {
|
|
153
|
-
const config = container.get<Config>({ key: 'config' });
|
|
154
|
-
return new DatabaseConnection(config.dbUrl);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### BindingKeys Helper
|
|
160
|
-
|
|
161
|
-
```typescript
|
|
162
|
-
import { BindingKeys } from '@venizia/ignis-inversion';
|
|
163
|
-
|
|
164
|
-
const key = BindingKeys.build({ namespace: 'services', key: 'UserService' });
|
|
165
|
-
// Result: 'services.UserService'
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
### Type Definitions
|
|
169
|
-
|
|
170
|
-
| Type | Description |
|
|
171
|
-
|------|-------------|
|
|
172
|
-
| `TNullable<T>` | `T \| undefined \| null` |
|
|
173
|
-
| `TClass<T>` | Class constructor type |
|
|
174
|
-
| `TConstructor<T>` | Generic constructor |
|
|
175
|
-
| `TBindingScope` | `'singleton' \| 'transient'` |
|
|
176
|
-
| `IPropertyMetadata` | Property injection metadata |
|
|
177
|
-
| `IInjectMetadata` | Constructor injection metadata |
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
## Injection Metadata
|
|
181
|
-
|
|
182
|
-
### Property Injection
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
interface IPropertyMetadata {
|
|
186
|
-
bindingKey: string | symbol;
|
|
187
|
-
isOptional?: boolean;
|
|
188
|
-
[key: string]: any;
|
|
189
|
-
}
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### Constructor Injection
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
interface IInjectMetadata {
|
|
196
|
-
key: string | symbol;
|
|
197
|
-
index: number;
|
|
198
|
-
isOptional?: boolean;
|
|
199
|
-
}
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
## Project Structure
|
|
204
|
-
|
|
205
|
-
```
|
|
206
|
-
packages/inversion/
|
|
207
|
-
├── package.json
|
|
208
|
-
├── tsconfig.json
|
|
209
|
-
├── src/
|
|
210
|
-
│ ├── index.ts # Main exports + reflect-metadata import
|
|
211
|
-
│ ├── container.ts # Container and Binding classes
|
|
212
|
-
│ ├── registry.ts # MetadataRegistry class
|
|
213
|
-
│ └── common/
|
|
214
|
-
│ ├── index.ts # Common exports
|
|
215
|
-
│ ├── types.ts # Types, interfaces, BindingScopes, etc.
|
|
216
|
-
│ ├── keys.ts # MetadataKeys symbols
|
|
217
|
-
│ ├── app-error.ts # ApplicationError class
|
|
218
|
-
│ ├── base-helper.ts # BaseHelper base class
|
|
219
|
-
│ └── logger.ts # Simple Logger class
|
|
220
|
-
├── scripts/
|
|
221
|
-
│ ├── build.sh
|
|
222
|
-
│ ├── clean.sh
|
|
223
|
-
│ └── rebuild.sh
|
|
224
|
-
└── dist/ # Built output
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
## Usage Examples
|
|
229
|
-
|
|
230
|
-
### Basic Container Usage
|
|
231
|
-
|
|
232
|
-
```typescript
|
|
233
|
-
import { Container, BindingScopes } from '@venizia/ignis-inversion';
|
|
234
|
-
|
|
235
|
-
// Create container
|
|
236
|
-
const container = new Container();
|
|
237
|
-
|
|
238
|
-
// Register services
|
|
239
|
-
container.bind({ key: 'logger' }).toValue(console);
|
|
240
|
-
container.bind({ key: 'services.UserService' })
|
|
241
|
-
.toClass(UserService)
|
|
242
|
-
.setScope(BindingScopes.SINGLETON);
|
|
243
|
-
|
|
244
|
-
// Resolve
|
|
245
|
-
const logger = container.get({ key: 'logger' });
|
|
246
|
-
const userService = container.get({ key: 'services.UserService' });
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
### Using Providers
|
|
250
|
-
|
|
251
|
-
```typescript
|
|
252
|
-
import { Container, IProvider } from '@venizia/ignis-inversion';
|
|
253
|
-
|
|
254
|
-
// Function provider
|
|
255
|
-
container.bind({ key: 'database' })
|
|
256
|
-
.toProvider((container) => {
|
|
257
|
-
return new Database(container.get({ key: 'config.dbUrl' }));
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
// Class provider
|
|
261
|
-
class ConfigProvider implements IProvider<Config> {
|
|
262
|
-
value(container: Container): Config {
|
|
263
|
-
return {
|
|
264
|
-
env: process.env.NODE_ENV,
|
|
265
|
-
port: parseInt(process.env.PORT || '3000'),
|
|
266
|
-
};
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
container.bind({ key: 'config' }).toProvider(ConfigProvider);
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
### Tag-based Discovery
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
// Register with tags
|
|
277
|
-
container.bind({ key: 'handlers.UserHandler' })
|
|
278
|
-
.toClass(UserHandler)
|
|
279
|
-
.setTags('handlers', 'user');
|
|
280
|
-
|
|
281
|
-
container.bind({ key: 'handlers.OrderHandler' })
|
|
282
|
-
.toClass(OrderHandler)
|
|
283
|
-
.setTags('handlers', 'order');
|
|
284
|
-
|
|
285
|
-
// Find all handlers
|
|
286
|
-
const handlers = container.findByTag({ tag: 'handlers' });
|
|
287
|
-
handlers.forEach(binding => {
|
|
288
|
-
const handler = binding.getValue(container);
|
|
289
|
-
// Use handler...
|
|
290
|
-
});
|
|
291
|
-
```
|
|
292
|
-
|
|
293
|
-
### Optional Dependencies
|
|
294
|
-
|
|
295
|
-
```typescript
|
|
296
|
-
// Get optional dependency (returns undefined if not bound)
|
|
297
|
-
const cache = container.get<CacheService>({
|
|
298
|
-
key: 'services.CacheService',
|
|
299
|
-
isOptional: true
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
if (cache) {
|
|
303
|
-
// Use cache service
|
|
304
|
-
}
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
## Integration with Framework
|
|
309
|
-
|
|
310
|
-
The core `@venizia/ignis` package extends this base inversion package with:
|
|
311
|
-
|
|
312
|
-
- **ApplicationLogger integration**: Container with structured logging
|
|
313
|
-
- **Framework-specific metadata**: Controllers, models, repositories, data sources
|
|
314
|
-
- **Decorator implementations**: `@inject`, `@controller`, `@service`, etc.
|
|
315
|
-
|
|
316
|
-
For framework usage, import from `@venizia/ignis`. For standalone DI container usage, import directly from `@venizia/ignis-inversion`.
|
|
317
|
-
|
|
318
|
-
```typescript
|
|
319
|
-
// Standalone usage
|
|
320
|
-
import { Container, Binding } from '@venizia/ignis-inversion';
|
|
321
|
-
|
|
322
|
-
// Framework usage (includes logging and framework metadata)
|
|
323
|
-
import { Container, inject, service } from '@venizia/ignis';
|
|
324
|
-
```
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
## Building the Package
|
|
328
|
-
|
|
329
|
-
```bash
|
|
330
|
-
cd packages/inversion
|
|
331
|
-
|
|
332
|
-
# Build
|
|
333
|
-
bun run build
|
|
334
|
-
|
|
335
|
-
# Clean
|
|
336
|
-
bun run clean
|
|
337
|
-
|
|
338
|
-
# Rebuild (clean + build)
|
|
339
|
-
bun run rebuild
|
|
340
|
-
```
|