assemblerjs 0.9.7 → 1.0.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.
Files changed (81) hide show
  1. package/README.md +193 -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 +46 -0
  34. package/dist/index23.mjs +41 -0
  35. package/dist/index24.js +20 -0
  36. package/dist/index24.mjs +14 -0
  37. package/dist/index25.js +19 -0
  38. package/dist/index25.mjs +13 -0
  39. package/dist/index26.js +100 -0
  40. package/dist/index26.mjs +94 -0
  41. package/dist/index27.js +69 -0
  42. package/dist/index27.mjs +65 -0
  43. package/dist/index28.js +37 -0
  44. package/dist/index28.mjs +33 -0
  45. package/dist/index29.js +71 -0
  46. package/dist/index29.mjs +67 -0
  47. package/dist/index3.js +20 -0
  48. package/dist/index3.mjs +14 -0
  49. package/dist/index30.js +37 -0
  50. package/dist/index30.mjs +33 -0
  51. package/dist/index31.js +37 -0
  52. package/dist/index31.mjs +33 -0
  53. package/dist/index32.js +28 -0
  54. package/dist/index32.mjs +24 -0
  55. package/dist/index33.js +54 -0
  56. package/dist/index33.mjs +50 -0
  57. package/dist/index34.js +14 -0
  58. package/dist/index34.mjs +10 -0
  59. package/dist/index35.js +34 -0
  60. package/dist/index35.mjs +29 -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,233 @@
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](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/performance/benchmarks.md)
17
+
7
18
  ---
8
19
 
9
- `assembler.js` is inspired by both DIOD and Nestjs.
20
+ ## Features
10
21
 
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)>).
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)
12
33
 
