assemblerjs 0.9.7 → 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.
Files changed (81) hide show
  1. package/README.md +220 -56
  2. package/dist/index.d.ts +700 -465
  3. package/dist/index.js +59 -1
  4. package/dist/index.mjs +21 -919
  5. package/dist/index10.js +8 -0
  6. package/dist/index10.mjs +4 -0
  7. package/dist/index11.js +27 -0
  8. package/dist/index11.mjs +23 -0
  9. package/dist/index12.js +16 -0
  10. package/dist/index12.mjs +12 -0
  11. package/dist/index13.js +94 -0
  12. package/dist/index13.mjs +90 -0
  13. package/dist/index14.js +22 -0
  14. package/dist/index14.mjs +18 -0
  15. package/dist/index15.js +22 -0
  16. package/dist/index15.mjs +18 -0
  17. package/dist/index16.js +22 -0
  18. package/dist/index16.mjs +18 -0
  19. package/dist/index17.js +22 -0
  20. package/dist/index17.mjs +18 -0
  21. package/dist/index18.js +31 -0
  22. package/dist/index18.mjs +26 -0
  23. package/dist/index19.js +31 -0
  24. package/dist/index19.mjs +26 -0
  25. package/dist/index2.js +22 -0
  26. package/dist/index2.mjs +17 -0
  27. package/dist/index20.js +31 -0
  28. package/dist/index20.mjs +27 -0
  29. package/dist/index21.js +33 -0
  30. package/dist/index21.mjs +25 -0
  31. package/dist/index22.js +53 -0
  32. package/dist/index22.mjs +48 -0
  33. package/dist/index23.js +69 -0
  34. package/dist/index23.mjs +65 -0
  35. package/dist/index24.js +37 -0
  36. package/dist/index24.mjs +33 -0
  37. package/dist/index25.js +71 -0
  38. package/dist/index25.mjs +67 -0
  39. package/dist/index26.js +37 -0
  40. package/dist/index26.mjs +33 -0
  41. package/dist/index27.js +37 -0
  42. package/dist/index27.mjs +33 -0
  43. package/dist/index28.js +46 -0
  44. package/dist/index28.mjs +41 -0
  45. package/dist/index29.js +20 -0
  46. package/dist/index29.mjs +14 -0
  47. package/dist/index3.js +20 -0
  48. package/dist/index3.mjs +14 -0
  49. package/dist/index30.js +19 -0
  50. package/dist/index30.mjs +13 -0
  51. package/dist/index31.js +100 -0
  52. package/dist/index31.mjs +94 -0
  53. package/dist/index32.js +28 -0
  54. package/dist/index32.mjs +24 -0
  55. package/dist/index33.js +34 -0
  56. package/dist/index33.mjs +29 -0
  57. package/dist/index34.js +14 -0
  58. package/dist/index34.mjs +10 -0
  59. package/dist/index35.js +54 -0
  60. package/dist/index35.mjs +50 -0
  61. package/dist/index36.js +117 -0
  62. package/dist/index36.mjs +113 -0
  63. package/dist/index37.js +19 -0
  64. package/dist/index37.mjs +15 -0
  65. package/dist/index38.js +31 -0
  66. package/dist/index38.mjs +27 -0
  67. package/dist/index39.js +55 -0
  68. package/dist/index39.mjs +50 -0
  69. package/dist/index4.js +81 -0
  70. package/dist/index4.mjs +77 -0
  71. package/dist/index5.js +94 -0
  72. package/dist/index5.mjs +90 -0
  73. package/dist/index6.js +114 -0
  74. package/dist/index6.mjs +110 -0
  75. package/dist/index7.js +9 -0
  76. package/dist/index7.mjs +5 -0
  77. package/dist/index8.js +10 -0
  78. package/dist/index8.mjs +6 -0
  79. package/dist/index9.js +8 -0
  80. package/dist/index9.mjs +4 -0
  81. package/package.json +8 -5
package/README.md CHANGED
@@ -1,96 +1,260 @@
1
1
  # assembler.js
2
2
 
