assemblerjs 0.9.6 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +220 -56
- package/dist/index.d.ts +701 -464
- package/dist/index.js +59 -1
- package/dist/index.mjs +21 -916
- package/dist/index10.js +8 -0
- package/dist/index10.mjs +4 -0
- package/dist/index11.js +27 -0
- package/dist/index11.mjs +23 -0
- package/dist/index12.js +16 -0
- package/dist/index12.mjs +12 -0
- package/dist/index13.js +94 -0
- package/dist/index13.mjs +90 -0
- package/dist/index14.js +22 -0
- package/dist/index14.mjs +18 -0
- package/dist/index15.js +22 -0
- package/dist/index15.mjs +18 -0
- package/dist/index16.js +22 -0
- package/dist/index16.mjs +18 -0
- package/dist/index17.js +22 -0
- package/dist/index17.mjs +18 -0
- package/dist/index18.js +31 -0
- package/dist/index18.mjs +26 -0
- package/dist/index19.js +31 -0
- package/dist/index19.mjs +26 -0
- package/dist/index2.js +22 -0
- package/dist/index2.mjs +17 -0
- package/dist/index20.js +31 -0
- package/dist/index20.mjs +27 -0
- package/dist/index21.js +33 -0
- package/dist/index21.mjs +25 -0
- package/dist/index22.js +53 -0
- package/dist/index22.mjs +48 -0
- package/dist/index23.js +69 -0
- package/dist/index23.mjs +65 -0
- package/dist/index24.js +37 -0
- package/dist/index24.mjs +33 -0
- package/dist/index25.js +71 -0
- package/dist/index25.mjs +67 -0
- package/dist/index26.js +37 -0
- package/dist/index26.mjs +33 -0
- package/dist/index27.js +37 -0
- package/dist/index27.mjs +33 -0
- package/dist/index28.js +46 -0
- package/dist/index28.mjs +41 -0
- package/dist/index29.js +20 -0
- package/dist/index29.mjs +14 -0
- package/dist/index3.js +20 -0
- package/dist/index3.mjs +14 -0
- package/dist/index30.js +19 -0
- package/dist/index30.mjs +13 -0
- package/dist/index31.js +100 -0
- package/dist/index31.mjs +94 -0
- package/dist/index32.js +28 -0
- package/dist/index32.mjs +24 -0
- package/dist/index33.js +34 -0
- package/dist/index33.mjs +29 -0
- package/dist/index34.js +14 -0
- package/dist/index34.mjs +10 -0
- package/dist/index35.js +54 -0
- package/dist/index35.mjs +50 -0
- package/dist/index36.js +117 -0
- package/dist/index36.mjs +113 -0
- package/dist/index37.js +19 -0
- package/dist/index37.mjs +15 -0
- package/dist/index38.js +31 -0
- package/dist/index38.mjs +27 -0
- package/dist/index39.js +55 -0
- package/dist/index39.mjs +50 -0
- package/dist/index4.js +81 -0
- package/dist/index4.mjs +77 -0
- package/dist/index5.js +94 -0
- package/dist/index5.mjs +90 -0
- package/dist/index6.js +114 -0
- package/dist/index6.mjs +110 -0
- package/dist/index7.js +9 -0
- package/dist/index7.mjs +5 -0
- package/dist/index8.js +10 -0
- package/dist/index8.mjs +6 -0
- package/dist/index9.js +8 -0
- package/dist/index9.mjs +4 -0
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -1,96 +1,260 @@
|
|
|
1
1
|
# assembler.js
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A modern, type-safe, and lightweight [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library for **Node.js and Browsers** 🌐.
|
|
4
|
+
|
|
5
|
+
> ✨ **Universal Library**: Works seamlessly in Node.js, browsers, and any JavaScript environment that supports ES2020+
|
|
4
6
|
|
|
5
7
|
   
|
|
6
8
|
|
|
9
|
+
## Performance Metrics
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
[→ Full Benchmarks](../../docs/assemblerjs/performance/benchmarks.md)
|
|
17
|
+
|
|
7
18
|
---
|
|
8
19
|
|
|
9
|
-
|
|
20
|
+
## Features
|
|
21
|
+
|
|
22
|
+
- 🎯 **Minimal Dependencies** - Only requires `reflect-metadata`
|
|
23
|
+
- 🔒 **Type-Safe** - Full TypeScript support with generics
|
|
24
|
+
- 🌳 **Tree-Shakable** - Optimized bundle size (~5-6 KB for minimal usage)
|
|
25
|
+
- ♻️ **Lifecycle Hooks** - `onRegister`, `onInit`, `onDispose`
|
|
26
|
+
- 📡 **Built-in Event System** - Integrated EventManager
|
|
27
|
+
- 🎨 **Custom Decorators** - Easy creation with `ParameterDecoratorFactory` and `createConstructorDecorator`
|
|
28
|
+
- 🔧 **Flexible Configuration** - Runtime configuration override
|
|
29
|
+
- 🏷️ **Tags Support** - Group and retrieve dependencies by tags
|
|
30
|
+
- 🌐 **Universal** - **Works in Node.js AND Browsers** - No platform-specific dependencies
|
|
31
|
+
- 🔄 **Singleton & Transient** - Control instance lifecycle
|
|
32
|
+
- 📦 **Small Bundle Size** - Perfect for frontend applications (~5-6 KB minified)
|
|
10
33
|
|
|
11
|
-
|
|
34
|
+
Inspired by [DIOD](https://github.com/artberri/diod) and [NestJS](https://nestjs.com/).
|
|
12
35
|
|
|
13
|
-
##
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
Install `assemblerjs` and its peer dependency `reflect-metadata` using npm or yarn:
|
|
14
39
|
|
|
15
40
|
```sh
|
|
16
|
-
|
|
41
|
+
npm install assemblerjs reflect-metadata
|
|
17
42
|
```
|
|
18
43
|
|
|
19
44
|
```sh
|
|
20
|
-
|
|
45
|
+
yarn add assemblerjs reflect-metadata
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
**Important:** You must import `reflect-metadata` at the entry point of your application:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
import 'reflect-metadata';
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
> ✨ **Works everywhere**: This installation works for **Node.js, browsers (with Vite/Webpack/Rollup), React, Vue, Angular, and any JavaScript environment**.
|
|
55
|
+
|
|
56
|
+
### Alternative: CDN (for quick prototyping)
|
|
57
|
+
|
|
58
|
+
If you want to try assemblerjs without a build step:
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<script src="https://unpkg.com/reflect-metadata@latest/Reflect.js"></script>
|
|
62
|
+
<script type="module">
|
|
63
|
+
import { Assemblage, Assembler } from 'https://unpkg.com/assemblerjs@latest/dist/index.js';
|
|
64
|
+
// Your code here
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quick Start
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import 'reflect-metadata';
|
|
72
|
+
import { Assemblage, Assembler, AbstractAssemblage } from 'assemblerjs';
|
|
73
|
+
|
|
74
|
+
// Define a service
|
|
75
|
+
@Assemblage()
|
|
76
|
+
class Logger implements AbstractAssemblage {
|
|
77
|
+
log(message: string) {
|
|
78
|
+
console.log(message);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Define an application that depends on Logger
|
|
83
|
+
@Assemblage({
|
|
84
|
+
inject: [[Logger]], // Declare dependencies
|
|
85
|
+
})
|
|
86
|
+
class App implements AbstractAssemblage {
|
|
87
|
+
constructor(private logger: Logger) {}
|
|
88
|
+
|
|
89
|
+
start() {
|
|
90
|
+
this.logger.log('App started!');
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Bootstrap the application
|
|
95
|
+
const app = Assembler.build(App);
|
|
96
|
+
app.start(); // Output: "App started!"
|
|
21
97
|
```
|
|
22
98
|
|
|
23
|
-
##
|
|
99
|
+
## 📚 Documentation
|
|
100
|
+
|
|
101
|
+
Comprehensive documentation is available at:
|
|
102
|
+
|
|
103
|
+
**[→ Full Documentation](../../docs/assemblerjs/)**
|
|
104
|
+
|
|
105
|
+
### Quick Links
|
|
106
|
+
|
|
107
|
+
#### Getting Started
|
|
108
|
+
- [Installation](../../docs/assemblerjs/getting-started/installation.md)
|
|
109
|
+
- [Quick Start Guide](../../docs/assemblerjs/getting-started/quick-start.md)
|
|
110
|
+
- [TypeScript Setup](../../docs/assemblerjs/getting-started/typescript-setup.md)
|
|
111
|
+
|
|
112
|
+
#### Core Concepts
|
|
113
|
+
- [Assemblage](../../docs/assemblerjs/core-concepts/assemblage.md) - Building blocks
|
|
114
|
+
- [Dependency Injection](../../docs/assemblerjs/core-concepts/dependency-injection.md) - DI patterns
|
|
115
|
+
- [Abstraction Pattern](../../docs/assemblerjs/core-concepts/abstraction-pattern.md) - Interface-based design
|
|
116
|
+
- [Lifecycle Hooks](../../docs/assemblerjs/core-concepts/lifecycle-hooks.md) - Initialization & cleanup
|
|
117
|
+
|
|
118
|
+
#### Decorators
|
|
119
|
+
- [Parameter Decorators](../../docs/assemblerjs/decorators/parameter-decorators.md) - Built-in decorators
|
|
120
|
+
- [Custom Parameter Decorators](../../docs/assemblerjs/decorators/custom-parameter.md) - Create your own
|
|
121
|
+
- [Custom Class Decorators](../../docs/assemblerjs/decorators/custom-class.md) - Type-safe class decorators
|
|
24
122
|
|
|
25
|
-
|
|
26
|
-
|
|
123
|
+
#### Features
|
|
124
|
+
- [Event System](../../docs/assemblerjs/features/events.md) - Event-driven architecture
|
|
125
|
+
- [Tags](../../docs/assemblerjs/features/tags.md) - Group assemblages
|
|
126
|
+
- [Singleton vs Transient](../../docs/assemblerjs/features/singleton-transient.md) - Instance lifecycle
|
|
27
127
|
|
|
28
|
-
|
|
128
|
+
#### API Reference
|
|
129
|
+
- [Assembler API](../../docs/assemblerjs/api/assembler.md) - Container methods
|
|
130
|
+
- [AssemblerContext API](../../docs/assemblerjs/api/context.md) - Context interface
|
|
131
|
+
- [Types](../../docs/assemblerjs/api/types.md) - TypeScript types
|
|
29
132
|
|
|
30
|
-
|
|
133
|
+
#### Guides
|
|
134
|
+
- [Advanced Examples](../../docs/assemblerjs/guides/advanced-examples.md) - Real-world patterns
|
|
135
|
+
- [Tree-Shaking](../../docs/assemblerjs/guides/tree-shaking.md) - Bundle optimization
|
|
31
136
|
|
|
32
|
-
|
|
137
|
+
#### Performance
|
|
138
|
+
- [Benchmarks](../../docs/assemblerjs/performance/benchmarks.md) - Performance metrics & best practices
|
|
33
139
|
|
|
34
|
-
|
|
35
|
-
Other dependencies may or may not have been registered at this point, and dependency tree is not built yet.
|
|
140
|
+
## Requirements
|
|
36
141
|
|
|
37
|
-
|
|
142
|
+
- **Node.js:** ≥ 18.12.0
|
|
143
|
+
- **TypeScript:** ≥ 5.0 (with decorator support)
|
|
144
|
+
- **reflect-metadata:** Required for dependency injection
|
|
38
145
|
|
|
39
|
-
|
|
40
|
-
If the dependency is not a singleton a new instance is returned, meaning the same dependency required in another assemblage will be another object, as when using the `require` method of the `AssemblerContext` passed to hooks or injected by the `@Context` decorator.
|
|
146
|
+
## For Contributors
|
|
41
147
|
|
|
42
|
-
|
|
148
|
+
### Architecture
|
|
43
149
|
|
|
44
|
-
|
|
45
|
-
Except for the entry assemblage (i.e. the one built on bootstrap by `Assembler.build`) the hook is called according to the latter.
|
|
46
|
-
The entry point assemblage is called last.
|
|
150
|
+
This package is part of the `assemblerjs` monorepo and depends on:
|
|
47
151
|
|
|
48
|
-
|
|
152
|
+
- **`@assemblerjs/core`** - Internal utilities package
|
|
49
153
|
|
|
50
|
-
|
|
51
|
-
This will be called like the `onInit` method, walking through the dependency tree, except for the entry point assemblage, called last.
|
|
154
|
+
### Development
|
|
52
155
|
|
|
53
|
-
|
|
156
|
+
```bash
|
|
157
|
+
# Install dependencies from workspace root
|
|
158
|
+
yarn install
|
|
54
159
|
|
|
55
|
-
|
|
160
|
+
# Build the package
|
|
161
|
+
npx nx build assemblerjs
|
|
56
162
|
|
|
57
|
-
|
|
163
|
+
# Run tests
|
|
164
|
+
npx nx test assemblerjs
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Tree-Shaking & Bundle Optimization
|
|
168
|
+
|
|
169
|
+
`assembler.js` is optimized for tree-shaking with modular exports. Import only what you need:
|
|
58
170
|
|
|
59
171
|
```typescript
|
|
60
|
-
|
|
172
|
+
// ❌ Large bundle (imports everything)
|
|
173
|
+
import * as Assembler from 'assemblerjs';
|
|
61
174
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
175
|
+
// ✅ Optimal (only imports required modules)
|
|
176
|
+
import { Assemblage, Assembler, AbstractAssemblage } from 'assemblerjs';
|
|
177
|
+
```
|
|
65
178
|
|
|
66
|
-
|
|
67
|
-
events: Object.values(EmitterAssemblageEvents),
|
|
68
|
-
})
|
|
69
|
-
export class EmitterAssemblage
|
|
70
|
-
extends EventManager
|
|
71
|
-
implements AbstractEventAssemblage
|
|
72
|
-
{
|
|
73
|
-
constructor() {
|
|
74
|
-
super();
|
|
75
|
-
}
|
|
179
|
+
### Bundle Size Examples
|
|
76
180
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
181
|
+
- **Minimal usage** (~5-6 KB): Core DI features only
|
|
182
|
+
- **Medium usage** (~15-18 KB): DI + Events + Parameter decorators
|
|
183
|
+
- **Full library** (~35 KB): All features
|
|
81
184
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
185
|
+
The package uses:
|
|
186
|
+
- ✅ `"sideEffects": false` - Safe to remove unused modules
|
|
187
|
+
- ✅ Modular exports - Each feature in separate files
|
|
188
|
+
- ✅ ESM format - Native tree-shaking support
|
|
189
|
+
|
|
190
|
+
## TypeScript Configuration
|
|
191
|
+
|
|
192
|
+
Enable decorators and reflection in your `tsconfig.json`:
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"compilerOptions": {
|
|
197
|
+
"experimentalDecorators": true,
|
|
198
|
+
"emitDecoratorMetadata": true,
|
|
199
|
+
"target": "ES2020",
|
|
200
|
+
"module": "ESNext",
|
|
201
|
+
"lib": ["ES2020"]
|
|
92
202
|
}
|
|
93
203
|
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Requirements
|
|
94
207
|
|
|
95
|
-
|
|
208
|
+
- **Node.js:** ≥ 18.12.0
|
|
209
|
+
- **TypeScript:** ≥ 5.0 (with decorator support)
|
|
210
|
+
- **reflect-metadata:** Required for dependency injection
|
|
211
|
+
|
|
212
|
+
## For Contributors
|
|
213
|
+
|
|
214
|
+
### Architecture
|
|
215
|
+
|
|
216
|
+
This package is part of the `assemblerjs` monorepo and depends on:
|
|
217
|
+
|
|
218
|
+
- **`@assemblerjs/core`** - Internal utilities package providing:
|
|
219
|
+
- Type utilities and helpers
|
|
220
|
+
- Collection management utilities
|
|
221
|
+
- Error handling utilities
|
|
222
|
+
- Conditional utilities
|
|
223
|
+
- Array manipulation helpers
|
|
224
|
+
|
|
225
|
+
This dependency is automatically installed with `assemblerjs` and transparent to end users.
|
|
226
|
+
|
|
227
|
+
### Development
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
# Install dependencies from workspace root
|
|
231
|
+
yarn install
|
|
232
|
+
|
|
233
|
+
# Build the package
|
|
234
|
+
npx nx build assemblerjs
|
|
235
|
+
|
|
236
|
+
# Run tests
|
|
237
|
+
npx nx test assemblerjs
|
|
96
238
|
```
|
|
239
|
+
|
|
240
|
+
### Monorepo Structure
|
|
241
|
+
|
|
242
|
+
```
|
|
243
|
+
assemblerjs/
|
|
244
|
+
├── packages/
|
|
245
|
+
│ ├── assemblerjs/ # Main DI library (this package)
|
|
246
|
+
│ ├── core/ # Internal utilities
|
|
247
|
+
│ ├── dto/ # DTO utilities
|
|
248
|
+
│ ├── electron/ # Electron integration
|
|
249
|
+
│ ├── fetch/ # Fetch utilities
|
|
250
|
+
│ ├── mongo/ # MongoDB integration
|
|
251
|
+
│ └── rest/ # REST utilities
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## License
|
|
255
|
+
|
|
256
|
+
MIT
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
260
|
+
**Made with ❤️ in Marseille**
|