13
- ## Install
34
+ Inspired by [DIOD](https://github.com/artberri/diod) and [NestJS](https://nestjs.com/).
35
+
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
21
46
  ```
22
47
 
23
- ## Usage
48
+ **Important:** You must import `reflect-metadata` at the entry point of your application:
24
49
 
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.
50
+ ```typescript
51
+ import 'reflect-metadata';
52
+ ```
27
53
 
28
- ## Order of execution
54
+ > **Works everywhere**: This installation works for **Node.js, browsers (with Vite/Webpack/Rollup), React, Vue, Angular, and any JavaScript environment**.
29
55
 
30
- Dependencies are registered and built recursively from the entry assemblage resolved by `Assembler.build`.
56
+ ### Alternative: CDN (for quick prototyping)
31
57
 
32
- ##### `onRegister`
58
+ If you want to try assemblerjs without a build step:
33
59
 
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.
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
+ ```
36
67
 
37
- ##### `constructor`
68
+ ## Quick Start
38
69
 
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.
70
+ ```typescript
71
+ import 'reflect-metadata';
72
+ import { Assemblage, Assembler, AbstractAssemblage } from 'assemblerjs';
41
73
 
42
- ##### `onInit`
74
+ // Define a service
75
+ @Assemblage()
76
+ class Logger implements AbstractAssemblage {
77
+ log(message: string) {
78
+ console.log(message);
79
+ }
80
+ }
43
81
 
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.
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) {}
47
88
 
48
- ##### `onDispose`
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!"
97
+ ```
98
+
99
+ ## 📚 Documentation
100
+
101
+ Comprehensive documentation is available at:
102
+
103
+ **[→ Full Documentation](https://github.com/benoitlahoz/assemblerjs/tree/main/docs/assemblerjs)**
104
+
105
+ ### Quick Links
106
+
107
+ #### Getting Started
108
+ - [Installation](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/getting-started/installation.md)
109
+ - [Quick Start Guide](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/getting-started/quick-start.md)
110
+ - [TypeScript Setup](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/getting-started/typescript-setup.md)
49
111
 
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.
112
+ #### Core Concepts
113
+ - [Assemblage](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/core-concepts/assemblage.md) - Building blocks
114
+ - [Dependency Injection](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/core-concepts/dependency-injection.md) - DI patterns
115
+ - [Abstraction Pattern](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/core-concepts/abstraction-pattern.md) - Interface-based design
116
+ - [Lifecycle Hooks](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/core-concepts/lifecycle-hooks.md) - Initialization & cleanup
52
117
 
53
- ## Events
118
+ #### Decorators
119
+ - [Parameter Decorators](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/decorators/parameter-decorators.md) - Built-in decorators
120
+ - [Custom Parameter Decorators](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/decorators/custom-parameter.md) - Create your own
121
+ - [Custom Class Decorators](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/decorators/custom-class.md) - Type-safe class decorators
54
122
 
55
- `assembler.js` provides an `EventManager` that can be subclassed by any assemblage.
123
+ #### Features
124
+ - [Event System](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/features/events.md) - Event-driven architecture
125
+ - [Tags](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/features/tags.md) - Group assemblages
126
+ - [Singleton vs Transient](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/features/singleton-transient.md) - Instance lifecycle
56
127
 
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`.
128
+ #### API Reference
129
+ - [Assembler API](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/api/assembler.md) - Container methods
130
+ - [AssemblerContext API](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/api/context.md) - Context interface
131
+ - [Types](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/api/types.md) - TypeScript types
132
+
133
+ #### Guides
134
+ - [Advanced Examples](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/guides/advanced-examples.md) - Real-world patterns
135
+ - [Tree-Shaking](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/guides/tree-shaking.md) - Bundle optimization
136
+
137
+ #### Performance
138
+ - [Benchmarks](https://github.com/benoitlahoz/assemblerjs/blob/main/docs/assemblerjs/performance/benchmarks.md) - Performance metrics & best practices
139
+
140
+ ## Tree-Shaking & Bundle Optimization
141
+
142
+ `assembler.js` is optimized for tree-shaking with modular exports. Import only what you need:
58
143
 
59
144
  ```typescript
60
- const prefix = 'com.domain.app.emitter-assemblage';
145
+ // Large bundle (imports everything)
146
+ import * as Assembler from 'assemblerjs';
61
147
 
62
- export enum EmitterAssemblageEvents {
63
- Init = `${prefix}:init`,
64
- }
148
+ // Optimal (only imports required modules)
149
+ import { Assemblage, Assembler, AbstractAssemblage } from 'assemblerjs';
150
+ ```
65
151
 
66
- @Assemblage({
67
- events: Object.values(EmitterAssemblageEvents),
68
- })
69
- export class EmitterAssemblage
70
- extends EventManager
71
- implements AbstractEventAssemblage
72
- {
73
- constructor() {
74
- super();
75
- }
152
+ ### Bundle Size Examples
76
153
 
77
- public async onInit(): Promise<void> {
78
- this.emit(EmitterAssemblageEvents.Init, true);
79
- }
80
- }
154
+ - **Minimal usage** (~5-6 KB): Core DI features only
155
+ - **Medium usage** (~15-18 KB): DI + Events + Parameter decorators
156
+ - **Full library** (~35 KB): All features
81
157
 
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
- });
158
+ The package uses:
159
+ - `"sideEffects": false` - Safe to remove unused modules
160
+ - Modular exports - Each feature in separate files
161
+ - ESM format - Native tree-shaking support
162
+
163
+ ## TypeScript Configuration
164
+
165
+ Enable decorators and reflection in your `tsconfig.json`:
166
+
167
+ ```json
168
+ {
169
+ "compilerOptions": {
170
+ "experimentalDecorators": true,
171
+ "emitDecoratorMetadata": true,
172
+ "target": "ES2020",
173
+ "module": "ESNext",
174
+ "lib": ["ES2020"]
92
175
  }
93
176
  }
177
+ ```
178
+
179
+ ## Requirements
180
+
181
+ - **Node.js:** ≥ 18.12.0
182
+ - **TypeScript:** ≥ 5.0 (with decorator support)
183
+ - **reflect-metadata:** Required for dependency injection
184
+
185
+ ## For Contributors
186
+
187
+ ### Architecture
94
188
 
95
- Assembler.build(SubcriberAssemblage);
189
+ This package is part of the `assemblerjs` monorepo and depends on:
190
+
191
+ - **`@assemblerjs/core`** - Internal utilities package providing:
192
+ - Type utilities and helpers
193
+ - Collection management utilities
194
+ - Error handling utilities
195
+ - Conditional utilities
196
+ - Array manipulation helpers
197
+
198
+ This dependency is automatically installed with `assemblerjs` and transparent to end users.
199
+
200
+ ### Development
201
+
202
+ ```bash
203
+ # Install dependencies from workspace root
204
+ yarn install
205
+
206
+ # Build the package
207
+ npx nx build assemblerjs
208
+
209
+ # Run tests
210
+ npx nx test assemblerjs
96
211
  ```
212
+
213
+ ### Monorepo Structure
214
+
215
+ ```
216
+ assemblerjs/
217
+ ├── packages/
218
+ │ ├── assemblerjs/ # Main DI library (this package)
219
+ │ ├── core/ # Internal utilities
220
+ │ ├── dto/ # DTO utilities
221
+ │ ├── electron/ # Electron integration
222
+ │ ├── fetch/ # Fetch utilities
223
+ │ ├── mongo/ # MongoDB integration
224
+ │ └── rest/ # REST utilities
225
+ ```
226
+
227
+ ## License
228
+
229
+ MIT
230
+
231
+ ---
232
+
233
+ **Made with ❤️ in Marseille**