3
- A general purpose and zero-dependency [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library for node and browser.
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
  ![Statements](https://img.shields.io/badge/statements-91.01%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-79.6%25-red.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-87.62%25-yellow.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-90.76%25-brightgreen.svg?style=flat)
6
8
 
9
+ ## Performance Metrics
10
+
11
+ ![Assembler Building](https://img.shields.io/badge/assembler%20building-156k%20ops%2Fsec-brightgreen.svg?style=flat)
12
+ ![Injectable Resolution](https://img.shields.io/badge/singleton%20cache-1.2M%20ops%2Fsec-brightgreen.svg?style=flat)
13
+ ![Event System](https://img.shields.io/badge/event%20emit-432k%20ops%2Fsec-brightgreen.svg?style=flat)
14
+ ![Decorators](https://img.shields.io/badge/decorators-890k%20ops%2Fsec-brightgreen.svg?style=flat)
15
+
16
+ [→ Full Benchmarks](../../docs/assemblerjs/performance/benchmarks.md)
17
+
7
18
  ---
8
19
 
9
- `assembler.js` is inspired by both DIOD and Nestjs.
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
- `assembler.js` name is a tribute to Gilles Deleuze and Felix Guattari concept of [_Agencement_](<https://fr.wikipedia.org/wiki/Agencement_(philosophie)>) (in french) that can be translated into [Assemblage](<https://en.wikipedia.org/wiki/Assemblage_(philosophy)>).
34
+ Inspired by [DIOD](https://github.com/artberri/diod) and [NestJS](https://nestjs.com/).
12
35
 
13
- ## Install
36
+ ## Installation
37
+
38
+ Install `assemblerjs` and its peer dependency `reflect-metadata` using npm or yarn:
14
39
 
15
40
  ```sh
16
- yarn add assemblerjs
41
+ npm install assemblerjs reflect-metadata
17
42
  ```
18
43
 
19
44
  ```sh
20
- npm install assemblerjs
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
- ## Usage
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
- The main block of `assembler.js` is the **Assemblage**. It is created by decorating classes with the `@Assemblage` decorator. To keep everything type-safe, classes may implement `AbstractAssemblage` abstract class or define their own abstract class that extends it.
26
- These abstract classes are used as identifiers to inject dependencies.
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
- ## Order of execution
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
- Dependencies are registered and built recursively from the entry assemblage resolved by `Assembler.build`.
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
- ##### `onRegister`
137
+ #### Performance
138
+ - [Benchmarks](../../docs/assemblerjs/performance/benchmarks.md) - Performance metrics & best practices
33
139
 
34
- Static hook called when registering the assemblage.
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
- ##### `constructor`
142
+ - **Node.js:** ≥ 18.12.0
143
+ - **TypeScript:** ≥ 5.0 (with decorator support)
144
+ - **reflect-metadata:** Required for dependency injection
38
145
 
39
- Build the instance and requires an instance of each dependency passed to the constructor.
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
- ##### `onInit`
148
+ ### Architecture
43
149
 
44
- Called on every dependency when the dependency tree is ready.
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
- ##### `onDispose`
152
+ - **`@assemblerjs/core`** - Internal utilities package
49
153
 
50
- Called when disposing the assembler via the `dispose` method injected by the `@Dispose` decorator.
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
- ## Events
156
+ ```bash
157
+ # Install dependencies from workspace root
158
+ yarn install
54
159
 
55
- `assembler.js` provides an `EventManager` that can be subclassed by any assemblage.
160
+ # Build the package
161
+ npx nx build assemblerjs
56
162
 
57
- Because all events **are forwarded by `AssemblerContext`** the `EventManager` is quite strict on which events can be broadcasted and they must be registered explicitly using the `events` property of the `AssemblageDefinition`. To avoid collision between events channels, user is strongly encouraged to create _strong_ channels names, e.g.: `com.domain.app.assemblage-name:init`.
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
- const prefix = 'com.domain.app.emitter-assemblage';
172
+ // Large bundle (imports everything)
173
+ import * as Assembler from 'assemblerjs';
61
174
 
62
- export enum EmitterAssemblageEvents {
63
- Init = `${prefix}:init`,
64
- }
175
+ // Optimal (only imports required modules)
176
+ import { Assemblage, Assembler, AbstractAssemblage } from 'assemblerjs';
177
+ ```
65
178
 
66
- @Assemblage({
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
- public async onInit(): Promise<void> {
78
- this.emit(EmitterAssemblageEvents.Init, true);
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
- @Assemblage()
83
- export class SubcriberAssemblage implements AbstractAssemblage {
84
- constructor(@Context() private context: AssemblerContext) {
85
- context.on(EmitterAssemblageEvents.Init, (value: boolean) => {
86
- console.log(value); // true.
87
- });
88
-
89
- context.on('*', (value: boolean) => {
90
- console.log(value); // true.
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
- Assembler.build(SubcriberAssemblage);
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**